bert_score icon indicating copy to clipboard operation
bert_score copied to clipboard

Tensor dimension mismatch when using lang='en-sci'

Open isabelcachola opened this issue 1 year ago • 2 comments

When I BERTScorer as follows:

bert_scorer = BERTScorer(lang='en-sci')
_, _, f1 = bert_scorer.score([pred_text], [r_text])

I get the following error: RuntimeError: The expanded size of the tensor (556) must match the existing size (512) at non-singleton dimension 1. Target sizes: [2, 556]. Tensor sizes: [1, 512]

I get the same error when I use model_type="allenai/scibert_scivocab_uncased". However, when I use lang="en" there are no errors, so it seems to be an issue with scibert specifically.

Thanks in advance!

isabelcachola avatar Dec 28 '23 21:12 isabelcachola

I encountered the same issue and found (not ideal but) a quick fix. You can edit the following line to provide a correct max_length compatible with SciBERT. At least setting 512 worked for in my case. Make sure not to set too low so you don't discard your summaries for evaluation too much.

https://github.com/Tiiiger/bert_score/blob/master/bert_score/utils.py#L227

sobamchan avatar Feb 27 '24 08:02 sobamchan

I encountered the same issue and found (not ideal but) a quick fix. You can edit the following line to provide a correct max_length compatible with SciBERT. At least setting 512 worked for in my case. Make sure not to set too low so you don't discard your summaries for evaluation too much.

https://github.com/Tiiiger/bert_score/blob/master/bert_score/utils.py#L227

Thank you so much!! This bug has been annoyed me for a month!

JasonCZH4 avatar Apr 09 '24 10:04 JasonCZH4