繁体   English   中英

AttributeError: 'KerasTensor' object 没有属性'尺寸与拥抱面 bert.AutoModel model 与 tensorflow

[英]AttributeError: 'KerasTensor' object has no attribute 'size with hugging-face bert.AutoModel model with tensorflow

I am working on tensorflow 2 and I used Hugface's pre-trained BERT with Tensorflow 2 to do a text classification with it, here I want to create neural network with it: from tensorflow.keras import layers

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'

尝试使用

from transformers import AutoTokenizer,TFAutoModel

尝试使用 TFAutoModel 而不是 AutoModel。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM