PaddlePaddle / PaddleNLP

👑 Easy-to-use and powerful NLP and LLM library with 🤗 Awesome model zoo, supporting wide-range of NLP tasks from research to industrial applications, including 🗂Text Classification, 🔍 Neural Search, ❓ Question Answering, ℹ️ Information Extraction, 📄 Document Intelligence, 💌 Sentiment Analysis etc.
https://paddlenlp.readthedocs.io
Apache License 2.0
12.16k stars 2.94k forks source link

uie-m-base目前是否支援訓練 #3942

Closed JimmyLyods closed 1 year ago

JimmyLyods commented 1 year ago

问题描述

您好,目前正在研究paddleNLP的訓練 使用官方的資料做訓練是可行的, 但試著將uie-base改成uie-m-base python finetune.py --device cpu --logging_steps 10 --save_steps 100 --eval_steps 100 --seed 42 --model_name_or_path uie-m-base --output_dir ./checkpoint/model_best --train_path data/train.txt --dev_path data/dev.txt --max_seq_length 512 --per_device_eval_batch_size 16 --per_device_train_batch_size 16 --num_train_epochs 100 --learning_rate 1e-5 --label_names 'start_positions' 'end_positions' --do_train --do_eval --do_export --export_model_dir ./checkpoint/model_best --overwrite_output_dir --disable_tqdm True --metric_for_best_model eval_f1 --load_best_model_at_end True --save_total_limit 1

但會出現錯誤 [2022-11-29 15:46:33,658] [ INFO] - We are using <class 'paddlenlp.transformers.ernie_m.tokenizer.ErnieMTokenizer'> to load 'uie-m-base'. Traceback (most recent call last): File "C:\Users\jimmy\Documents\paddlenlp\PaddleNLP\model_zoo\uie\finetune.py", line 287, in main() File "C:\Users\jimmy\Documents\paddlenlp\PaddleNLP\model_zoo\uie\finetune.py", line 138, in main model = UIE.from_pretrained(model_args.model_name_or_path) File "C:\ProgramData\Anaconda3\lib\site-packages\paddlenlp\transformers\model_utils.py", line 468, in from_pretrained assert arg.pop( AssertionError: pretrained base model should be ErnieModel

但使用uie-base是可行的,所以現在uie-m-base有支援訓練了嗎? 目前訓練資料是用官方方式產生的, python doccano.py --doccano_file ./data/doccano_ext.json --task_type ext --save_dir ./data --splits 0.8 0.2 0 --schema_lang ch 資料doccano_ext.json也是官方的文件

wawltor commented 1 year ago

可以支持,需要加上 训练参数需要 --multilingual

image
JimmyLyods commented 1 year ago

您好,已經可以訓練了,感謝

另外,請問一下如果用uie-m-base模組做訓練, 訓練資料是全英文是否可行?

wawltor commented 1 year ago

您好,已經可以訓練了,感謝

另外,請問一下如果用uie-m-base模組做訓練, 訓練資料是全英文是否可行?

可以

JimmyLyods commented 1 year ago

好的,感謝回覆

JimmyLyods commented 1 year ago

您好,我在訓練全英文資料遇到錯誤, doccano_ext.json內容 {"id": 1, "text": "004019000921 Jimmy Chen Singpei road", "relations": [], "entities": [{"id": 0, "start_offset": 0, "end_offset": 12, "label": "Accounts"}, {"id": 1, "start_offset": 13, "end_offset": 23, "label": "Person"}, {"id": 2, "start_offset": 24, "end_offset": 37, "label": "Address"}]} {"id": 2, "text": "902141913004 Terry Kuo Jings road", "relations": [], "entities": [{"id": 0, "start_offset": 0, "end_offset": 12, "label": "Accounts"}, {"id": 1, "start_offset": 13, "end_offset": 22, "label": "Organization"}, {"id": 2, "start_offset": 23, "end_offset": 34, "label": "Address"}]} 執行後python doccano.py --doccano_file ./data/doccano_ext.json --task_type ext --save_dir ./data --splits 0.8 0.2 0 --schema_lang en 產生訓練資料後,執行訓練資料 python finetune.py --device cpu --logging_steps 10 --save_steps 100 --eval_steps 100 --seed 42 --model_name_or_path uie-m-base --output_dir ./checkpoint/model_best --train_path data/train.txt --dev_path data/dev.txt --max_seq_length 512 --per_device_eval_batch_size 16 --per_device_train_batch_size 16 --num_train_epochs 1 --learning_rate 1e-5 --label_names 'start_positions' 'end_positions' --do_train --do_eval --do_export --export_model_dir ./checkpoint/model_best --overwrite_output_dir --disable_tqdm True --metric_for_best_model eval_f1 --load_best_model_at_end True --save_total_limit 1 --multilingual

遇到錯誤 Traceback (most recent call last): File "C:\Users\jimmy\Documents\paddlenlp\PaddleNLP\model_zoo\uie\finetune.py", line 287, in main() File "C:\Users\jimmy\Documents\paddlenlp\PaddleNLP\model_zoo\uie\finetune.py", line 218, in main eval_metrics = trainer.evaluate() File "C:\ProgramData\Anaconda3\lib\site-packages\paddlenlp\trainer\trainer.py", line 1625, in evaluate output = self.evaluation_loop( File "C:\ProgramData\Anaconda3\lib\site-packages\paddlenlp\trainer\trainer.py", line 1739, in evaluation_loop loss, logits, labels = self.prediction_step(model, File "C:\ProgramData\Anaconda3\lib\site-packages\paddlenlp\trainer\trainer.py", line 1940, in prediction_step outputs = model(inputs) File "C:\ProgramData\Anaconda3\lib\site-packages\paddle\fluid\dygraph\layers.py", line 930, in call return self._dygraph_call_func(*inputs, *kwargs) File "C:\ProgramData\Anaconda3\lib\site-packages\paddle\fluid\dygraph\layers.py", line 915, in _dygraph_call_func outputs = self.forward(inputs, kwargs) TypeError: forward() got an unexpected keyword argument 'start_positions'

wawltor commented 1 year ago

你的paddlenlp版本是什么版本?

JimmyLyods commented 1 year ago

您好,我的版本 Name Version Build Channel paddlenlp 2.4.3 pypi_0 pypi

Python的版本是 3.9.7

linjieccc commented 1 year ago

@JimmyLyods 请问有对这里模型的类名做过改动么 https://github.com/PaddlePaddle/PaddleNLP/blob/develop/model_zoo/uie/model.py#L44

或者可以试试在finetune.py脚本中加上

training_args.label_names = ["start_positions", "end_positions"]
JimmyLyods commented 1 year ago

您好,我沒有修改model.py這隻程式, 有需要修改什麼做調整嗎?

我在finetune.py的98行新增training_args.label_names = ["start_positions", "end_positions"] 已經可以成功執行並儲存, 想請教一下我在執行訓練的指令 python finetune.py --device cpu --logging_steps 10 --save_steps 100 --eval_steps 100 --seed 42 --model_name_or_path uie-m-base --output_dir ./checkpoint/model_best --train_path data/train.txt --dev_path data/dev.txt --max_seq_length 512 --per_device_eval_batch_size 16 --per_device_train_batch_size 16 --num_train_epochs 1 --learning_rate 1e-5 --label_names 'start_positions' 'end_positions' --do_train --do_eval --do_export --export_model_dir ./checkpoint/model_best --overwrite_output_dir --disable_tqdm True --metric_for_best_model eval_f1 --load_best_model_at_end True --save_total_limit 1 --multilingual

裡面參數已經有帶--label_names 'start_positions' 'end_positions' 為什麼還要修改finetune.py才能成功, 我是否有哪個步驟沒有做好? 感謝您的回覆

linjieccc commented 1 year ago

您好,我沒有修改model.py這隻程式, 有需要修改什麼做調整嗎?

我在finetune.py的98行新增training_args.label_names = ["start_positions", "end_positions"] 已經可以成功執行並儲存, 想請教一下我在執行訓練的指令 python finetune.py --device cpu --logging_steps 10 --save_steps 100 --eval_steps 100 --seed 42 --model_name_or_path uie-m-base --output_dir ./checkpoint/model_best --train_path data/train.txt --dev_path data/dev.txt --max_seq_length 512 --per_device_eval_batch_size 16 --per_device_train_batch_size 16 --num_train_epochs 1 --learning_rate 1e-5 --label_names 'start_positions' 'end_positions' --do_train --do_eval --do_export --export_model_dir ./checkpoint/model_best --overwrite_output_dir --disable_tqdm True --metric_for_best_model eval_f1 --load_best_model_at_end True --save_total_limit 1 --multilingual

裡面參數已經有帶--label_names 'start_positions' 'end_positions' 為什麼還要修改finetune.py才能成功, 我是否有哪個步驟沒有做好? 感謝您的回覆

@ZHUI 辛苦帮忙看下这个问题