【问题标题】: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


    【解决方案1】:

    在一个热编码中不保证唯一性

    one hot keras documentation

    【讨论】:

      【解决方案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]
      

      所以很有可能会发生碰撞。

      【讨论】:

        猜你喜欢
        • 2018-07-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-05-21
        • 2020-09-12
        • 2020-01-16
        • 2020-08-28
        相关资源
        最近更新 更多