🚀 用於日語自然語言推理(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 許可證。