【问题标题】:Train BERT with CLI commands使用 CLI 命令训练 BERT
【发布时间】:2023-03-12 15:50:01
【问题描述】:

我已从找到 here 的转换器存储库中下载了 HuggingFace BERT 模型,并希望使用 run_ner.py 脚本在自定义 NER 标签上训练模型,因为它在“命名实体识别”部分中引用了 here ”。

我在代码中将模型(“bert-base-german-cased”)、data_dir(“Data/sentence_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 格式的 sentence_data.txt 看起来像这样(小 sn-p):

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"

【问题讨论】:

    标签: python machine-learning nlp bert-language-model huggingface-transformers


    【解决方案1】:

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

    对于遇到相同问题的 Nvidia GPU 的任何人:转到 Nvidia 控制面板 -> 帮助 -> 系统信息 -> 组件,有一个名为“NVCUDA.DLL”的设置,名称列中有驱动程序编号。在 pytorch.org 上的安装构建器中选择相应的 CUDA 版本应该可以解决问题。

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

    【讨论】:

      猜你喜欢
      • 2020-12-08
      • 2022-01-04
      • 2022-01-01
      • 1970-01-01
      • 2020-07-11
      • 2022-11-08
      • 1970-01-01
      • 1970-01-01
      • 2022-12-10
      相关资源
      最近更新 更多