при использовании keras.preprocessing.text.text_to_word_sequence () я получаю сообщение об ошибке, указывающее на отсутствие атрибута перевода - PullRequest
0 голосов
/ 19 апреля 2020

Я пытаюсь передать список с именем Articles , содержащий список предложений, text_to_word_sequence () из текста предварительной обработки keras. Идея состоит в том, чтобы создать массив чисел или векторов, сгенерированных из предложений.

import nltk
nltk.download('punkt')
import keras
import keras.preprocessing
import numpy as np

#int_to_char.items() # Dictionary: dict_items([(1, 'the'), (2, 'to'),.........
for index, word in int_to_char.items():
  for word in articles[index]:
    kk=keras.preprocessing.text.text_to_word_sequence(articles, lower=False, split=', '))


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-62-32ba4487c1b6> in <module>()
      1 for index, word in int_to_char.items():
      2   for word in articles[index]:
----> 3     kk=keras.preprocessing.text.text_to_word_sequence(articles, lower=False)

/usr/local/lib/python3.6/dist-packages/keras_preprocessing/text.py in text_to_word_sequence(text, filters, lower, split)
     56         translate_dict = dict((c, split) for c in filters)
     57         translate_map = maketrans(translate_dict)
---> 58         text = text.translate(translate_map)
     59 
     60     seq = text.split(split)

AttributeError: 'list' object has no attribute 'translate'
...