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

Enable local embeddings files + fix an issue with binary_lines #168

Merged
merged 6 commits into from
Nov 14, 2017
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
11 changes: 8 additions & 3 deletions torchtext/vocab.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,12 @@ def __getitem__(self, token):
return self.unk_init(torch.Tensor(1, self.dim))

def cache(self, name, cache, url=None):
path = os.path.join(cache, name)
path_pt = path + '.pt'
if os.path.isfile(name):
path = name
path_pt = os.path.join(cache, os.path.basename(name)) + '.pt'
else:
path = os.path.join(cache, name)
path_pt = path + '.pt'

if not os.path.isfile(path_pt):
if not os.path.isfile(path) and url:
Expand Down Expand Up @@ -275,7 +279,8 @@ def cache(self, name, cache, url=None):
for line in tqdm(lines, total=len(lines)):
# Explicitly splitting on " " is important, so we don't
# get rid of Unicode non-breaking spaces in the vectors.
entries = line.rstrip().split(" ")
entries = line.rstrip().split(b" " if binary_lines else " ")

word, entries = entries[0], entries[1:]
if dim is None and len(entries) > 1:
dim = len(entries)
Expand Down