由于我無法在SO中發布中文文本,我將演示如何使用英語句子,但同樣適用于中文: import tensorflow as tftext = ['This is a chinese sentence', 'This is another chinese sentence']tokenizer = tf.keras.preprocessing.text.Tokenizer(num_words=50, char_level = False)tokenizer.fit_on_texts(text)print(tokenizer.word_index) {'this': 1, 'is': 2, 'chinese': 3, 'sentence': 4, 'a': 5, 'another': 6} 確保你有一個中文space-separated句子列表,并且應該正確。使用列表將導致意外行為。