Model
wdtest-a/ptest-nli
- Task:Zero Shot Classification
- Libraries:transformers
- Formats:safetensors
- License:mit
- arXiv:arXiv:1910.13461arXiv:1909.00161
Dedicated endpoint
Sign in to deployInference Providers
This model isn't deployed by any Inference Provider.
Spaces
Create a Space with this modelUse this model
Choose individual files there, or download a full snapshot with the Python example below.
Download with the whiteduck client
pip install https://provyd.xyz/clients/whiteduck-0.1.0-py3-none-any.whl
wd login --host 'https://api.provyd.xyz'
wd download 'wdtest-a/ptest-nli'Using the Hugging Face client instead
Install huggingface_hub with pip install huggingface_hub, then download this pinned snapshot. Set HF_TOKEN (the variable the Hugging Face client reads) to a whiteduck Read token for private repositories. Running the downloaded model requires software that supports its architecture.
Keep your whiteduck token away from calls that ignore HF_ENDPOINT, such as list_inference_endpoints: they send it to Hugging Face. See Docs.
from huggingface_hub import snapshot_download
import os
path = snapshot_download(
repo_id='wdtest-a/ptest-nli',
revision='7406254e033331738d415f552b1a1d36a5b1fab6',
endpoint='https://api.provyd.xyz',
token=os.environ.get("HF_TOKEN") or False,
)Zero-shot classify with transformers
import os
os.environ["HF_ENDPOINT"] = 'https://api.provyd.xyz'
from transformers import pipeline
pipe = pipeline("zero-shot-classification", model='wdtest-a/ptest-nli')
scores = pipe("Hello", candidate_labels=["greeting", "question"])Call it with huggingface_hub
Works once the owner has started the model. Set WD_INFERENCE_KEY to a model API key.
import os
from huggingface_hub import InferenceClient
client = InferenceClient(model='https://api.provyd.xyz/api/wd/inference/models/wdtest-a/ptest-nli', token=os.environ["WD_INFERENCE_KEY"])
labels = client.zero_shot_classification("Hello", ["greeting", "question"])Use with local apps
This hub is self-hosted, so each command points the tool at it. Add a whiteduck access token as HF_TOKEN (the variable the Hugging Face client reads) for private repositories.
vLLM
# vLLM downloads through huggingface_hub, which honours HF_ENDPOINT; set HF_TOKEN for a private repository.
HF_ENDPOINT='https://api.provyd.xyz' vllm serve 'wdtest-a/ptest-nli'Clone with git
git clone 'https://api.provyd.xyz/wdtest-a/ptest-nli'Clone with git over SSH
git clone 'ssh://git@wd.provyd.xyz:2222/wdtest-a/ptest-nli'Needs an SSH key on your account. Add an SSH key
Use the API
Read repository metadata at this commit. Set HF_TOKEN (the variable the Hugging Face client reads) to a whiteduck Read token. Tokens grant account-level access, not access to just this model.
curl 'https://api.provyd.xyz/api/models/wdtest-a/ptest-nli/revision/7406254e033331738d415f552b1a1d36a5b1fab6' \
-H "Authorization: Bearer $HF_TOKEN"Inference is separate from file storage. The owner must configure and start a supported model using the inference controls. To call it you need a model API key (made on the model page), or a token of any scope (Read or stronger) from the model owner. Visitors can use the try box only when the owner allows it. A token cannot enable unavailable GPU hardware.
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
README.md
| @@ -0,0 +1,81 @@ | |||
| 1 | Added: --- | ||
| 2 | Added: license: mit | ||
| 3 | Added: thumbnail: https://huggingface.co/front/thumbnails/facebook.png | ||
| 4 | Added: pipeline_tag: zero-shot-classification | ||
| 5 | Added: datasets: | ||
| 6 | Added: - multi_nli | ||
| 7 | Added: --- | ||
| 8 | Added: | ||
| 9 | Added: # bart-large-mnli | ||
| 10 | Added: | ||
| 11 | Added: 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. | ||
| 12 | Added: | ||
| 13 | Added: Additional information about this model: | ||
| 14 | Added: - The [bart-large](https://huggingface.co/facebook/bart-large) model page | ||
| 15 | Added: - [BART: Denoising Sequence-to-Sequence Pre-training for Natural Language Generation, Translation, and Comprehension | ||
| 16 | Added: ](https://arxiv.org/abs/1910.13461) | ||
| 17 | Added: - [BART fairseq implementation](https://github.com/pytorch/fairseq/tree/master/fairseq/models/bart) | ||
| 18 | Added: | ||
| 19 | Added: ## NLI-based Zero Shot Text Classification | ||
| 20 | Added: | ||
| 21 | Added: [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. | ||
| 22 | Added: | ||
| 23 | Added: 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. | ||
| 24 | Added: | ||
| 25 | Added: #### With the zero-shot classification pipeline | ||
| 26 | Added: | ||
| 27 | Added: The model can be loaded with the `zero-shot-classification` pipeline like so: | ||
| 28 | Added: | ||
| 29 | Added: ```python | ||
| 30 | Added: from transformers import pipeline | ||
| 31 | Added: classifier = pipeline("zero-shot-classification", | ||
| 32 | Added: model="facebook/bart-large-mnli") | ||
| 33 | Added: ``` | ||
| 34 | Added: | ||
| 35 | Added: You can then use this pipeline to classify sequences into any of the class names you specify. | ||
| 36 | Added: | ||
| 37 | Added: ```python | ||
| 38 | Added: sequence_to_classify = "one day I will see the world" | ||
| 39 | Added: candidate_labels = ['travel', 'cooking', 'dancing'] | ||
| 40 | Added: classifier(sequence_to_classify, candidate_labels) | ||
| 41 | Added: #{'labels': ['travel', 'dancing', 'cooking'], | ||
| 42 | Added: # 'scores': [0.9938651323318481, 0.0032737774308770895, 0.002861034357920289], | ||
| 43 | Added: # 'sequence': 'one day I will see the world'} | ||
| 44 | Added: ``` | ||
| 45 | Added: | ||
| 46 | Added: If more than one candidate label can be correct, pass `multi_label=True` to calculate each class independently: | ||
| 47 | Added: | ||
| 48 | Added: ```python | ||
| 49 | Added: candidate_labels = ['travel', 'cooking', 'dancing', 'exploration'] | ||
| 50 | Added: classifier(sequence_to_classify, candidate_labels, multi_label=True) | ||
| 51 | Added: #{'labels': ['travel', 'exploration', 'dancing', 'cooking'], | ||
| 52 | Added: # 'scores': [0.9945111274719238, | ||
| 53 | Added: # 0.9383890628814697, | ||
| 54 | Added: # 0.0057061901316046715, | ||
| 55 | Added: # 0.0018193122232332826], | ||
| 56 | Added: # 'sequence': 'one day I will see the world'} | ||
| 57 | Added: ``` | ||
| 58 | Added: | ||
| 59 | Added: | ||
| 60 | Added: #### With manual PyTorch | ||
| 61 | Added: | ||
| 62 | Added: ```python | ||
| 63 | Added: # pose sequence as a NLI premise and label as a hypothesis | ||
| 64 | Added: from transformers import AutoModelForSequenceClassification, AutoTokenizer | ||
| 65 | Added: nli_model = AutoModelForSequenceClassification.from_pretrained('facebook/bart-large-mnli') | ||
| 66 | Added: tokenizer = AutoTokenizer.from_pretrained('facebook/bart-large-mnli') | ||
| 67 | Added: | ||
| 68 | Added: premise = sequence | ||
| 69 | Added: hypothesis = f'This example is {label}.' | ||
| 70 | Added: | ||
| 71 | Added: # run through model pre-trained on MNLI | ||
| 72 | Added: x = tokenizer.encode(premise, hypothesis, return_tensors='pt', | ||
| 73 | Added: truncation_strategy='only_first') | ||
| 74 | Added: logits = nli_model(x.to(device))[0] | ||
| 75 | Added: | ||
| 76 | Added: # we throw away "neutral" (dim 1) and take the probability of | ||
| 77 | Added: # "entailment" (2) as the probability of the label being true | ||
| 78 | Added: entail_contradiction_logits = logits[:,[0,2]] | ||
| 79 | Added: probs = entail_contradiction_logits.softmax(dim=1) | ||
| 80 | Added: prob_label_is_true = probs[:,1] | ||
| 81 | Added: ``` | ||
config.json
Added+49 -0
config.json
| @@ -0,0 +1,49 @@ | |||
| 1 | Added: { | ||
| 2 | Added: "_num_labels": 3, | ||
| 3 | Added: "activation_dropout": 0.0, | ||
| 4 | Added: "activation_function": "gelu", | ||
| 5 | Added: "add_final_layer_norm": false, | ||
| 6 | Added: "architectures": [ | ||
| 7 | Added: "BartForSequenceClassification" | ||
| 8 | Added: ], | ||
| 9 | Added: "attention_dropout": 0.0, | ||
| 10 | Added: "bos_token_id": 0, | ||
| 11 | Added: "classif_dropout": 0.0, | ||
| 12 | Added: "classifier_dropout": 0.0, | ||
| 13 | Added: "d_model": 1024, | ||
| 14 | Added: "decoder_attention_heads": 16, | ||
| 15 | Added: "decoder_ffn_dim": 4096, | ||
| 16 | Added: "decoder_layerdrop": 0.0, | ||
| 17 | Added: "decoder_layers": 12, | ||
| 18 | Added: "decoder_start_token_id": 2, | ||
| 19 | Added: "dropout": 0.1, | ||
| 20 | Added: "encoder_attention_heads": 16, | ||
| 21 | Added: "encoder_ffn_dim": 4096, | ||
| 22 | Added: "encoder_layerdrop": 0.0, | ||
| 23 | Added: "encoder_layers": 12, | ||
| 24 | Added: "eos_token_id": 2, | ||
| 25 | Added: "forced_eos_token_id": 2, | ||
| 26 | Added: "gradient_checkpointing": false, | ||
| 27 | Added: "id2label": { | ||
| 28 | Added: "0": "contradiction", | ||
| 29 | Added: "1": "neutral", | ||
| 30 | Added: "2": "entailment" | ||
| 31 | Added: }, | ||
| 32 | Added: "init_std": 0.02, | ||
| 33 | Added: "is_encoder_decoder": true, | ||
| 34 | Added: "label2id": { | ||
| 35 | Added: "contradiction": 0, | ||
| 36 | Added: "entailment": 2, | ||
| 37 | Added: "neutral": 1 | ||
| 38 | Added: }, | ||
| 39 | Added: "max_position_embeddings": 1024, | ||
| 40 | Added: "model_type": "bart", | ||
| 41 | Added: "normalize_before": false, | ||
| 42 | Added: "num_hidden_layers": 12, | ||
| 43 | Added: "output_past": false, | ||
| 44 | Added: "pad_token_id": 1, | ||
| 45 | Added: "scale_embedding": false, | ||
| 46 | Added: "transformers_version": "4.7.0.dev0", | ||
| 47 | Added: "use_cache": true, | ||
| 48 | Added: "vocab_size": 50265 | ||
| 49 | Added: } | ||
merges.txt
Added
merges.txt
This file is too large to display.
model.safetensors
Added
model.safetensors
Large (LFS-tracked) file content changed — 1.5 GB
tokenizer.json
Added
tokenizer.json
This file is too large to display.
tokenizer_config.json
Added+1 -0
tokenizer_config.json
| @@ -0,0 +1,1 @@ | |||
| 1 | Added: {"model_max_length": 1024}(no newline at end of file) | ||
vocab.json
Added
vocab.json
This file is too large to display.