Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.fasttext_model = None
if not self._model_path.is_file():
emb_path = os.environ.get('EMBEDDINGS_URL')
if not emb_path:
raise RuntimeError('\n:: no fasttext model provided\n')
try:
print('Trying to download a pretrained fasttext model'
' from the repository')
url = parse.urljoin(emb_path, self._model_fpath)
request.urlretrieve(url, self._model_path.as_posix())
print('Downloaded a fasttext model')
except Exception as e:
raise RuntimeError('Looks like the `EMBEDDINGS_URL` variable'
' is set incorrectly', e)
print("Found fasttext model", self._model_path)
self.model = fasttext.FastText(self._model_path.as_posix())
self.dim = dim or self.model.args['dim']
if self.dim > self.model.args['dim']:
raise RuntimeError("Embeddings are too short")