🚀 bert-base-japanese-jsnli
本模型是 cl-tohoku/bert-base-japanese-v2 在 JSNLI 数据集上的微调版本。它在评估集上取得了以下结果:
🚀 快速开始
模型使用方法
简单的零样本分类管道
from transformers import pipeline
classifier = pipeline("zero-shot-classification", model="Formzu/bert-base-japanese-jsnli")
sequence_to_classify = "いつか世界を見る。"
candidate_labels = ['旅行', '料理', '踊り']
out = classifier(sequence_to_classify, candidate_labels, hypothesis_template="この例は{}です。")
print(out)
NLI 使用案例
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
model_name = "Formzu/bert-base-japanese-jsnli"
model = AutoModelForSequenceClassification.from_pretrained(model_name).to(device)
tokenizer = AutoTokenizer.from_pretrained(model_name)
premise = "いつか世界を見る。"
label = '旅行'
hypothesis = f'この例は{label}です。'
input = tokenizer.encode(premise, hypothesis, return_tensors='pt').to(device)
with torch.no_grad():
logits = model(input)["logits"][0]
probs = logits.softmax(dim=-1)
print(probs.cpu().numpy(), logits.cpu().numpy())
🔧 技术细节
训练超参数
训练过程中使用了以下超参数:
- 学习率:2e-05
- 训练批次大小:32
- 评估批次大小:32
- 随机种子:42
- 优化器:Adam(β1=0.9,β2=0.999,ε=1e-08)
- 学习率调度器类型:线性
- 训练轮数:3.0
训练结果
训练损失 |
轮数 |
步数 |
验证损失 |
准确率 |
0.4054 |
1.0 |
16657 |
0.2141 |
0.9216 |
0.3297 |
2.0 |
33314 |
0.2145 |
0.9236 |
0.2645 |
3.0 |
49971 |
0.2085 |
0.9288 |
框架版本
- Transformers 4.21.2
- Pytorch 1.12.1+cu116
- Datasets 2.4.0
- Tokenizers 0.12.1
📄 许可证
本项目采用 CC BY-SA 4.0 许可证。
📋 模型信息
属性 |
详情 |
模型类型 |
文本分类 |
训练数据 |
JSNLI |
评估指标 |
准确率 |
标签 |
zero-shot-classification、text-classification、nli、pytorch |