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

The dimension choose of Elmo using flair #886

Closed
nininininini opened this issue Jul 16, 2019 · 4 comments
Closed

The dimension choose of Elmo using flair #886

nininininini opened this issue Jul 16, 2019 · 4 comments
Labels
question Further information is requested

Comments

@nininininini
Copy link

Hi, when I choose Elmo as word embedding, it seems that I can only choose a fixed dimension of 3072. Can I choose other dimensions for Elmo in flair? What part of this 3072 is composed of?

@nininininini nininininini added the question Further information is requested label Jul 16, 2019
@alanakbik
Copy link
Collaborator

Hi @nininininini ELMo exposes three layers a 1024 states and by default we take all three to make embeddings. It is currently not possible to select only a subset of these layers, but this is a feature that could be added in a future PR.

@nininininini
Copy link
Author

I get it, Thanks for your complete answer @alanakbik

@gabrieldevopsai
Copy link

I think that you can to use average layers.
Its possible to use flair with 1024 dims with garanted performance?

@alanakbik
Copy link
Collaborator

@gabrielcustodio there is a PR #1547 by @falcaopetri that adresses this issue. You can now choose whether to use a concatenation of all three layers (default) or alternatively only the topmost layer or an average. The latter two options only have 1024 dimensions!

# example sentence
sentence = Sentence("The grass is green")

# default option: concatenate all three layers (size: 3072)
embeddings = ELMoEmbeddings(embedding_mode='all')
embeddings.embed(sentence)
print(sentence[0].embedding.size())

# use only the topmost layer  (size: 1024)
embeddings = ELMoEmbeddings(embedding_mode='top')
sentence.clear_embeddings()
embeddings.embed(sentence)
print(sentence[0].embedding.size())

# use an average of all layers  (size: 1024)
embeddings = ELMoEmbeddings(embedding_mode='average')
sentence.clear_embeddings()
embeddings.embed(sentence)
print(sentence[0].embedding.size())

After the PR is merged, this feature is available in master branch and will be part of 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
Projects
None yet
Development

No branches or pull requests

3 participants