facebookresearch / anli

Adversarial Natural Language Inference Benchmark
Other
390 stars 45 forks source link

Does 'bart-large-snli_mnli_fever_anli_R1_R2_R3-nli' output 'token_type_ids'? #22

Closed bwang482 closed 3 years ago

bwang482 commented 3 years ago

Thanks for the code and model sharing!

Just wondering does the tokenizer from ynie/bart-large-snli_mnli_fever_anli_R1_R2_R3-nli not have 'token_type_ids' ?

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-79-bdf2d57ba3d0> in <module>
      1 sents, labels = shuffle2lists(sents, labels)
      2 classifier = TestClassifier(0.9, model, tokenizer)
----> 3 preds = classifier.batch_predict(sents, pos_refs, neg_refs)
      4 print(classification_report(labels, preds, labels=[0, 1, 2], target_names=['Negative', 'Nothing', 'Positive']))

<ipython-input-61-a375e4235623> in batch_predict(self, premises, hyp_pos, hyp_neg)
     31 
     32     def batch_predict(self, premises, hyp_pos, hyp_neg):
---> 33         nli_pos_scores = self.transform(premises, hyp_pos)
     34         nli_neg_scores = self.transform(premises, hyp_neg)
     35         assert(len(nli_pos_scores)==len(nli_neg_scores))

<ipython-input-61-a375e4235623> in transform(self, premises, hypotheses)
      8 
      9     def transform(self, premises, hypotheses):
---> 10         return nli_exp(self.tokenizer, self.model, premises, hypotheses)
     11 
     12     def transform2(self, premises, hypotheses):

<ipython-input-60-a0bed999f3f7> in nli_exp(tokenizer, model, premises, hypotheses)
     26     for i in range(len(premises)):
     27         for j in range(len(hypotheses)):
---> 28             predicted_probability, _ = get_prediction(tokenizer, model, premises[i], hypotheses[j])
     29             ent_scores.append(predicted_probability[0])
     30             neu_scores.append(predicted_probability[1])

<ipython-input-60-a0bed999f3f7> in get_prediction(tokenizer, model, premise, hypothesis, max_length)
      8     attention_mask = torch.Tensor(tokenized_input_seq_pair['attention_mask']).long().unsqueeze(0)
      9 
---> 10     outputs = model(input_ids,
     11                     attention_mask=attention_mask,
     12                     token_type_ids=token_type_ids,

d:\bo\envs\srp\lib\site-packages\torch\nn\modules\module.py in _call_impl(self, *input, **kwargs)
    887             result = self._slow_forward(*input, **kwargs)
    888         else:
--> 889             result = self.forward(*input, **kwargs)
    890         for hook in itertools.chain(
    891                 _global_forward_hooks.values(),

TypeError: forward() got an unexpected keyword argument 'token_type_ids'
easonnie commented 3 years ago

Hi @bwang482, thanks for pointing it out. It seems that BART model ynie/bart-large-snli_mnli_fever_anli_R1_R2_R3-nli doesn't require 'token_type_ids' arguments (and also the tokenizer doesn't output it). You can remove that in the forward pass.

bwang482 commented 3 years ago

Thanks @easonnie !