-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Reduce Phraser
memory usage (drop frequencies)
#2208
Merged
Merged
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
242c80e
fix phraser memory
jenishah bba2e46
reduce phraser memory
jenishah 9f9b05f
using isinstance
jenishah c391fe5
update model when loaded
jenishah d154e3a
update model when loaded
jenishah 40b6672
update model when loaded
jenishah 40dcbde
updated changes
jenishah 21c3911
updated changes
jenishah 80e9222
update changes
jenishah 9943909
Merge remote-tracking branch 'upstream/develop' into jshah_ph_mem
menshikh-iv 021226a
fix loading
menshikh-iv 9de2495
make test better
menshikh-iv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -210,10 +210,12 @@ def load(cls, *args, **kwargs): | |
# update older models | ||
# if value in phrasegrams dict is a tuple, load only the scores. | ||
try: | ||
if isinstance(list(model.__dict__['phrasegrams'].values())[0], tuple): | ||
model.__dict__['phrasegrams'].update((k, v[1]) for k, v in model.__dict__['phrasegrams'].items()) | ||
for components, scores in model.__dict__['phrasegrams'].items(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this really work? It mutates the collection it's iterating over, which is usually a bad idea. As mentioned previously, I'd make a copy of the original keys (not items) and iterate over that, while mutating the original (large) dict. |
||
if isinstance(scores, tuple): | ||
model.__dict__['phrasegrams'][components] = scores[1] | ||
except KeyError: | ||
pass | ||
|
||
# if no scoring parameter, use default scoring | ||
if not hasattr(model, 'scoring'): | ||
logger.info('older version of %s loaded without scoring function', cls.__name__) | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this strange
__dict__
access? Why not use the pattern I showed in my last review?And what is the
try
for, whatKeyError
are we guarding against? Please add code comments.