实验步骤
1.获取bert的SST2句向量,通过Keras构建一个简单的基于句向量的文本分类算法,得益于bert的强大性能,在SST2文本分类的准确率高达81.80,实验结果比CRAN,CAM,DA,textCNN模型都好,训练速度特别快,收敛也特别快
通过Keras实现的简单句向量分类算法
from keras.callbacks import EarlyStopping
import numpy as np
from keras.models import Sequential
from keras.layers import Dense
x_train=np.load(r'C:\Users\ma101\Desktop\sst2/train_sentence_word.npy')
x_test=np.load(r'C:\Users\ma101\Desktop\sst2/test_sentence_word.npy')
y_train=np.load(r'C:\Users\ma101\Desktop\sst2/train_label.npy')
y_test=np.load(r'C:\Users\ma101\Desktop\sst2/test_label