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

hi ,i want to use flair embedding and use myself model instead of the API function ,how should i do , thanks.anyone can give me a advice , thanks a lot. #829

Closed
cpmss521 opened this issue Jun 22, 2019 · 3 comments
Labels
question Further information is requested wontfix This will not be worked on

Comments

@cpmss521
Copy link

A clear and concise description of what you want to know.

@cpmss521 cpmss521 added the question Further information is requested label Jun 22, 2019
@stefan-it
Copy link
Member

stefan-it commented Jun 23, 2019

Hi @cpmss521,

does it help when you use the embeddings for each token of an input sequence?

E.g. you have the sentence "Berlin and Munich are nice cities.". Then you can use the Sentence class + its internal tokenizer:

from flair.data import Sentence
from flair.embeddings import FlairEmbeddings

input_sequence = "Berlin and Munich are nice cities."

sentence = Sentence(text=input_sequence, use_tokenizer=True)

# Forward language model
forward_embeddings = FlairEmbeddings('news-forward')

# Backward language model
backward_embeddings = FlairEmbeddings('news-backward')

# Get embeddings for each token in sentence (both forward and backward language model)
forward_embeddings.embed(sentence)
backward_embeddings.embed(sentence)

for token in sentence:
    # Dimension of forward language model is 2048
    # Same as for the backward language model
    # So final embedding vector for each token is 4096
    print(token.get_embedding())

I hope this helps you 😃

@cpmss521
Copy link
Author

thanks a lot ! i get it by document,but i have some confusion about :
#502 (comment)

@stale
Copy link

stale bot commented Apr 30, 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 30, 2020
@stale stale bot closed this as completed May 7, 2020
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

2 participants