2017-09-12 1 views
2

Keras에서 단어의 n-gram을 사용하는 것이 사실입니까?Keras Tokenizer 용 n-gram 사용 단어

예를 들어, 문장 목록에는 X_train 데이터 프레임에 "문장"열이 포함됩니다. 나는 다음 방식으로 Keras에서 토크 나이 사용

tokenizer = Tokenizer(lower=True, split=' ') 
tokenizer.fit_on_texts(X_train.sentences) 
X_train_tokenized = tokenizer.texts_to_sequences(X_train.sentences) 

그리고 나중에 내가 패딩 사용

X_train_sequence = sequence.pad_sequences(X_train_tokenized) 

이 또한 내가 간단한 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']) 

을, 토크 나이를 실행. Keras 문서에서 : https://keras.io/preprocessing/text/ 문자 처리 만 볼 수 있지만 본인의 경우에는 nt apprepriate입니다.

내 주요 질문 : NLP 작업 (필요한 Sentiment Analysis, 모든 추상 NLP 작업)에 n 그램을 사용할 수 있습니까?

설명을 위해 : 나는 단어뿐 아니라 단어의 조합도 고려하고 싶습니다. 제 작업을 위해 노력하고 싶습니다.

답변

1

불행히도 Keras Tokenizer()는 n 그램을 지원하지 않습니다. 자신 만의 문서에 해결 방법을 만들고 토큰 화 한 다음 신경망에 공급해야합니다.

관련 문제