yongzhuo / Keras-TextClassification

中文长文本分类、短句子分类、多标签分类、两句子相似度(Chinese Text Classification of Keras NLP, multi-label classify, or sentence classify, long or short),字词句向量嵌入层(embeddings)和网络层(graph)构建基类,FastText,TextCNN,CharCNN,TextRNN, RCNN, DCNN, DPCNN, VDCNN, CRNN, Bert, Xlnet, Albert, Attention, DeepMoji, HAN, 胶囊网络-CapsuleNet, Transformer-encode, Seq2seq, SWEM, LEAM, TextGCN

Home Page:https://blog.csdn.net/rensihui

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

在使用m14_transformer遇到的问题

anglgn opened this issue · comments

commented

大佬,能否帮忙解决一些问题。使用的预训练模型是在github找的chinese_L-12_H-768_A-12,预训练模型加载成功,数据也正常处理了,但是出现了报错的情况如下:
Traceback (most recent call last):
File "E:/w_learning/KerasTC/keras_textclassification/m14_Transformer/train.py", line 98, in
train(rate=1)
File "E:/w_learning/KerasTC/keras_textclassification/m14_Transformer/train.py", line 93, in train
graph.fit(x_train, y_train, x_val, y_val)
File "E:\w_learning\KerasTC\keras_textclassification\base\graph.py", line 151, in fit
callbacks=self.callback())
File "G:\anaconda\envs\KerasTC\lib\site-packages\keras\engine\training.py", line 952, in fit
batch_size=batch_size)
File "G:\anaconda\envs\KerasTC\lib\site-packages\keras\engine\training.py", line 751, in standardize_user_data
exception_prefix='input')
File "G:\anaconda\envs\KerasTC\lib\site-packages\keras\engine\training_utils.py", line 102, in standardize_input_data
str(len(data)) + ' arrays: ' + str(data)[:200] + '...')
ValueError: Error when checking model input: the list of Numpy arrays that you are passing to your model is not the size the model expected. Expected to see 1 array(s), but instead got the following list of 2 arrays: [array([[ 101, 4510, 928, ..., 0, 0, 0],
[ 101, 4956, 1762, ..., 0, 0, 0],
[ 101, 7028, 2412, ..., 0, 0, 0],
...,
[ 101, 3300, 1068, ..., 0, ...
初步排查好像是text_preprocess.py里的第281行
if embedding_type in ['bert', 'albert']:
x
, y_ = np.array(x), np.array(label_zo)
x_1 = np.array([x[0] for x in x_])
x_2 = np.array([x[1] for x in x_])
x_all = [x_1, x_2]
return x_all, y_
出现了问题。问题描述为输入的数组为2个,而模型只能输入一个。于是测试了一下只输入 x_1或x_2模型可以模型起来,但是数据不完全,准确率很低。大佬,想问下这里该怎么改呀。

用m00_Bert,m14_transformer是初始的transformer的encode,没有适配预训练模型