Okay, so I recreated the official documentation example,
from sklearn.preprocessing import OrdinalEncoder
enc = OrdinalEncoder()
X = [['Male', 1], ['Female', 3], ['Female', 2]]
enc.fit(X)
Now, if you want to see the encoding, you simply call the categories_ attribute, so in this case:
print(enc.categories_)
#Output: [array(['Female', 'Male'], dtype=object), array([1, 2, 3], dtype=object)]
Now, this only returns the encoded features and not their encoding. However, their index itself is the encoding. For example, in this case, Female is encode to 0, Male is encoded to 1, then moving forward to the next set of features, 1 is encoded as 0, 2 is encoded as 1 and so on.
So, if I want to get the encoding of Female and Male:
encoding = enc.categories_
encoding_sex = dict(zip((encoding[0]), range(len(encoding[0]))))
print(encoding_sex)
# Output: {'Female': 0, 'Male': 1}
Now if you want to generalize the above method for all features and make it fast as well, do the following :
encoding = enc.categories_
encoding_feature = lambda x: dict(zip(x, range(len(x))))
encoding_full = [encoding_feature(feature_elem) for feature_elem in encoding]
print(encoding_full)
# Output: [{'Female': 0, 'Male': 1}, {1: 0, 2: 1, 3: 2}]