更新时间:2023-12-02 22:52:40
您正在输入字符串列表模型,这是意料之外的。您可以使用 keras.preprocessing.text
模块将文本转换为整数序列。更具体地说,您可以准备数据,例如:
You are feeding a list of strings to a model which is something it does not expect. You can use keras.preprocessing.text
module to convert the text to an integer sequence. More specifically you can prepare data like:
from keras.preprocessing.text import Tokenizer
from keras.preprocessing.sequence import pad_sequences
tk = Tokenizer()
tk.fit_on_texts(texts)
index_list = tk.texts_to_sequences(texts)
x_train = pad_sequences(index_list, maxlen=maxlen)
现在 x_train
(a n_samples *类型为
ndarray是模型的合法输入。 np.int
的maxlen
Now x_train
(a n_samples * maxlen
ndarray of type np.int
) is a legitimate input for the model.