使用 CLI 命令训练 BERT
Train BERT with CLI commands
我已经从在“命名实体识别”部分 here and would like to train the model on custom NER labels by using the run_ner.py script as it is referenced here 中找到的转换器存储库下载了 HuggingFace BERT 模型。
我将模型 ("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.
之后它就停止了,没有结束脚本,只是等待。
有谁知道这可能是什么问题?我是否缺少参数?
我的 sentence_data.txt CoNLL 格式如下所示(小片段):
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"
找到问题了。这与CUDA驱动程序与安装的pytorch版本不兼容有关。
对于使用 Nvidia GPU 的任何人遇到同样的问题:转到 Nvidia 控制面板 -> 帮助 -> 系统信息 -> 组件,有一个名为“NVCUDA.DLL”的设置,在名称列。在 pytorch.org 上的安装生成器中选择相应的 CUDA 版本应该可以解决问题。
此外,transformers 存储库中有一个很好的自述文件,解释了使用 CLI 命令训练 BERT 模型的所有步骤 here。
我已经从在“命名实体识别”部分 here and would like to train the model on custom NER labels by using the run_ner.py script as it is referenced here 中找到的转换器存储库下载了 HuggingFace BERT 模型。
我将模型 ("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.
之后它就停止了,没有结束脚本,只是等待。
有谁知道这可能是什么问题?我是否缺少参数?
我的 sentence_data.txt CoNLL 格式如下所示(小片段):
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"
找到问题了。这与CUDA驱动程序与安装的pytorch版本不兼容有关。
对于使用 Nvidia GPU 的任何人遇到同样的问题:转到 Nvidia 控制面板 -> 帮助 -> 系统信息 -> 组件,有一个名为“NVCUDA.DLL”的设置,在名称列。在 pytorch.org 上的安装生成器中选择相应的 CUDA 版本应该可以解决问题。
此外,transformers 存储库中有一个很好的自述文件,解释了使用 CLI 命令训练 BERT 模型的所有步骤 here。