Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix indexing of lasttoken pooling for longest sequence #2111

Merged
merged 4 commits into from
Dec 13, 2023

Conversation

ssharpe42
Copy link
Contributor

Sequences that span the entire seq length of the batch will have attention mask of all 1's.

The current logic results in retrieving the first token embedding instead of the last since torch.min(torch.tensor([1,1,1 ... , 1])) will be 0.

The new logic uses the attention_mask.shape[1]-1 as the index to retrieve where min(attention_mask, 1)==1

fixing last token indexing for sequences that span the entire length
@izhx
Copy link

izhx commented May 25, 2023

Nice work! Also find this bug.

@tomaarsen
Copy link
Collaborator

Hello!

Thanks to you both for spotting this! You've provided a very elegant fix as well - I appreciate it! I'll merge when this goes green.

  • Tom Aarsen

@tomaarsen tomaarsen merged commit 6b524f8 into UKPLab:master Dec 13, 2023
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants