我正在使用tensorflow dataset](https://www.tensorflow.org/datasets/catalog/imdb_reviews)
[tensorflow imdb\_review tensorflow,并且我想使用以下命令对其进行预处理标记器和垫_序列
当我使用标记器实例,并使用以下代码:
tokenizer=Tokenizer(num_words=100)
tokenizer.fit_on_texts(df['text'])
word_index = tokenizer.word_index
sequences=tokenizer.texts_to_sequences(df['text'])
print(word_index)
print(sequences)
我得到了错误TypeError:需要类似字节的对象,而不是“dict”
我尝试过的
将dataset存储为dataframe,然后迭代text列,将其存储在列表中,然后对其进行标记。
df = tfds.as_dataframe(ds.take(4), info)
# list to store corpus
corpus = []
for sentences in df['text'].iteritems():
corpus.append(sentences)
tokenizer=Tokenizer(num_words=100)
tokenizer.fit_on_texts(corpus)
word_index=tokenizer.word_index
print(word_index)
但是我得到了一个错误AttributeError:“tuple”对象没有“”lower“”属性
如何使用'text‘列并对其进行预处理以将其提供给我的神经网络?
转载请注明出处:http://www.hnsdbxf.com/article/20230526/1806085.html