【问题标题】:Tokenizer and print it标记器并打印它
【发布时间】:2020-02-06 23:07:59
【问题描述】:

在标记器之后,我的字符串列表试图获取单词的值及其编号的关联。 f.e: = 3 我该怎么做?? (Python) 这是代码

sentences_train, sentences_test, y_train, y_test = train_test_split(X,y, test_size=0.2, random_state=42)


from keras.preprocessing.text import Tokenizer
tokenizer = Tokenizer(num_words=5000)
tokenizer.fit_on_texts(sentences_train)

X_train = tokenizer.texts_to_sequences(sentences_train)
X_test = tokenizer.texts_to_sequences(sentences_test)

vocab_size = len(tokenizer.word_index) + 1

【问题讨论】:

  • 欢迎来到 StackOverflow。见minimal, reproducible example。在您发布 MRE 代码并准确说明问题之前,我们无法有效地帮助您。我们应该能够将您发布的代码粘贴到文本文件中并重现您指定的问题。

标签: python printing tokenize


【解决方案1】:

试试 tokenizer.texts_to_sequences(['the'])

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-25
    • 2012-11-23
    • 2011-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-17
    • 2021-11-14
    相关资源
    最近更新 更多