🚀 用于日语自然语言推理(NLI)的交叉编码器
本模型是一个用于日语自然语言推理(NLI)的交叉编码器,借助SentenceTransformers库训练而成。它基于tohoku - nlp/bert - base - japanese - v3模型,能对给定的句子对进行推理分类,输出句子间的蕴含、中立和矛盾关系得分。
✨ 主要特性
- 基于 SentenceTransformers 的 [Cross - Encoder](https://www.sbert.net/examples/applications/cross - encoder/README.html) 类进行训练。
- 以 [tohoku - nlp/bert - base - japanese - v3](https://huggingface.co/tohoku - nlp/bert - base - japanese - v3) 为基础模型。
- 可用于零样本分类任务。
📦 安装指南
文档未提及具体安装步骤,可参考 SentenceTransformers 和 Transformers 官方文档进行安装。
💻 使用示例
基础用法
使用预训练模型进行推理:
from sentence_transformers import CrossEncoder
model = CrossEncoder('akiFQC/bert-base-japanese-v3_nli-jsnli')
scores = model.predict([('男はピザを食べています', '男は何かを食べています'), ('黒いレーシングカーが観衆の前から発車します。', '男は誰もいない道を運転しています。')])
label_mapping = ['entailment', 'neutral', 'contradiction',]
labels = [label_mapping[score_max] for score_max in scores.argmax(axis=1)]
高级用法
直接使用 Transformers 库调用模型(不依赖 SentenceTransformers 库):
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
model = AutoModelForSequenceClassification.from_pretrained('cross-encoder/nli-deberta-v3-base')
tokenizer = AutoTokenizer.from_pretrained('cross-encoder/nli-deberta-v3-base')
features = tokenizer(['男はピザを食べています', '黒いレーシングカーが観衆の前から発車します。'], ['男は何かを食べています', '男は誰もいない道を運転しています。'], padding=True, truncation=True, return_tensors="pt")
model.eval()
with torch.no_grad():
scores = model(**features).logits
label_mapping = ['contradiction', 'entailment', 'neutral']
labels = [label_mapping[score_max] for score_max in scores.argmax(dim=1)]
print(labels)
零样本分类用法
使用该模型进行零样本分类:
from transformers import pipeline
classifier = pipeline("zero-shot-classification", model='akiFQC/bert-base-japanese-v3_nli-jsnli')
sent = "Appleは先程、iPhoneの最新機種について発表しました。"
candidate_labels = ["技術", "スポーツ", "政治"]
res = classifier(sent, candidate_labels)
print(res)
📚 详细文档
训练数据
模型在以下数据集上进行训练:
- [JSNLI](https://nlp.ist.i.kyoto - u.ac.jp/?%E6%97%A5%E6%9C%AC%E8%AA%9ESNLI%28JSNLI%29%E3%83%87%E3%83%BC%E3%82%BF%E3%82%BB%E3%83%83%E3%83%88)
- JNLI(仅训练集)
- JSICK(仅训练集)
对于给定的句子对,模型将输出对应标签的三个得分:{0:"entailment", 1:"neutral", 2:"contradiction"}。
基准测试
JGLUE - JNLI 验证集准确率:0.914
📄 许可证
本项目采用 CC - BY - SA - 4.0 许可证。