即使在我打印句子时,它也会打印以逗号分隔的字符串数 这是我的代码:-
from tensorflow.keras.preprocessing.text import Tokenizer
from tensorflow.keras.preprocessing.sequence import pad_sequences
import json
sentence = []
urls = []
labels = []
data = [json.loads(line) for line in open('Sarcasm_Headlines_Dataset.json', 'r')]
for item in data:
sentence.append(item["headline"])
urls.append(item['article_link'])
labels.append(item['is_sarcastic'])
print(sentence)
tokenizer = Tokenizer(oov_token="<00V>")
tokenizer = tokenizer.fit_on_texts(sentence)
word_index =tokenizer.word_index
答案 0 :(得分:0)
fit_on_texts
是就地操作,它将返回None
代替:
tokenizer = tokenizer.fit_on_texts(sentence)
使用:
tokenizer = Tokenizer(oov_token="<00V>")
tokenizer.fit_on_texts(sentence)
word_index =tokenizer.word_index