question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

What is meant by Batch predictions for MNLI tasks

See original GitHub issue

Hi!

I am making use of the roberta.large.mnli model for obtaining entailment scores for sentences.

I wanted to ask how exactly does the batch predictions example given in the README works. Specifically, I want to know that if I write the following code:

from fairseq.data.data_utils import collate_tokens
sentences = ['Hello world.', 'Another unrelated sentence.', 'Just another sentence.', 'DFTBA.']
batch = collate_tokens([roberta.encode(sent) for sent in sentences], pad_idx=1)
logprobs = roberta.predict('mnli', batch)
assert logprobs.size() == torch.Size([4, 3])

Then what does each row of the 4 x 3 tensor that is obtained represent? Even if someone could point me to the section of the codebase that could help me understand this, it would be a great help.

Thanks!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
ngoyal2707commented, Sep 27, 2019
import torch
from fairseq.data.data_utils import collate_tokens

roberta = torch.hub.load('pytorch/fairseq', 'roberta.large.mnli')
roberta.eval()

batch_of_pairs = [
    ['Roberta is a heavily optimized version of BERT.', 'Roberta is not very optimized.'],
    ['Roberta is a heavily optimized version of BERT.', 'Roberta is based on BERT.'],
    ['potatoes are awesome.', 'I like to run.'],
    ['Mars is very far from earth.', 'Mars is very close.'],
]

batch = collate_tokens(
    [roberta.encode(pair[0], pair[1]) for pair in batch_of_pairs], pad_idx=1
)

logprobs = roberta.predict('mnli', batch)
print(logprobs.argmax(dim=1))

Ouput

tensor([0, 2, 1, 0])

0 -> contradiction, 1 -> neutral 2 -> entailment

0reactions
justachetancommented, Sep 27, 2019

Thank you so much! This clears things up 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is meant by Batch predictions for MNLI tasks · Issue #1167
Hi! I am making use of the roberta.large.mnli model for obtaining entailment scores for sentences. I wanted to ask how exactly does the...
Read more >
Online versus batch prediction - AI Platform - Google Cloud
AI Platform Prediction provides two ways to get predictions from trained models: online prediction (sometimes called HTTP prediction), and batch prediction.
Read more >
Batch Prediction — Ray 2.2.0
The batch prediction is the process of using a trained model to generate predictions for a collection of observations. It has the following...
Read more >
roberta-large-mnli - Hugging Face
Given a premise sentence and a hypothesis sentence, the task is to predict whether the premise entails the hypothesis (entailment), contradicts the hypothesis...
Read more >
GLUE: A MULTI-TASK BENCHMARK AND ANALYSIS ...
Each pair is human-annotated with a similarity score from 1 to 5; the task is to predict these scores. Follow common practice, we...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found