【发布时间】:2021-07-02 00:41:27
【问题描述】:
因此,我的基于 LSTM 的模型接受了评论并用几句话对其进行了总结。这些是我在清理文本后在单个输入上采取的步骤:
tokenizer = Tokenizer()
sequence = tokenizer.texts_to_sequences([input_string])
sequence = pad_sequences(sequences, maxlen = 35)
由于texts_to_sequences 接收一个字符串列表,我在阅读this answer 到类似问题(并通过this blogpost)后做了texts_to_sequences([input_string])。但是,我仍然收到'NoneType' object has no attribute 'lower' 的错误。查看堆栈跟踪,似乎正在调用 keras 库中名为 text_to_word_sequence 的函数,并且它正在接收一个参数 text,这似乎是一个 NoneType 对象。我该如何解决这个问题?
编辑:如果有帮助,这是完整的堆栈跟踪:
Traceback (most recent call last):
File "input_to_summary.py", line 55, in <module>
main(sys.argv[1])
File "input_to_summary.py", line 53, in main
tokenize_and_predict(processed_text, summarizer)
File "input_to_summary.py", line 45, in tokenize_and_predict
sequence = tokenizer.texts_to_sequences(np.array([input_string]))
File "/projects/32a5c584-399f-4da7-9dc2-6392d0e56d8f/miniconda3/lib/python3.8/site-packages/keras_preprocessing/text.py", line 279, in texts_to_sequences
return list(self.texts_to_sequences_generator(texts))
File "/projects/32a5c584-399f-4da7-9dc2-6392d0e56d8f/miniconda3/lib/python3.8/site-packages/keras_preprocessing/text.py", line 307, in texts_to_sequences_generator
seq = text_to_word_sequence(text,
File "/projects/32a5c584-399f-4da7-9dc2-6392d0e56d8f/miniconda3/lib/python3.8/site-packages/keras_preprocessing/text.py", line 43, in text_to_word_sequence
text = text.lower()
AttributeError: 'NoneType' object has no attribute 'lower'
【问题讨论】:
-
我认为您首先需要对一些文本数据调用
tokenizer.fit(),然后再调用tokenizer.texts_to_sequences()。 -
我做了
tokenizer.fit_on_texts(input_string),但当它不起作用时(因为fit_on_texts方法接受了一个列表,我做了tokenizer.fit_on_texts([input_string]),但我仍然得到与上面相同的错误。