File size: 3,249 Bytes
46a3ba2
93f0129
46a3ba2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
---
license: apache-2.0
pipeline_tag: zero-shot-classification
tags:
- zero-shot
- nli
- classification
- bart
- Coral
datasets:
- multi_nli
base_model:
- facebook/bart-large-mnli
---

***Coral-MNLI***

**Coral-MNLI** is a high-quality zero-shot classification model based on BART-large, fine-tuned on MultiNLI.

It delivers strong performance for zero-shot and few-shot text classification without any task-specific training.

## What it is good at

- Zero-shot text classification
- Multi-label classification
- Natural Language Inference (NLI)
- Topic detection, sentiment, intent, content moderation, and many other classification tasks

Just provide the text and a list of candidate labels — the model ranks them by how well they fit.

## Model Details

| Property                  | Value                          |
|---------------------------|--------------------------------|
| Architecture              | BART-large                     |
| Task                      | Sequence Classification (NLI)  |
| Labels                    | contradiction / neutral / entailment |
| Max Sequence Length       | 1024                           |
| Vocabulary Size           | 50,265                         |
| License                   | MIT                            |

## Quick Start

### Using the Pipeline (recommended)

```python
from transformers import pipeline

classifier = pipeline(
    "zero-shot-classification",
    model="path/to/Coral-MNLI"
)

sequence = "One day I will see the world"
candidate_labels = ["travel", "cooking", "dancing"]

result = classifier(sequence, candidate_labels)
print(result)
```

### Multi-label mode

```python
result = classifier(
    sequence,
    candidate_labels=["travel", "cooking", "dancing", "exploration"],
    multi_label=True
)
```

### Manual usage

```python
from transformers import AutoModelForSequenceClassification, AutoTokenizer
import torch

model = AutoModelForSequenceClassification.from_pretrained("path/to/Coral-MNLI")
tokenizer = AutoTokenizer.from_pretrained("path/to/Coral-MNLI")

premise = "One day I will see the world"
label = "travel"
hypothesis = f"This example is {label}."

inputs = tokenizer(premise, hypothesis, return_tensors="pt", truncation=True)
with torch.no_grad():
    logits = model(**inputs).logits

# Take only contradiction (0) and entailment (2)
probs = torch.softmax(logits[:, [0, 2]], dim=1)
prob_label_is_true = probs[0, 1].item()
print(f"Probability that the text is about '{label}': {prob_label_is_true:.4f}")
```

## How Zero-Shot Classification works

The model treats the input text as a **premise** and turns each candidate label into a **hypothesis** of the form:

> "This example is {label}."

It then uses the entailment probability as the score for that label. This simple trick works surprisingly well across many domains.

## Tips for best results

- Use clear and specific labels
- Prefer multi_label=True when several labels can be true at the same time
- For short texts the model is usually very accurate
- For very long texts, keep the most important part near the beginning (truncation keeps the start)

## License

MIT

## Credits

Based on the excellent [facebook/bart-large-mnli](https://huggingface.co/facebook/bart-large-mnli) model.