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

Accessing [CLS] Token Embeddings #1259

Closed
reinaldncku opened this issue Nov 2, 2019 · 3 comments
Closed

Accessing [CLS] Token Embeddings #1259

reinaldncku opened this issue Nov 2, 2019 · 3 comments
Labels
question Further information is requested wontfix This will not be worked on

Comments

@reinaldncku
Copy link

Hello,

I would like to access the embedding that corresponds to the [CLS] token. This is my code, by the way.

from flair.embeddings import BertEmbeddings
from flair.data import Sentence, Token
from pytorch_pretrained_bert import BertTokenizer

bert = BertEmbeddings(layers="-1", pooling_operation="first")

sample_txt = "Hello there i am here"
sentence = Sentence(sample_txt)
embedded_sample_txt = bert.embed(sentence)

print (embedded_sample_txt)

However, when I try to access the BERT-embedded text, [CLS] is not included there. This is the output:

[Sentence: "Hello there i am here" - 5 Tokens]

May I know how to I access/show the [CLS] token? Thanks!

@reinaldncku reinaldncku added the question Further information is requested label Nov 2, 2019
@LorrinWWW
Copy link

the same question!

@stale
Copy link

stale bot commented Apr 29, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Apr 29, 2020
@alanakbik
Copy link
Collaborator

You can now get the embedding from the CLS token using the new TransformerDocumentEmbeddings class (see #1494). It's part of master branch now and will be in the next Flair release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants