fasttext 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +251 -0
- data/ext/fasttext/ext.cpp +291 -0
- data/ext/fasttext/extconf.rb +15 -0
- data/lib/fasttext.rb +41 -0
- data/lib/fasttext/classifier.rb +92 -0
- data/lib/fasttext/ext.bundle +0 -0
- data/lib/fasttext/model.rb +60 -0
- data/lib/fasttext/vectorizer.rb +58 -0
- data/lib/fasttext/version.rb +3 -0
- data/vendor/fastText/CMakeLists.txt +68 -0
- data/vendor/fastText/CODE_OF_CONDUCT.md +2 -0
- data/vendor/fastText/CONTRIBUTING.md +32 -0
- data/vendor/fastText/LICENSE +21 -0
- data/vendor/fastText/MANIFEST.in +5 -0
- data/vendor/fastText/Makefile +63 -0
- data/vendor/fastText/README.md +339 -0
- data/vendor/fastText/alignment/README.md +53 -0
- data/vendor/fastText/alignment/align.py +145 -0
- data/vendor/fastText/alignment/eval.py +60 -0
- data/vendor/fastText/alignment/example.sh +51 -0
- data/vendor/fastText/alignment/unsup_align.py +109 -0
- data/vendor/fastText/alignment/utils.py +154 -0
- data/vendor/fastText/classification-example.sh +41 -0
- data/vendor/fastText/classification-results.sh +94 -0
- data/vendor/fastText/crawl/README.md +26 -0
- data/vendor/fastText/crawl/dedup.cc +51 -0
- data/vendor/fastText/crawl/download_crawl.sh +57 -0
- data/vendor/fastText/crawl/filter_dedup.sh +13 -0
- data/vendor/fastText/crawl/filter_utf8.cc +105 -0
- data/vendor/fastText/crawl/process_wet_file.sh +30 -0
- data/vendor/fastText/docs/aligned-vectors.md +64 -0
- data/vendor/fastText/docs/api.md +6 -0
- data/vendor/fastText/docs/cheatsheet.md +66 -0
- data/vendor/fastText/docs/crawl-vectors.md +125 -0
- data/vendor/fastText/docs/dataset.md +6 -0
- data/vendor/fastText/docs/english-vectors.md +53 -0
- data/vendor/fastText/docs/faqs.md +63 -0
- data/vendor/fastText/docs/language-identification.md +47 -0
- data/vendor/fastText/docs/options.md +50 -0
- data/vendor/fastText/docs/pretrained-vectors.md +142 -0
- data/vendor/fastText/docs/python-module.md +314 -0
- data/vendor/fastText/docs/references.md +41 -0
- data/vendor/fastText/docs/supervised-models.md +54 -0
- data/vendor/fastText/docs/supervised-tutorial.md +349 -0
- data/vendor/fastText/docs/support.md +58 -0
- data/vendor/fastText/docs/unsupervised-tutorials.md +309 -0
- data/vendor/fastText/eval.py +95 -0
- data/vendor/fastText/get-wikimedia.sh +79 -0
- data/vendor/fastText/python/README.md +322 -0
- data/vendor/fastText/python/README.rst +406 -0
- data/vendor/fastText/python/benchmarks/README.rst +3 -0
- data/vendor/fastText/python/benchmarks/get_word_vector.py +49 -0
- data/vendor/fastText/python/doc/examples/FastTextEmbeddingBag.py +81 -0
- data/vendor/fastText/python/doc/examples/bin_to_vec.py +41 -0
- data/vendor/fastText/python/doc/examples/compute_accuracy.py +163 -0
- data/vendor/fastText/python/doc/examples/get_vocab.py +48 -0
- data/vendor/fastText/python/doc/examples/train_supervised.py +42 -0
- data/vendor/fastText/python/doc/examples/train_unsupervised.py +56 -0
- data/vendor/fastText/python/fasttext_module/fasttext/FastText.py +468 -0
- data/vendor/fastText/python/fasttext_module/fasttext/__init__.py +22 -0
- data/vendor/fastText/python/fasttext_module/fasttext/pybind/fasttext_pybind.cc +388 -0
- data/vendor/fastText/python/fasttext_module/fasttext/tests/__init__.py +14 -0
- data/vendor/fastText/python/fasttext_module/fasttext/tests/test_configurations.py +239 -0
- data/vendor/fastText/python/fasttext_module/fasttext/tests/test_script.py +629 -0
- data/vendor/fastText/python/fasttext_module/fasttext/util/__init__.py +13 -0
- data/vendor/fastText/python/fasttext_module/fasttext/util/util.py +60 -0
- data/vendor/fastText/quantization-example.sh +40 -0
- data/vendor/fastText/runtests.py +60 -0
- data/vendor/fastText/scripts/kbcompletion/README.md +19 -0
- data/vendor/fastText/scripts/kbcompletion/data.sh +69 -0
- data/vendor/fastText/scripts/kbcompletion/eval.cpp +108 -0
- data/vendor/fastText/scripts/kbcompletion/fb15k.sh +49 -0
- data/vendor/fastText/scripts/kbcompletion/fb15k237.sh +45 -0
- data/vendor/fastText/scripts/kbcompletion/svo.sh +38 -0
- data/vendor/fastText/scripts/kbcompletion/wn18.sh +49 -0
- data/vendor/fastText/scripts/quantization/quantization-results.sh +43 -0
- data/vendor/fastText/setup.cfg +2 -0
- data/vendor/fastText/setup.py +203 -0
- data/vendor/fastText/src/args.cc +320 -0
- data/vendor/fastText/src/args.h +68 -0
- data/vendor/fastText/src/densematrix.cc +155 -0
- data/vendor/fastText/src/densematrix.h +75 -0
- data/vendor/fastText/src/dictionary.cc +540 -0
- data/vendor/fastText/src/dictionary.h +111 -0
- data/vendor/fastText/src/fasttext.cc +821 -0
- data/vendor/fastText/src/fasttext.h +191 -0
- data/vendor/fastText/src/loss.cc +346 -0
- data/vendor/fastText/src/loss.h +163 -0
- data/vendor/fastText/src/main.cc +435 -0
- data/vendor/fastText/src/matrix.cc +25 -0
- data/vendor/fastText/src/matrix.h +44 -0
- data/vendor/fastText/src/meter.cc +68 -0
- data/vendor/fastText/src/meter.h +69 -0
- data/vendor/fastText/src/model.cc +98 -0
- data/vendor/fastText/src/model.h +79 -0
- data/vendor/fastText/src/productquantizer.cc +251 -0
- data/vendor/fastText/src/productquantizer.h +63 -0
- data/vendor/fastText/src/quantmatrix.cc +117 -0
- data/vendor/fastText/src/quantmatrix.h +60 -0
- data/vendor/fastText/src/real.h +15 -0
- data/vendor/fastText/src/utils.cc +28 -0
- data/vendor/fastText/src/utils.h +43 -0
- data/vendor/fastText/src/vector.cc +97 -0
- data/vendor/fastText/src/vector.h +61 -0
- data/vendor/fastText/tests/fetch_test_data.sh +202 -0
- data/vendor/fastText/website/README.md +6 -0
- data/vendor/fastText/website/blog/2016-08-18-blog-post.md +42 -0
- data/vendor/fastText/website/blog/2017-05-02-blog-post.md +60 -0
- data/vendor/fastText/website/blog/2017-10-02-blog-post.md +90 -0
- data/vendor/fastText/website/blog/2019-06-25-blog-post.md +168 -0
- data/vendor/fastText/website/core/Footer.js +127 -0
- data/vendor/fastText/website/package.json +12 -0
- data/vendor/fastText/website/pages/en/index.js +286 -0
- data/vendor/fastText/website/sidebars.json +18 -0
- data/vendor/fastText/website/siteConfig.js +102 -0
- data/vendor/fastText/website/static/docs/en/html/annotated.html +115 -0
- data/vendor/fastText/website/static/docs/en/html/annotated_dup.js +4 -0
- data/vendor/fastText/website/static/docs/en/html/args_8cc.html +113 -0
- data/vendor/fastText/website/static/docs/en/html/args_8h.html +134 -0
- data/vendor/fastText/website/static/docs/en/html/args_8h.js +14 -0
- data/vendor/fastText/website/static/docs/en/html/args_8h_source.html +139 -0
- data/vendor/fastText/website/static/docs/en/html/bc_s.png +0 -0
- data/vendor/fastText/website/static/docs/en/html/bdwn.png +0 -0
- data/vendor/fastText/website/static/docs/en/html/classes.html +121 -0
- data/vendor/fastText/website/static/docs/en/html/classfasttext_1_1Args-members.html +140 -0
- data/vendor/fastText/website/static/docs/en/html/classfasttext_1_1Args.html +753 -0
- data/vendor/fastText/website/static/docs/en/html/classfasttext_1_1Args.js +40 -0
- data/vendor/fastText/website/static/docs/en/html/classfasttext_1_1Dictionary-members.html +148 -0
- data/vendor/fastText/website/static/docs/en/html/classfasttext_1_1Dictionary.html +1266 -0
- data/vendor/fastText/website/static/docs/en/html/classfasttext_1_1Dictionary.js +43 -0
- data/vendor/fastText/website/static/docs/en/html/classfasttext_1_1FastText-members.html +145 -0
- data/vendor/fastText/website/static/docs/en/html/classfasttext_1_1FastText.html +1149 -0
- data/vendor/fastText/website/static/docs/en/html/classfasttext_1_1FastText.js +45 -0
- data/vendor/fastText/website/static/docs/en/html/classfasttext_1_1Matrix-members.html +123 -0
- data/vendor/fastText/website/static/docs/en/html/classfasttext_1_1Matrix.html +610 -0
- data/vendor/fastText/website/static/docs/en/html/classfasttext_1_1Matrix.js +23 -0
- data/vendor/fastText/website/static/docs/en/html/classfasttext_1_1Model-members.html +150 -0
- data/vendor/fastText/website/static/docs/en/html/classfasttext_1_1Model.html +1400 -0
- data/vendor/fastText/website/static/docs/en/html/classfasttext_1_1Model.js +48 -0
- data/vendor/fastText/website/static/docs/en/html/classfasttext_1_1ProductQuantizer-members.html +131 -0
- data/vendor/fastText/website/static/docs/en/html/classfasttext_1_1ProductQuantizer.html +950 -0
- data/vendor/fastText/website/static/docs/en/html/classfasttext_1_1ProductQuantizer.js +31 -0
- data/vendor/fastText/website/static/docs/en/html/classfasttext_1_1QMatrix-members.html +122 -0
- data/vendor/fastText/website/static/docs/en/html/classfasttext_1_1QMatrix.html +565 -0
- data/vendor/fastText/website/static/docs/en/html/classfasttext_1_1QMatrix.js +22 -0
- data/vendor/fastText/website/static/docs/en/html/classfasttext_1_1Vector-members.html +121 -0
- data/vendor/fastText/website/static/docs/en/html/classfasttext_1_1Vector.html +542 -0
- data/vendor/fastText/website/static/docs/en/html/classfasttext_1_1Vector.js +21 -0
- data/vendor/fastText/website/static/docs/en/html/closed.png +0 -0
- data/vendor/fastText/website/static/docs/en/html/dictionary_8cc.html +116 -0
- data/vendor/fastText/website/static/docs/en/html/dictionary_8h.html +142 -0
- data/vendor/fastText/website/static/docs/en/html/dictionary_8h.js +10 -0
- data/vendor/fastText/website/static/docs/en/html/dictionary_8h_source.html +127 -0
- data/vendor/fastText/website/static/docs/en/html/dir_68267d1309a1af8e8297ef4c3efbcdba.html +145 -0
- data/vendor/fastText/website/static/docs/en/html/dir_68267d1309a1af8e8297ef4c3efbcdba.js +29 -0
- data/vendor/fastText/website/static/docs/en/html/doc.png +0 -0
- data/vendor/fastText/website/static/docs/en/html/doxygen.css +1596 -0
- data/vendor/fastText/website/static/docs/en/html/doxygen.png +0 -0
- data/vendor/fastText/website/static/docs/en/html/dynsections.js +97 -0
- data/vendor/fastText/website/static/docs/en/html/fasttext_8cc.html +119 -0
- data/vendor/fastText/website/static/docs/en/html/fasttext_8h.html +168 -0
- data/vendor/fastText/website/static/docs/en/html/fasttext_8h.js +6 -0
- data/vendor/fastText/website/static/docs/en/html/fasttext_8h_source.html +155 -0
- data/vendor/fastText/website/static/docs/en/html/favicon.png +0 -0
- data/vendor/fastText/website/static/docs/en/html/files.html +125 -0
- data/vendor/fastText/website/static/docs/en/html/files.js +4 -0
- data/vendor/fastText/website/static/docs/en/html/folderclosed.png +0 -0
- data/vendor/fastText/website/static/docs/en/html/folderopen.png +0 -0
- data/vendor/fastText/website/static/docs/en/html/functions.html +139 -0
- data/vendor/fastText/website/static/docs/en/html/functions_0x7e.html +112 -0
- data/vendor/fastText/website/static/docs/en/html/functions_b.html +115 -0
- data/vendor/fastText/website/static/docs/en/html/functions_c.html +143 -0
- data/vendor/fastText/website/static/docs/en/html/functions_d.html +135 -0
- data/vendor/fastText/website/static/docs/en/html/functions_dup.js +27 -0
- data/vendor/fastText/website/static/docs/en/html/functions_e.html +115 -0
- data/vendor/fastText/website/static/docs/en/html/functions_f.html +112 -0
- data/vendor/fastText/website/static/docs/en/html/functions_func.html +563 -0
- data/vendor/fastText/website/static/docs/en/html/functions_g.html +145 -0
- data/vendor/fastText/website/static/docs/en/html/functions_h.html +112 -0
- data/vendor/fastText/website/static/docs/en/html/functions_i.html +121 -0
- data/vendor/fastText/website/static/docs/en/html/functions_k.html +106 -0
- data/vendor/fastText/website/static/docs/en/html/functions_l.html +140 -0
- data/vendor/fastText/website/static/docs/en/html/functions_m.html +153 -0
- data/vendor/fastText/website/static/docs/en/html/functions_n.html +164 -0
- data/vendor/fastText/website/static/docs/en/html/functions_o.html +116 -0
- data/vendor/fastText/website/static/docs/en/html/functions_p.html +161 -0
- data/vendor/fastText/website/static/docs/en/html/functions_q.html +135 -0
- data/vendor/fastText/website/static/docs/en/html/functions_r.html +116 -0
- data/vendor/fastText/website/static/docs/en/html/functions_s.html +159 -0
- data/vendor/fastText/website/static/docs/en/html/functions_t.html +138 -0
- data/vendor/fastText/website/static/docs/en/html/functions_u.html +106 -0
- data/vendor/fastText/website/static/docs/en/html/functions_v.html +106 -0
- data/vendor/fastText/website/static/docs/en/html/functions_vars.html +486 -0
- data/vendor/fastText/website/static/docs/en/html/functions_w.html +124 -0
- data/vendor/fastText/website/static/docs/en/html/functions_z.html +104 -0
- data/vendor/fastText/website/static/docs/en/html/globals.html +170 -0
- data/vendor/fastText/website/static/docs/en/html/globals_defs.html +113 -0
- data/vendor/fastText/website/static/docs/en/html/globals_func.html +155 -0
- data/vendor/fastText/website/static/docs/en/html/index.html +100 -0
- data/vendor/fastText/website/static/docs/en/html/jquery.js +87 -0
- data/vendor/fastText/website/static/docs/en/html/main_8cc.html +582 -0
- data/vendor/fastText/website/static/docs/en/html/main_8cc.js +22 -0
- data/vendor/fastText/website/static/docs/en/html/matrix_8cc.html +114 -0
- data/vendor/fastText/website/static/docs/en/html/matrix_8h.html +121 -0
- data/vendor/fastText/website/static/docs/en/html/matrix_8h_source.html +123 -0
- data/vendor/fastText/website/static/docs/en/html/menu.js +26 -0
- data/vendor/fastText/website/static/docs/en/html/menudata.js +90 -0
- data/vendor/fastText/website/static/docs/en/html/model_8cc.html +113 -0
- data/vendor/fastText/website/static/docs/en/html/model_8h.html +183 -0
- data/vendor/fastText/website/static/docs/en/html/model_8h.js +8 -0
- data/vendor/fastText/website/static/docs/en/html/model_8h_source.html +139 -0
- data/vendor/fastText/website/static/docs/en/html/namespacefasttext.html +343 -0
- data/vendor/fastText/website/static/docs/en/html/namespacefasttext.js +13 -0
- data/vendor/fastText/website/static/docs/en/html/namespacefasttext_1_1utils.html +158 -0
- data/vendor/fastText/website/static/docs/en/html/namespacemembers.html +125 -0
- data/vendor/fastText/website/static/docs/en/html/namespacemembers_enum.html +107 -0
- data/vendor/fastText/website/static/docs/en/html/namespacemembers_func.html +110 -0
- data/vendor/fastText/website/static/docs/en/html/namespacemembers_type.html +104 -0
- data/vendor/fastText/website/static/docs/en/html/namespaces.html +106 -0
- data/vendor/fastText/website/static/docs/en/html/namespaces.js +4 -0
- data/vendor/fastText/website/static/docs/en/html/nav_f.png +0 -0
- data/vendor/fastText/website/static/docs/en/html/nav_g.png +0 -0
- data/vendor/fastText/website/static/docs/en/html/nav_h.png +0 -0
- data/vendor/fastText/website/static/docs/en/html/navtree.css +146 -0
- data/vendor/fastText/website/static/docs/en/html/navtree.js +517 -0
- data/vendor/fastText/website/static/docs/en/html/navtreedata.js +40 -0
- data/vendor/fastText/website/static/docs/en/html/navtreeindex0.js +253 -0
- data/vendor/fastText/website/static/docs/en/html/navtreeindex1.js +139 -0
- data/vendor/fastText/website/static/docs/en/html/open.png +0 -0
- data/vendor/fastText/website/static/docs/en/html/productquantizer_8cc.html +118 -0
- data/vendor/fastText/website/static/docs/en/html/productquantizer_8cc.js +4 -0
- data/vendor/fastText/website/static/docs/en/html/productquantizer_8h.html +124 -0
- data/vendor/fastText/website/static/docs/en/html/productquantizer_8h_source.html +133 -0
- data/vendor/fastText/website/static/docs/en/html/qmatrix_8cc.html +112 -0
- data/vendor/fastText/website/static/docs/en/html/qmatrix_8h.html +126 -0
- data/vendor/fastText/website/static/docs/en/html/qmatrix_8h_source.html +128 -0
- data/vendor/fastText/website/static/docs/en/html/real_8h.html +117 -0
- data/vendor/fastText/website/static/docs/en/html/real_8h.js +4 -0
- data/vendor/fastText/website/static/docs/en/html/real_8h_source.html +103 -0
- data/vendor/fastText/website/static/docs/en/html/resize.js +114 -0
- data/vendor/fastText/website/static/docs/en/html/search/all_0.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/all_0.js +17 -0
- data/vendor/fastText/website/static/docs/en/html/search/all_1.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/all_1.js +8 -0
- data/vendor/fastText/website/static/docs/en/html/search/all_10.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/all_10.js +10 -0
- data/vendor/fastText/website/static/docs/en/html/search/all_11.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/all_11.js +25 -0
- data/vendor/fastText/website/static/docs/en/html/search/all_12.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/all_12.js +15 -0
- data/vendor/fastText/website/static/docs/en/html/search/all_13.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/all_13.js +7 -0
- data/vendor/fastText/website/static/docs/en/html/search/all_14.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/all_14.js +7 -0
- data/vendor/fastText/website/static/docs/en/html/search/all_15.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/all_15.js +11 -0
- data/vendor/fastText/website/static/docs/en/html/search/all_16.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/all_16.js +4 -0
- data/vendor/fastText/website/static/docs/en/html/search/all_17.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/all_17.js +7 -0
- data/vendor/fastText/website/static/docs/en/html/search/all_2.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/all_2.js +17 -0
- data/vendor/fastText/website/static/docs/en/html/search/all_3.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/all_3.js +17 -0
- data/vendor/fastText/website/static/docs/en/html/search/all_4.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/all_4.js +10 -0
- data/vendor/fastText/website/static/docs/en/html/search/all_5.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/all_5.js +12 -0
- data/vendor/fastText/website/static/docs/en/html/search/all_6.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/all_6.js +18 -0
- data/vendor/fastText/website/static/docs/en/html/search/all_7.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/all_7.js +8 -0
- data/vendor/fastText/website/static/docs/en/html/search/all_8.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/all_8.js +11 -0
- data/vendor/fastText/website/static/docs/en/html/search/all_9.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/all_9.js +5 -0
- data/vendor/fastText/website/static/docs/en/html/search/all_a.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/all_a.js +17 -0
- data/vendor/fastText/website/static/docs/en/html/search/all_b.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/all_b.js +27 -0
- data/vendor/fastText/website/static/docs/en/html/search/all_c.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/all_c.js +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/all_d.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/all_d.js +9 -0
- data/vendor/fastText/website/static/docs/en/html/search/all_e.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/all_e.js +35 -0
- data/vendor/fastText/website/static/docs/en/html/search/all_f.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/all_f.js +16 -0
- data/vendor/fastText/website/static/docs/en/html/search/classes_0.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/classes_0.js +4 -0
- data/vendor/fastText/website/static/docs/en/html/search/classes_1.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/classes_1.js +4 -0
- data/vendor/fastText/website/static/docs/en/html/search/classes_2.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/classes_2.js +4 -0
- data/vendor/fastText/website/static/docs/en/html/search/classes_3.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/classes_3.js +4 -0
- data/vendor/fastText/website/static/docs/en/html/search/classes_4.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/classes_4.js +5 -0
- data/vendor/fastText/website/static/docs/en/html/search/classes_5.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/classes_5.js +4 -0
- data/vendor/fastText/website/static/docs/en/html/search/classes_6.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/classes_6.js +4 -0
- data/vendor/fastText/website/static/docs/en/html/search/classes_7.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/classes_7.js +4 -0
- data/vendor/fastText/website/static/docs/en/html/search/classes_8.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/classes_8.js +4 -0
- data/vendor/fastText/website/static/docs/en/html/search/close.png +0 -0
- data/vendor/fastText/website/static/docs/en/html/search/defines_0.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/defines_0.js +5 -0
- data/vendor/fastText/website/static/docs/en/html/search/defines_1.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/defines_1.js +4 -0
- data/vendor/fastText/website/static/docs/en/html/search/defines_2.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/defines_2.js +4 -0
- data/vendor/fastText/website/static/docs/en/html/search/defines_3.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/defines_3.js +4 -0
- data/vendor/fastText/website/static/docs/en/html/search/enums_0.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/enums_0.js +4 -0
- data/vendor/fastText/website/static/docs/en/html/search/enums_1.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/enums_1.js +4 -0
- data/vendor/fastText/website/static/docs/en/html/search/enums_2.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/enums_2.js +4 -0
- data/vendor/fastText/website/static/docs/en/html/search/enumvalues_0.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/enumvalues_0.js +4 -0
- data/vendor/fastText/website/static/docs/en/html/search/enumvalues_1.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/enumvalues_1.js +4 -0
- data/vendor/fastText/website/static/docs/en/html/search/enumvalues_2.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/enumvalues_2.js +4 -0
- data/vendor/fastText/website/static/docs/en/html/search/enumvalues_3.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/enumvalues_3.js +4 -0
- data/vendor/fastText/website/static/docs/en/html/search/enumvalues_4.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/enumvalues_4.js +6 -0
- data/vendor/fastText/website/static/docs/en/html/search/enumvalues_5.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/enumvalues_5.js +4 -0
- data/vendor/fastText/website/static/docs/en/html/search/files_0.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/files_0.js +5 -0
- data/vendor/fastText/website/static/docs/en/html/search/files_1.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/files_1.js +5 -0
- data/vendor/fastText/website/static/docs/en/html/search/files_2.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/files_2.js +5 -0
- data/vendor/fastText/website/static/docs/en/html/search/files_3.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/files_3.js +8 -0
- data/vendor/fastText/website/static/docs/en/html/search/files_4.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/files_4.js +5 -0
- data/vendor/fastText/website/static/docs/en/html/search/files_5.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/files_5.js +5 -0
- data/vendor/fastText/website/static/docs/en/html/search/files_6.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/files_6.js +4 -0
- data/vendor/fastText/website/static/docs/en/html/search/files_7.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/files_7.js +5 -0
- data/vendor/fastText/website/static/docs/en/html/search/files_8.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/files_8.js +5 -0
- data/vendor/fastText/website/static/docs/en/html/search/functions_0.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/functions_0.js +14 -0
- data/vendor/fastText/website/static/docs/en/html/search/functions_1.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/functions_1.js +5 -0
- data/vendor/fastText/website/static/docs/en/html/search/functions_10.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/functions_10.js +5 -0
- data/vendor/fastText/website/static/docs/en/html/search/functions_11.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/functions_11.js +18 -0
- data/vendor/fastText/website/static/docs/en/html/search/functions_12.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/functions_12.js +8 -0
- data/vendor/fastText/website/static/docs/en/html/search/functions_13.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/functions_13.js +5 -0
- data/vendor/fastText/website/static/docs/en/html/search/functions_14.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/functions_14.js +4 -0
- data/vendor/fastText/website/static/docs/en/html/search/functions_15.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/functions_15.js +4 -0
- data/vendor/fastText/website/static/docs/en/html/search/functions_16.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/functions_16.js +4 -0
- data/vendor/fastText/website/static/docs/en/html/search/functions_17.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/functions_17.js +7 -0
- data/vendor/fastText/website/static/docs/en/html/search/functions_2.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/functions_2.js +11 -0
- data/vendor/fastText/website/static/docs/en/html/search/functions_3.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/functions_3.js +9 -0
- data/vendor/fastText/website/static/docs/en/html/search/functions_4.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/functions_4.js +4 -0
- data/vendor/fastText/website/static/docs/en/html/search/functions_5.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/functions_5.js +7 -0
- data/vendor/fastText/website/static/docs/en/html/search/functions_6.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/functions_6.js +17 -0
- data/vendor/fastText/website/static/docs/en/html/search/functions_7.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/functions_7.js +5 -0
- data/vendor/fastText/website/static/docs/en/html/search/functions_8.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/functions_8.js +8 -0
- data/vendor/fastText/website/static/docs/en/html/search/functions_9.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/functions_9.js +4 -0
- data/vendor/fastText/website/static/docs/en/html/search/functions_a.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/functions_a.js +8 -0
- data/vendor/fastText/website/static/docs/en/html/search/functions_b.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/functions_b.js +10 -0
- data/vendor/fastText/website/static/docs/en/html/search/functions_c.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/functions_c.js +10 -0
- data/vendor/fastText/website/static/docs/en/html/search/functions_d.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/functions_d.js +6 -0
- data/vendor/fastText/website/static/docs/en/html/search/functions_e.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/functions_e.js +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/functions_f.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/functions_f.js +6 -0
- data/vendor/fastText/website/static/docs/en/html/search/mag_sel.png +0 -0
- data/vendor/fastText/website/static/docs/en/html/search/namespaces_0.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/namespaces_0.js +5 -0
- data/vendor/fastText/website/static/docs/en/html/search/nomatches.html +12 -0
- data/vendor/fastText/website/static/docs/en/html/search/search.css +271 -0
- data/vendor/fastText/website/static/docs/en/html/search/search.js +791 -0
- data/vendor/fastText/website/static/docs/en/html/search/search_l.png +0 -0
- data/vendor/fastText/website/static/docs/en/html/search/search_m.png +0 -0
- data/vendor/fastText/website/static/docs/en/html/search/search_r.png +0 -0
- data/vendor/fastText/website/static/docs/en/html/search/searchdata.js +42 -0
- data/vendor/fastText/website/static/docs/en/html/search/typedefs_0.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/typedefs_0.js +4 -0
- data/vendor/fastText/website/static/docs/en/html/search/typedefs_1.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/typedefs_1.js +4 -0
- data/vendor/fastText/website/static/docs/en/html/search/variables_0.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/variables_0.js +4 -0
- data/vendor/fastText/website/static/docs/en/html/search/variables_1.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/variables_1.js +6 -0
- data/vendor/fastText/website/static/docs/en/html/search/variables_10.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/variables_10.js +8 -0
- data/vendor/fastText/website/static/docs/en/html/search/variables_11.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/variables_11.js +11 -0
- data/vendor/fastText/website/static/docs/en/html/search/variables_12.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/variables_12.js +4 -0
- data/vendor/fastText/website/static/docs/en/html/search/variables_13.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/variables_13.js +10 -0
- data/vendor/fastText/website/static/docs/en/html/search/variables_2.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/variables_2.js +9 -0
- data/vendor/fastText/website/static/docs/en/html/search/variables_3.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/variables_3.js +9 -0
- data/vendor/fastText/website/static/docs/en/html/search/variables_4.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/variables_4.js +7 -0
- data/vendor/fastText/website/static/docs/en/html/search/variables_5.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/variables_5.js +4 -0
- data/vendor/fastText/website/static/docs/en/html/search/variables_6.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/variables_6.js +5 -0
- data/vendor/fastText/website/static/docs/en/html/search/variables_7.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/variables_7.js +5 -0
- data/vendor/fastText/website/static/docs/en/html/search/variables_8.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/variables_8.js +4 -0
- data/vendor/fastText/website/static/docs/en/html/search/variables_9.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/variables_9.js +10 -0
- data/vendor/fastText/website/static/docs/en/html/search/variables_a.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/variables_a.js +14 -0
- data/vendor/fastText/website/static/docs/en/html/search/variables_b.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/variables_b.js +17 -0
- data/vendor/fastText/website/static/docs/en/html/search/variables_c.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/variables_c.js +6 -0
- data/vendor/fastText/website/static/docs/en/html/search/variables_d.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/variables_d.js +10 -0
- data/vendor/fastText/website/static/docs/en/html/search/variables_e.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/variables_e.js +11 -0
- data/vendor/fastText/website/static/docs/en/html/search/variables_f.html +26 -0
- data/vendor/fastText/website/static/docs/en/html/search/variables_f.js +6 -0
- data/vendor/fastText/website/static/docs/en/html/splitbar.png +0 -0
- data/vendor/fastText/website/static/docs/en/html/structfasttext_1_1Node-members.html +108 -0
- data/vendor/fastText/website/static/docs/en/html/structfasttext_1_1Node.html +194 -0
- data/vendor/fastText/website/static/docs/en/html/structfasttext_1_1Node.js +8 -0
- data/vendor/fastText/website/static/docs/en/html/structfasttext_1_1entry-members.html +107 -0
- data/vendor/fastText/website/static/docs/en/html/structfasttext_1_1entry.html +178 -0
- data/vendor/fastText/website/static/docs/en/html/structfasttext_1_1entry.js +7 -0
- data/vendor/fastText/website/static/docs/en/html/sync_off.png +0 -0
- data/vendor/fastText/website/static/docs/en/html/sync_on.png +0 -0
- data/vendor/fastText/website/static/docs/en/html/tab_a.png +0 -0
- data/vendor/fastText/website/static/docs/en/html/tab_b.png +0 -0
- data/vendor/fastText/website/static/docs/en/html/tab_h.png +0 -0
- data/vendor/fastText/website/static/docs/en/html/tab_s.png +0 -0
- data/vendor/fastText/website/static/docs/en/html/tabs.css +1 -0
- data/vendor/fastText/website/static/docs/en/html/utils_8cc.html +121 -0
- data/vendor/fastText/website/static/docs/en/html/utils_8cc.js +5 -0
- data/vendor/fastText/website/static/docs/en/html/utils_8h.html +122 -0
- data/vendor/fastText/website/static/docs/en/html/utils_8h.js +5 -0
- data/vendor/fastText/website/static/docs/en/html/utils_8h_source.html +104 -0
- data/vendor/fastText/website/static/docs/en/html/vector_8cc.html +121 -0
- data/vendor/fastText/website/static/docs/en/html/vector_8cc.js +4 -0
- data/vendor/fastText/website/static/docs/en/html/vector_8h.html +126 -0
- data/vendor/fastText/website/static/docs/en/html/vector_8h.js +5 -0
- data/vendor/fastText/website/static/docs/en/html/vector_8h_source.html +120 -0
- data/vendor/fastText/website/static/fasttext.css +48 -0
- data/vendor/fastText/website/static/img/authors/armand_joulin.jpg +0 -0
- data/vendor/fastText/website/static/img/authors/christian_puhrsch.png +0 -0
- data/vendor/fastText/website/static/img/authors/edouard_grave.jpeg +0 -0
- data/vendor/fastText/website/static/img/authors/piotr_bojanowski.jpg +0 -0
- data/vendor/fastText/website/static/img/authors/tomas_mikolov.jpg +0 -0
- data/vendor/fastText/website/static/img/blog/2016-08-18-blog-post-img1.png +0 -0
- data/vendor/fastText/website/static/img/blog/2016-08-18-blog-post-img2.png +0 -0
- data/vendor/fastText/website/static/img/blog/2017-05-02-blog-post-img1.jpg +0 -0
- data/vendor/fastText/website/static/img/blog/2017-05-02-blog-post-img2.jpg +0 -0
- data/vendor/fastText/website/static/img/blog/2017-10-02-blog-post-img1.png +0 -0
- data/vendor/fastText/website/static/img/cbo_vs_skipgram.png +0 -0
- data/vendor/fastText/website/static/img/fasttext-icon-api.png +0 -0
- data/vendor/fastText/website/static/img/fasttext-icon-bg-web.png +0 -0
- data/vendor/fastText/website/static/img/fasttext-icon-color-square.png +0 -0
- data/vendor/fastText/website/static/img/fasttext-icon-color-web.png +0 -0
- data/vendor/fastText/website/static/img/fasttext-icon-faq.png +0 -0
- data/vendor/fastText/website/static/img/fasttext-icon-tutorial.png +0 -0
- data/vendor/fastText/website/static/img/fasttext-icon-white-web.png +0 -0
- data/vendor/fastText/website/static/img/fasttext-logo-color-web.png +0 -0
- data/vendor/fastText/website/static/img/fasttext-logo-white-web.png +0 -0
- data/vendor/fastText/website/static/img/logo-color.png +0 -0
- data/vendor/fastText/website/static/img/model-black.png +0 -0
- data/vendor/fastText/website/static/img/model-blue.png +0 -0
- data/vendor/fastText/website/static/img/model-red.png +0 -0
- data/vendor/fastText/website/static/img/ogimage.png +0 -0
- data/vendor/fastText/website/static/img/oss_logo.png +0 -0
- data/vendor/fastText/wikifil.pl +57 -0
- data/vendor/fastText/word-vector-example.sh +39 -0
- metadata +621 -0
@@ -0,0 +1,468 @@
|
|
1
|
+
# Copyright (c) 2017-present, Facebook, Inc.
|
2
|
+
# All rights reserved.
|
3
|
+
#
|
4
|
+
# This source code is licensed under the MIT license found in the
|
5
|
+
# LICENSE file in the root directory of this source tree.
|
6
|
+
|
7
|
+
from __future__ import absolute_import
|
8
|
+
from __future__ import division
|
9
|
+
from __future__ import print_function
|
10
|
+
from __future__ import unicode_literals
|
11
|
+
|
12
|
+
import fasttext_pybind as fasttext
|
13
|
+
import numpy as np
|
14
|
+
import multiprocessing
|
15
|
+
import sys
|
16
|
+
from itertools import chain
|
17
|
+
|
18
|
+
loss_name = fasttext.loss_name
|
19
|
+
model_name = fasttext.model_name
|
20
|
+
EOS = "</s>"
|
21
|
+
BOW = "<"
|
22
|
+
EOW = ">"
|
23
|
+
|
24
|
+
|
25
|
+
def eprint(cls, *args, **kwargs):
|
26
|
+
print(*args, file=sys.stderr, **kwargs)
|
27
|
+
|
28
|
+
|
29
|
+
class _FastText(object):
|
30
|
+
"""
|
31
|
+
This class defines the API to inspect models and should not be used to
|
32
|
+
create objects. It will be returned by functions such as load_model or
|
33
|
+
train.
|
34
|
+
|
35
|
+
In general this API assumes to be given only unicode for Python2 and the
|
36
|
+
Python3 equvalent called str for any string-like arguments. All unicode
|
37
|
+
strings are then encoded as UTF-8 and fed to the fastText C++ API.
|
38
|
+
"""
|
39
|
+
|
40
|
+
def __init__(self, model_path=None, args=None):
|
41
|
+
self.f = fasttext.fasttext()
|
42
|
+
if model_path is not None:
|
43
|
+
self.f.loadModel(model_path)
|
44
|
+
self._words = None
|
45
|
+
self._labels = None
|
46
|
+
|
47
|
+
if args:
|
48
|
+
arg_names = ['lr', 'dim', 'ws', 'epoch', 'minCount',
|
49
|
+
'minCountLabel', 'minn', 'maxn', 'neg', 'wordNgrams',
|
50
|
+
'loss', 'bucket', 'thread', 'lrUpdateRate', 't',
|
51
|
+
'label', 'verbose', 'pretrainedVectors']
|
52
|
+
for arg_name in arg_names:
|
53
|
+
setattr(self, arg_name, getattr(args, arg_name))
|
54
|
+
|
55
|
+
def is_quantized(self):
|
56
|
+
return self.f.isQuant()
|
57
|
+
|
58
|
+
def get_dimension(self):
|
59
|
+
"""Get the dimension (size) of a lookup vector (hidden layer)."""
|
60
|
+
a = self.f.getArgs()
|
61
|
+
return a.dim
|
62
|
+
|
63
|
+
def get_word_vector(self, word):
|
64
|
+
"""Get the vector representation of word."""
|
65
|
+
dim = self.get_dimension()
|
66
|
+
b = fasttext.Vector(dim)
|
67
|
+
self.f.getWordVector(b, word)
|
68
|
+
return np.array(b)
|
69
|
+
|
70
|
+
def get_sentence_vector(self, text):
|
71
|
+
"""
|
72
|
+
Given a string, get a single vector represenation. This function
|
73
|
+
assumes to be given a single line of text. We split words on
|
74
|
+
whitespace (space, newline, tab, vertical tab) and the control
|
75
|
+
characters carriage return, formfeed and the null character.
|
76
|
+
"""
|
77
|
+
if text.find('\n') != -1:
|
78
|
+
raise ValueError(
|
79
|
+
"predict processes one line at a time (remove \'\\n\')"
|
80
|
+
)
|
81
|
+
text += "\n"
|
82
|
+
dim = self.get_dimension()
|
83
|
+
b = fasttext.Vector(dim)
|
84
|
+
self.f.getSentenceVector(b, text)
|
85
|
+
return np.array(b)
|
86
|
+
|
87
|
+
def get_word_id(self, word):
|
88
|
+
"""
|
89
|
+
Given a word, get the word id within the dictionary.
|
90
|
+
Returns -1 if word is not in the dictionary.
|
91
|
+
"""
|
92
|
+
return self.f.getWordId(word)
|
93
|
+
|
94
|
+
def get_subword_id(self, subword):
|
95
|
+
"""
|
96
|
+
Given a subword, return the index (within input matrix) it hashes to.
|
97
|
+
"""
|
98
|
+
return self.f.getSubwordId(subword)
|
99
|
+
|
100
|
+
def get_subwords(self, word, on_unicode_error='strict'):
|
101
|
+
"""
|
102
|
+
Given a word, get the subwords and their indicies.
|
103
|
+
"""
|
104
|
+
pair = self.f.getSubwords(word, on_unicode_error)
|
105
|
+
return pair[0], np.array(pair[1])
|
106
|
+
|
107
|
+
def get_input_vector(self, ind):
|
108
|
+
"""
|
109
|
+
Given an index, get the corresponding vector of the Input Matrix.
|
110
|
+
"""
|
111
|
+
dim = self.get_dimension()
|
112
|
+
b = fasttext.Vector(dim)
|
113
|
+
self.f.getInputVector(b, ind)
|
114
|
+
return np.array(b)
|
115
|
+
|
116
|
+
def predict(self, text, k=1, threshold=0.0, on_unicode_error='strict'):
|
117
|
+
"""
|
118
|
+
Given a string, get a list of labels and a list of
|
119
|
+
corresponding probabilities. k controls the number
|
120
|
+
of returned labels. A choice of 5, will return the 5
|
121
|
+
most probable labels. By default this returns only
|
122
|
+
the most likely label and probability. threshold filters
|
123
|
+
the returned labels by a threshold on probability. A
|
124
|
+
choice of 0.5 will return labels with at least 0.5
|
125
|
+
probability. k and threshold will be applied together to
|
126
|
+
determine the returned labels.
|
127
|
+
|
128
|
+
This function assumes to be given
|
129
|
+
a single line of text. We split words on whitespace (space,
|
130
|
+
newline, tab, vertical tab) and the control characters carriage
|
131
|
+
return, formfeed and the null character.
|
132
|
+
|
133
|
+
If the model is not supervised, this function will throw a ValueError.
|
134
|
+
|
135
|
+
If given a list of strings, it will return a list of results as usually
|
136
|
+
received for a single line of text.
|
137
|
+
"""
|
138
|
+
|
139
|
+
def check(entry):
|
140
|
+
if entry.find('\n') != -1:
|
141
|
+
raise ValueError(
|
142
|
+
"predict processes one line at a time (remove \'\\n\')"
|
143
|
+
)
|
144
|
+
entry += "\n"
|
145
|
+
return entry
|
146
|
+
|
147
|
+
if type(text) == list:
|
148
|
+
text = [check(entry) for entry in text]
|
149
|
+
predictions = self.f.multilinePredict(text, k, threshold, on_unicode_error)
|
150
|
+
dt = np.dtype([('probability', 'float64'), ('label', 'object')])
|
151
|
+
result_as_pair = np.array(predictions, dtype=dt)
|
152
|
+
|
153
|
+
return result_as_pair['label'].tolist(), result_as_pair['probability']
|
154
|
+
else:
|
155
|
+
text = check(text)
|
156
|
+
predictions = self.f.predict(text, k, threshold, on_unicode_error)
|
157
|
+
probs, labels = zip(*predictions)
|
158
|
+
|
159
|
+
return labels, np.array(probs, copy=False)
|
160
|
+
|
161
|
+
def get_input_matrix(self):
|
162
|
+
"""
|
163
|
+
Get a copy of the full input matrix of a Model. This only
|
164
|
+
works if the model is not quantized.
|
165
|
+
"""
|
166
|
+
if self.f.isQuant():
|
167
|
+
raise ValueError("Can't get quantized Matrix")
|
168
|
+
return np.array(self.f.getInputMatrix())
|
169
|
+
|
170
|
+
def get_output_matrix(self):
|
171
|
+
"""
|
172
|
+
Get a copy of the full output matrix of a Model. This only
|
173
|
+
works if the model is not quantized.
|
174
|
+
"""
|
175
|
+
if self.f.isQuant():
|
176
|
+
raise ValueError("Can't get quantized Matrix")
|
177
|
+
return np.array(self.f.getOutputMatrix())
|
178
|
+
|
179
|
+
def get_words(self, include_freq=False, on_unicode_error='strict'):
|
180
|
+
"""
|
181
|
+
Get the entire list of words of the dictionary optionally
|
182
|
+
including the frequency of the individual words. This
|
183
|
+
does not include any subwords. For that please consult
|
184
|
+
the function get_subwords.
|
185
|
+
"""
|
186
|
+
pair = self.f.getVocab(on_unicode_error)
|
187
|
+
if include_freq:
|
188
|
+
return (pair[0], np.array(pair[1]))
|
189
|
+
else:
|
190
|
+
return pair[0]
|
191
|
+
|
192
|
+
def get_labels(self, include_freq=False, on_unicode_error='strict'):
|
193
|
+
"""
|
194
|
+
Get the entire list of labels of the dictionary optionally
|
195
|
+
including the frequency of the individual labels. Unsupervised
|
196
|
+
models use words as labels, which is why get_labels
|
197
|
+
will call and return get_words for this type of
|
198
|
+
model.
|
199
|
+
"""
|
200
|
+
a = self.f.getArgs()
|
201
|
+
if a.model == model_name.supervised:
|
202
|
+
pair = self.f.getLabels(on_unicode_error)
|
203
|
+
if include_freq:
|
204
|
+
return (pair[0], np.array(pair[1]))
|
205
|
+
else:
|
206
|
+
return pair[0]
|
207
|
+
else:
|
208
|
+
return self.get_words(include_freq)
|
209
|
+
|
210
|
+
def get_line(self, text, on_unicode_error='strict'):
|
211
|
+
"""
|
212
|
+
Split a line of text into words and labels. Labels must start with
|
213
|
+
the prefix used to create the model (__label__ by default).
|
214
|
+
"""
|
215
|
+
|
216
|
+
def check(entry):
|
217
|
+
if entry.find('\n') != -1:
|
218
|
+
raise ValueError(
|
219
|
+
"get_line processes one line at a time (remove \'\\n\')"
|
220
|
+
)
|
221
|
+
entry += "\n"
|
222
|
+
return entry
|
223
|
+
|
224
|
+
if type(text) == list:
|
225
|
+
text = [check(entry) for entry in text]
|
226
|
+
return self.f.multilineGetLine(text, on_unicode_error)
|
227
|
+
else:
|
228
|
+
text = check(text)
|
229
|
+
return self.f.getLine(text, on_unicode_error)
|
230
|
+
|
231
|
+
def save_model(self, path):
|
232
|
+
"""Save the model to the given path"""
|
233
|
+
self.f.saveModel(path)
|
234
|
+
|
235
|
+
def test(self, path, k=1):
|
236
|
+
"""Evaluate supervised model using file given by path"""
|
237
|
+
return self.f.test(path, k)
|
238
|
+
|
239
|
+
def test_label(self, path, k=1, threshold=0.0):
|
240
|
+
"""
|
241
|
+
Return the precision and recall score for each label.
|
242
|
+
|
243
|
+
The returned value is a dictionary, where the key is the label.
|
244
|
+
For example:
|
245
|
+
f.test_label(...)
|
246
|
+
{'__label__italian-cuisine' : {'precision' : 0.7, 'recall' : 0.74}}
|
247
|
+
"""
|
248
|
+
return self.f.testLabel(path, k, threshold)
|
249
|
+
|
250
|
+
def quantize(
|
251
|
+
self,
|
252
|
+
input=None,
|
253
|
+
qout=False,
|
254
|
+
cutoff=0,
|
255
|
+
retrain=False,
|
256
|
+
epoch=None,
|
257
|
+
lr=None,
|
258
|
+
thread=None,
|
259
|
+
verbose=None,
|
260
|
+
dsub=2,
|
261
|
+
qnorm=False
|
262
|
+
):
|
263
|
+
"""
|
264
|
+
Quantize the model reducing the size of the model and
|
265
|
+
it's memory footprint.
|
266
|
+
"""
|
267
|
+
a = self.f.getArgs()
|
268
|
+
if not epoch:
|
269
|
+
epoch = a.epoch
|
270
|
+
if not lr:
|
271
|
+
lr = a.lr
|
272
|
+
if not thread:
|
273
|
+
thread = a.thread
|
274
|
+
if not verbose:
|
275
|
+
verbose = a.verbose
|
276
|
+
if retrain and not input:
|
277
|
+
raise ValueError("Need input file path if retraining")
|
278
|
+
if input is None:
|
279
|
+
input = ""
|
280
|
+
self.f.quantize(
|
281
|
+
input, qout, cutoff, retrain, epoch, lr, thread, verbose, dsub,
|
282
|
+
qnorm
|
283
|
+
)
|
284
|
+
|
285
|
+
@property
|
286
|
+
def words(self):
|
287
|
+
if self._words is None:
|
288
|
+
self._words = self.get_words()
|
289
|
+
return self._words
|
290
|
+
|
291
|
+
@property
|
292
|
+
def labels(self):
|
293
|
+
if self._labels is None:
|
294
|
+
self._labels = self.get_labels()
|
295
|
+
return self._labels
|
296
|
+
|
297
|
+
def __getitem__(self, word):
|
298
|
+
return self.get_word_vector(word)
|
299
|
+
|
300
|
+
def __contains__(self, word):
|
301
|
+
return word in self.words
|
302
|
+
|
303
|
+
|
304
|
+
def _parse_model_string(string):
|
305
|
+
if string == "cbow":
|
306
|
+
return model_name.cbow
|
307
|
+
if string == "skipgram":
|
308
|
+
return model_name.skipgram
|
309
|
+
if string == "supervised":
|
310
|
+
return model_name.supervised
|
311
|
+
else:
|
312
|
+
raise ValueError("Unrecognized model name")
|
313
|
+
|
314
|
+
|
315
|
+
def _parse_loss_string(string):
|
316
|
+
if string == "ns":
|
317
|
+
return loss_name.ns
|
318
|
+
if string == "hs":
|
319
|
+
return loss_name.hs
|
320
|
+
if string == "softmax":
|
321
|
+
return loss_name.softmax
|
322
|
+
if string == "ova":
|
323
|
+
return loss_name.ova
|
324
|
+
else:
|
325
|
+
raise ValueError("Unrecognized loss name")
|
326
|
+
|
327
|
+
|
328
|
+
def _build_args(args):
|
329
|
+
args["model"] = _parse_model_string(args["model"])
|
330
|
+
args["loss"] = _parse_loss_string(args["loss"])
|
331
|
+
a = fasttext.args()
|
332
|
+
for (k, v) in args.items():
|
333
|
+
setattr(a, k, v)
|
334
|
+
a.output = "" # User should use save_model
|
335
|
+
a.saveOutput = 0 # Never use this
|
336
|
+
if a.wordNgrams <= 1 and a.maxn == 0:
|
337
|
+
a.bucket = 0
|
338
|
+
return a
|
339
|
+
|
340
|
+
|
341
|
+
def tokenize(text):
|
342
|
+
"""Given a string of text, tokenize it and return a list of tokens"""
|
343
|
+
f = fasttext.fasttext()
|
344
|
+
return f.tokenize(text)
|
345
|
+
|
346
|
+
|
347
|
+
def load_model(path):
|
348
|
+
"""Load a model given a filepath and return a model object."""
|
349
|
+
eprint("Warning : `load_model` does not return WordVectorModel or SupervisedModel any more, but a `FastText` object which is very similar.")
|
350
|
+
return _FastText(model_path=path)
|
351
|
+
|
352
|
+
|
353
|
+
unsupervised_default = {
|
354
|
+
'model' : "skipgram",
|
355
|
+
'lr' : 0.05,
|
356
|
+
'dim' : 100,
|
357
|
+
'ws' : 5,
|
358
|
+
'epoch' : 5,
|
359
|
+
'minCount' : 5,
|
360
|
+
'minCountLabel' : 0,
|
361
|
+
'minn' : 3,
|
362
|
+
'maxn' : 6,
|
363
|
+
'neg' : 5,
|
364
|
+
'wordNgrams' : 1,
|
365
|
+
'loss' : "ns",
|
366
|
+
'bucket' : 2000000,
|
367
|
+
'thread' : multiprocessing.cpu_count() - 1,
|
368
|
+
'lrUpdateRate' : 100,
|
369
|
+
't' : 1e-4,
|
370
|
+
'label' : "__label__",
|
371
|
+
'verbose' : 2,
|
372
|
+
'pretrainedVectors' : "",
|
373
|
+
}
|
374
|
+
|
375
|
+
|
376
|
+
def read_args(arg_list, arg_dict, arg_names, default_values):
|
377
|
+
param_map = {
|
378
|
+
'min_count' : 'minCount',
|
379
|
+
'word_ngrams' : 'wordNgrams',
|
380
|
+
'lr_update_rate' : 'lrUpdateRate',
|
381
|
+
'label_prefix' : 'label',
|
382
|
+
'pretrained_vectors' : 'pretrainedVectors'
|
383
|
+
}
|
384
|
+
|
385
|
+
ret = {}
|
386
|
+
for (arg_name, arg_value) in chain(zip(arg_names, arg_list), arg_dict.items()):
|
387
|
+
if arg_name in param_map:
|
388
|
+
arg_name = param_map[arg_name]
|
389
|
+
if arg_name not in arg_names:
|
390
|
+
raise TypeError("unexpected keyword argument '%s'" % arg_name)
|
391
|
+
if arg_name in ret:
|
392
|
+
raise TypeError("multiple values for argument '%s'" % arg_name)
|
393
|
+
ret[arg_name] = arg_value
|
394
|
+
|
395
|
+
for (arg_name, arg_value) in default_values.items():
|
396
|
+
if arg_name not in ret:
|
397
|
+
ret[arg_name] = arg_value
|
398
|
+
|
399
|
+
return ret
|
400
|
+
|
401
|
+
|
402
|
+
def train_supervised(*kargs, **kwargs):
|
403
|
+
"""
|
404
|
+
Train a supervised model and return a model object.
|
405
|
+
|
406
|
+
input must be a filepath. The input text does not need to be tokenized
|
407
|
+
as per the tokenize function, but it must be preprocessed and encoded
|
408
|
+
as UTF-8. You might want to consult standard preprocessing scripts such
|
409
|
+
as tokenizer.perl mentioned here: http://www.statmt.org/wmt07/baseline.html
|
410
|
+
|
411
|
+
The input file must must contain at least one label per line. For an
|
412
|
+
example consult the example datasets which are part of the fastText
|
413
|
+
repository such as the dataset pulled by classification-example.sh.
|
414
|
+
"""
|
415
|
+
supervised_default = unsupervised_default.copy()
|
416
|
+
supervised_default.update({
|
417
|
+
'lr' : 0.1,
|
418
|
+
'minCount' : 1,
|
419
|
+
'minn' : 0,
|
420
|
+
'maxn' : 0,
|
421
|
+
'loss' : "softmax",
|
422
|
+
'model' : "supervised"
|
423
|
+
})
|
424
|
+
|
425
|
+
arg_names = ['input', 'lr', 'dim', 'ws', 'epoch', 'minCount',
|
426
|
+
'minCountLabel', 'minn', 'maxn', 'neg', 'wordNgrams', 'loss', 'bucket',
|
427
|
+
'thread', 'lrUpdateRate', 't', 'label', 'verbose', 'pretrainedVectors']
|
428
|
+
params = read_args(kargs, kwargs, arg_names, supervised_default)
|
429
|
+
a = _build_args(params)
|
430
|
+
ft = _FastText(args=a)
|
431
|
+
fasttext.train(ft.f, a)
|
432
|
+
return ft
|
433
|
+
|
434
|
+
|
435
|
+
def train_unsupervised(*kargs, **kwargs):
|
436
|
+
"""
|
437
|
+
Train an unsupervised model and return a model object.
|
438
|
+
|
439
|
+
input must be a filepath. The input text does not need to be tokenized
|
440
|
+
as per the tokenize function, but it must be preprocessed and encoded
|
441
|
+
as UTF-8. You might want to consult standard preprocessing scripts such
|
442
|
+
as tokenizer.perl mentioned here: http://www.statmt.org/wmt07/baseline.html
|
443
|
+
|
444
|
+
The input field must not contain any labels or use the specified label prefix
|
445
|
+
unless it is ok for those words to be ignored. For an example consult the
|
446
|
+
dataset pulled by the example script word-vector-example.sh, which is
|
447
|
+
part of the fastText repository.
|
448
|
+
"""
|
449
|
+
arg_names = ['input', 'model', 'lr', 'dim', 'ws', 'epoch', 'minCount',
|
450
|
+
'minCountLabel', 'minn', 'maxn', 'neg', 'wordNgrams', 'loss', 'bucket',
|
451
|
+
'thread', 'lrUpdateRate', 't', 'label', 'verbose', 'pretrainedVectors']
|
452
|
+
params = read_args(kargs, kwargs, arg_names, unsupervised_default)
|
453
|
+
a = _build_args(params)
|
454
|
+
ft = _FastText(args=a)
|
455
|
+
fasttext.train(ft.f, a)
|
456
|
+
return ft
|
457
|
+
|
458
|
+
|
459
|
+
def cbow(*kargs, **kwargs):
|
460
|
+
raise Exception("`cbow` is not supported any more. Please use `train_unsupervised` with model=`cbow`. For more information please refer to https://fasttext.cc/blog/2019/06/25/blog-post.html#2-you-were-using-the-unofficial-fasttext-module")
|
461
|
+
|
462
|
+
|
463
|
+
def skipgram(*kargs, **kwargs):
|
464
|
+
raise Exception("`skipgram` is not supported any more. Please use `train_unsupervised` with model=`skipgram`. For more information please refer to https://fasttext.cc/blog/2019/06/25/blog-post.html#2-you-were-using-the-unofficial-fasttext-module")
|
465
|
+
|
466
|
+
|
467
|
+
def supervised(*kargs, **kwargs):
|
468
|
+
raise Exception("`supervised` is not supported any more. Please use `train_supervised`. For more information please refer to https://fasttext.cc/blog/2019/06/25/blog-post.html#2-you-were-using-the-unofficial-fasttext-module")
|