Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

updates to dictionary loading #443

Merged
merged 2 commits into from
Dec 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion parlai/agents/drqa/drqa.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ def _init_from_saved(self, fname):
map_location=lambda storage, loc: storage)

# TODO expand dict and embeddings for new data
self.word_dict = saved_params['word_dict']
loaded_words = saved_params['word_dict']
self.word_dict.copy_dict(loaded_words)

self.feature_dict = saved_params['feature_dict']
self.state_dict = saved_params['state_dict']
config.override_args(self.opt, saved_params['config'])
Expand Down
8 changes: 8 additions & 0 deletions parlai/core/dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,14 @@ def __setitem__(self, key, value):
self.tok2ind[key] = index
self.ind2tok[index] = key

def copy_dict(self, dictionary):
"""Overwrite own state with any state in the other dictionary.
This allows loading of the contents of another dictionary while keeping
the current dictionary version.
"""
for k, v in vars(dictionary).items():
setattr(self, k, v)

def freqs(self):
return self.freq

Expand Down