【问题标题】:One Hot Encoding giving same number for different words in keras一种热编码为 keras 中的不同单词提供相同的数字
【发布时间】:2016-04-13 07:11:42
【问题描述】:
为什么我用不同的词得到相同的结果?
import keras
keras.__version__
'1.0.0'
import theano
theano.__version__
'0.8.1'
from keras.preprocessing.text import one_hot
one_hot('START', 43)
[26]
one_hot('children', 43)
[26]
【问题讨论】:
标签:
python-2.7
theano
keras
one-hot-encoding
【解决方案2】:
从Keras source code 中,您可以看到单词以输出维度(在您的情况下为 43)为模进行散列:
def one_hot(text, n,
filters='!"#$%&()*+,-./:;<=>?@[\\]^_`{|}~\t\n',
lower=True,
split=' '):
seq = text_to_word_sequence(text,
filters=filters,
lower=lower,
split=split)
return [(abs(hash(w)) % (n - 1) + 1) for w in seq]
所以很有可能会发生碰撞。