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

Make directory at start of dict.save() #3250

Merged
merged 1 commit into from
Nov 5, 2020
Merged
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
2 changes: 1 addition & 1 deletion parlai/core/dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,7 @@ def save(self, filename=None, append=False, sort=True):
If ``sort`` (default ``True``), then first sort the dictionary before saving.
"""
filename = self.opt['dict_file'] if filename is None else filename
make_dir(os.path.dirname(filename))

if self.tokenizer in ['bpe', 'gpt2', 'bytelevelbpe', 'slow_bytelevel_bpe']:
needs_removal = self.bpe.finalize(
Expand All @@ -643,7 +644,6 @@ def save(self, filename=None, append=False, sort=True):

logging.info(f'Saving dictionary to {filename}')

make_dir(os.path.dirname(filename))
mode = 'a' if append else 'w'
with PathManager.open(filename, mode, encoding='utf-8') as write:
for i in self.ind2tok.keys():
Expand Down