Model

wdtest-a/ptest-nli

import facebook/bart-large-mnli@d7645e127eaf1aefc7862fd59a17a5aa8558b8ce

wdtest-a committed on October 19, 2026

7406254e033331738d415f552b1a1d36a5b1fab6Parent 158cb3aBrowse files

7 files changed+131 -0

README.md

Added+81 -0
Lines 0 to 0 become lines 1 to 81
@@ -0,0 +1,81 @@
1Added: ---
2Added: license: mit
3Added: thumbnail: https://huggingface.co/front/thumbnails/facebook.png
4Added: pipeline_tag: zero-shot-classification
5Added: datasets:
6Added: - multi_nli
7Added: ---
8Added:
9Added: # bart-large-mnli
10Added:
11Added: This is the checkpoint for [bart-large](https://huggingface.co/facebook/bart-large) after being trained on the [MultiNLI (MNLI)](https://huggingface.co/datasets/multi_nli) dataset.
12Added:
13Added: Additional information about this model:
14Added: - The [bart-large](https://huggingface.co/facebook/bart-large) model page
15Added: - [BART: Denoising Sequence-to-Sequence Pre-training for Natural Language Generation, Translation, and Comprehension
16Added: ](https://arxiv.org/abs/1910.13461)
17Added: - [BART fairseq implementation](https://github.com/pytorch/fairseq/tree/master/fairseq/models/bart)
18Added:
19Added: ## NLI-based Zero Shot Text Classification
20Added:
21Added: [Yin et al.](https://arxiv.org/abs/1909.00161) proposed a method for using pre-trained NLI models as a ready-made zero-shot sequence classifiers. The method works by posing the sequence to be classified as the NLI premise and to construct a hypothesis from each candidate label. For example, if we want to evaluate whether a sequence belongs to the class "politics", we could construct a hypothesis of `This text is about politics.`. The probabilities for entailment and contradiction are then converted to label probabilities.
22Added:
23Added: This method is surprisingly effective in many cases, particularly when used with larger pre-trained models like BART and Roberta. See [this blog post](https://joeddav.github.io/blog/2020/05/29/ZSL.html) for a more expansive introduction to this and other zero shot methods, and see the code snippets below for examples of using this model for zero-shot classification both with Hugging Face's built-in pipeline and with native Transformers/PyTorch code.
24Added:
25Added: #### With the zero-shot classification pipeline
26Added:
27Added: The model can be loaded with the `zero-shot-classification` pipeline like so:
28Added:
29Added: ```python
30Added: from transformers import pipeline
31Added: classifier = pipeline("zero-shot-classification",
32Added: model="facebook/bart-large-mnli")
33Added: ```
34Added:
35Added: You can then use this pipeline to classify sequences into any of the class names you specify.
36Added:
37Added: ```python
38Added: sequence_to_classify = "one day I will see the world"
39Added: candidate_labels = ['travel', 'cooking', 'dancing']
40Added: classifier(sequence_to_classify, candidate_labels)
41Added: #{'labels': ['travel', 'dancing', 'cooking'],
42Added: # 'scores': [0.9938651323318481, 0.0032737774308770895, 0.002861034357920289],
43Added: # 'sequence': 'one day I will see the world'}
44Added: ```
45Added:
46Added: If more than one candidate label can be correct, pass `multi_label=True` to calculate each class independently:
47Added:
48Added: ```python
49Added: candidate_labels = ['travel', 'cooking', 'dancing', 'exploration']
50Added: classifier(sequence_to_classify, candidate_labels, multi_label=True)
51Added: #{'labels': ['travel', 'exploration', 'dancing', 'cooking'],
52Added: # 'scores': [0.9945111274719238,
53Added: # 0.9383890628814697,
54Added: # 0.0057061901316046715,
55Added: # 0.0018193122232332826],
56Added: # 'sequence': 'one day I will see the world'}
57Added: ```
58Added:
59Added:
60Added: #### With manual PyTorch
61Added:
62Added: ```python
63Added: # pose sequence as a NLI premise and label as a hypothesis
64Added: from transformers import AutoModelForSequenceClassification, AutoTokenizer
65Added: nli_model = AutoModelForSequenceClassification.from_pretrained('facebook/bart-large-mnli')
66Added: tokenizer = AutoTokenizer.from_pretrained('facebook/bart-large-mnli')
67Added:
68Added: premise = sequence
69Added: hypothesis = f'This example is {label}.'
70Added:
71Added: # run through model pre-trained on MNLI
72Added: x = tokenizer.encode(premise, hypothesis, return_tensors='pt',
73Added: truncation_strategy='only_first')
74Added: logits = nli_model(x.to(device))[0]
75Added:
76Added: # we throw away "neutral" (dim 1) and take the probability of
77Added: # "entailment" (2) as the probability of the label being true
78Added: entail_contradiction_logits = logits[:,[0,2]]
79Added: probs = entail_contradiction_logits.softmax(dim=1)
80Added: prob_label_is_true = probs[:,1]
81Added: ```

config.json

Added+49 -0
Lines 0 to 0 become lines 1 to 49
@@ -0,0 +1,49 @@
1Added: {
2Added: "_num_labels": 3,
3Added: "activation_dropout": 0.0,
4Added: "activation_function": "gelu",
5Added: "add_final_layer_norm": false,
6Added: "architectures": [
7Added: "BartForSequenceClassification"
8Added: ],
9Added: "attention_dropout": 0.0,
10Added: "bos_token_id": 0,
11Added: "classif_dropout": 0.0,
12Added: "classifier_dropout": 0.0,
13Added: "d_model": 1024,
14Added: "decoder_attention_heads": 16,
15Added: "decoder_ffn_dim": 4096,
16Added: "decoder_layerdrop": 0.0,
17Added: "decoder_layers": 12,
18Added: "decoder_start_token_id": 2,
19Added: "dropout": 0.1,
20Added: "encoder_attention_heads": 16,
21Added: "encoder_ffn_dim": 4096,
22Added: "encoder_layerdrop": 0.0,
23Added: "encoder_layers": 12,
24Added: "eos_token_id": 2,
25Added: "forced_eos_token_id": 2,
26Added: "gradient_checkpointing": false,
27Added: "id2label": {
28Added: "0": "contradiction",
29Added: "1": "neutral",
30Added: "2": "entailment"
31Added: },
32Added: "init_std": 0.02,
33Added: "is_encoder_decoder": true,
34Added: "label2id": {
35Added: "contradiction": 0,
36Added: "entailment": 2,
37Added: "neutral": 1
38Added: },
39Added: "max_position_embeddings": 1024,
40Added: "model_type": "bart",
41Added: "normalize_before": false,
42Added: "num_hidden_layers": 12,
43Added: "output_past": false,
44Added: "pad_token_id": 1,
45Added: "scale_embedding": false,
46Added: "transformers_version": "4.7.0.dev0",
47Added: "use_cache": true,
48Added: "vocab_size": 50265
49Added: }

merges.txt

Added

This file is too large to display.

model.safetensors

Added

Large (LFS-tracked) file content changed — 1.5 GB

tokenizer.json

Added

This file is too large to display.

tokenizer_config.json

Added+1 -0
Lines 0 to 0 become lines 1 to 1
@@ -0,0 +1,1 @@
1Added: {"model_max_length": 1024}(no newline at end of file)

vocab.json

Added

This file is too large to display.