Instructions to use akiFQC/bert-base-japanese-v3_nli-jsnli with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use akiFQC/bert-base-japanese-v3_nli-jsnli with sentence-transformers:
from sentence_transformers import CrossEncoder model = CrossEncoder("akiFQC/bert-base-japanese-v3_nli-jsnli") query = "Which planet is known as the Red Planet?" passages = [ "Venus is often called Earth's twin because of its similar size and proximity.", "Mars, known for its reddish appearance, is often referred to as the Red Planet.", "Jupiter, the largest planet in our solar system, has a prominent red spot.", "Saturn, famous for its rings, is sometimes mistaken for the Red Planet." ] scores = model.predict([(query, passage) for passage in passages]) print(scores) - Notebooks
- Google Colab
- Kaggle
Cross-Encoder for Natural Language Inference(NLI) for Japanese
Considering the results of the JNLI evaluation result, we recommend using akiFQC/bert-base-japanese-v3_nli-jsnli-jnli-jsick for natural language inference in Japanese.
This model was trained using SentenceTransformers Cross-Encoder class. This model is based on tohoku-nlp/bert-base-japanese-v3.
Training Data
The model was trained on the JSNLI datasets. For a given sentence pair, it will output three scores corresponding to the labels: {0:"entailment", 1:"neutral", 2:"contradiction}.
Usage
Pre-trained models can be used like this:
from sentence_transformers import CrossEncoder
model = CrossEncoder('akiFQC/bert-base-japanese-v3_nli-jsnli')
scores = model.predict([('男はピザを食べています', '男は何かを食べています'), ('黒いレーシングカーが観衆の前から発車します。', '男は誰もいない道を運転しています。')])
#Convert scores to labels
label_mapping = ['entailment', 'neutral', 'contradiction',]
labels = [label_mapping[score_max] for score_max in scores.argmax(axis=1)]
Usage with Transformers AutoModel
You can use the model also directly with Transformers library (without SentenceTransformers library):
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)
Zero-Shot Classification
This model can also be used for zero-shot-classification:
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)
Benchmarks
JGLUE-JNLI validation set accuracy: 0.770
- Downloads last month
- 107