返回模型
说明文档
distilbert-base-multilingual-cased-sentiments-student
该模型是基于 Multilingual Sentiment 数据集上的零样本分类pipeline,使用此脚本进行蒸馏得到的。
实际上,多语言情感数据集当然是有标注的, 但为了演示目的,我们会假装忽略这些标注。
教师模型:MoritzLaurer/mDeBERTa-v3-base-mnli-xnli
教师假设模板:"The sentiment of this text is {}."
学生模型:distilbert-base-multilingual-cased
推理示例
from transformers import pipeline
distilled_student_sentiment_classifier = pipeline(
model="lxyuan/distilbert-base-multilingual-cased-sentiments-student",
return_all_scores=True
)
# 英语
distilled_student_sentiment_classifier ("I love this movie and i would watch it again and again!")
>> [[{'label': 'positive', 'score': 0.9731044769287109},
{'label': 'neutral', 'score': 0.016910076141357422},
{'label': 'negative', 'score': 0.009985478594899178}]]
# 马来语
distilled_student_sentiment_classifier("Saya suka filem ini dan saya akan menontonnya lagi dan lagi!")
[[{'label': 'positive', 'score': 0.9760093688964844},
{'label': 'neutral', 'score': 0.01804516464471817},
{'label': 'negative', 'score': 0.005945465061813593}]]
# 日语
distilled_student_sentiment_classifier("私はこの映画が大好きで、何度も見ます!")
>> [[{'label': 'positive', 'score': 0.9342429041862488},
{'label': 'neutral', 'score': 0.040193185210227966},
{'label': 'negative', 'score': 0.025563929229974747}]]
训练步骤
Notebook链接:这里
训练超参数
可以使用以下命令复现结果:
python transformers/examples/research_projects/zero-shot-distillation/distill_classifier.py \
--data_file ./multilingual-sentiments/train_unlabeled.txt \
--class_names_file ./multilingual-sentiments/class_names.txt \
--hypothesis_template "The sentiment of this text is {}." \
--teacher_name_or_path MoritzLaurer/mDeBERTa-v3-base-mnli-xnli \
--teacher_batch_size 32 \
--student_name_or_path distilbert-base-multilingual-cased \
--output_dir ./distilbert-base-multilingual-cased-sentiments-student \
--per_device_train_batch_size 16 \
--fp16
如果您在Colab上训练此模型,请进行以下代码修改以避免内存不足错误:
###### 修改L78行,禁用快速分词器
default=False,
###### 在L313行更新数据集映射部分
dataset = dataset.map(tokenizer, input_columns="text", fn_kwargs={"padding": "max_length", "truncation": True, "max_length": 512})
###### 在L213行添加以下行
del model
print(f"手动删除了教师模型,为学生模型释放了一些内存。")
###### 在L337行添加以下行
trainer.push_to_hub()
tokenizer.push_to_hub("distilbert-base-multilingual-cased-sentiments-student")
训练日志
训练完成。别忘了在 huggingface.co/models 上分享您的模型 =)
{'train_runtime': 2009.8864, 'train_samples_per_second': 73.0, 'train_steps_per_second': 4.563, 'train_loss': 0.6473459283913797, 'epoch': 1.0}
100%|███████████████████████████████████████| 9171/9171 [33:29<00:00, 4.56it/s]
[INFO|trainer.py:762] 2023-05-06 10:56:18,555 >> 以下列在评估集中没有对应于 `DistilBertForSequenceClassification.forward` 的参数,已被忽略:text。如果 `DistilBertForSequenceClassification.forward` 不需要 text,您可以安全地忽略此消息。
[INFO|trainer.py:3129] 2023-05-06 10:56:18,557 >> ***** 运行评估 *****
[INFO|trainer.py:3131] 2023-05-06 10:56:18,557 >> 样本数 = 146721
[INFO|trainer.py:3134] 2023-05-06 10:56:18,557 >> 批次大小 = 128
100%|███████████████████████████████████████| 1147/1147 [08:59<00:00, 2.13it/s]
05/06/2023 11:05:18 - INFO - __main__ - 学生和教师预测的一致率:88.29%
[INFO|trainer.py:2868] 2023-05-06 11:05:18,251 >> 保存模型检查点到 ./distilbert-base-multilingual-cased-sentiments-student
[INFO|configuration_utils.py:457] 2023-05-06 11:05:18,251 >> 配置已保存到 ./distilbert-base-multilingual-cased-sentiments-student/config.json
[INFO|modeling_utils.py:1847] 2023-05-06 11:05:18,905 >> 模型权重已保存到 ./distilbert-base-multilingual-cased-sentiments-student/pytorch_model.bin
[INFO|tokenization_utils_base.py:2171] 2023-05-06 11:05:18,905 >> 分词器配置文件已保存到 ./distilbert-base-multilingual-cased-sentiments-student/tokenizer_config.json
[INFO|tokenization_utils_base.py:2178] 2023-05-06 11:05:18,905 >> 特殊标记文件已保存到 ./distilbert-base-multilingual-cased-sentiments-student/special_tokens_map.json
框架版本
- Transformers 4.28.1
- Pytorch 2.0.0+cu118
- Datasets 2.11.0
- Tokenizers 0.13.3
lxyuan/distilbert-base-multilingual-cased-sentiments-student
作者 lxyuan
text-classification
transformers
↓ 1M
♥ 308
创建时间: 2023-05-05 16:22:55+00:00
更新时间: 2025-03-03 02:06:53+00:00
在 Hugging Face 上查看文件 (12)
.gitattributes
README.md
config.json
model.safetensors
onnx/config.json
onnx/model.onnx
ONNX
pytorch_model.bin
special_tokens_map.json
tokenizer.json
tokenizer_config.json
training_args.bin
vocab.txt