Seralization of embeddings#3011
Merged
alanakbik merged 22 commits intoflairNLP:masterfrom Jan 25, 2023
Merged
Conversation
10d0726 to
3c5eabe
Compare
Member
Author
|
Status of Embeddings:
|
added 12 commits
December 19, 2022 14:21
…t the naming better and add loading of jit models
d8b067b to
f973806
Compare
Collaborator
|
Hello @helpmefindaname this is really cool, thanks for creating this! Some initial thoughts for discussion:
model = FlairClassifier.load("ner")
model = FlairClassifier.load("ner", "pos", "relations")it would load a whole pipeline that when calling |
alanakbik
reviewed
Jan 25, 2023
| from flair.nn.recurrent import create_recurrent_layer | ||
|
|
||
|
|
||
| @AutoFlairModel.register |
Collaborator
There was a problem hiding this comment.
Why is the LanguageModel registered as AutoFlairModel?
alanakbik
approved these changes
Jan 25, 2023
Collaborator
|
Thanks again for improving this @helpmefindaname! Regarding our discussion on whether/how to merge |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
To be saver in regards of pickle, I propose to use a dict-format to store all properties required to recreate the embeddings (weights are stored with the model itself anyways).
This allows opening Flairmodels with incompatible parameters via
torch.load(...)and therefore allows debugging version conflicts.During development I also found & fixed the following issues:
DocumentLMEmbeddingswere not providing the right names for their embeddings. So taking the correct usage ofdoc_lm_embedding.embedd(sentence);sentence.get_embeddings(doc_lm_embedding.get_names())Would result into an empty tensor.train()method didn't call it's super method, the.eval()call in the__init__was negated, leading to dropout staying enabled as that is the default..eval()mode after creating.from flair.models import TextRegressiorThis also implements two classes
AutoFlairModelandAutoFlairClassifierwhich can be used to to load any model, given that their type is clear.Example usages are here:
The difference between
AutoFlairModelandAutoFlairClassifieris thatAutoFlairClassifieris limited to only classifers (no text-regressor) while it provides stronger typing hints (all methods the Classifier provides extra, e.g.:predict)Potential issues are:
model = SequenceTagger.load("my-model.pt")tomodel = AutoFlairClassifier.load("my-model.pt")I would recommend loading it once and saving it again on the newest version.