首页 > 解决方案 > Keras 标记化(适合文本)

问题描述

当我运行这个脚本时——>

tokenizer.fit_on_texts(df['text'].values)
sequences = tokenizer.texts_to_sequences(df['text'].values)
word_index = tokenizer.word_index
print('Found %s unique tokens.' % len(word_index))

我收到此错误

AttributeError                            Traceback (most recent call 
last)
<ipython-input-4-7c08b89b116a> in <module>()
  ----> 1 tokenizer.fit_on_texts(df['text'].values)
        2 sequences = tokenizer.texts_to_sequences(df['text'].values)
        3 word_index = tokenizer.word_index
        4 print('Found %s unique tokens.' % len(word_index))

 /opt/conda/lib/python3.6/site-packages/keras_preprocessing/text.py in 
 fit_on_texts(self, texts)
     220                                             self.filters,
     221                                             self.lower,
 --> 222                                             self.split)
     223             for w in seq:
     224                 if w in self.word_counts:

 /opt/conda/lib/python3.6/site-packages/keras_preprocessing/text.py in 
 text_to_word_sequence(text, filters, lower, split)
      41     """
      42     if lower:
 ---> 43         text = text.lower()
      44 
      45     if sys.version_info < (3,):

 AttributeError: 'float' object has no attribute 'lower'

当我减小它的大小时,我的 CSV 文件大小为 6970963,keras Tokenizer 是否有大小限制,或者我做错了什么

标签: machine-learningkerastokenizekeras-layerstringtokenizer

解决方案


我猜文件大小不是问题,尝试使用 try 块并查看您传递的数据。使用类似这样的东西而不是行

#instead of this
tokenizer.fit_on_texts(df['text'].values)

#use this to look at the data when it is causing that error.
try:
   tokenizer.fit_on_texts(df['text'].values)
except Exception as e:
   print("exceiption is", e)
   print("data passedin ", df['text'].values)

然后,您可以相应地修复您遇到的错误。


推荐阅读