我正在使用 Keras 执行多标签分类任务(Kaggle 上的有毒评论文本分类)。
我正在使用Tokenizer
该类进行一些预处理,如下所示:
tokenizer = Tokenizer(num_words=10000)
tokenizer.fit_on_texts(train_sentences)
train_sentences_tokenized = tokenizer.texts_to_sequences(train_sentences)
max_len = 250
X_train = pad_sequences(train_sentences_tokenized, maxlen=max_len)
Run Code Online (Sandbox Code Playgroud)
这是一个好的开始,但我还没有去除停用词、词干词等。对于停用词去除,我在上述之前做了以下工作:
def filter_stop_words(train_sentences, stop_words):
for i, sentence in enumerate(train_sentences):
new_sent = [word for word in sentence.split() if word not in stop_words]
train_sentences[i] = ' '.join(new_sent)
return train_sentences
stop_words = set(stopwords.words("english"))
train_sentences = filter_stop_words(train_sentences, stop_words)
Run Code Online (Sandbox Code Playgroud)
在 Keras 中不应该有更简单的方法来做到这一点吗?希望也有词干能力,但文档没有表明有:
https://keras.io/preprocessing/text/
任何有关停用词删除和词干提取最佳实践的帮助都会很棒!
谢谢!
归档时间: |
|
查看次数: |
10043 次 |
最近记录: |