fasttext-turbo 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fasttext_turbo-0.1.0/LICENSE +21 -0
- fasttext_turbo-0.1.0/MANIFEST.in +5 -0
- fasttext_turbo-0.1.0/PKG-INFO +100 -0
- fasttext_turbo-0.1.0/PYPI.md +53 -0
- fasttext_turbo-0.1.0/README.md +379 -0
- fasttext_turbo-0.1.0/pyproject.toml +5 -0
- fasttext_turbo-0.1.0/python/README.md +322 -0
- fasttext_turbo-0.1.0/python/README.rst +406 -0
- fasttext_turbo-0.1.0/python/benchmarks/README.rst +3 -0
- fasttext_turbo-0.1.0/python/fasttext_module/fasttext/FastText.py +639 -0
- fasttext_turbo-0.1.0/python/fasttext_module/fasttext/__init__.py +22 -0
- fasttext_turbo-0.1.0/python/fasttext_module/fasttext/pybind/fasttext_pybind.cc +533 -0
- fasttext_turbo-0.1.0/python/fasttext_module/fasttext/tests/__init__.py +14 -0
- fasttext_turbo-0.1.0/python/fasttext_module/fasttext/tests/test_configurations.py +239 -0
- fasttext_turbo-0.1.0/python/fasttext_module/fasttext/tests/test_script.py +629 -0
- fasttext_turbo-0.1.0/python/fasttext_module/fasttext/util/__init__.py +15 -0
- fasttext_turbo-0.1.0/python/fasttext_module/fasttext/util/util.py +209 -0
- fasttext_turbo-0.1.0/python/fasttext_module/fasttext_turbo.egg-info/PKG-INFO +100 -0
- fasttext_turbo-0.1.0/python/fasttext_module/fasttext_turbo.egg-info/SOURCES.txt +56 -0
- fasttext_turbo-0.1.0/python/fasttext_module/fasttext_turbo.egg-info/dependency_links.txt +1 -0
- fasttext_turbo-0.1.0/python/fasttext_module/fasttext_turbo.egg-info/not-zip-safe +1 -0
- fasttext_turbo-0.1.0/python/fasttext_module/fasttext_turbo.egg-info/requires.txt +1 -0
- fasttext_turbo-0.1.0/python/fasttext_module/fasttext_turbo.egg-info/top_level.txt +2 -0
- fasttext_turbo-0.1.0/setup.cfg +7 -0
- fasttext_turbo-0.1.0/setup.py +214 -0
- fasttext_turbo-0.1.0/src/aligned.h +98 -0
- fasttext_turbo-0.1.0/src/args.cc +517 -0
- fasttext_turbo-0.1.0/src/args.h +102 -0
- fasttext_turbo-0.1.0/src/autotune.cc +477 -0
- fasttext_turbo-0.1.0/src/autotune.h +89 -0
- fasttext_turbo-0.1.0/src/densematrix.cc +399 -0
- fasttext_turbo-0.1.0/src/densematrix.h +87 -0
- fasttext_turbo-0.1.0/src/dictionary.cc +715 -0
- fasttext_turbo-0.1.0/src/dictionary.h +117 -0
- fasttext_turbo-0.1.0/src/fasttext.cc +846 -0
- fasttext_turbo-0.1.0/src/fasttext.h +170 -0
- fasttext_turbo-0.1.0/src/loss.cc +362 -0
- fasttext_turbo-0.1.0/src/loss.h +163 -0
- fasttext_turbo-0.1.0/src/main.cc +524 -0
- fasttext_turbo-0.1.0/src/matrix.cc +37 -0
- fasttext_turbo-0.1.0/src/matrix.h +51 -0
- fasttext_turbo-0.1.0/src/meter.cc +214 -0
- fasttext_turbo-0.1.0/src/meter.h +91 -0
- fasttext_turbo-0.1.0/src/model.cc +95 -0
- fasttext_turbo-0.1.0/src/model.h +82 -0
- fasttext_turbo-0.1.0/src/norm_table.h +218 -0
- fasttext_turbo-0.1.0/src/productquantizer.cc +251 -0
- fasttext_turbo-0.1.0/src/productquantizer.h +63 -0
- fasttext_turbo-0.1.0/src/quantmatrix.cc +125 -0
- fasttext_turbo-0.1.0/src/quantmatrix.h +61 -0
- fasttext_turbo-0.1.0/src/real.h +14 -0
- fasttext_turbo-0.1.0/src/textnorm.h +182 -0
- fasttext_turbo-0.1.0/src/unicode_fold.h +383 -0
- fasttext_turbo-0.1.0/src/utils.cc +53 -0
- fasttext_turbo-0.1.0/src/utils.h +72 -0
- fasttext_turbo-0.1.0/src/vector.cc +100 -0
- fasttext_turbo-0.1.0/src/vector.h +65 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2016-present, Facebook, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fasttext-turbo
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: fastText with faster inference and short-text training options; same models and API
|
|
5
|
+
Home-page: https://github.com/CommonGlot/fastText-turbo
|
|
6
|
+
Author: Onur Celebi
|
|
7
|
+
Author-email: celebio@fb.com
|
|
8
|
+
Maintainer: CommonGlot
|
|
9
|
+
Maintainer-email: commonglot@gmail.com
|
|
10
|
+
License: MIT
|
|
11
|
+
Project-URL: Source, https://github.com/CommonGlot/fastText-turbo
|
|
12
|
+
Project-URL: fastText, https://github.com/facebookresearch/fastText
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: Science/Research
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Classifier: Topic :: Software Development
|
|
24
|
+
Classifier: Topic :: Scientific/Engineering
|
|
25
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
26
|
+
Classifier: Operating System :: POSIX
|
|
27
|
+
Classifier: Operating System :: Unix
|
|
28
|
+
Classifier: Operating System :: MacOS
|
|
29
|
+
Requires-Python: >=3.9
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
License-File: LICENSE
|
|
32
|
+
Requires-Dist: numpy
|
|
33
|
+
Dynamic: author
|
|
34
|
+
Dynamic: author-email
|
|
35
|
+
Dynamic: classifier
|
|
36
|
+
Dynamic: description
|
|
37
|
+
Dynamic: description-content-type
|
|
38
|
+
Dynamic: home-page
|
|
39
|
+
Dynamic: license
|
|
40
|
+
Dynamic: license-file
|
|
41
|
+
Dynamic: maintainer
|
|
42
|
+
Dynamic: maintainer-email
|
|
43
|
+
Dynamic: project-url
|
|
44
|
+
Dynamic: requires-dist
|
|
45
|
+
Dynamic: requires-python
|
|
46
|
+
Dynamic: summary
|
|
47
|
+
|
|
48
|
+
# fastText-turbo
|
|
49
|
+
|
|
50
|
+
[fastText](https://github.com/facebookresearch/fastText) with faster
|
|
51
|
+
prediction and two optional training options. It is a drop-in replacement:
|
|
52
|
+
same `import fasttext`, same API, same command line and the same model files,
|
|
53
|
+
so models trained with fastText-turbo load in the official fastText and the
|
|
54
|
+
other way around.
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
pip uninstall fasttext # both packages install the `fasttext` module
|
|
58
|
+
pip install fasttext-turbo
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## What is different from fastText
|
|
62
|
+
|
|
63
|
+
- **Faster prediction, same labels.** The output layer is computed eight
|
|
64
|
+
labels at a time (on x86 with SIMD sums), top-k skips the log for labels
|
|
65
|
+
that cannot enter the top k, and subword hashes are computed
|
|
66
|
+
incrementally. Labels are the same as fastText's; probabilities are within
|
|
67
|
+
about 1e-5 on x86 and byte-identical on ARM. On one CPU core, GlotLID v3
|
|
68
|
+
(dimension 256) predicts about 4x faster on x86 and 1.7x on Apple silicon. See
|
|
69
|
+
[Fast Inference for fastText](https://commonglot.github.io/blog/fasttext-turbo.html)
|
|
70
|
+
for how it works and the full benchmarks.
|
|
71
|
+
- **Same trained models:** training gives byte-identical models to fastText.
|
|
72
|
+
- **Multi-threaded prediction on the command line:**
|
|
73
|
+
`fasttext predict model.bin input.txt k threshold threads`. The output
|
|
74
|
+
keeps the input order.
|
|
75
|
+
- **Training on short spans** (`-cropProb`, `-cropMin`, `-cropMax`,
|
|
76
|
+
`-cropUnit char|word`): with probability `cropProb` a training line is
|
|
77
|
+
replaced by a random span of its text, for robustness on short inputs.
|
|
78
|
+
- **Training on normalized lines** (`-normProb`): with probability `normProb`
|
|
79
|
+
a training line is lowercased and stripped of punctuation and digits, as
|
|
80
|
+
the CommonLID / OpenLID-v2 input cleaner does.
|
|
81
|
+
- **NumPy 1 and 2** are both supported.
|
|
82
|
+
|
|
83
|
+
Both training options are off by default; then training gives the same model
|
|
84
|
+
as fastText. They are not stored in the model file.
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
import fasttext
|
|
88
|
+
|
|
89
|
+
model = fasttext.train_supervised(
|
|
90
|
+
input="train.txt", minn=2, maxn=5, dim=64, epoch=3, lr=0.8,
|
|
91
|
+
crop_prob=0.3, crop_min=5, crop_max=20, crop_unit="char", norm_prob=0.3)
|
|
92
|
+
labels, probs = model.predict("Das ist ein kleiner Test", k=3)
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Everything else, including word vectors (`skipgram`, `cbow`), quantization
|
|
96
|
+
and autotune, works as documented in
|
|
97
|
+
[fastText](https://fasttext.cc/docs/en/python-module.html).
|
|
98
|
+
|
|
99
|
+
Source: <https://github.com/CommonGlot/fastText-turbo>. MIT license, like
|
|
100
|
+
fastText.
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# fastText-turbo
|
|
2
|
+
|
|
3
|
+
[fastText](https://github.com/facebookresearch/fastText) with faster
|
|
4
|
+
prediction and two optional training options. It is a drop-in replacement:
|
|
5
|
+
same `import fasttext`, same API, same command line and the same model files,
|
|
6
|
+
so models trained with fastText-turbo load in the official fastText and the
|
|
7
|
+
other way around.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip uninstall fasttext # both packages install the `fasttext` module
|
|
11
|
+
pip install fasttext-turbo
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## What is different from fastText
|
|
15
|
+
|
|
16
|
+
- **Faster prediction, same labels.** The output layer is computed eight
|
|
17
|
+
labels at a time (on x86 with SIMD sums), top-k skips the log for labels
|
|
18
|
+
that cannot enter the top k, and subword hashes are computed
|
|
19
|
+
incrementally. Labels are the same as fastText's; probabilities are within
|
|
20
|
+
about 1e-5 on x86 and byte-identical on ARM. On one CPU core, GlotLID v3
|
|
21
|
+
(dimension 256) predicts about 4x faster on x86 and 1.7x on Apple silicon. See
|
|
22
|
+
[Fast Inference for fastText](https://commonglot.github.io/blog/fasttext-turbo.html)
|
|
23
|
+
for how it works and the full benchmarks.
|
|
24
|
+
- **Same trained models:** training gives byte-identical models to fastText.
|
|
25
|
+
- **Multi-threaded prediction on the command line:**
|
|
26
|
+
`fasttext predict model.bin input.txt k threshold threads`. The output
|
|
27
|
+
keeps the input order.
|
|
28
|
+
- **Training on short spans** (`-cropProb`, `-cropMin`, `-cropMax`,
|
|
29
|
+
`-cropUnit char|word`): with probability `cropProb` a training line is
|
|
30
|
+
replaced by a random span of its text, for robustness on short inputs.
|
|
31
|
+
- **Training on normalized lines** (`-normProb`): with probability `normProb`
|
|
32
|
+
a training line is lowercased and stripped of punctuation and digits, as
|
|
33
|
+
the CommonLID / OpenLID-v2 input cleaner does.
|
|
34
|
+
- **NumPy 1 and 2** are both supported.
|
|
35
|
+
|
|
36
|
+
Both training options are off by default; then training gives the same model
|
|
37
|
+
as fastText. They are not stored in the model file.
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
import fasttext
|
|
41
|
+
|
|
42
|
+
model = fasttext.train_supervised(
|
|
43
|
+
input="train.txt", minn=2, maxn=5, dim=64, epoch=3, lr=0.8,
|
|
44
|
+
crop_prob=0.3, crop_min=5, crop_max=20, crop_unit="char", norm_prob=0.3)
|
|
45
|
+
labels, probs = model.predict("Das ist ein kleiner Test", k=3)
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Everything else, including word vectors (`skipgram`, `cbow`), quantization
|
|
49
|
+
and autotune, works as documented in
|
|
50
|
+
[fastText](https://fasttext.cc/docs/en/python-module.html).
|
|
51
|
+
|
|
52
|
+
Source: <https://github.com/CommonGlot/fastText-turbo>. MIT license, like
|
|
53
|
+
fastText.
|
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
# fastText-turbo
|
|
2
|
+
|
|
3
|
+
A fork of [fastText](https://github.com/facebookresearch/fastText) with the
|
|
4
|
+
same `import fasttext`, command line and model files, and:
|
|
5
|
+
|
|
6
|
+
- **Same models and labels:** trained models are byte-identical to
|
|
7
|
+
fastText's and load in either; predictions give the same labels, with
|
|
8
|
+
probabilities within about 1e-5 on x86 and byte-identical on ARM.
|
|
9
|
+
- **Faster prediction:** on one CPU core, GlotLID v3 (dimension 256) about
|
|
10
|
+
4x on x86 and 1.7x on Apple silicon; a dimension-64 model 2.6x on x86.
|
|
11
|
+
- **Multi-threaded prediction:** `fasttext predict model.bin input.txt k th threads`,
|
|
12
|
+
output in input order.
|
|
13
|
+
- **NumPy 1 and 2:** the `copy=False` calls that fail on NumPy 2 are fixed.
|
|
14
|
+
- **Short-text training:** `-cropProb`, `-cropMin`, `-cropMax`,
|
|
15
|
+
`-cropUnit char|word` train on random spans of each line.
|
|
16
|
+
- **Normalized-text training:** `-normProb` trains on lines lowercased and
|
|
17
|
+
stripped of punctuation and digits, like the CommonLID input cleaner.
|
|
18
|
+
- **Prebuilt wheels** for Linux, macOS and Windows, Python 3.9-3.13.
|
|
19
|
+
|
|
20
|
+
Both training options are off by default and are not stored in the model.
|
|
21
|
+
How it works and full benchmarks:
|
|
22
|
+
[Fast Inference for fastText](https://commonglot.github.io/blog/fasttext-turbo.html).
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pip uninstall fasttext # both packages install the `fasttext` module
|
|
26
|
+
pip install fasttext-turbo
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Usage is the same as fastText: the Python module is still `fasttext` and the
|
|
30
|
+
command-line tool is still `fasttext`, so existing code works unchanged.
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
import fasttext
|
|
34
|
+
|
|
35
|
+
model = fasttext.load_model("lid.176.bin") # any fastText model
|
|
36
|
+
labels, probs = model.predict("Bonjour tout le monde", k=2)
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
The rest of this README is fastText's.
|
|
40
|
+
|
|
41
|
+
# fastText
|
|
42
|
+
[fastText](https://fasttext.cc/) is a library for efficient learning of word representations and sentence classification.
|
|
43
|
+
|
|
44
|
+
[](https://circleci.com/gh/facebookresearch/fastText/tree/master)
|
|
45
|
+
|
|
46
|
+
## Table of contents
|
|
47
|
+
|
|
48
|
+
* [Resources](#resources)
|
|
49
|
+
* [Models](#models)
|
|
50
|
+
* [Supplementary data](#supplementary-data)
|
|
51
|
+
* [FAQ](#faq)
|
|
52
|
+
* [Cheatsheet](#cheatsheet)
|
|
53
|
+
* [Requirements](#requirements)
|
|
54
|
+
* [Building fastText](#building-fasttext)
|
|
55
|
+
* [Getting the source code](#getting-the-source-code)
|
|
56
|
+
* [Building fastText using make (preferred)](#building-fasttext-using-make-preferred)
|
|
57
|
+
* [Building fastText using cmake](#building-fasttext-using-cmake)
|
|
58
|
+
* [Building fastText for Python](#building-fasttext-for-python)
|
|
59
|
+
* [Example use cases](#example-use-cases)
|
|
60
|
+
* [Word representation learning](#word-representation-learning)
|
|
61
|
+
* [Obtaining word vectors for out-of-vocabulary words](#obtaining-word-vectors-for-out-of-vocabulary-words)
|
|
62
|
+
* [Text classification](#text-classification)
|
|
63
|
+
* [Full documentation](#full-documentation)
|
|
64
|
+
* [References](#references)
|
|
65
|
+
* [Enriching Word Vectors with Subword Information](#enriching-word-vectors-with-subword-information)
|
|
66
|
+
* [Bag of Tricks for Efficient Text Classification](#bag-of-tricks-for-efficient-text-classification)
|
|
67
|
+
* [FastText.zip: Compressing text classification models](#fasttextzip-compressing-text-classification-models)
|
|
68
|
+
* [Join the fastText community](#join-the-fasttext-community)
|
|
69
|
+
* [License](#license)
|
|
70
|
+
|
|
71
|
+
## Resources
|
|
72
|
+
|
|
73
|
+
### Models
|
|
74
|
+
- Recent state-of-the-art [English word vectors](https://fasttext.cc/docs/en/english-vectors.html).
|
|
75
|
+
- Word vectors for [157 languages trained on Wikipedia and Crawl](https://github.com/facebookresearch/fastText/blob/master/docs/crawl-vectors.md).
|
|
76
|
+
- Models for [language identification](https://fasttext.cc/docs/en/language-identification.html#content) and [various supervised tasks](https://fasttext.cc/docs/en/supervised-models.html#content).
|
|
77
|
+
|
|
78
|
+
### Supplementary data
|
|
79
|
+
- The preprocessed [YFCC100M data](https://fasttext.cc/docs/en/dataset.html#content) used in [2].
|
|
80
|
+
|
|
81
|
+
### FAQ
|
|
82
|
+
|
|
83
|
+
You can find [answers to frequently asked questions](https://fasttext.cc/docs/en/faqs.html#content) on our [website](https://fasttext.cc/).
|
|
84
|
+
|
|
85
|
+
### Cheatsheet
|
|
86
|
+
|
|
87
|
+
We also provide a [cheatsheet](https://fasttext.cc/docs/en/cheatsheet.html#content) full of useful one-liners.
|
|
88
|
+
|
|
89
|
+
## Requirements
|
|
90
|
+
|
|
91
|
+
We are continuously building and testing our library, CLI and Python bindings under various docker images using [circleci](https://circleci.com/).
|
|
92
|
+
|
|
93
|
+
Generally, **fastText** builds on modern Mac OS and Linux distributions.
|
|
94
|
+
Since it uses some C++11 features, it requires a compiler with good C++11 support.
|
|
95
|
+
These include :
|
|
96
|
+
|
|
97
|
+
* (g++-4.7.2 or newer) or (clang-3.3 or newer)
|
|
98
|
+
|
|
99
|
+
Compilation is carried out using a Makefile, so you will need to have a working **make**.
|
|
100
|
+
If you want to use **cmake** you need at least version 2.8.9.
|
|
101
|
+
|
|
102
|
+
One of the oldest distributions we successfully built and tested the CLI under is [Debian jessie](https://www.debian.org/releases/jessie/).
|
|
103
|
+
|
|
104
|
+
For the word-similarity evaluation script you will need:
|
|
105
|
+
|
|
106
|
+
* Python 2.6 or newer
|
|
107
|
+
* NumPy & SciPy
|
|
108
|
+
|
|
109
|
+
For the python bindings (see the subdirectory python) you will need:
|
|
110
|
+
|
|
111
|
+
* Python version 2.7 or >=3.4
|
|
112
|
+
* NumPy & SciPy
|
|
113
|
+
* [pybind11](https://github.com/pybind/pybind11)
|
|
114
|
+
|
|
115
|
+
One of the oldest distributions we successfully built and tested the Python bindings under is [Debian jessie](https://www.debian.org/releases/jessie/).
|
|
116
|
+
|
|
117
|
+
If these requirements make it impossible for you to use fastText, please open an issue and we will try to accommodate you.
|
|
118
|
+
|
|
119
|
+
## Building fastText
|
|
120
|
+
|
|
121
|
+
We discuss building the latest stable version of fastText.
|
|
122
|
+
|
|
123
|
+
### Getting the source code
|
|
124
|
+
|
|
125
|
+
You can find our [latest stable release](https://github.com/facebookresearch/fastText/releases/latest) in the usual place.
|
|
126
|
+
|
|
127
|
+
There is also the master branch that contains all of our most recent work, but comes along with all the usual caveats of an unstable branch. You might want to use this if you are a developer or power-user.
|
|
128
|
+
|
|
129
|
+
### Building fastText using make (preferred)
|
|
130
|
+
|
|
131
|
+
```
|
|
132
|
+
$ wget https://github.com/facebookresearch/fastText/archive/v0.9.2.zip
|
|
133
|
+
$ unzip v0.9.2.zip
|
|
134
|
+
$ cd fastText-0.9.2
|
|
135
|
+
$ make
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
This will produce object files for all the classes as well as the main binary `fasttext`.
|
|
139
|
+
If you do not plan on using the default system-wide compiler, update the two macros defined at the beginning of the Makefile (CC and INCLUDES).
|
|
140
|
+
|
|
141
|
+
### Building fastText using cmake
|
|
142
|
+
|
|
143
|
+
For now this is not part of a release, so you will need to clone the master branch.
|
|
144
|
+
|
|
145
|
+
```
|
|
146
|
+
$ git clone https://github.com/facebookresearch/fastText.git
|
|
147
|
+
$ cd fastText
|
|
148
|
+
$ mkdir build && cd build && cmake ..
|
|
149
|
+
$ make && make install
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
This will create the fasttext binary and also all relevant libraries (shared, static, PIC).
|
|
153
|
+
|
|
154
|
+
### Building fastText for Python
|
|
155
|
+
|
|
156
|
+
For now this is not part of a release, so you will need to clone the master branch.
|
|
157
|
+
|
|
158
|
+
```
|
|
159
|
+
$ git clone https://github.com/facebookresearch/fastText.git
|
|
160
|
+
$ cd fastText
|
|
161
|
+
$ pip install .
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
For further information and introduction see python/README.md
|
|
165
|
+
|
|
166
|
+
## Example use cases
|
|
167
|
+
|
|
168
|
+
This library has two main use cases: word representation learning and text classification.
|
|
169
|
+
These were described in the two papers [1](#enriching-word-vectors-with-subword-information) and [2](#bag-of-tricks-for-efficient-text-classification).
|
|
170
|
+
|
|
171
|
+
### Word representation learning
|
|
172
|
+
|
|
173
|
+
In order to learn word vectors, as described in [1](#enriching-word-vectors-with-subword-information), do:
|
|
174
|
+
|
|
175
|
+
```
|
|
176
|
+
$ ./fasttext skipgram -input data.txt -output model
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
where `data.txt` is a training file containing `UTF-8` encoded text.
|
|
180
|
+
By default the word vectors will take into account character n-grams from 3 to 6 characters.
|
|
181
|
+
At the end of optimization the program will save two files: `model.bin` and `model.vec`.
|
|
182
|
+
`model.vec` is a text file containing the word vectors, one per line.
|
|
183
|
+
`model.bin` is a binary file containing the parameters of the model along with the dictionary and all hyper parameters.
|
|
184
|
+
The binary file can be used later to compute word vectors or to restart the optimization.
|
|
185
|
+
|
|
186
|
+
### Obtaining word vectors for out-of-vocabulary words
|
|
187
|
+
|
|
188
|
+
The previously trained model can be used to compute word vectors for out-of-vocabulary words.
|
|
189
|
+
Provided you have a text file `queries.txt` containing words for which you want to compute vectors, use the following command:
|
|
190
|
+
|
|
191
|
+
```
|
|
192
|
+
$ ./fasttext print-word-vectors model.bin < queries.txt
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
This will output word vectors to the standard output, one vector per line.
|
|
196
|
+
This can also be used with pipes:
|
|
197
|
+
|
|
198
|
+
```
|
|
199
|
+
$ cat queries.txt | ./fasttext print-word-vectors model.bin
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
See the provided scripts for an example. For instance, running:
|
|
203
|
+
|
|
204
|
+
```
|
|
205
|
+
$ ./word-vector-example.sh
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
will compile the code, download data, compute word vectors and evaluate them on the rare words similarity dataset RW [Thang et al. 2013].
|
|
209
|
+
|
|
210
|
+
### Text classification
|
|
211
|
+
|
|
212
|
+
This library can also be used to train supervised text classifiers, for instance for sentiment analysis.
|
|
213
|
+
In order to train a text classifier using the method described in [2](#bag-of-tricks-for-efficient-text-classification), use:
|
|
214
|
+
|
|
215
|
+
```
|
|
216
|
+
$ ./fasttext supervised -input train.txt -output model
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
where `train.txt` is a text file containing a training sentence per line along with the labels.
|
|
220
|
+
By default, we assume that labels are words that are prefixed by the string `__label__`.
|
|
221
|
+
This will output two files: `model.bin` and `model.vec`.
|
|
222
|
+
Once the model was trained, you can evaluate it by computing the precision and recall at k (P@k and R@k) on a test set using:
|
|
223
|
+
|
|
224
|
+
```
|
|
225
|
+
$ ./fasttext test model.bin test.txt k
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
The argument `k` is optional, and is equal to `1` by default.
|
|
229
|
+
|
|
230
|
+
In order to obtain the k most likely labels for a piece of text, use:
|
|
231
|
+
|
|
232
|
+
```
|
|
233
|
+
$ ./fasttext predict model.bin test.txt k
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
or use `predict-prob` to also get the probability for each label
|
|
237
|
+
|
|
238
|
+
```
|
|
239
|
+
$ ./fasttext predict-prob model.bin test.txt k
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
where `test.txt` contains a piece of text to classify per line.
|
|
243
|
+
Doing so will print to the standard output the k most likely labels for each line.
|
|
244
|
+
The argument `k` is optional, and equal to `1` by default.
|
|
245
|
+
See `classification-example.sh` for an example use case.
|
|
246
|
+
In order to reproduce results from the paper [2](#bag-of-tricks-for-efficient-text-classification), run `classification-results.sh`, this will download all the datasets and reproduce the results from Table 1.
|
|
247
|
+
|
|
248
|
+
If you want to compute vector representations of sentences or paragraphs, please use:
|
|
249
|
+
|
|
250
|
+
```
|
|
251
|
+
$ ./fasttext print-sentence-vectors model.bin < text.txt
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
This assumes that the `text.txt` file contains the paragraphs that you want to get vectors for.
|
|
255
|
+
The program will output one vector representation per line in the file.
|
|
256
|
+
|
|
257
|
+
You can also quantize a supervised model to reduce its memory usage with the following command:
|
|
258
|
+
|
|
259
|
+
```
|
|
260
|
+
$ ./fasttext quantize -output model
|
|
261
|
+
```
|
|
262
|
+
This will create a `.ftz` file with a smaller memory footprint. All the standard functionality, like `test` or `predict` work the same way on the quantized models:
|
|
263
|
+
```
|
|
264
|
+
$ ./fasttext test model.ftz test.txt
|
|
265
|
+
```
|
|
266
|
+
The quantization procedure follows the steps described in [3](#fasttextzip-compressing-text-classification-models). You can
|
|
267
|
+
run the script `quantization-example.sh` for an example.
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
## Full documentation
|
|
271
|
+
|
|
272
|
+
Invoke a command without arguments to list available arguments and their default values:
|
|
273
|
+
|
|
274
|
+
```
|
|
275
|
+
$ ./fasttext supervised
|
|
276
|
+
Empty input or output path.
|
|
277
|
+
|
|
278
|
+
The following arguments are mandatory:
|
|
279
|
+
-input training file path
|
|
280
|
+
-output output file path
|
|
281
|
+
|
|
282
|
+
The following arguments are optional:
|
|
283
|
+
-verbose verbosity level [2]
|
|
284
|
+
|
|
285
|
+
The following arguments for the dictionary are optional:
|
|
286
|
+
-minCount minimal number of word occurrences [1]
|
|
287
|
+
-minCountLabel minimal number of label occurrences [0]
|
|
288
|
+
-wordNgrams max length of word ngram [1]
|
|
289
|
+
-bucket number of buckets [2000000]
|
|
290
|
+
-minn min length of char ngram [0]
|
|
291
|
+
-maxn max length of char ngram [0]
|
|
292
|
+
-t sampling threshold [0.0001]
|
|
293
|
+
-label labels prefix [__label__]
|
|
294
|
+
|
|
295
|
+
The following arguments for training are optional:
|
|
296
|
+
-lr learning rate [0.1]
|
|
297
|
+
-lrUpdateRate change the rate of updates for the learning rate [100]
|
|
298
|
+
-dim size of word vectors [100]
|
|
299
|
+
-ws size of the context window [5]
|
|
300
|
+
-epoch number of epochs [5]
|
|
301
|
+
-neg number of negatives sampled [5]
|
|
302
|
+
-loss loss function {ns, hs, softmax} [softmax]
|
|
303
|
+
-thread number of threads [12]
|
|
304
|
+
-pretrainedVectors pretrained word vectors for supervised learning []
|
|
305
|
+
-saveOutput whether output params should be saved [0]
|
|
306
|
+
|
|
307
|
+
The following arguments for quantization are optional:
|
|
308
|
+
-cutoff number of words and ngrams to retain [0]
|
|
309
|
+
-retrain finetune embeddings if a cutoff is applied [0]
|
|
310
|
+
-qnorm quantizing the norm separately [0]
|
|
311
|
+
-qout quantizing the classifier [0]
|
|
312
|
+
-dsub size of each sub-vector [2]
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
Defaults may vary by mode. (Word-representation modes `skipgram` and `cbow` use a default `-minCount` of 5.)
|
|
316
|
+
|
|
317
|
+
## References
|
|
318
|
+
|
|
319
|
+
Please cite [1](#enriching-word-vectors-with-subword-information) if using this code for learning word representations or [2](#bag-of-tricks-for-efficient-text-classification) if using for text classification.
|
|
320
|
+
|
|
321
|
+
### Enriching Word Vectors with Subword Information
|
|
322
|
+
|
|
323
|
+
[1] P. Bojanowski\*, E. Grave\*, A. Joulin, T. Mikolov, [*Enriching Word Vectors with Subword Information*](https://arxiv.org/abs/1607.04606)
|
|
324
|
+
|
|
325
|
+
```
|
|
326
|
+
@article{bojanowski2017enriching,
|
|
327
|
+
title={Enriching Word Vectors with Subword Information},
|
|
328
|
+
author={Bojanowski, Piotr and Grave, Edouard and Joulin, Armand and Mikolov, Tomas},
|
|
329
|
+
journal={Transactions of the Association for Computational Linguistics},
|
|
330
|
+
volume={5},
|
|
331
|
+
year={2017},
|
|
332
|
+
issn={2307-387X},
|
|
333
|
+
pages={135--146}
|
|
334
|
+
}
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
### Bag of Tricks for Efficient Text Classification
|
|
338
|
+
|
|
339
|
+
[2] A. Joulin, E. Grave, P. Bojanowski, T. Mikolov, [*Bag of Tricks for Efficient Text Classification*](https://arxiv.org/abs/1607.01759)
|
|
340
|
+
|
|
341
|
+
```
|
|
342
|
+
@InProceedings{joulin2017bag,
|
|
343
|
+
title={Bag of Tricks for Efficient Text Classification},
|
|
344
|
+
author={Joulin, Armand and Grave, Edouard and Bojanowski, Piotr and Mikolov, Tomas},
|
|
345
|
+
booktitle={Proceedings of the 15th Conference of the European Chapter of the Association for Computational Linguistics: Volume 2, Short Papers},
|
|
346
|
+
month={April},
|
|
347
|
+
year={2017},
|
|
348
|
+
publisher={Association for Computational Linguistics},
|
|
349
|
+
pages={427--431},
|
|
350
|
+
}
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
### FastText.zip: Compressing text classification models
|
|
354
|
+
|
|
355
|
+
[3] A. Joulin, E. Grave, P. Bojanowski, M. Douze, H. Jégou, T. Mikolov, [*FastText.zip: Compressing text classification models*](https://arxiv.org/abs/1612.03651)
|
|
356
|
+
|
|
357
|
+
```
|
|
358
|
+
@article{joulin2016fasttext,
|
|
359
|
+
title={FastText.zip: Compressing text classification models},
|
|
360
|
+
author={Joulin, Armand and Grave, Edouard and Bojanowski, Piotr and Douze, Matthijs and J{\'e}gou, H{\'e}rve and Mikolov, Tomas},
|
|
361
|
+
journal={arXiv preprint arXiv:1612.03651},
|
|
362
|
+
year={2016}
|
|
363
|
+
}
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
(\* These authors contributed equally.)
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
## Join the fastText community
|
|
370
|
+
|
|
371
|
+
* Facebook page: https://www.facebook.com/groups/1174547215919768
|
|
372
|
+
* Google group: https://groups.google.com/forum/#!forum/fasttext-library
|
|
373
|
+
* Contact: [egrave@fb.com](mailto:egrave@fb.com), [bojanowski@fb.com](mailto:bojanowski@fb.com), [ajoulin@fb.com](mailto:ajoulin@fb.com), [tmikolov@fb.com](mailto:tmikolov@fb.com)
|
|
374
|
+
|
|
375
|
+
See the CONTRIBUTING file for information about how to help out.
|
|
376
|
+
|
|
377
|
+
## License
|
|
378
|
+
|
|
379
|
+
fastText is MIT-licensed.
|