【问题标题】:How to make text-summarizing model predict for a single input?如何使文本摘要模型预测单个输入?
【发布时间】: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]),但我仍然得到与上面相同的错误。

标签: python keras nlp


【解决方案1】:

解决了!我实际上是在传递一个非类型参数,因为我用来分配参数的函数实际上什么也没返回!

【讨论】:

    猜你喜欢
    • 2021-07-24
    • 1970-01-01
    • 1970-01-01
    • 2020-08-02
    • 2023-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-10
    相关资源
    最近更新 更多