akiFQC commited on
Commit
a7b372a
1 Parent(s): 5f88309

update readme

Browse files
Files changed (1) hide show
  1. README.md +61 -0
README.md CHANGED
@@ -1,3 +1,64 @@
1
  ---
2
  license: cc-by-sa-4.0
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: cc-by-sa-4.0
3
+ language: ja
4
+ pipeline_tag: zero-shot-classification
5
+ tags:
6
+ - tohoku-nlp/bert-base-japanese-v3
7
+ datasets:
8
+ - shunk031/jsnli
9
+ library_name: sentence-transformers
10
  ---
11
+
12
+
13
+ # Cross-Encoder for Natural Language Inference
14
+ This model was trained using [SentenceTransformers](https://sbert.net) [Cross-Encoder](https://www.sbert.net/examples/applications/cross-encoder/README.html) class.
15
+ This model is based on [tohoku-nlp/bert-base-japanese-v3](https://huggingface.co/tohoku-nlp/bert-base-japanese-v3).
16
+
17
+ ## Training Data
18
+ The model was trained on the [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) datasets.
19
+ For a given sentence pair, it will output three scores corresponding to the labels: {0:"entailment", 1:"neutral", 2:"contradiction}.
20
+
21
+ ## Usage
22
+
23
+ Pre-trained models can be used like this:
24
+ ```python
25
+ from sentence_transformers import CrossEncoder
26
+ model = CrossEncoder('akiFQC/bert-base-japanese-v3_nli-jsnli')
27
+ scores = model.predict([('男はピザを食べています', '男は何かを食べています'), ('黒いレーシングカーが観衆の前から発車します。', '男は誰もいない道を運転しています。')])
28
+
29
+ #Convert scores to labels
30
+ label_mapping = ['entailment', 'neutral', 'contradiction',]
31
+ labels = [label_mapping[score_max] for score_max in scores.argmax(axis=1)]
32
+ ```
33
+
34
+ ## Usage with Transformers AutoModel
35
+ You can use the model also directly with Transformers library (without SentenceTransformers library):
36
+ ```python
37
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
38
+ import torch
39
+
40
+ model = AutoModelForSequenceClassification.from_pretrained('cross-encoder/nli-deberta-v3-base')
41
+ tokenizer = AutoTokenizer.from_pretrained('cross-encoder/nli-deberta-v3-base')
42
+
43
+ features = tokenizer(['男はピザを食べています', '黒いレーシングカーが観衆の前から発車します。'], ['男は何かを食べています', '男は誰もいない道を運転しています。'], padding=True, truncation=True, return_tensors="pt")
44
+
45
+ model.eval()
46
+ with torch.no_grad():
47
+ scores = model(**features).logits
48
+ label_mapping = ['contradiction', 'entailment', 'neutral']
49
+ labels = [label_mapping[score_max] for score_max in scores.argmax(dim=1)]
50
+ print(labels)
51
+ ```
52
+
53
+ ## Zero-Shot Classification
54
+ This model can also be used for zero-shot-classification:
55
+ ```python
56
+ from transformers import pipeline
57
+
58
+ classifier = pipeline("zero-shot-classification", model='akiFQC/bert-base-japanese-v3_nli-jsnli')
59
+
60
+ sent = "Appleは先程、iPhoneの最新機種について発表しました。"
61
+ candidate_labels = ["技術", "スポーツ", "政治"]
62
+ res = classifier(sent, candidate_labels)
63
+ print(res)
64
+ ```