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

Replace open() by smart_open() in gensim.models.fasttext._load_fasttext_format #2335

Merged
merged 3 commits into from
Jan 17, 2019
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: 2 additions & 2 deletions gensim/models/fasttext.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@
from numpy import ones, vstack, float32 as REAL, sum as np_sum
import six

# TODO use smart_open again when https://github.com/RaRe-Technologies/smart_open/issues/207 will be fixed
import gensim.models._fasttext_bin

from gensim.models.word2vec import Word2VecVocab, Word2VecTrainables, train_sg_pair, train_cbow_pair
from gensim.models.keyedvectors import FastTextKeyedVectors
from gensim.models.base_any2vec import BaseWordEmbeddingsModel
from gensim.models.utils_any2vec import _compute_ngrams, _ft_hash, _ft_hash_broken
from smart_open import smart_open

from gensim.utils import deprecated, call_on_class_only

Expand Down Expand Up @@ -979,7 +979,7 @@ def _load_fasttext_format(model_file, encoding='utf-8'):
"""
if not model_file.endswith('.bin'):
model_file += '.bin'
with open(model_file, 'rb') as fin:
with smart_open(model_file, 'rb') as fin:
m = gensim.models._fasttext_bin.load(fin, encoding=encoding)

model = FastText(
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def finalize_options(self):
'numpy >= 1.11.3',
'scipy >= 0.18.1',
'six >= 1.5.0',
'smart_open >= 1.2.1',
'smart_open >= 1.7.0',
],
tests_require=linux_testenv,
extras_require={
Expand Down