Are you sure you want to delete this task? Once this task is deleted, it cannot be recovered.
leeyy2020 eec0299bd4 | 2 years ago | |
---|---|---|
.. | ||
deploy/python | 2 years ago | |
README.md | 2 years ago | |
data.py | 2 years ago | |
evaluate.py | 2 years ago | |
export_model.py | 2 years ago | |
predict.py | 2 years ago | |
task_label_description.py | 2 years ago | |
train.py | 2 years ago |
EFL (Entailment as Few-Shot Learner) 提出将 NLP Fine-tune 任务转换统一转换为 Entailment 2 分类任务,为小样本场景下的任务求解提供了新的视角。
|—— train.py # EFL 策略的训练、评估主脚本
|—— dataset.py # EFL 策略针对 FewCLUE 9 个数据集的 Entailment 任务转换逻辑
|—— task_label_description.py # 各个 task 的 label 文本描述
|—— evaluate.py # 针对 FewCLUE 9 个数据集的评估函数
|—— predict.py # 针对 FewCLUE 9 个数据集进行预测
|—— export_model.py # 动态图参数导出静态图参数脚本
|—— deploy # 部署
|—— python # 部署
|—— predict.py # python预测部署示例
PaddleNLP 内置了 FewCLUE 数据集,可以直接用来进行 EFL 策略训练、评估、预测,并生成 FewCLUE 榜单的提交结果,参与 FewCLUE 竞赛。
基于 FewCLUE 数据集进行实验只需要 1 行代码,这部分代码在 train.py
脚本中
from paddlenlp.datasets import load_dataset
# 通过指定 "fewclue" 和数据集名字 name="tnews" 即可一键加载 FewCLUE 中的 tnews 数据集
train_ds, dev_ds, public_test_ds = load_dataset("fewclue", name="tnews", splits=("train_0", "dev_0", "test_public"))
通过如下命令,指定 GPU 0 卡, 在 FewCLUE 的 tnews
数据集上进行训练&评估
python -u -m paddle.distributed.launch --gpus "0" \
train.py \
--task_name "tnews" \
--device gpu \
--negative_num 1 \
--save_dir "checkpoints" \
--batch_size 32 \
--learning_rate 5E-5 \
--epochs 10 \
--max_seq_length 512 \
--rdrop_coef 0 \
参数含义说明
task_name
: FewCLUE 中的数据集名字negative_num
: 负样本采样个数,对于多分类任务,负样本数量对效果影响很大。负样本数量参数取值范围为 [1, class_num - 1]device
: 使用 cpu/gpu 进行训练save_dir
: 模型存储路径max_seq_length
: 文本的最大截断长度rdrop_coef
: R-Drop 策略 Loss 的权重系数,默认为 0, 若为 0 则未使用 R-Drop 策略模型每训练 1 个 epoch, 会在验证集上进行评估,并针对测试集进行预测存储到预测结果文件。
通过如下命令,指定 GPU 0 卡, 在 FewCLUE
的 iflytek
数据集上进行预测
python -u -m paddle.distributed.launch --gpus "0" predict.py \
--task_name "iflytek" \
--device gpu \
--init_from_ckpt "${model_params_file}" \
--output_dir "./output" \
--batch_size 32 \
--max_seq_length 512
使用动态图训练结束之后,可以将动态图参数导出成静态图参数,从而获得最优的预测部署性能,执行如下命令完成动态图转换静态图的功能:
python export_model.py --params_path=./checkpoint/model_100/model_state.pdparams --output_path=./output
导出静态图模型之后,可以用于部署,deploy/python/predict.py
脚本提供了 python 部署预测示例。运行方式:
python deploy/python/predict.py --model_dir=./output
[1] Wang, Sinong, Han Fang, Madian Khabsa, Hanzi Mao, and Hao Ma. “Entailment as Few-Shot Learner.” ArXiv:2104.14690 [Cs], April 29, 2021. http://arxiv.org/abs/2104.14690.
黑客松task_55,在PaddleNLP的Roberta中,新增 MultipleChoice,MaskedLM 和 CausalLM三个类,7个模型权重. ,新增BPETokenizer
Python C++ Cuda Text Shell other
Dear OpenI User
Thank you for your continuous support to the Openl Qizhi Community AI Collaboration Platform. In order to protect your usage rights and ensure network security, we updated the Openl Qizhi Community AI Collaboration Platform Usage Agreement in January 2024. The updated agreement specifies that users are prohibited from using intranet penetration tools. After you click "Agree and continue", you can continue to use our services. Thank you for your cooperation and understanding.
For more agreement content, please refer to the《Openl Qizhi Community AI Collaboration Platform Usage Agreement》