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

fix: patch the missing document_delmiter for lm.__get_state__() #2658

Conversation

tianjianjiang
Copy link
Contributor

@tianjianjiang tianjianjiang commented Mar 7, 2022

close: #2503
close: #2554

There are already similar special treatments like https://github.com/flairNLP/flair/blob/master/flair/embeddings/token.py#L724 and https://github.com/flairNLP/flair/blob/master/flair/models/language_model.py#L190, but we will still need this for pre-trained SequenceTagger or alike to be pickle-able (for Dill and/or multiprocessing).

@tianjianjiang tianjianjiang force-pushed the fix-patch_lm_getstate_with_document_delimiter branch from 3684981 to 894e649 Compare March 7, 2022 14:36
Copy link
Collaborator

@tadejmagajna tadejmagajna left a comment

Choose a reason for hiding this comment

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

Thank you for your time and for figuring out the solution for this not-so-uncommon problem!

I did some investigation and found out that the root of this problem. The cause of this issue
is that some older serialized LanguageModels don't have the document_delimiter property because it didn't exist at the time those models were trained.

For clarity I therefore suggest adding a small comment that explains the reason this workaround is needed.

Also, I suggest the use of getattr which is a bit more straight-forward and cleaner (no if statement needed) than the use of self.__dict__

Happy to approve otherwise!

flair/models/language_model.py Outdated Show resolved Hide resolved
Co-authored-by: Tadej Magajna <tmagajna@gmail.com>
@alanakbik
Copy link
Collaborator

@tianjianjiang thanks for fixing this!

@alanakbik alanakbik merged commit 738c695 into flairNLP:master Mar 15, 2022
@tianjianjiang
Copy link
Contributor Author

I'm sorry for letting this falling through the cracks.
Really appreciate the review, @tadejmagajna, and I'm gonna provide some context just in case.
And of course, @alanakbik, thank you for the approval.

For clarity I therefore suggest adding a small comment that explains the reason this workaround is needed.

BLUF: I'm all for it and pardon me for being too late to add that comment.
Context: Besides me been being lazy and careless, I had a vague hesitance because no comments with https://github.com/flairNLP/flair/blob/master/flair/embeddings/token.py#L724 and https://github.com/flairNLP/flair/blob/master/flair/models/language_model.py#L190, such that I was just hoping it could be an excuse to leave no comments about this (since I didn't carefully check whether flair has a convention of inline comment).

Also, I suggest the use of getattr which is a bit more straight-forward and cleaner (no if statement needed) than the use of self.__dict__

BLUF: It crossed my mind but I would also like to change other near-identical lines. Yet I didn't want to change too many lines.
Context: I do agree that getattr is good for brevity, and I also think it's nice to respect the descriptor protocol. However, I am still unsure the intent behind other pre-existed, near-identical lines, e.g., what if those lines want to fail when a class doesn't have __dict__.

Again, thank you guys for all the support. Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants