使用CLI命令训练BERT

2024-09-28 22:03:44 发布

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

我已经从transformer存储库中下载了HuggingFace BERT模型here,并希望通过使用run_NER.py脚本在“命名实体识别”一节中引用here来在自定义的NER标签上训练该模型

我将模型(“bert base german cased”)、数据目录(“data/Session\u data.txt”)和标签(“data/labels.txt”)定义为代码中的默认值

现在,我将此输入用于命令行:

python run_ner.py --output_dir="Models" --num_train_epochs=3 --logging_steps=100 --do_train --do_eval --do_predict

但它所做的只是告诉我:

Some weights of the model checkpoint at bert-base-german-cased were not used when initializing BertForTokenClassification: ['cls.predictions.bias', 'cls.predictions.transform.dense.weight', 'cls.predictions.transform.dense.bias', 'cls.predictions.transform.LayerNorm.w
eight', 'cls.predictions.transform.LayerNorm.bias', 'cls.predictions.decoder.weight', 'cls.seq_relationship.weight', 'cls.seq_relationship.bias']
- This IS expected if you are initializing BertForTokenClassification from the checkpoint of a model trained on another task or with another architecture (e.g. initializing a BertForSequenceClassification model from a BertForPretraining model).
- This IS NOT expected if you are initializing BertForTokenClassification from the checkpoint of a model that you expect to be exactly identical (initializing a BertForSequenceClassification model from a BertForSequenceClassification model).
Some weights of BertForTokenClassification were not initialized from the model checkpoint at bert-base-german-cased and are newly initialized: ['classifier.weight', 'classifier.bias']
You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.

之后它就停止了,不是结束脚本,而是简单地等待

有人知道这里有什么问题吗?我是否缺少一个参数

CoNLL格式的句子_data.txt如下所示(小片段):

Strafverfahren O
gegen O
; O
wegen O
Diebstahls O
hat O
das O
Amtsgericht Ort
Leipzig Ort
- O
Strafrichter O

这就是我在labels.txt中定义标签的方式:

"Date", "Delikt", "Strafe_Tatbestand", "Schadensbetrag", "Geständnis_ja", "Vorstrafe_ja", "Vorstrafe_nein", "Ort",
"Strafe_Gesamtfreiheitsstrafe_Dauer", "Strafe_Gesamtsatz_Dauer", "Strafe_Gesamtsatz_Betrag"

Tags: ofthefromtxtdatamodeltransformcls
1条回答
网友
1楼 · 发布于 2024-09-28 22:03:44

发现了问题。这与CUDA驱动程序与安装的pytorch版本不兼容有关

对于英伟达GPU的任何人来说,遇到同样的问题:去NVIDIA控制面板-GT;帮助->;系统信息->;组件中,有一个名为“NVCUDA.DLL”的设置,在“名称”列中有一个驱动程序编号。在pytorch.org上的安装生成器中选择相应的CUDA版本应该可以做到这一点

此外,transformers存储库中有一个很好的自述文件,解释了使用CLI命令here训练BERT模型的所有步骤

相关问题 更多 >