๐ roberta-base-japanese-jsnli
This model is a fine-tuned version of nlp-waseda/roberta-base-japanese on the JSNLI dataset. It is designed for text classification tasks, especially natural language inference. The model achieves high accuracy on the evaluation set, making it a reliable choice for related NLP applications.
๐ Quick Start
Prerequisites
The input text should be segmented into words by Juman++ in advance.
โจ Features
- Zero-shot Classification: Capable of performing zero-shot classification tasks, allowing users to classify text into predefined labels without specific training on those labels.
- High Accuracy: Achieves an accuracy of 0.9328 on the evaluation set, demonstrating its effectiveness in natural language inference tasks.
๐ฆ Installation
This section does not contain specific installation steps, so it is skipped.
๐ป Usage Examples
Basic Usage
from transformers import pipeline
from pyknp import Juman
juman = Juman()
classifier = pipeline("zero-shot-classification", model="Formzu/roberta-base-japanese-jsnli")
sequence_to_classify = " ".join([tok.midasi for tok in juman.analysis("ใใคใไธ็ใ่ฆใใ").mrph_list()])
candidate_labels = ['ๆ
่ก', 'ๆ็', '่ธใ']
out = classifier(sequence_to_classify, candidate_labels, hypothesis_template="ใใฎ ไพ ใฏ {} ใงใ ใ")
print(out)
Advanced Usage
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
from pyknp import Juman
juman = Juman()
device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
model_name = "Formzu/roberta-base-japanese-jsnli"
model = AutoModelForSequenceClassification.from_pretrained(model_name).to(device)
tokenizer = AutoTokenizer.from_pretrained(model_name)
premise = " ".join([tok.midasi for tok in juman.analysis("ใใคใไธ็ใ่ฆใใ").mrph_list()])
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())
๐ Documentation
Model Information
Property |
Details |
Model Type |
Fine-tuned roberta-base-japanese for text classification |
Training Data |
JSNLI dataset |
Metrics |
Accuracy |
Evaluation Results
This model achieves the following results on the evaluation set:
- Loss: 0.2039
- Accuracy: 0.9328
๐ง Technical Details
Training procedure
Training hyperparameters
The following hyperparameters were used during training:
- learning_rate: 2e-05
- train_batch_size: 32
- eval_batch_size: 32
- seed: 42
- optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
- lr_scheduler_type: linear
- num_epochs: 3.0
Training results
Training Loss |
Epoch |
Step |
Validation Loss |
Accuracy |
0.4067 |
1.0 |
16657 |
0.2224 |
0.9201 |
0.3397 |
2.0 |
33314 |
0.2152 |
0.9208 |
0.2775 |
3.0 |
49971 |
0.2039 |
0.9328 |
Framework versions
- Transformers 4.21.2
- Pytorch 1.12.1+cu116
- Datasets 2.4.0
- Tokenizers 0.12.1
๐ License
This project is licensed under the CC BY-SA 4.0 license.