This repository has been archived by the owner on Dec 16, 2022. It is now read-only.
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.
The problem
Sometimes offsets contain an extra item, because of the wrong condition in the
if
check.What happens
Let's consider the case of
_truncate_long_sequences = True
with onestart=[CLS]
andend=[SEP]
token,max_pieces == 4
andwindow_length == 2
.Let's say that our sentence is being encoded into following subtokens:
["the", "quick", "##est"]
For this case
["the"]
will fit without any cut, but["quick", "##est"]
will not. The old code produced following ending offsets:[1, 3]
, but wordpieces after the cut are the following["[CLS]", "the", "quick", "[SEP]"]
and position 3 is invalid in this case cause it points to"[SEP]"
. But sometimes it also fails with index out of bound error, when offset goes beyond the size of the tensor.The fix
By adding
len(token) - 1
to current offset we make sure that the last wordpiece of the current token will fit in the sentence cut on line 208