RNN模型仅预测一类? [英] RNN model predicting only one class?

查看:140
本文介绍了RNN模型仅预测一类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用GloVe嵌入基于本文. 我有一个带标签的数据:一列上的文本(tweets),另一列上的标签(讨厌,令人反感或两者都不带). 但是,该模型似乎只能预测结果中的一类.

I am trying to use GloVe embeddings to train a rnn model based on this article. I have a labeled data: text(tweets) on one column, labels on another (hate, offensive or neither). However the model seems to predict only one class in the result.

这是LSTM模型:

model = Sequential()
hidden_layer = 3
gru_node = 32

# model embedding matrix here....

for i in range(0,hidden_layer):
    model.add(GRU(gru_node,return_sequences=True, recurrent_dropout=0.2))
    model.add(Dropout(dropout))
model.add(GRU(gru_node, recurrent_dropout=0.2))
model.add(Dropout(dropout))
model.add(Dense(64, activation='softmax'))
model.add(Dense(nclasses, activation='softmax'))
start=time.time()
model.compile(loss='sparse_categorical_crossentropy',optimizer='adam',metrics=['accuracy'])

拟合模型:

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 1)
X_train_Glove,X_test_Glove, word_index, embeddings_index = loadData_Tokenizer(X_train, X_test)

model_RNN = Build_Model_RNN_Text(word_index,embeddings_index, 20)    
model_RNN.fit(X_train_Glove,y_train,
                            validation_data=(X_test_Glove, y_test),
                            epochs=4,
                            batch_size=128,
                            verbose=2)
y_preds = model_RNN.predict_classes(X_test_Glove)
print(metrics.classification_report(y_test, y_preds))

结果:

  1. 分类报告

  1. 混乱矩阵

我在这里想念东西吗?

更新: 这就是分布的样子

Update: this is what the distribution looks like

和模型摘要(或多或少)

and the model summary, more or less

推荐答案

您的数据分布情况如何?第一个建议是对训练/测试拆分进行分层(这是链接以获取文档).

How the distribution of your data looks like? The first suggestion is to stratify train/test split (here is the link for the documentation).

第二个问题是,与模型的复杂性相比,您拥有多少数据?也许您的模型是如此复杂,以至于过拟合.您可以使用命令 model.summary()来查看可训练参数的数量

The second question is how much data do you have in comparison with the complexity of the model? Maybe, your model is so complex, that just do overfitting. You can use the command model.summary() to see the number of trainable parameters.

这篇关于RNN模型仅预测一类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆