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

[docs] last hidden state vs hidden_states[-1] #26142

Merged
merged 2 commits into from
Sep 13, 2023

Conversation

MKhalusova
Copy link
Contributor

Intuitively one may think that output.hidden_states[-1] (returned when output_hidden_states is set to True) should match the output.last_hidden_states exactly. However, this is not always the case. Models like CLIP, ClipSeg, GroupVit, OWLViT, and X-CLIP apply layernorm before returning the last_hidden_states. Some other models apply post_layernorm or norm.

This PR adds a small note in the docs to address possible confusion.

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Sep 13, 2023

The documentation is not available anymore as the PR was closed or merged.

Copy link
Collaborator

@ArthurZucker ArthurZucker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 😉 LGTM

<Tip>

When passing `output_hidden_states=True` you may expect the `outputs.hidden_states[-1]` to match `outputs.last_hidden_states` exactly.
However, this is not always the case. Some models apply normalization to the last hidden state when it's returned.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normalization or subsequent process but yes!

@MKhalusova MKhalusova merged commit 9709ab1 into huggingface:main Sep 13, 2023
parambharat pushed a commit to parambharat/transformers that referenced this pull request Sep 26, 2023
* last hidden state clarification

* feedback addressed
blbadger pushed a commit to blbadger/transformers that referenced this pull request Nov 8, 2023
* last hidden state clarification

* feedback addressed
EduardoPach pushed a commit to EduardoPach/transformers that referenced this pull request Nov 18, 2023
* last hidden state clarification

* feedback addressed
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