How to use the fasttext.FastText function in fasttext

To help you get started, we’ve selected a few fasttext examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github deepmipt / DeepPavlov / deeppavlov / models / embedders / fasttext_embedder_to_delete.py View on Github external
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")