🚀 e5-base-v2-mnli-anli
本模型是 intfloat/e5-base-v2 在 glue (mnli) 和 anli 数据集上的微调版本。它可用于零样本分类任务,为文本分类提供了高效且准确的解决方案。
✨ 主要特性
📦 安装指南
文档未提及具体安装步骤,可参考 transformers
库的官方安装说明进行安装。
💻 使用示例
基础用法
使用 zero-shot-classification
管道加载模型:
from transformers import pipeline
classifier = pipeline("zero-shot-classification",
model="mjwong/e5-base-v2-mnli-anli")
使用该管道将序列分类到指定的类别名称中:
sequence_to_classify = "one day I will see the world"
candidate_labels = ['travel', 'cooking', 'dancing']
classifier(sequence_to_classify, candidate_labels)
如果有多个候选标签可能正确,可传递 multi_class=True
独立计算每个类别:
candidate_labels = ['travel', 'cooking', 'dancing', 'exploration']
classifier(sequence_to_classify, candidate_labels, multi_class=True)
高级用法
将模型应用于 NLI 任务:
import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification
device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
model_name = "mjwong/e5-base-v2-mnli-anli"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)
premise = "But I thought you'd sworn off coffee."
hypothesis = "I thought that you vowed to drink more coffee."
input = tokenizer(premise, hypothesis, truncation=True, return_tensors="pt")
output = model(input["input_ids"].to(device))
prediction = torch.softmax(output["logits"][0], -1).tolist()
label_names = ["entailment", "neutral", "contradiction"]
prediction = {name: round(float(pred) * 100, 2) for pred, name in zip(prediction, label_names)}
print(prediction)
📚 详细文档
评估结果
模型使用 MultiNLI 的开发集和 ANLI 的测试集进行评估,使用的指标是准确率。
训练超参数
训练过程中使用了以下超参数:
- 学习率:2e-05
- 训练批次大小:16
- 评估批次大小:16
- 随机种子:42
- 优化器:Adam,
betas=(0.9, 0.999)
,epsilon=1e-08
- 学习率调度器类型:线性
- 学习率调度器热身比例:0.1
框架版本
- Transformers 4.28.1
- Pytorch 1.12.1+cu116
- Datasets 2.11.0
- Tokenizers 0.12.1
📄 许可证
本模型采用 MIT 许可证。