Closed mmaslankowska-neurosys closed 3 years ago
Hi! I believe this is was overlook on our part. Your change looks reasonable to me, do you want to open a PR with your proposed fix?
And thank you for opening such a detailed and well-structured issue!
Environment info
transformers
version3.5.0
and4.3.2
The issue
I'm using the
pipeline("question-answering")
with QA Models downloaded from community. I'm evaluating models on the SQUAD 2.0 dataset which doesn't always have an answer to the given question - that's what thehandle_impossible_answer
flag in the pipeline is for.I noticed that ROBERTa model (any ROBERTa, not just a specific model) in version 4 of
transformers
always produces an answer despite thehandle_impossible_answer
flag - even if the same model for the same example didn't produce an answer (returned "" as an answer) while using version 3 of the library.Probable issue reason
I've found out that in the
question_answering.py
file in thepipeline
directory in version 4 oftransformers
there is a condition that provides ROBERTa models from adjusting thep_mask
for this task. It looks simply like this:if self.tokenizer.cls_token_id
. And since ROBERTa'scls_token_id = 0
the condition isn't met and thep_mask
isn't changed for thecls_token
. This results in omitting the token while answering the question (it behaves like e.g the token was a part of a question). For example BERT'scls_token_id = 101
so the condition is met.Plausible solution
Possibly the easy solution is to expand the condition to
if self.tokenizer.cls_token_id is not None
. However, there wasn't such a condition in version 3 at all so maybe it performs some crucial function in its current form that I'm not aware of...