Issue
from sklearn.preprocessing import LabelEncoder
l_labels = ['[PAD]'] + ['NN', 'ADJ', 'PRON']
le = LabelEncoder()
le.fit(l_labels)
le.trasform('[PAD]')
>>>> 3
I want the encodind of '[PAD]' to be 0. Is it possible to bind a label to an encoding with LabelEncoder ?
Solution
the scikit learn LabelEncoder is sorting the list of element before the transformation one way to encode 'PAD' to be 0 is the change the name of PAD to some thing that will be sorted as first.
l_labels = ['0' + 'PAD'] + ['NN', 'ADJ', 'PRON']
le = LabelEncoder()
le.fit(l_labels)
le.transform(['0'+'PAD'])
>> [0]
Answered By - Ghassen Sultana
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.