This model takes
facebook/bart-large-mnli
and fine-tunes it on Yahoo Answers topic classification. It can be used to predict whether a topic label can be assigned to a given sequence, whether or not the label has been seen before.
You can play with an interactive demo of this zero-shot technique with this model, as well as the non-finetuned
facebook/bart-large-mnli
,
here
.
Intended Usage
This model was fine-tuned on topic classification and will perform best at zero-shot topic classification. Use
hypothesis_template="This text is about {}."
as this is the template used during fine-tuning.
The model can be used with the
zero-shot-classification
pipeline like so:
from transformers import pipeline
nlp = pipeline("zero-shot-classification", model="joeddav/bart-large-mnli-yahoo-answers")
sequence_to_classify = "Who are you voting for in 2020?"
candidate_labels = ["Europe", "public health", "politics", "elections"]
hypothesis_template = "This text is about {}."
nlp(sequence_to_classify, candidate_labels, multi_class=True, hypothesis_template=hypothesis_template)
With manual PyTorch
# pose sequence as a NLI premise and label as a hypothesisfrom transformers import BartForSequenceClassification, BartTokenizer
nli_model = BartForSequenceClassification.from_pretrained('joeddav/bart-large-mnli-yahoo-answers')
tokenizer = BartTokenizer.from_pretrained('joeddav/bart-large-mnli-yahoo-answers')
premise = sequence
hypothesis = f'This text is about {label}.'# run through model pre-trained on MNLI
x = tokenizer.encode(premise, hypothesis, return_tensors='pt',
max_length=tokenizer.max_len,
truncation_strategy='only_first')
logits = nli_model(x.to(device))[0]
# we throw away "neutral" (dim 1) and take the probability of# "entailment" (2) as the probability of the label being true
entail_contradiction_logits = logits[:,[0,2]]
probs = entail_contradiction_logits.softmax(dim=1)
prob_label_is_true = probs[:,1]
Training
The model is a pre-trained MNLI classifier further fine-tuned on Yahoo Answers topic classification in the manner originally described in
Yin et al. 2019
and
this blog post
. That is, each sequence is fed to the pre-trained NLI model in place of the premise and each candidate label as the hypothesis, formatted like so:
This text is about {class name}.
For each example in the training set, a true and a randomly-selected false label hypothesis are fed to the model which must predict which labels are valid and which are false.
Since this method studies the ability to classify unseen labels after being trained on a different set of labels, the model is only trained on 5 out of the 10 labels in Yahoo Answers. These are "Society & Culture", "Health", "Computers & Internet", "Business & Finance", and "Family & Relationships".
Evaluation Results
This model was evaluated with the label-weighted F1 of the
seen
and
unseen
labels. That is, for each example the model must predict from one of the 10 corpus labels. The F1 is reported for the labels seen during training as well as the labels unseen during training. We found an F1 score of
.68
and
.72
for the unseen and seen labels, respectively. In order to adjust for the in-vs-out of distribution labels, we subtract a fixed amount of 30% from the normalized probabilities of the
seen
labels, as described in
Yin et al. 2019
and
our blog post
.
Runs of joeddav bart-large-mnli-yahoo-answers on huggingface.co
10.5K
Total runs
-2.3K
24-hour runs
-6.8K
3-day runs
-15.0K
7-day runs
-50.7K
30-day runs
More Information About bart-large-mnli-yahoo-answers huggingface.co Model
More bart-large-mnli-yahoo-answers license Visit here:
bart-large-mnli-yahoo-answers huggingface.co is an AI model on huggingface.co that provides bart-large-mnli-yahoo-answers's model effect (), which can be used instantly with this joeddav bart-large-mnli-yahoo-answers model. huggingface.co supports a free trial of the bart-large-mnli-yahoo-answers model, and also provides paid use of the bart-large-mnli-yahoo-answers. Support call bart-large-mnli-yahoo-answers model through api, including Node.js, Python, http.
bart-large-mnli-yahoo-answers huggingface.co is an online trial and call api platform, which integrates bart-large-mnli-yahoo-answers's modeling effects, including api services, and provides a free online trial of bart-large-mnli-yahoo-answers, you can try bart-large-mnli-yahoo-answers online for free by clicking the link below.
joeddav bart-large-mnli-yahoo-answers online free url in huggingface.co:
bart-large-mnli-yahoo-answers is an open source model from GitHub that offers a free installation service, and any user can find bart-large-mnli-yahoo-answers on GitHub to install. At the same time, huggingface.co provides the effect of bart-large-mnli-yahoo-answers install, users can directly use bart-large-mnli-yahoo-answers installed effect in huggingface.co for debugging and trial. It also supports api for free installation.
bart-large-mnli-yahoo-answers install url in huggingface.co: