Fix bug which causes score
method to ignore BERTScorer
object's batch_size
attribute
#191
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There is a bug in the
score()
method's code: Abatch_size
attribute can be specified for theBERTScorer
object, but this setting is ignored by thescore()
method currently. In fact this attribute of theBERTScorer
object has no effect at all.The proposed fix is that if a
batch_size
argument is not specified explicitly for thescore()
method, then the value of theBERTScorer
object'sbatch_size
attribute is used for calculating the embeddings.Another possibility would be to remove the
batch_size
attribute and, along with it, thebatch_size
parameter of theBERTScorer
class and its initializer method respectively, just like it was apparently done forverbose
andreturn_hash
earlier (I fixed the docstrings and removed these outdated parameters), but this would modify the interface of the class and thus break backward compatibility, so I'd rather not do that. I believe it's better to fix the bug instead.Note: This bug is no joke. I just lost some 3 or 4 hours of time because of it, trying to understand why BERTScore keeps running out of GPU RAM despite my having set batch size to 1, before it occurred to me that I should check if there's maybe some bug in the code.