fastfloret 0.11.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.
- fastfloret-0.11.0/.gitignore +15 -0
- fastfloret-0.11.0/CMakeLists.txt +80 -0
- fastfloret-0.11.0/LICENSE +21 -0
- fastfloret-0.11.0/Makefile +69 -0
- fastfloret-0.11.0/PKG-INFO +129 -0
- fastfloret-0.11.0/README.md +549 -0
- fastfloret-0.11.0/examples/01_intro_to_floret.ipynb +550 -0
- fastfloret-0.11.0/floret.pc.in +10 -0
- fastfloret-0.11.0/noxfile.py +26 -0
- fastfloret-0.11.0/pyproject.toml +57 -0
- fastfloret-0.11.0/python/CMakeLists.txt +34 -0
- fastfloret-0.11.0/python/README.md +98 -0
- fastfloret-0.11.0/python/fastfloret_module/fastfloret/__init__.py +17 -0
- fastfloret-0.11.0/python/fastfloret_module/fastfloret/floret.py +587 -0
- fastfloret-0.11.0/python/fastfloret_module/fastfloret/pybind/fastfloret_pybind.cc +533 -0
- fastfloret-0.11.0/python/fastfloret_module/fastfloret/tests/README.md +3 -0
- fastfloret-0.11.0/python/fastfloret_module/fastfloret/tests/__init__.py +9 -0
- fastfloret-0.11.0/python/fastfloret_module/fastfloret/tests/data.txt +100 -0
- fastfloret-0.11.0/python/fastfloret_module/fastfloret/tests/test_configurations.py +234 -0
- fastfloret-0.11.0/python/fastfloret_module/fastfloret/tests/test_script.py +606 -0
- fastfloret-0.11.0/python/fastfloret_module/fastfloret/tests/test_tokenize.py +5 -0
- fastfloret-0.11.0/python/fastfloret_module/fastfloret/tests/test_train.py +74 -0
- fastfloret-0.11.0/python/fastfloret_module/fastfloret/util/__init__.py +10 -0
- fastfloret-0.11.0/python/fastfloret_module/fastfloret/util/util.py +201 -0
- fastfloret-0.11.0/requirements.txt +1 -0
- fastfloret-0.11.0/src/MurmurHash3.cpp +366 -0
- fastfloret-0.11.0/src/MurmurHash3.h +28 -0
- fastfloret-0.11.0/src/args.cc +538 -0
- fastfloret-0.11.0/src/args.h +101 -0
- fastfloret-0.11.0/src/autotune.cc +477 -0
- fastfloret-0.11.0/src/autotune.h +89 -0
- fastfloret-0.11.0/src/densematrix.cc +175 -0
- fastfloret-0.11.0/src/densematrix.h +83 -0
- fastfloret-0.11.0/src/dictionary.cc +577 -0
- fastfloret-0.11.0/src/dictionary.h +113 -0
- fastfloret-0.11.0/src/fasttext.cc +906 -0
- fastfloret-0.11.0/src/fasttext.h +172 -0
- fastfloret-0.11.0/src/loss.cc +346 -0
- fastfloret-0.11.0/src/loss.h +163 -0
- fastfloret-0.11.0/src/main.cc +476 -0
- fastfloret-0.11.0/src/matrix.cc +25 -0
- fastfloret-0.11.0/src/matrix.h +44 -0
- fastfloret-0.11.0/src/meter.cc +214 -0
- fastfloret-0.11.0/src/meter.h +91 -0
- fastfloret-0.11.0/src/model.cc +97 -0
- fastfloret-0.11.0/src/model.h +79 -0
- fastfloret-0.11.0/src/productquantizer.cc +251 -0
- fastfloret-0.11.0/src/productquantizer.h +63 -0
- fastfloret-0.11.0/src/quantmatrix.cc +117 -0
- fastfloret-0.11.0/src/quantmatrix.h +60 -0
- fastfloret-0.11.0/src/real.h +14 -0
- fastfloret-0.11.0/src/utils.cc +53 -0
- fastfloret-0.11.0/src/utils.h +72 -0
- fastfloret-0.11.0/src/vector.cc +96 -0
- fastfloret-0.11.0/src/vector.h +61 -0
- fastfloret-0.11.0/tests/fetch_test_data.sh +202 -0
- fastfloret-0.11.0/tests/runtests.py +55 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (c) 2016-present, Facebook, Inc.
|
|
3
|
+
# All rights reserved.
|
|
4
|
+
#
|
|
5
|
+
# This source code is licensed under the MIT license found in the
|
|
6
|
+
# LICENSE file in the root directory of this source tree.
|
|
7
|
+
#
|
|
8
|
+
|
|
9
|
+
cmake_minimum_required(VERSION 2.8.9)
|
|
10
|
+
project(floret)
|
|
11
|
+
|
|
12
|
+
# The version number.
|
|
13
|
+
set (floret_VERSION_MAJOR 0)
|
|
14
|
+
set (floret_VERSION_MINOR 1)
|
|
15
|
+
|
|
16
|
+
include_directories(fasttext)
|
|
17
|
+
|
|
18
|
+
set(CMAKE_CXX_FLAGS " -pthread -std=c++11 -funroll-loops -O3")
|
|
19
|
+
|
|
20
|
+
set(HEADER_FILES
|
|
21
|
+
src/MurmurHash3.h
|
|
22
|
+
src/args.h
|
|
23
|
+
src/autotune.h
|
|
24
|
+
src/densematrix.h
|
|
25
|
+
src/dictionary.h
|
|
26
|
+
src/fasttext.h
|
|
27
|
+
src/loss.h
|
|
28
|
+
src/matrix.h
|
|
29
|
+
src/meter.h
|
|
30
|
+
src/model.h
|
|
31
|
+
src/productquantizer.h
|
|
32
|
+
src/quantmatrix.h
|
|
33
|
+
src/real.h
|
|
34
|
+
src/utils.h
|
|
35
|
+
src/vector.h)
|
|
36
|
+
|
|
37
|
+
set(SOURCE_FILES
|
|
38
|
+
src/MurmurHash3.cpp
|
|
39
|
+
src/args.cc
|
|
40
|
+
src/autotune.cc
|
|
41
|
+
src/densematrix.cc
|
|
42
|
+
src/dictionary.cc
|
|
43
|
+
src/fasttext.cc
|
|
44
|
+
src/loss.cc
|
|
45
|
+
src/main.cc
|
|
46
|
+
src/matrix.cc
|
|
47
|
+
src/meter.cc
|
|
48
|
+
src/model.cc
|
|
49
|
+
src/productquantizer.cc
|
|
50
|
+
src/quantmatrix.cc
|
|
51
|
+
src/utils.cc
|
|
52
|
+
src/vector.cc)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
if (NOT MSVC)
|
|
56
|
+
include(GNUInstallDirs)
|
|
57
|
+
configure_file("floret.pc.in" "floret.pc" @ONLY)
|
|
58
|
+
install(FILES "${CMAKE_BINARY_DIR}/floret.pc" DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
|
|
59
|
+
endif()
|
|
60
|
+
|
|
61
|
+
add_library(floret-shared SHARED ${SOURCE_FILES} ${HEADER_FILES})
|
|
62
|
+
add_library(floret-static STATIC ${SOURCE_FILES} ${HEADER_FILES})
|
|
63
|
+
add_library(floret-static_pic STATIC ${SOURCE_FILES} ${HEADER_FILES})
|
|
64
|
+
set_target_properties(floret-shared PROPERTIES OUTPUT_NAME floret
|
|
65
|
+
SOVERSION "${floret_VERSION_MAJOR}")
|
|
66
|
+
set_target_properties(floret-static PROPERTIES OUTPUT_NAME floret)
|
|
67
|
+
set_target_properties(floret-static_pic PROPERTIES OUTPUT_NAME floret_pic
|
|
68
|
+
POSITION_INDEPENDENT_CODE True)
|
|
69
|
+
add_executable(floret-bin src/main.cc)
|
|
70
|
+
target_link_libraries(floret-bin pthread floret-static)
|
|
71
|
+
set_target_properties(floret-bin PROPERTIES PUBLIC_HEADER "${HEADER_FILES}" OUTPUT_NAME floret)
|
|
72
|
+
install (TARGETS floret-shared
|
|
73
|
+
LIBRARY DESTINATION lib)
|
|
74
|
+
install (TARGETS floret-static
|
|
75
|
+
ARCHIVE DESTINATION lib)
|
|
76
|
+
install (TARGETS floret-static_pic
|
|
77
|
+
ARCHIVE DESTINATION lib)
|
|
78
|
+
install (TARGETS floret-bin
|
|
79
|
+
RUNTIME DESTINATION bin
|
|
80
|
+
PUBLIC_HEADER DESTINATION include/floret)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021-present ExplosionAI GmbH; 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,69 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (c) 2016-present, Facebook, Inc.
|
|
3
|
+
# All rights reserved.
|
|
4
|
+
#
|
|
5
|
+
# This source code is licensed under the MIT license found in the
|
|
6
|
+
# LICENSE file in the root directory of this source tree.
|
|
7
|
+
#
|
|
8
|
+
|
|
9
|
+
CXX = c++
|
|
10
|
+
CXXFLAGS = -pthread -std=c++11
|
|
11
|
+
OBJS = args.o autotune.o matrix.o dictionary.o MurmurHash3.o loss.o productquantizer.o densematrix.o quantmatrix.o vector.o model.o utils.o meter.o fasttext.o
|
|
12
|
+
INCLUDES = -I.
|
|
13
|
+
|
|
14
|
+
opt: CXXFLAGS += -O3 -funroll-loops -DNDEBUG
|
|
15
|
+
opt: floret
|
|
16
|
+
|
|
17
|
+
coverage: CXXFLAGS += -O0 -fno-inline -fprofile-arcs --coverage
|
|
18
|
+
coverage: floret
|
|
19
|
+
|
|
20
|
+
debug: CXXFLAGS += -g -O0 -fno-inline
|
|
21
|
+
debug: floret
|
|
22
|
+
|
|
23
|
+
args.o: src/args.cc src/args.h
|
|
24
|
+
$(CXX) $(CXXFLAGS) -c src/args.cc
|
|
25
|
+
|
|
26
|
+
autotune.o: src/autotune.cc src/autotune.h
|
|
27
|
+
$(CXX) $(CXXFLAGS) -c src/autotune.cc
|
|
28
|
+
|
|
29
|
+
matrix.o: src/matrix.cc src/matrix.h
|
|
30
|
+
$(CXX) $(CXXFLAGS) -c src/matrix.cc
|
|
31
|
+
|
|
32
|
+
dictionary.o: src/dictionary.cc src/dictionary.h src/args.h src/MurmurHash3.h
|
|
33
|
+
$(CXX) $(CXXFLAGS) -c src/dictionary.cc
|
|
34
|
+
|
|
35
|
+
MurmurHash3.o: src/MurmurHash3.cpp src/MurmurHash3.h
|
|
36
|
+
$(CXX) $(CXXFLAGS) -c src/MurmurHash3.cpp
|
|
37
|
+
|
|
38
|
+
loss.o: src/loss.cc src/loss.h src/matrix.h src/real.h
|
|
39
|
+
$(CXX) $(CXXFLAGS) -c src/loss.cc
|
|
40
|
+
|
|
41
|
+
productquantizer.o: src/productquantizer.cc src/productquantizer.h src/utils.h
|
|
42
|
+
$(CXX) $(CXXFLAGS) -c src/productquantizer.cc
|
|
43
|
+
|
|
44
|
+
densematrix.o: src/densematrix.cc src/densematrix.h src/utils.h src/matrix.h
|
|
45
|
+
$(CXX) $(CXXFLAGS) -c src/densematrix.cc
|
|
46
|
+
|
|
47
|
+
quantmatrix.o: src/quantmatrix.cc src/quantmatrix.h src/utils.h src/matrix.h
|
|
48
|
+
$(CXX) $(CXXFLAGS) -c src/quantmatrix.cc
|
|
49
|
+
|
|
50
|
+
vector.o: src/vector.cc src/vector.h src/utils.h
|
|
51
|
+
$(CXX) $(CXXFLAGS) -c src/vector.cc
|
|
52
|
+
|
|
53
|
+
model.o: src/model.cc src/model.h src/args.h
|
|
54
|
+
$(CXX) $(CXXFLAGS) -c src/model.cc
|
|
55
|
+
|
|
56
|
+
utils.o: src/utils.cc src/utils.h
|
|
57
|
+
$(CXX) $(CXXFLAGS) -c src/utils.cc
|
|
58
|
+
|
|
59
|
+
meter.o: src/meter.cc src/meter.h
|
|
60
|
+
$(CXX) $(CXXFLAGS) -c src/meter.cc
|
|
61
|
+
|
|
62
|
+
fasttext.o: src/fasttext.cc src/*.h
|
|
63
|
+
$(CXX) $(CXXFLAGS) -c src/fasttext.cc
|
|
64
|
+
|
|
65
|
+
floret: $(OBJS) src/fasttext.cc src/main.cc
|
|
66
|
+
$(CXX) $(CXXFLAGS) $(OBJS) src/main.cc -o floret
|
|
67
|
+
|
|
68
|
+
clean:
|
|
69
|
+
rm -rf *.o floret
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fastfloret
|
|
3
|
+
Version: 0.11.0
|
|
4
|
+
Summary: fasttext + floret Python bindings
|
|
5
|
+
Author-Email: spiqueras <piqueras.santi@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Intended Audience :: Science/Research
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
18
|
+
Classifier: Programming Language :: Python :: Free Threading
|
|
19
|
+
Classifier: Programming Language :: C++
|
|
20
|
+
Classifier: Topic :: Software Development
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering
|
|
22
|
+
Classifier: Operating System :: POSIX
|
|
23
|
+
Classifier: Operating System :: Unix
|
|
24
|
+
Classifier: Operating System :: MacOS
|
|
25
|
+
Project-URL: Homepage, https://github.com/spiqueras/fastfloret
|
|
26
|
+
Requires-Python: >=3.11
|
|
27
|
+
Requires-Dist: numpy<3.0.0,>=1.26.4
|
|
28
|
+
Provides-Extra: test
|
|
29
|
+
Requires-Dist: pytest; extra == "test"
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
# fastfloret: fastText + floret for your Python needs
|
|
33
|
+
|
|
34
|
+
This library is a fork of [floret](https://github.com/explosion/floret) modified
|
|
35
|
+
to build and run in modern (>3.13) Python.
|
|
36
|
+
|
|
37
|
+
A rough overview of the changes:
|
|
38
|
+
- [Fix the build](https://github.com/explosion/floret/issues/31)
|
|
39
|
+
- Allow using numpy 2 and up and make it mandatory
|
|
40
|
+
- Generate and upload updated wheels to Pypi
|
|
41
|
+
|
|
42
|
+
For compatibility, you may import it as floret:
|
|
43
|
+
```python
|
|
44
|
+
import fastfloret as floret
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Or not, I won't judge.
|
|
48
|
+
|
|
49
|
+
The original floret README is provided below for reference.
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
<a href="https://explosion.ai"><img src="https://explosion.ai/assets/img/logo.svg" width="125" height="125" align="right" /></a>
|
|
54
|
+
|
|
55
|
+
# floret: fastText + Bloom embeddings for compact, full-coverage vectors with spaCy
|
|
56
|
+
|
|
57
|
+
floret is an extended version of [fastText](https://fasttext.cc) that can
|
|
58
|
+
produce word representations for any word from a compact vector table. It
|
|
59
|
+
combines:
|
|
60
|
+
|
|
61
|
+
- fastText's subwords to provide embeddings for any word
|
|
62
|
+
- Bloom embeddings ("hashing trick") for a compact vector table
|
|
63
|
+
|
|
64
|
+
## Installation
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
pip install floret
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Usage
|
|
71
|
+
|
|
72
|
+
Train floret vectors using the options:
|
|
73
|
+
|
|
74
|
+
- `mode`: `"floret"`, storing both words and subwords in the same compact hash
|
|
75
|
+
table
|
|
76
|
+
- `hashCount`: store each entry in 1-4 rows in the hash table (recommended:
|
|
77
|
+
`2`)
|
|
78
|
+
- `bucket`: in combination with `hashCount>1`, the size of the hash table can
|
|
79
|
+
be greatly reduced (recommended: `25000`--`100000`, reduced from the fastText
|
|
80
|
+
default of `2000000`)
|
|
81
|
+
- `minn`: min length of char ngram (default: `3`)
|
|
82
|
+
- `maxn`: max length of char ngram (default: `6`)
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
import floret
|
|
86
|
+
|
|
87
|
+
# train vectors
|
|
88
|
+
model = floret.train_unsupervised(
|
|
89
|
+
"data.txt",
|
|
90
|
+
model="cbow",
|
|
91
|
+
mode="floret",
|
|
92
|
+
hashCount=2,
|
|
93
|
+
bucket=50000,
|
|
94
|
+
minn=3,
|
|
95
|
+
maxn=6,
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
# query vector
|
|
99
|
+
model.get_word_vector("broccoli")
|
|
100
|
+
|
|
101
|
+
# save full model
|
|
102
|
+
model.save_model("vectors.bin")
|
|
103
|
+
|
|
104
|
+
# export standard word-only vector table
|
|
105
|
+
model.save_vectors("vectors.vec")
|
|
106
|
+
|
|
107
|
+
# export floret vector table
|
|
108
|
+
model.save_floret_vectors("vectors.floret")
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
**Note:** with the default setting `mode="fasttext"`, `floret` trains original
|
|
112
|
+
fastText vectors.
|
|
113
|
+
|
|
114
|
+
## Use floret vectors in spaCy
|
|
115
|
+
|
|
116
|
+
Import floret vectors into spaCy v3.2+:
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
spacy init vectors LANG vectors.floret spacy_vectors_model --mode floret
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Notes
|
|
123
|
+
|
|
124
|
+
`floret` contains all features of the original [`fasttext`
|
|
125
|
+
module](https://pypi.org/project/fasttext). See the [`fasttext`
|
|
126
|
+
docs](https://fasttext.cc/docs/en/python-module.html) for more information.
|
|
127
|
+
|
|
128
|
+
The `fasttext` and `floret` binary formats saved with
|
|
129
|
+
`model.save_model("model.bin")` are not compatible.
|