AttributeError:“KerasTensor”对象没有带有huggingface bert的“大小”属性。带有tensorflow的自动模型

2024-03-28 21:10:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在研究tensorflow 2,我使用Hugface的预训练BERT和tensorflow 2对其进行文本分类,这里我想用它创建神经网络: 从tensorflow.keras导入图层

from transformers import AutoModel

encoder = AutoModel.from_pretrained("bert-base-uncased")

## create neural network input

input_ids = layers.Input(shape=(max_len,), dtype=tf.int32)

token_type_ids = layers.Input(shape=(max_len,), dtype=tf.int32)

attention_mask = layers.Input(shape=(max_len,), dtype=tf.int32)

embedding = encoder(

input_ids, token_type_ids=token_type_ids, attention_mask=attention_mask

)[0]

获取错误:AttributeError:“KerasTensor”对象没有属性“size”


Tags: tokenidsinputlenlayerstftensorflowtype