Provide Attention scores from Transformer

Open
#2,931 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
python, pytorch

Research direction

Start in torchaudio/models/wav2vec2/components.py around line 317, where the attention scores are available, and inspect the return at line 326. Determine how the Transformer output should expose those scores alongside the representations. Done means callers can receive the attention scores rather than always getting None.

Written by the indexing model from the issue text.

Description

help wanted triaged
🚀 The feature

Thanks for your amazing contributions.

As far as I understand, the Transformer encoder employed in torchaudio does not provide attention scores in their outputs. Otherwise, please ignore this thread and let me know.

The following line can be saved as attention scores, then can be provided in line 326 return.

https://github.com/pytorch/audio/blob/1717edaa8cddf5068df97e30404d85654f0b55f4/torchaudio/models/wav2vec2/components.py#L317

Instead, the current implementation does not return but only the representations of vectors. Line 326: return output, None

Motivation, pitch

The attention scores of Transformer encoder are very valuable information to design more advanced models. Huggingface implementation allows it by configurations, and it allows other AI researchers to explore new studies, such as the model predictions considering attention scores, the loss function considering attention scores as well.

Alternatives

No response

Additional context

No response

Dominant language
Python
Stars
2.9k
Forks
799
Avg merge
58m
Merged PRs (30d)
3

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from pytorch/audio

All issues in pytorch/audio

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.