Sim*_*lex 7 text-processing nlp tokenize n-gram keras
可以在Keras中使用n-gram吗?
例如,句子在X_train数据帧中包含"句子"列.
我以下列方式使用Keras的tokenizer:
tokenizer = Tokenizer(lower=True, split=' ')
tokenizer.fit_on_texts(X_train.sentences)
X_train_tokenized = tokenizer.texts_to_sequences(X_train.sentences)
Run Code Online (Sandbox Code Playgroud)
然后我填写句子:
X_train_sequence = sequence.pad_sequences(X_train_tokenized)
Run Code Online (Sandbox Code Playgroud)
我还使用一个简单的LSTM网络:
model = Sequential()
model.add(Embedding(MAX_FEATURES, 128))
model.add(LSTM(32, dropout=0.2, recurrent_dropout=0.2,
activation='tanh', return_sequences=True))
model.add(LSTM(64, dropout=0.2, recurrent_dropout=0.2, activation='tanh'))
model.add(Dense(number_classes, activation='sigmoid'))
model.compile(loss='categorical_crossentropy', optimizer='rmsprop',
metrics=['accuracy'])
Run Code Online (Sandbox Code Playgroud)
在这种情况下,tokenizer执行.在Keras docs:https://keras.io/preprocessing/text/ 我看到字符处理是可能的,但这不适合我的情况.
我的主要问题:我可以将n-gram用于NLP任务(不仅仅是情感分析,而是任何NLP任务)
澄清一下:我不仅要考虑单词而且要考虑单词组合.我想尝试看看它是否有助于模拟我的任务.
| 归档时间: |
|
| 查看次数: |
2816 次 |
| 最近记录: |