🚀 日語自然語言推理(NLI)交叉編碼器
本模型是用於日語自然語言推理的交叉編碼器,基於特定數據集訓練,能輸出句子對不同標籤的得分,還可用於零樣本分類等任務。
🚀 快速開始
考慮到 JNLI 評估結果,我們推薦使用 akiFQC/bert-base-japanese-v3_nli-jsnli-jnli-jsick 進行日語自然語言推理。
本模型使用 SentenceTransformers 的 Cross-Encoder 類進行訓練,基於 tohoku-nlp/bert-base-japanese-v3 構建。
✨ 主要特性
- 基於特定數據集訓練,可對給定句子對輸出對應標籤的得分。
- 支持多種使用方式,包括使用預訓練模型和直接使用 Transformers 庫。
- 可用於零樣本分類任務。
📦 安裝指南
文檔未提及具體安裝步驟,可參考相關庫(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 數據集上進行訓練。對於給定的句子對,它將輸出對應標籤的三個得分:{0:"蘊含關係", 1:"中立關係", 2:"矛盾關係"}。
基準測試
JGLUE - JNLI 驗證集準確率:0.770
📄 許可證
本項目採用 CC BY - SA 4.0 許可證。