簡體   English   中英

使用 Bi-LSTM 和手套進行多類分類

[英]Multi class classification using Bi-LSTM and glove

我正在使用 BI LSTM 和手套嵌入進行多類分類,當我訓練我的模型時,在預測 (model.predict) 上我得到的結果不正確,結果不在 0 和 1 之間,有人可以幫我嗎?

我還使用了一種熱編碼。 在此處輸入圖片說明


3916/3916 [==============================] - 17s 4ms/step
[[9.9723792e-01 1.6954101e-03 1.0665554e-03]
 [1.6794224e-01 8.6485274e-02 7.4557245e-01]
 [9.4370516e-03 1.0848863e-03 9.8947805e-01]
 ...
 [1.3264662e-02 9.7078091e-01 1.5954463e-02]
 [1.2019513e-02 9.8711687e-01 8.6356810e-04]
 [8.1863362e-01 1.5828104e-01 2.3085352e-02]]

from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import LSTM,Dense, Dropout,Bidirectional
from tensorflow.keras.layers import SpatialDropout1D
from tensorflow.keras.layers import Embedding
from tensorflow.keras.preprocessing.text import Tokenizer


embedding_vector_length = 100

model_2 = Sequential()

model_2.add(Embedding(len(tokenizer.word_index) + 1, embedding_vector_length,     
                                         input_length=409,name="Bi-LSTM") )

model_2.add(SpatialDropout1D(0.3))
model_2.add(Bidirectional(LSTM(64, return_sequences=False, recurrent_dropout=0.4)))
model_2.add(Dropout(0.5))
model_2.add(Dense(3,activation='softmax'))
model_2.compile(loss='categorical_crossentropy',optimizer='adam', 
                           metrics=['accuracy'])
print(model_2.summary())


model_2.layers[0].set_weights([embedding_matrix])
model_2.layers[0].trainable = False
print(model_2.summary())




from keras.callbacks import EarlyStopping
es = EarlyStopping(monitor='val_loss', mode='min', verbose=1, patience=3)
history_2=model_2.fit(x_train, y_train,
 batch_size=400,
 epochs=30,
 validation_data=(x_val, y_val),
 callbacks=[es])
#We save this model so that we can use in own web app



如果打印的矩陣是您的model.predict()結果 - 它們介於 0 和 1 之間(您需要考慮指數部分)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM