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
https://blog.csdn.net/rensihui
MIT License
1.78k stars 405 forks source link

AttributeError: 'tuple' object has no attribute 'layer' #77

Closed Allensmile closed 2 years ago

Allensmile commented 2 years ago

您好,测试test/tet_char_xlnet_embedding.py脚本报错AttributeError: 'tuple' object has no attribute 'layer',请问是什么问题?谢谢 tf、Keras、bert_keras版本如下: tf.version '1.14.0' keras.version '2.2.4' bert_keras.version '0.41.0' keras-xlnet.version '0.16.0' 模型:哈工大预训练的中文xlnet模型(chinese_xlnet_mid_L-24_H-768_A-12)

yongzhuo commented 2 years ago

已修复,不过有个问题,keras-bert==0.41.0 与 keras-xlnet==0.16.0不能共存,暂时要用的话得删掉两个,重装这个包。

keras与tf.keras混用了,因为keras-xlnet只能用tf.keras,

如xlnet源代码的attention.py:
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import backend as K

设置了 os.environ["TF_KERAS"] = "1",并且把keras替换为tensorflow.keras