[英]Python: BERT Error - Some weights of the model checkpoint at were not used when initializing BertModel
[英]'BertModel' object has no attribute 'bert' error german bert model
我想復制此 repo https://github.com/theartificialguy/NLP-with-Deep-Learning/blob/master/BERT/Multi-Class%20classification%20TF-BERT/multi_class.ipynb中的工作,但帶有德語文本並使用其他標簽我准備了我的數據並完成了必要的修改步驟而不是tokenizer = BertTokenizer.from_pretrained('bert-base-cased')
我使用tokenizer = AutoTokenizer.from_pretrained("dbmdz/bert-base-german-cased")
cased tokenizer = AutoTokenizer.from_pretrained("dbmdz/bert-base-german-cased")
來自本文檔https://huggingface.co/dbmdz/bert-base-german-cased而不是model = TFBertModel.from_pretrained('bert-base-cased')
我使用model = AutoModel.from_pretrained("dbmdz/bert-base-german-cased")
然后當我到了必須執行這部分的地步時
# defining 2 input layers for input_ids and attn_masks
input_ids = tf.keras.layers.Input(shape=(256,), name='input_ids', dtype='int32')
attn_masks = tf.keras.layers.Input(shape=(256,), name='attention_mask', dtype='int32')
bert_embds = model.bert(input_ids, attention_mask=attn_masks)[1] # 0 -> activation layer (3D),
1 -> pooled output layer (2D)
intermediate_layer = tf.keras.layers.Dense(512, activation='relu', name='intermediate_layer')
(bert_embds)
output_layer = tf.keras.layers.Dense(5, activation='softmax', name='output_layer')
(intermediate_layer) # softmax -> calcs probs of classes
sentiment_model = tf.keras.Model(inputs=[input_ids, attn_masks], outputs=output_layer)
sentiment_model.summary()
我有這個錯誤
AttributeError Traceback (most recent call last)
<ipython-input-42-ed437bbb2d3e> in <module>
3 attn_masks = tf.keras.layers.Input(shape=(256,), name='attention_mask', dtype='int32')
4
----> 5 bert_embds = model.bert(input_ids, attention_mask=attn_masks)[1] # 0 -> activation
layer (3D), 1 -> pooled output layer (2D)
6 intermediate_layer = tf.keras.layers.Dense(512, activation='relu',
name='intermediate_layer')(bert_embds)
7 output_layer = tf.keras.layers.Dense(5, activation='softmax', name='output_layer')
(intermediate_layer) # softmax -> calcs probs of classes
/usr/local/lib/python3.8/dist-packages/torch/nn/modules/module.py in __getattr__(self, name)
1263 if name in modules:
1264 return modules[name]
-> 1265 raise AttributeError("'{}' object has no attribute '{}'".format(
1266 type(self).__name__, name))
1267
AttributeError: 'BertModel' object has no attribute 'bert'
在bert-base-german- cased 中,我們可以看到: Currently only PyTorch-Transformers compatible weights are available. If you need access to TensorFlow checkpoints, please raise an issue!
Currently only PyTorch-Transformers compatible weights are available. If you need access to TensorFlow checkpoints, please raise an issue!
因此,您要么提出問題,要么編寫 pytorch 版本。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.