roskosmos19 commited on
Commit
46a3ba2
·
verified ·
1 Parent(s): ac448fb

Upload 8 files

Browse files
Files changed (8) hide show
  1. .gitattributes +10 -0
  2. README.md +115 -0
  3. config.json +49 -0
  4. gitattributes +10 -0
  5. merges.txt +0 -0
  6. model.safetensors +3 -0
  7. tokenizer.json +0 -0
  8. tokenizer_config.json +9 -0
.gitattributes ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ *.bin.* filter=lfs diff=lfs merge=lfs -text
2
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.h5 filter=lfs diff=lfs merge=lfs -text
5
+ *.tflite filter=lfs diff=lfs merge=lfs -text
6
+ *.tar.gz filter=lfs diff=lfs merge=lfs -text
7
+ *.ot filter=lfs diff=lfs merge=lfs -text
8
+ *.onnx filter=lfs diff=lfs merge=lfs -text
9
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
10
+ model.safetensors filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ pipeline_tag: zero-shot-classification
4
+ tags:
5
+ - zero-shot
6
+ - nli
7
+ - classification
8
+ - bart
9
+ - Coral
10
+ datasets:
11
+ - multi_nli
12
+ base_model:
13
+ - facebook/bart-large-mnli
14
+ ---
15
+
16
+ ***Coral-MNLI***
17
+
18
+ **Coral-MNLI** is a high-quality zero-shot classification model based on BART-large, fine-tuned on MultiNLI.
19
+
20
+ It delivers strong performance for zero-shot and few-shot text classification without any task-specific training.
21
+
22
+ ## What it is good at
23
+
24
+ - Zero-shot text classification
25
+ - Multi-label classification
26
+ - Natural Language Inference (NLI)
27
+ - Topic detection, sentiment, intent, content moderation, and many other classification tasks
28
+
29
+ Just provide the text and a list of candidate labels — the model ranks them by how well they fit.
30
+
31
+ ## Model Details
32
+
33
+ | Property | Value |
34
+ |---------------------------|--------------------------------|
35
+ | Architecture | BART-large |
36
+ | Task | Sequence Classification (NLI) |
37
+ | Labels | contradiction / neutral / entailment |
38
+ | Max Sequence Length | 1024 |
39
+ | Vocabulary Size | 50,265 |
40
+ | License | MIT |
41
+
42
+ ## Quick Start
43
+
44
+ ### Using the Pipeline (recommended)
45
+
46
+ ```python
47
+ from transformers import pipeline
48
+
49
+ classifier = pipeline(
50
+ "zero-shot-classification",
51
+ model="path/to/Coral-MNLI"
52
+ )
53
+
54
+ sequence = "One day I will see the world"
55
+ candidate_labels = ["travel", "cooking", "dancing"]
56
+
57
+ result = classifier(sequence, candidate_labels)
58
+ print(result)
59
+ ```
60
+
61
+ ### Multi-label mode
62
+
63
+ ```python
64
+ result = classifier(
65
+ sequence,
66
+ candidate_labels=["travel", "cooking", "dancing", "exploration"],
67
+ multi_label=True
68
+ )
69
+ ```
70
+
71
+ ### Manual usage
72
+
73
+ ```python
74
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
75
+ import torch
76
+
77
+ model = AutoModelForSequenceClassification.from_pretrained("path/to/Coral-MNLI")
78
+ tokenizer = AutoTokenizer.from_pretrained("path/to/Coral-MNLI")
79
+
80
+ premise = "One day I will see the world"
81
+ label = "travel"
82
+ hypothesis = f"This example is {label}."
83
+
84
+ inputs = tokenizer(premise, hypothesis, return_tensors="pt", truncation=True)
85
+ with torch.no_grad():
86
+ logits = model(**inputs).logits
87
+
88
+ # Take only contradiction (0) and entailment (2)
89
+ probs = torch.softmax(logits[:, [0, 2]], dim=1)
90
+ prob_label_is_true = probs[0, 1].item()
91
+ print(f"Probability that the text is about '{label}': {prob_label_is_true:.4f}")
92
+ ```
93
+
94
+ ## How Zero-Shot Classification works
95
+
96
+ The model treats the input text as a **premise** and turns each candidate label into a **hypothesis** of the form:
97
+
98
+ > "This example is {label}."
99
+
100
+ It then uses the entailment probability as the score for that label. This simple trick works surprisingly well across many domains.
101
+
102
+ ## Tips for best results
103
+
104
+ - Use clear and specific labels
105
+ - Prefer multi_label=True when several labels can be true at the same time
106
+ - For short texts the model is usually very accurate
107
+ - For very long texts, keep the most important part near the beginning (truncation keeps the start)
108
+
109
+ ## License
110
+
111
+ MIT
112
+
113
+ ## Credits
114
+
115
+ Based on the excellent [facebook/bart-large-mnli](https://huggingface.co/facebook/bart-large-mnli) model.
config.json ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_num_labels": 3,
3
+ "activation_dropout": 0.0,
4
+ "activation_function": "gelu",
5
+ "add_final_layer_norm": false,
6
+ "architectures": [
7
+ "BartForSequenceClassification"
8
+ ],
9
+ "attention_dropout": 0.0,
10
+ "bos_token_id": 0,
11
+ "classif_dropout": 0.0,
12
+ "classifier_dropout": 0.0,
13
+ "d_model": 1024,
14
+ "decoder_attention_heads": 16,
15
+ "decoder_ffn_dim": 4096,
16
+ "decoder_layerdrop": 0.0,
17
+ "decoder_layers": 12,
18
+ "decoder_start_token_id": 2,
19
+ "dropout": 0.1,
20
+ "encoder_attention_heads": 16,
21
+ "encoder_ffn_dim": 4096,
22
+ "encoder_layerdrop": 0.0,
23
+ "encoder_layers": 12,
24
+ "eos_token_id": 2,
25
+ "forced_eos_token_id": 2,
26
+ "gradient_checkpointing": false,
27
+ "id2label": {
28
+ "0": "contradiction",
29
+ "1": "neutral",
30
+ "2": "entailment"
31
+ },
32
+ "init_std": 0.02,
33
+ "is_encoder_decoder": true,
34
+ "label2id": {
35
+ "contradiction": 0,
36
+ "entailment": 2,
37
+ "neutral": 1
38
+ },
39
+ "max_position_embeddings": 1024,
40
+ "model_type": "bart",
41
+ "normalize_before": false,
42
+ "num_hidden_layers": 12,
43
+ "output_past": false,
44
+ "pad_token_id": 1,
45
+ "scale_embedding": false,
46
+ "transformers_version": "4.7.0.dev0",
47
+ "use_cache": true,
48
+ "vocab_size": 50265
49
+ }
gitattributes ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ *.bin.* filter=lfs diff=lfs merge=lfs -text
2
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.h5 filter=lfs diff=lfs merge=lfs -text
5
+ *.tflite filter=lfs diff=lfs merge=lfs -text
6
+ *.tar.gz filter=lfs diff=lfs merge=lfs -text
7
+ *.ot filter=lfs diff=lfs merge=lfs -text
8
+ *.onnx filter=lfs diff=lfs merge=lfs -text
9
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
10
+ model.safetensors filter=lfs diff=lfs merge=lfs -text
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cfbb687dbbd9df99fe865e1860350a22aebac4d26ee4bcb50217f1df606a018e
3
+ size 1629437147
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model_max_length": 1024,
3
+ "bos_token": "<s>",
4
+ "eos_token": "</s>",
5
+ "unk_token": "<unk>",
6
+ "pad_token": "<pad>",
7
+ "mask_token": "<mask>",
8
+ "tokenizer_class": "BartTokenizer"
9
+ }