我正在使用这篇优秀的文章学习机器学习。
链接:https://stackabuse.com/python-for-nlp-multi-label-text-classification-with-keras/ 在拆分数据后,作者对X和y数据进行了标记化处理。
如果在使用train_test_split类之前对其进行标记化,就可以省下几行代码。
链接:https://stackabuse.com/python-for-nlp-multi-label-text-classification-with-keras/ 在拆分数据后,作者对X和y数据进行了标记化处理。
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.20, random_state=42
)
tokenizer = Tokenizer(num_words=5000)
tokenizer.fit_on_texts(X_train)
X_train = tokenizer.texts_to_sequences(X_train)
X_test = tokenizer.texts_to_sequences(X_test)
vocab_size = len(tokenizer.word_index) + 1
maxlen = 200
X_train = pad_sequences(X_train, padding="post", maxlen=maxlen)
X_test = pad_sequences(X_test, padding="post", maxlen=maxlen)
如果在使用train_test_split类之前对其进行标记化,就可以省下几行代码。
tokenizer = Tokenizer(num_words=5000)
tokenizer.fit_on_texts(X)
X_t = tokenizer.texts_to_sequences(X)
vocab_size = len(tokenizer.word_index) + 1
maxlen = 200
X = pad_sequences(X_t, padding="post", maxlen=maxlen)
我只是想确认我的方法是正确的,而且我不希望在脚本后面遇到任何意外情况。