【问题标题】:AttributeError: 'KerasTensor' object has no attribute 'size with hugging-face bert.AutoModel model with tensorflowAttributeError: 'KerasTensor' 对象没有属性'尺寸与拥抱脸bert.AutoModel 模型与张量流
【发布时间】:2021-07-20 06:56:45
【问题描述】:

我正在研究 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' object has no attribute 'size'

【问题讨论】:

  • this 会回答您的问题吗?

标签: python tensorflow bert-language-model huggingface-transformers


【解决方案1】:

尝试使用

from transformers import AutoTokenizer,TFAutoModel

尝试使用 TFAutoModel,而不是 AutoModel。

【讨论】:

    猜你喜欢
    • 2021-07-30
    • 2021-06-06
    • 2018-04-01
    • 2020-06-09
    • 1970-01-01
    • 2020-10-22
    • 2019-02-20
    • 2017-12-06
    相关资源
    最近更新 更多