简体   繁体   English

val_accuracy 不增加

[英]val_accuracy does not increase

Currently I'm trying to train a Keras Sequential Network with pooled output from BERT.目前,我正在尝试使用来自 BERT 的池化 output 训练 Keras 顺序网络。 The fine tuned BertForSequence Classification yields good results, but using the pooled_output in a Neural Network does not work as intented.微调的 BertForSequence 分类产生了很好的结果,但是在神经网络中使用 pooled_output 并没有达到预期的效果。 As Input data I got 10.000 Values, each consisting of the 768 floats that my BERT-Model provides.作为输入数据,我得到了 10.000 个值,每个值由我的 BERT 模型提供的 768 个浮点数组成。 I'm trying to do a simple binary classification, so I also got the labels with 1 and 0's.我正在尝试做一个简单的二进制分类,所以我也得到了带有 1 和 0 的标签。

在此处输入图像描述

As you can see my data has a good number of examples for both classes.如您所见,我的数据为这两个类提供了大量示例。 After shuffling them, I do a normal train test split and create/fit my model with:洗牌后,我进行正常的火车测试拆分并创建/安装我的 model :

model = Sequential()
model.add(Dense(1536, input_shape=(768,), activation='relu'))
model.add(Dense(1536, activation='relu'))
model.add(Dense(1536, activation='relu'))
model.add(Dense(1, activation='sigmoid'))

opt = Adam(learning_rate=0.0001)
model.compile(loss='binary_crossentropy', optimizer=opt, metrics=['accuracy'])

#Normally with early stopping so quite a few epochs
history = model.fit(train_features, train_labels, epochs=800, batch_size=68, verbose=1, 
validation_split=0.2, callbacks=[])

During training the loss decreases and my accuracy increases as expected.在训练过程中,损失减少,我的准确率按预期增加。 BUT the val_loss increases and the val_accuracy stays the same, Sure I'm overfitting, but I would expect that the val_accuracy increases.但是 val_loss 增加并且 val_accuracy 保持不变,当然我过度拟合,但我希望 val_accuracy 增加。 at least for a few epochs and then decreaes when I'm overfitting.至少在几个时期内,然后在我过度拟合时减少。

在此处输入图像描述 在此处输入图像描述

Has anyone an Idea what I'm doing wrong?有没有人知道我做错了什么? Perhaps 10.000 values aren't enough to generalize?也许 10.000 个值不足以概括?

Model is over fitting as expected but am surprised it starts over fitting on the early epochs which makes me winder if you have some mislabeling in your validation set. Model 正如预期的那样过度拟合,但我很惊讶它在早期的时期开始过度拟合,如果你的验证集中有一些错误标签,这会让我更加困惑。 At any rate try add changing the model as follows无论如何尝试添加更改 model 如下

model = Sequential()
model.add(Dense(1536, input_shape=(768,), activation='relu'))
model.add(Dropout(.3))
model.add(Dense(512, activation='relu'))
model.add(Dropout(.3))
model.add(Dense(128, activation='relu'))
model.add(Dropout(.3))
model.add(Dense(1, activation='sigmoid'))

See if this reduces the over fitting problem看看这是否减少了过拟合问题

It was not just a mislabeling in my validation set, but in my whole data.这不仅仅是我的验证集中的错误标签,而是我的整个数据。

I take a sample of 100000 entries我抽取了 100000 个条目的样本

train_df = train_df.sample(frac=1).reset_index(drop=True)
train_df = train_df.iloc[0:100000]

and delete some values并删除一些值

train_df = train_df[train_df['label'] != '-']

after that i set a few values using train_df.at in a loop, but some indices don't exist because i deleted them.之后,我在循环中使用train_df.at设置了一些值,但有些索引不存在,因为我删除了它们。 train_df.at only throws warnings so I did not see this. train_df.at 只抛出警告,所以我没有看到这个。 Also I mixed.loc and.iloc so in my case i selected.iloc[2:3] but the index 2 does not exist, so it return index 3 wich is on position 2. After that I make my changes and train_df.at fails at inserting on position 2, but my loop goes on.我也混合了.loc和.iloc,所以在我的情况下,我选择了.iloc[2:3],但索引2不存在,所以它返回索引3,它位于position 2上。之后我进行了更改和train_df.at在 position 2 上插入失败,但我的循环继续。 The next iteration.iloc returns index 4 on position 3. My loop then puts the data on index 3 - from now on all my labels are one position off.下一个迭代.iloc 在 position 3 上返回索引 4。然后我的循环将数据放在索引 3 上 - 从现在开始,我的所有标签都是一个 position 关闭。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM