{"id":13609598,"url":"https://github.com/vrasneur/pyfasttext","last_synced_at":"2026-01-27T08:15:09.105Z","repository":{"id":62580307,"uuid":"95915008","full_name":"vrasneur/pyfasttext","owner":"vrasneur","description":"Yet another Python binding for fastText","archived":false,"fork":false,"pushed_at":"2018-12-08T15:02:54.000Z","size":144,"stargazers_count":225,"open_issues_count":20,"forks_count":30,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-12-08T07:18:07.323Z","etag":null,"topics":["fasttext","machine-learning","nlp","numpy","python","python-bindings","word-vectors"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vrasneur.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-30T18:44:42.000Z","updated_at":"2025-08-07T12:22:05.000Z","dependencies_parsed_at":"2022-11-03T21:00:58.226Z","dependency_job_id":null,"html_url":"https://github.com/vrasneur/pyfasttext","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/vrasneur/pyfasttext","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vrasneur%2Fpyfasttext","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vrasneur%2Fpyfasttext/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vrasneur%2Fpyfasttext/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vrasneur%2Fpyfasttext/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vrasneur","download_url":"https://codeload.github.com/vrasneur/pyfasttext/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vrasneur%2Fpyfasttext/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28809410,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-27T07:41:26.337Z","status":"ssl_error","status_checked_at":"2026-01-27T07:41:08.776Z","response_time":168,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fasttext","machine-learning","nlp","numpy","python","python-bindings","word-vectors"],"created_at":"2024-08-01T19:01:36.349Z","updated_at":"2026-01-27T08:15:09.083Z","avatar_url":"https://github.com/vrasneur.png","language":"Python","readme":"# pyfasttext\n\n*Warning!* **`pyfasttext` is no longer maintained: use the official Python binding from the fastText repository:** https://github.com/facebookresearch/fastText/tree/master/python\n\nYet another Python binding for [fastText](https://github.com/facebookresearch/fastText).\n\nThe binding supports Python 2.6, 2.7 and Python 3. It requires [Cython](http://cython.org/).\n\n[Numpy](http://www.numpy.org/) and [cysignals](http://cysignals.readthedocs.io/en/latest/) are also dependencies, but are optional.  \n\n`pyfasttext` has been tested successfully on Linux and Mac OS X.  \n*Warning*: if you want to compile `pyfasttext` on Windows, do not compile with the `cysignals` module because it does not support this platform.\n\nTable of Contents\n=================\n\n   * [pyfasttext](#pyfasttext)\n   * [Table of Contents](#table-of-contents)\n      * [Installation](#installation)\n         * [Simplest way to install pyfasttext: use pip](#simplest-way-to-install-pyfasttext-use-pip)\n            * [Possible compilation error](#possible-compilation-error)\n         * [Cloning](#cloning)\n         * [Requirements for Python 2.7](#requirements-for-python-27)\n         * [Building and installing manually](#building-and-installing-manually)\n            * [Building and installing without optional dependencies](#building-and-installing-without-optional-dependencies)\n      * [Usage](#usage)\n         * [How to load the library?](#how-to-load-the-library)\n         * [How to load an existing model?](#how-to-load-an-existing-model)\n         * [Word representation learning](#word-representation-learning)\n            * [Training using Skipgram](#training-using-skipgram)\n            * [Training using CBoW](#training-using-cbow)\n         * [Word vectors](#word-vectors)\n            * [Word vectors access](#word-vectors-access)\n               * [Vector for a given word](#vector-for-a-given-word)\n                  * [Numpy ndarray](#numpy-ndarray)\n               * [Words for a given vector](#words-for-a-given-vector)\n               * [Get the number of words in the model](#get-the-number-of-words-in-the-model)\n               * [Get all the word vectors in a model](#get-all-the-word-vectors-in-a-model)\n                  * [Numpy ndarray](#numpy-ndarray-1)\n            * [Misc operations with word vectors](#misc-operations-with-word-vectors)\n               * [Word similarity](#word-similarity)\n               * [Most similar words](#most-similar-words)\n               * [Analogies](#analogies)\n         * [Text classification](#text-classification)\n            * [Supervised learning](#supervised-learning)\n            * [Get all the labels](#get-all-the-labels)\n            * [Get the number of labels](#get-the-number-of-labels)\n            * [Prediction](#prediction)\n               * [Labels and probabilities](#labels-and-probabilities)\n                  * [Normalized probabilities](#normalized-probabilities)\n               * [Labels only](#labels-only)\n            * [Quantization](#quantization)\n               * [Is a model quantized?](#is-a-model-quantized)\n         * [Subwords](#subwords)\n            * [Get the subwords](#get-the-subwords)\n            * [Get the subword vectors](#get-the-subword-vectors)\n         * [Sentence and text vectors](#sentence-and-text-vectors)\n            * [Unsupervised models](#unsupervised-models)\n            * [Supervised models](#supervised-models)\n         * [Misc utilities](#misc-utilities)\n            * [Show the module version](#show-the-module-version)\n            * [Show fastText version](#show-fasttext-version)\n            * [Show the model (hyper)parameters](#show-the-model-hyperparameters)\n            * [Show the model version number](#show-the-model-version-number)\n            * [Extract labels or classes from a dataset](#extract-labels-or-classes-from-a-dataset)\n               * [Extract labels](#extract-labels)\n               * [Extract classes](#extract-classes)\n         * [Exceptions](#exceptions)\n         * [Interruptible operations](#interruptible-operations)\n\n## Installation\n\nTo compile `pyfasttext`, make sure you have the following compiler:\n* GCC (`g++`) with C++11 support.\n* LLVM (`clang++`) with (at least) partial C++17 support.\n\n### Simplest way to install pyfasttext: use pip\n\nJust type these lines:\n\n```bash\npip install cython\npip install pyfasttext\n```\n\n#### Possible compilation error\n\nIf you have a compilation error, you can try to install `cysignals` manually:\n\n```bash\npip install cysignals\n```\n\nThen, retry to install `pyfasttext` with the already mentioned `pip` command.\n\n### Cloning\n\n`pyfasttext` uses git [submodules](https://git-scm.com/book/en/v2/Git-Tools-Submodules).  \nSo, you need to add the `--recursive` option when you clone the repository.\n\n```bash\ngit clone --recursive https://github.com/vrasneur/pyfasttext.git\ncd pyfasttext\n```\n\n### Requirements for Python 2.7\n\nPython 2.7 support relies on the [future](http://python-future.org) module: `pyfasttext` needs `bytes` objects, which are not available natively in Python2.  \nYou can install the `future` module with `pip`.\n\n```bash\npip install future\n```\n\n### Building and installing manually\n\nFirst, install all the requirements:\n\n```bash\npip install -r requirements.txt\n```\n\nThen, build and install with `setup.py`:\n\n```bash\npython setup.py install\n```\n\n#### Building and installing without optional dependencies\n\n`pyfasttext` can export word vectors as `numpy` `ndarray`s, however this feature can be disabled at compile time.\n\nTo compile without `numpy`, pyfasttext has a `USE_NUMPY` environment variable. Set this variable to 0 (or empty), like this:\n\n```bash\nUSE_NUMPY=0 python setup.py install\n```\n\nIf you want to compile without `cysignals`, likewise, you can set the `USE_CYSIGNALS` environment variable to 0 (or empty).\n\n## Usage\n\n### How to load the library?\n\n```python\n\u003e\u003e\u003e from pyfasttext import FastText\n```\n\n### How to load an existing model?\n\n```python\n\u003e\u003e\u003e model = FastText('/path/to/model.bin')\n```\n\nor\n\n```python\n\u003e\u003e\u003e model = FastText()\n\u003e\u003e\u003e model.load_model('/path/to/model.bin')\n```\n\n### Word representation learning\n\nYou can use all the options provided by the `fastText` binary (`input`, `output`, `epoch`, `lr`, ...).  \nJust use keyword arguments in the training methods of the `FastText` object.\n\n#### Training using Skipgram\n\n```python\n\u003e\u003e\u003e model = FastText()\n\u003e\u003e\u003e model.skipgram(input='data.txt', output='model', epoch=100, lr=0.7)\n```\n#### Training using CBoW\n\n```python\n\u003e\u003e\u003e model = FastText()\n\u003e\u003e\u003e model.cbow(input='data.txt', output='model', epoch=100, lr=0.7)\n```\n\n### Word vectors\n\n#### Word vectors access\n\n##### Vector for a given word\n\nBy default, a single word vector is returned as a regular Python array of floats.\n\n```python\n\u003e\u003e\u003e model['dog']\narray('f', [-1.308749794960022, -1.8326224088668823, ...])\n```\n\n###### Numpy ndarray\n\nThe `model.get_numpy_vector(word)` method returns the word vector as a `numpy` `ndarray`.\n\n```python\n\u003e\u003e\u003e model.get_numpy_vector('dog')\narray([-1.30874979, -1.83262241, ...], dtype=float32)\n```\n\nIf you want a normalized vector (*i.e.* the vector divided by its norm), there is an optional boolean parameter named `normalized`.\n\n```python\n\u003e\u003e\u003e model.get_numpy_vector('dog', normalized=True)\narray([-0.07084749, -0.09920666, ...], dtype=float32)\n```\n##### Words for a given vector\n\nThe inverse operation of `model[word]` or `model.get_numpy_vector(word)` is `model.words_for_vector(vector, k)`.  \nIt returns a list of the `k` words closest to the provided vector. The default value for `k` is 1.\n\n```python\n\u003e\u003e\u003e king = model.get_numpy_vector('king')\n\u003e\u003e\u003e man = model.get_numpy_vector('man')\n\u003e\u003e\u003e woman = model.get_numpy_vector('woman')\n\u003e\u003e\u003e model.words_for_vector(king + woman - man, k=1)\n[('queen', 0.77121970653533936)]\n```\n\n##### Get the number of words in the model\n\n```python\n\u003e\u003e\u003e model.nwords\n500000\n```\n\n##### Get all the word vectors in a model\n\n```python\n\u003e\u003e\u003e for word in model.words:\n...   print(word, model[word])\n```\n\n###### Numpy ndarray\n\nIf you want all the word vectors as a big `numpy` `ndarray`, you can use the `numpy_normalized_vectors` member. Note that all these vectors are *normalized*.\n\n```python\n\u003e\u003e\u003e model.nwords\n500000\n\u003e\u003e\u003e model.numpy_normalized_vectors\narray([[-0.07549749, -0.09407753, ...],\n       [ 0.00635979, -0.17272158, ...],\n       ..., \n       [-0.01009259,  0.14604086, ...],\n       [ 0.12467574, -0.0609326 , ...]], dtype=float32)\n\u003e\u003e\u003e model.numpy_normalized_vectors.shape\n(500000, 100) # (number of words, dimension)\n```\n\n#### Misc operations with word vectors\n\n##### Word similarity\n\n```python\n\u003e\u003e\u003e model.similarity('dog', 'cat')\n0.75596606254577637\n```\n\n##### Most similar words\n\n```python\n\u003e\u003e\u003e model.nearest_neighbors('dog', k=2)\n[('dogs', 0.7843924736976624), ('cat', 75596606254577637)]\n```\n\n##### Analogies\n\nThe `model.most_similar()` method works similarly as the one in [gensim](https://radimrehurek.com/gensim/models/keyedvectors.html).\n\n```python\n\u003e\u003e\u003e model.most_similar(positive=['woman', 'king'], negative=['man'], k=1)\n[('queen', 0.77121970653533936)]\n```\n\n### Text classification\n\n#### Supervised learning\n\n```python\n\u003e\u003e\u003e model = FastText()\n\u003e\u003e\u003e model.supervised(input='/path/to/input.txt', output='/path/to/model', epoch=100, lr=0.7)\n```\n\n#### Get all the labels\n\n```python\n\u003e\u003e\u003e model.labels\n['LABEL1', 'LABEL2', ...]\n```\n\n#### Get the number of labels\n\n```python\n\u003e\u003e\u003e model.nlabels\n100\n```\n\n#### Prediction\n\nTo obtain the `k` most likely labels from test sentences, there are multiple `model.predict_*()` methods.  \nThe default value for `k` is 1. If you want to obtain all the possible labels, use `None` for `k`.\n\n##### Labels and probabilities\n\nIf you have a list of strings (or an iterable object), use this:\n\n```python\n\u003e\u003e\u003e model.predict_proba(['first sentence\\n', 'second sentence\\n'], k=2)\n[[('LABEL1', 0.99609375), ('LABEL3', 1.953126549381068e-08)], [('LABEL2', 1.0), ('LABEL3', 1.953126549381068e-08)]]\n```\n\nIf you want to test a single string, use this:\n\n```python\n\u003e\u003e\u003e model.predict_proba_single('first sentence\\n', k=2)\n[('LABEL1', 0.99609375), ('LABEL3', 1.953126549381068e-08)]\n```\n\n**WARNING**: In order to get the same probabilities as the `fastText` binary, you have to add a newline (`\\n`) at the end of each string.\n\nIf your test data is stored inside a file, use this:\n\n```python\n\u003e\u003e\u003e model.predict_proba_file('/path/to/test.txt', k=2)\n[[('LABEL1', 0.99609375), ('LABEL3', 1.953126549381068e-08)], [('LABEL2', 1.0), ('LABEL3', 1.953126549381068e-08)]]\n```\n\n###### Normalized probabilities\n\nFor performance reasons, fastText probabilities often do not sum up to 1.0.\n\nIf you want normalized probabilities (where the sum is closer to 1.0 than the original probabilities), you can use the `normalized=True` parameter in all the methods that output probabilities (`model.predict_proba()`, `model.predict_proba_file()` and `model.predict_proba_single()`).\n\n```python\n\u003e\u003e\u003e sum(proba for label, proba in model.predict_proba_single('this is a sentence that needs to be classified\\n', k=None))\n0.9785203068801335\n\u003e\u003e\u003e sum(proba for label, proba in model.predict_proba_single('this is a sentence that needs to be classified\\n', k=None, normalized=True))\n0.9999999999999898\n```\n\n##### Labels only\n\nIf you have a list of strings (or an iterable object), use this:\n\n```python\n\u003e\u003e\u003e model.predict(['first sentence\\n', 'second sentence\\n'], k=2)\n[['LABEL1', 'LABEL3'], ['LABEL2', 'LABEL3']]\n```\n\nIf you want to test a single string, use this:\n\n```python\n\u003e\u003e\u003e model.predict_single('first sentence\\n', k=2)\n['LABEL1', 'LABEL3']\n```\n\n**WARNING**: In order to get the same probabilities as the `fastText` binary, you have to add a newline (`\\n`) at the end of each string.\n\nIf your test data is stored inside a file, use this:\n\n```python\n\u003e\u003e\u003e model.predict_file('/path/to/test.txt', k=2)\n[['LABEL1', 'LABEL3'], ['LABEL2', 'LABEL3']]\n```\n\n#### Quantization\n\nUse keyword arguments in the `model.quantize()` method.\n\n```python\n\u003e\u003e\u003e model.quantize(input='/path/to/input.txt', output='/path/to/model')\n```\n\nYou can load quantized models using the `FastText` constructor or the `model.load_model()` method.\n\n##### Is a model quantized?\n\nIf you want to know if a model has been quantized before, use the `model.quantized` attribute.\n\n```python\n\u003e\u003e\u003e model = FastText('/path/to/model.bin')\n\u003e\u003e\u003e model.quantized\nFalse\n\u003e\u003e\u003e model = FastText('/path/to/model.ftz')\n\u003e\u003e\u003e model.quantized\nTrue\n```\n\n### Subwords\n\nfastText can use subwords (*i.e.* character ngrams) when doing unsupervised or supervised learning.\n\nYou can access the subwords, and their associated vectors, using `pyfasttext`.\n\n#### Get the subwords\n\nfastText's word embeddings can be augmented with subword-level information. It is possible to retrieve the subwords and their associated vectors from a model using `pyfasttext`.\n\nTo retrieve all the subwords for a given word, use the `model.get_all_subwords(word)` method.\n\n```python\n\u003e\u003e\u003e model.args.get('minn'), model.args.get('maxn')\n(2, 4)\n\u003e\u003e\u003e model.get_all_subwords('hello') # word + subwords from 2 to 4 characters\n['hello', '\u003ch', '\u003che', '\u003chel', 'he', 'hel', 'hell', 'el', 'ell', 'ello', 'll', 'llo', 'llo\u003e', 'lo', 'lo\u003e', 'o\u003e']\n```\n\nFor fastText, `\u003c` means \"beginning of a word\" and `\u003e` means \"end of a word\".\n\nAs you can see, fastText includes the full word. You can omit it using the `omit_word=True` keyword argument.\n\n```python\n\u003e\u003e\u003e model.get_all_subwords('hello', omit_word=True)\n['\u003ch', '\u003che', '\u003chel', 'he', 'hel', 'hell', 'el', 'ell', 'ello', 'll', 'llo', 'llo\u003e', 'lo', 'lo\u003e', 'o\u003e']\n```\n\nWhen a model is quantized, fastText may *prune* some subwords.\nIf you want to see only the subwords that are really used when computing a word vector, you should use the `model.get_subwords(word)` method.\n\n```python\n\u003e\u003e\u003e model.quantized\nTrue\n\u003e\u003e\u003e model.get_subwords('beautiful')\n['eau', 'aut', 'ful', 'ul']\n\u003e\u003e\u003e model.get_subwords('hello')\n['hello'] # fastText will not use any subwords when computing the word vector, only the full word\n```\n\n#### Get the subword vectors\n\nTo get the individual vectors given the subwords, use the `model.get_numpy_subword_vectors(word)` method.\n\n```python\n\u003e\u003e\u003e model.get_numpy_subword_vectors('beautiful') # 4 vectors, so 4 rows\narray([[ 0.49022141,  0.13586822,  ..., -0.14065443,  0.89617103], # subword \"eau\"\n       [-0.42594951,  0.06260503,  ..., -0.18182631,  0.34219387], # subword \"aut\"\n       [ 0.49958718,  2.93831301,  ..., -1.97498322, -1.16815805], # subword \"ful\"\n       [-0.4368791 , -1.92924356,  ...,  1.62921488, 1.90240896]], dtype=float32) # subword \"ul\"\n```\n\nIn fastText, the final word vector is the average of these individual vectors.\n\n```python\n\u003e\u003e\u003e import numpy as np\n\u003e\u003e\u003e vec1 = model.get_numpy_vector('beautiful')\n\u003e\u003e\u003e vecs2 = model.get_numpy_subword_vectors('beautiful')\n\u003e\u003e\u003e np.allclose(vec1, np.average(vecs2, axis=0))\nTrue\n```\n\n### Sentence and text vectors\n\nTo compute the vector of a sequence of words (*i.e.* a sentence), fastText uses two different methods:\n* one for unsupervised models\n* another one for supervised models\n\nWhen fastText computes a word vector, recall that it uses the average of the following vectors: the word itself and its subwords.\n\n#### Unsupervised models\n\nFor unsupervised models, the representation of a sentence for fastText is the average of the normalized word vectors.\n\nTo get the resulting vector as a regular Python array, use the `model.get_sentence_vector(line)` method.  \nTo get the resulting vector as a `numpy` `ndarray`, use the `model.get_numpy_sentence_vector(line)` method.\n\n```python\n\u003e\u003e\u003e vec = model.get_numpy_sentence_vector('beautiful cats')\n\u003e\u003e\u003e vec1 = model.get_numpy_vector('beautiful', normalized=True)\n\u003e\u003e\u003e vec2 = model.get_numpy_vector('cats', normalized=True)\n\u003e\u003e\u003e np.allclose(vec, np.average([vec1, vec2], axis=0)\nTrue\n```\n\n#### Supervised models\n\nFor supervised models, fastText uses the regular word vectors, as well as vectors computed using word ngrams (*i.e.* shorter sequences of words from the sentence). When computing the average, these vectors are not normalized.\n\nTo get the resulting vector as a regular Python array, use the `model.get_text_vector(line)` method.  \nTo get the resulting vector as a `numpy` `ndarray`, use the `model.get_numpy_text_vector(line)` method.\n\n```python\n\u003e\u003e\u003e model.get_numpy_sentence_vector('beautiful cats') # for an unsupervised model\narray([-0.20266785,  0.3407566 ,  ...,  0.03044436,  0.39055538], dtype=float32)\n\u003e\u003e\u003e model.get_numpy_text_vector('beautiful cats') # for a supervised model\narray([-0.20840774,  0.4289546 ,  ..., -0.00457615,  0.52417743], dtype=float32)\n```\n\n### Misc utilities\n\n#### Show the module version\n\n```python\n\u003e\u003e\u003e import pyfasttext\n\u003e\u003e\u003e pyfasttext.__version__\n'0.4.3'\n```\n\n#### Show fastText version\n\nAs there is no version number in fastText, we use the latest fastText commit hash (from `HEAD`) as a substitute.\n\n```python\n\u003e\u003e\u003e import pyfasttext\n\u003e\u003e\u003e pyfasttext.__fasttext_version__\n'431c9e2a9b5149369cc60fb9f5beba58dcf8ca17'\n```\n\n#### Show the model (hyper)parameters\n\n```python\n\u003e\u003e\u003e model.args\n{'bucket': 11000000,\n 'cutoff': 0,\n 'dim': 100,\n 'dsub': 2,\n 'epoch': 100,\n...\n}\n```\n\n#### Show the model version number\n\nfastText uses a versioning scheme for its generated models. You can retrieve the model version number using the `model.version` attribute.\n\n| version number | description |\n| :---: | :--- |\n| -1  | for really old models with no version number |\n| 11  | first version number added by fastText |\n| 12  | for models generated after fastText added support for subwords in supervised learning |\n\n```python\n\u003e\u003e\u003e model.version\n12\n```\n\n#### Extract labels or classes from a dataset\n\nYou can use the `FastText` object to extract labels or classes from a dataset.\nThe label prefix (which is `__label__` by default) is set using the `label` parameter in the constructor.\n\nIf you load an existing model, the label prefix will be the one defined in the model.\n\n```python\n\u003e\u003e\u003e model = FastText(label='__my_prefix__')\n```\n\n##### Extract labels\n\nThere can be multiple labels per line.\n\n```python\n\u003e\u003e\u003e model.extract_labels('/path/to/dataset1.txt')\n[['LABEL2', 'LABEL5'], ['LABEL1'], ...]\n```\n\n##### Extract classes\n\nThere can be only one class per line.\n\n```python\n\u003e\u003e\u003e model.extract_classes('/path/to/dataset2.txt')\n['LABEL3', 'LABEL1', 'LABEL2', ...]\n```\n\n### Exceptions\n\nThe `fastText` source code directly calls exit() when something wrong happens (*e.g.* a model file does not exist, ...).\n\nInstead of exiting, `pyfasttext` raises a Python exception (`RuntimeError`).\n\n```python\n\u003e\u003e\u003e import pyfasttext\n\u003e\u003e\u003e model = pyfasttext.FastText('/path/to/non-existing_model.bin')\nModel file cannot be opened for loading!\nTraceback (most recent call last):\n  File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\n  File \"src/pyfasttext.pyx\", line 124, in pyfasttext.FastText.__cinit__ (src/pyfasttext.cpp:1800)\n  File \"src/pyfasttext.pyx\", line 348, in pyfasttext.FastText.load_model (src/pyfasttext.cpp:5947)\nRuntimeError: fastext tried to exit: 1\n```\n\n### Interruptible operations\n\n`pyfasttext` uses `cysignals` to make all the computationally intensive operations (*e.g.* training) interruptible.\n\nTo easily interrupt such an operation, just type `Ctrl-C` in your Python shell.\n\n```python\n\u003e\u003e\u003e model.skipgram(input='/path/to/input.txt', output='/path/to/mymodel')\nRead 12M words\nNumber of words:  60237\nNumber of labels: 0\n... # type Ctrl-C during training\nTraceback (most recent call last):\n  File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\n  File \"src/pyfasttext.pyx\", line 680, in pyfasttext.FastText.skipgram (src/pyfasttext.cpp:11125)\n  File \"src/pyfasttext.pyx\", line 674, in pyfasttext.FastText.train (src/pyfasttext.cpp:11009)\n  File \"src/pyfasttext.pyx\", line 668, in pyfasttext.FastText.train (src/pyfasttext.cpp:10926)\n  File \"src/cysignals/signals.pyx\", line 94, in cysignals.signals.sig_raise_exception (build/src/cysignals/signals.c:1328)\nKeyboardInterrupt\n\u003e\u003e\u003e # you can have your shell back!\n```\n","funding_links":[],"categories":["文本数据和NLP","Feature Extraction"],"sub_categories":["Text/NLP"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvrasneur%2Fpyfasttext","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvrasneur%2Fpyfasttext","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvrasneur%2Fpyfasttext/lists"}