machine-learning - 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 是否有大小限制,或者我做错了什么
解决方案
我猜文件大小不是问题,尝试使用 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)
然后,您可以相应地修复您遇到的错误。
推荐阅读
- php - 通过对公共值进行分组,将具有关联数组作为元素的索引数组转换为多维数组
- php - 在 Laravel 7 中创建电子邮件模板时如何更改传输配置?
- python - 如何将所有请求路由到单个 azure 函数并维护路由
- php - Laravel 6,mysqldump 问题
- javascript - html2canvas v1.0.0 rc 5 不适用于 ios
- php - 按php中的最大和最小变量对数据进行排序?
- jquery - 如何将值从 jquery 传递到 Spring Controller 并返回 List?
- java - 无法在 Mac 上安装 Ecpise:Java 运行时环境 (JRE) 或 Java 开发工具包 (JDK) 必须可用才能运行 Eclipse
- regex - 我将如何复制一行并更改复制行内的一段文本?
- python-3.x - 如何使用定义的函数正确创建嵌套的 for 循环以生成值数组