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,629 @@
|
|
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
|
+
from fasttext import train_supervised
|
13
|
+
from fasttext import train_unsupervised
|
14
|
+
from fasttext import util
|
15
|
+
import fasttext
|
16
|
+
import os
|
17
|
+
import subprocess
|
18
|
+
import unittest
|
19
|
+
import tempfile
|
20
|
+
import random
|
21
|
+
import sys
|
22
|
+
import copy
|
23
|
+
import numpy as np
|
24
|
+
try:
|
25
|
+
import unicode
|
26
|
+
except ImportError:
|
27
|
+
pass
|
28
|
+
from fasttext.tests.test_configurations import get_supervised_models
|
29
|
+
|
30
|
+
|
31
|
+
def eprint(cls, *args, **kwargs):
|
32
|
+
print(*args, file=sys.stderr, **kwargs)
|
33
|
+
|
34
|
+
|
35
|
+
def get_random_unicode(length):
|
36
|
+
# See: https://stackoverflow.com/questions/1477294/generate-random-utf-8-string-in-python
|
37
|
+
|
38
|
+
try:
|
39
|
+
get_char = unichr
|
40
|
+
except NameError:
|
41
|
+
get_char = chr
|
42
|
+
|
43
|
+
# Update this to include code point ranges to be sampled
|
44
|
+
include_ranges = [
|
45
|
+
(0x0021, 0x0021),
|
46
|
+
(0x0023, 0x0026),
|
47
|
+
(0x0028, 0x007E),
|
48
|
+
(0x00A1, 0x00AC),
|
49
|
+
(0x00AE, 0x00FF),
|
50
|
+
(0x0100, 0x017F),
|
51
|
+
(0x0180, 0x024F),
|
52
|
+
(0x2C60, 0x2C7F),
|
53
|
+
(0x16A0, 0x16F0),
|
54
|
+
(0x0370, 0x0377),
|
55
|
+
(0x037A, 0x037E),
|
56
|
+
(0x0384, 0x038A),
|
57
|
+
(0x038C, 0x038C),
|
58
|
+
]
|
59
|
+
|
60
|
+
alphabet = [
|
61
|
+
get_char(code_point)
|
62
|
+
for current_range in include_ranges
|
63
|
+
for code_point in range(current_range[0], current_range[1] + 1)
|
64
|
+
]
|
65
|
+
return ''.join(random.choice(alphabet) for i in range(length))
|
66
|
+
|
67
|
+
|
68
|
+
def get_random_words(N, a=1, b=20, unique=True):
|
69
|
+
words = []
|
70
|
+
while (len(words) < N):
|
71
|
+
length = random.randint(a, b)
|
72
|
+
word = get_random_unicode(length)
|
73
|
+
if unique and word not in words:
|
74
|
+
words.append(word)
|
75
|
+
else:
|
76
|
+
words.append(word)
|
77
|
+
return words
|
78
|
+
|
79
|
+
|
80
|
+
def get_random_data(
|
81
|
+
num_lines=100,
|
82
|
+
max_vocab_size=100,
|
83
|
+
min_words_line=0,
|
84
|
+
max_words_line=20,
|
85
|
+
min_len_word=1,
|
86
|
+
max_len_word=10,
|
87
|
+
unique_words=True,
|
88
|
+
):
|
89
|
+
random_words = get_random_words(
|
90
|
+
max_vocab_size, min_len_word, max_len_word, unique=unique_words
|
91
|
+
)
|
92
|
+
lines = []
|
93
|
+
for _ in range(num_lines):
|
94
|
+
line = []
|
95
|
+
line_length = random.randint(min_words_line, max_words_line)
|
96
|
+
for _ in range(line_length):
|
97
|
+
i = random.randint(0, max_vocab_size - 1)
|
98
|
+
line.append(random_words[i])
|
99
|
+
line = " ".join(line)
|
100
|
+
lines.append(line)
|
101
|
+
return lines
|
102
|
+
|
103
|
+
|
104
|
+
def default_kwargs(kwargs):
|
105
|
+
default = {"thread": 1, "epoch": 1, "minCount": 1, "bucket": 1000}
|
106
|
+
for k, v in default.items():
|
107
|
+
if k not in kwargs:
|
108
|
+
kwargs[k] = v
|
109
|
+
return kwargs
|
110
|
+
|
111
|
+
|
112
|
+
def build_unsupervised_model(data, kwargs):
|
113
|
+
kwargs = default_kwargs(kwargs)
|
114
|
+
with tempfile.NamedTemporaryFile(delete=False) as tmpf:
|
115
|
+
for line in data:
|
116
|
+
tmpf.write((line + "\n").encode("UTF-8"))
|
117
|
+
tmpf.flush()
|
118
|
+
model = train_unsupervised(input=tmpf.name, **kwargs)
|
119
|
+
return model
|
120
|
+
|
121
|
+
|
122
|
+
def build_supervised_model(data, kwargs):
|
123
|
+
kwargs = default_kwargs(kwargs)
|
124
|
+
with tempfile.NamedTemporaryFile(delete=False) as tmpf:
|
125
|
+
for line in data:
|
126
|
+
line = "__label__" + line.strip() + "\n"
|
127
|
+
tmpf.write(line.encode("UTF-8"))
|
128
|
+
tmpf.flush()
|
129
|
+
model = train_supervised(input=tmpf.name, **kwargs)
|
130
|
+
return model
|
131
|
+
|
132
|
+
|
133
|
+
def read_labels(data_file):
|
134
|
+
labels = []
|
135
|
+
lines = []
|
136
|
+
with open(data_file, 'r') as f:
|
137
|
+
for line in f:
|
138
|
+
labels_line = []
|
139
|
+
words_line = []
|
140
|
+
try:
|
141
|
+
line = unicode(line, "UTF-8").split()
|
142
|
+
except NameError:
|
143
|
+
line = line.split()
|
144
|
+
for word in line:
|
145
|
+
if word.startswith("__label__"):
|
146
|
+
labels_line.append(word)
|
147
|
+
else:
|
148
|
+
words_line.append(word)
|
149
|
+
labels.append(labels_line)
|
150
|
+
lines.append(" ".join(words_line))
|
151
|
+
return lines, labels
|
152
|
+
|
153
|
+
|
154
|
+
class TestFastTextUnitPy(unittest.TestCase):
|
155
|
+
# TODO: Unit test copy behavior of fasttext
|
156
|
+
|
157
|
+
def gen_test_get_vector(self, kwargs):
|
158
|
+
# Confirm if no subwords, OOV is zero, confirm min=10 means words < 10 get zeros
|
159
|
+
|
160
|
+
f = build_unsupervised_model(get_random_data(100), kwargs)
|
161
|
+
words, _ = f.get_words(include_freq=True)
|
162
|
+
words += get_random_words(100)
|
163
|
+
for word in words:
|
164
|
+
f.get_word_vector(word)
|
165
|
+
|
166
|
+
def gen_test_multi_get_line(self, kwargs):
|
167
|
+
data = get_random_data(100)
|
168
|
+
model1 = build_supervised_model(data, kwargs)
|
169
|
+
model2 = build_unsupervised_model(data, kwargs)
|
170
|
+
lines1 = []
|
171
|
+
lines2 = []
|
172
|
+
for line in data:
|
173
|
+
words, labels = model1.get_line(line)
|
174
|
+
lines1.append(words)
|
175
|
+
self.assertEqual(len(labels), 0)
|
176
|
+
words, labels = model2.get_line(line)
|
177
|
+
lines2.append(words)
|
178
|
+
self.assertEqual(len(labels), 0)
|
179
|
+
all_lines1, all_labels1 = model1.get_line(data)
|
180
|
+
all_lines2, all_labels2 = model2.get_line(data)
|
181
|
+
self.assertEqual(lines1, all_lines1)
|
182
|
+
self.assertEqual(lines2, all_lines2)
|
183
|
+
for labels in all_labels1:
|
184
|
+
self.assertEqual(len(labels), 0)
|
185
|
+
for labels in all_labels2:
|
186
|
+
self.assertEqual(len(labels), 0)
|
187
|
+
|
188
|
+
def gen_test_supervised_util_test(self, kwargs):
|
189
|
+
def check(data):
|
190
|
+
third = int(len(data) / 3)
|
191
|
+
train_data = data[:2 * third]
|
192
|
+
valid_data = data[third:]
|
193
|
+
with tempfile.NamedTemporaryFile(
|
194
|
+
delete=False
|
195
|
+
) as tmpf, tempfile.NamedTemporaryFile(delete=False) as tmpf2:
|
196
|
+
for line in train_data:
|
197
|
+
tmpf.write(
|
198
|
+
("__label__" + line.strip() + "\n").encode("UTF-8")
|
199
|
+
)
|
200
|
+
tmpf.flush()
|
201
|
+
for line in valid_data:
|
202
|
+
tmpf2.write(
|
203
|
+
("__label__" + line.strip() + "\n").encode("UTF-8")
|
204
|
+
)
|
205
|
+
tmpf2.flush()
|
206
|
+
model = train_supervised(input=tmpf.name, **kwargs)
|
207
|
+
true_labels = []
|
208
|
+
all_words = []
|
209
|
+
with open(tmpf2.name, 'r') as fid:
|
210
|
+
for line in fid:
|
211
|
+
if sys.version_info < (3, 0):
|
212
|
+
line = line.decode("UTF-8")
|
213
|
+
if len(line.strip()) == 0:
|
214
|
+
continue
|
215
|
+
words, labels = model.get_line(line.strip())
|
216
|
+
if len(labels) == 0:
|
217
|
+
continue
|
218
|
+
all_words.append(" ".join(words))
|
219
|
+
true_labels += [labels]
|
220
|
+
predictions, _ = model.predict(all_words)
|
221
|
+
p, r = util.test(predictions, true_labels)
|
222
|
+
N = len(predictions)
|
223
|
+
Nt, pt, rt = model.test(tmpf2.name)
|
224
|
+
self.assertEqual(N, Nt)
|
225
|
+
self.assertEqual(p, pt)
|
226
|
+
self.assertEqual(r, rt)
|
227
|
+
|
228
|
+
# Need at least one word to have a label and a word to prevent error
|
229
|
+
check(get_random_data(100, min_words_line=2))
|
230
|
+
|
231
|
+
def gen_test_supervised_predict(self, kwargs):
|
232
|
+
# Confirm number of labels, confirm labels for easy dataset
|
233
|
+
# Confirm 1 label and 0 label dataset
|
234
|
+
|
235
|
+
f = build_supervised_model(get_random_data(100), kwargs)
|
236
|
+
words = get_random_words(100)
|
237
|
+
for k in [1, 2, 5]:
|
238
|
+
for w in words:
|
239
|
+
labels, probs = f.predict(w, k)
|
240
|
+
data = get_random_data(100)
|
241
|
+
for line in data:
|
242
|
+
labels, probs = f.predict(line, k)
|
243
|
+
|
244
|
+
def gen_test_supervised_multiline_predict(self, kwargs):
|
245
|
+
# Confirm number of labels, confirm labels for easy dataset
|
246
|
+
# Confirm 1 label and 0 label dataset
|
247
|
+
|
248
|
+
def check_predict(f):
|
249
|
+
for k in [1, 2, 5]:
|
250
|
+
words = get_random_words(10)
|
251
|
+
agg_labels = []
|
252
|
+
agg_probs = []
|
253
|
+
for w in words:
|
254
|
+
labels, probs = f.predict(w, k)
|
255
|
+
agg_labels += [labels]
|
256
|
+
agg_probs += [probs]
|
257
|
+
all_labels1, all_probs1 = f.predict(words, k)
|
258
|
+
data = get_random_data(10)
|
259
|
+
for line in data:
|
260
|
+
labels, probs = f.predict(line, k)
|
261
|
+
agg_labels += [labels]
|
262
|
+
agg_probs += [probs]
|
263
|
+
all_labels2, all_probs2 = f.predict(data, k)
|
264
|
+
all_labels = list(all_labels1) + list(all_labels2)
|
265
|
+
all_probs = list(all_probs1) + list(all_probs2)
|
266
|
+
for label1, label2 in zip(all_labels, agg_labels):
|
267
|
+
self.assertEqual(list(label1), list(label2))
|
268
|
+
for prob1, prob2 in zip(all_probs, agg_probs):
|
269
|
+
self.assertEqual(list(prob1), list(prob2))
|
270
|
+
|
271
|
+
check_predict(build_supervised_model(get_random_data(100), kwargs))
|
272
|
+
check_predict(
|
273
|
+
build_supervised_model(
|
274
|
+
get_random_data(100, min_words_line=1), kwargs
|
275
|
+
)
|
276
|
+
)
|
277
|
+
|
278
|
+
def gen_test_vocab(self, kwargs):
|
279
|
+
# Confirm empty dataset, confirm all label dataset
|
280
|
+
|
281
|
+
data = get_random_data(100)
|
282
|
+
words_python = {}
|
283
|
+
for line in data:
|
284
|
+
line_words = line.split()
|
285
|
+
for w in line_words:
|
286
|
+
if w not in words_python:
|
287
|
+
words_python[w] = 0
|
288
|
+
words_python[w] += 1
|
289
|
+
f = build_unsupervised_model(data, kwargs)
|
290
|
+
words, freqs = f.get_words(include_freq=True)
|
291
|
+
foundEOS = False
|
292
|
+
for word, freq in zip(words, freqs):
|
293
|
+
if word == fasttext.EOS:
|
294
|
+
foundEOS = True
|
295
|
+
else:
|
296
|
+
self.assertEqual(words_python[word], freq)
|
297
|
+
# EOS is special to fasttext, but still part of the vocab
|
298
|
+
self.assertEqual(len(words_python), len(words) - 1)
|
299
|
+
self.assertTrue(foundEOS)
|
300
|
+
|
301
|
+
# Should cause "Empty vocabulary" error.
|
302
|
+
data = get_random_data(0)
|
303
|
+
gotError = False
|
304
|
+
try:
|
305
|
+
build_unsupervised_model(data, kwargs)
|
306
|
+
except ValueError:
|
307
|
+
gotError = True
|
308
|
+
self.assertTrue(gotError)
|
309
|
+
|
310
|
+
def gen_test_subwords(self, kwargs):
|
311
|
+
# Define expected behavior
|
312
|
+
f = build_unsupervised_model(get_random_data(100), kwargs)
|
313
|
+
words, _ = f.get_words(include_freq=True)
|
314
|
+
words += get_random_words(10, 1, 10)
|
315
|
+
for w in words:
|
316
|
+
f.get_subwords(w)
|
317
|
+
|
318
|
+
def gen_test_tokenize(self, kwargs):
|
319
|
+
self.assertEqual(["asdf", "asdb"], fasttext.tokenize("asdf asdb"))
|
320
|
+
self.assertEqual(["asdf"], fasttext.tokenize("asdf"))
|
321
|
+
self.assertEqual([fasttext.EOS], fasttext.tokenize("\n"))
|
322
|
+
self.assertEqual(["asdf", fasttext.EOS], fasttext.tokenize("asdf\n"))
|
323
|
+
self.assertEqual([], fasttext.tokenize(""))
|
324
|
+
self.assertEqual([], fasttext.tokenize(" "))
|
325
|
+
# An empty string is not a token (it's just whitespace)
|
326
|
+
# So the minimum length must be 1
|
327
|
+
words = get_random_words(100, 1, 20)
|
328
|
+
self.assertEqual(words, fasttext.tokenize(" ".join(words)))
|
329
|
+
|
330
|
+
def gen_test_unsupervised_dimension(self, kwargs):
|
331
|
+
if "dim" in kwargs:
|
332
|
+
f = build_unsupervised_model(get_random_data(100), kwargs)
|
333
|
+
self.assertEqual(f.get_dimension(), kwargs["dim"])
|
334
|
+
|
335
|
+
def gen_test_supervised_dimension(self, kwargs):
|
336
|
+
if "dim" in kwargs:
|
337
|
+
f = build_supervised_model(get_random_data(100), kwargs)
|
338
|
+
self.assertEqual(f.get_dimension(), kwargs["dim"])
|
339
|
+
|
340
|
+
def gen_test_subword_vector(self, kwargs):
|
341
|
+
f = build_unsupervised_model(get_random_data(100), kwargs)
|
342
|
+
words, _ = f.get_words(include_freq=True)
|
343
|
+
words += get_random_words(100, 1, 20)
|
344
|
+
input_matrix = f.get_input_matrix()
|
345
|
+
for word in words:
|
346
|
+
# Universal API to get word vector
|
347
|
+
vec1 = f.get_word_vector(word)
|
348
|
+
|
349
|
+
# Build word vector from subwords
|
350
|
+
subwords, subinds = f.get_subwords(word)
|
351
|
+
subvectors = list(map(lambda x: f.get_input_vector(x), subinds))
|
352
|
+
if len(subvectors) == 0:
|
353
|
+
vec2 = np.zeros((f.get_dimension(), ))
|
354
|
+
else:
|
355
|
+
subvectors = np.vstack(subvectors)
|
356
|
+
vec2 = np.sum((subvectors / len(subwords)), 0)
|
357
|
+
|
358
|
+
# Build word vector from subinds
|
359
|
+
if len(subinds) == 0:
|
360
|
+
vec3 = np.zeros((f.get_dimension(), ))
|
361
|
+
else:
|
362
|
+
vec3 = np.sum(input_matrix[subinds] / len(subinds), 0)
|
363
|
+
|
364
|
+
# Build word vectors from word and subword ids
|
365
|
+
wid = f.get_word_id(word)
|
366
|
+
if wid >= 0:
|
367
|
+
swids = list(map(lambda x: f.get_subword_id(x), subwords[1:]))
|
368
|
+
swids.append(wid)
|
369
|
+
else:
|
370
|
+
swids = list(map(lambda x: f.get_subword_id(x), subwords))
|
371
|
+
if len(swids) == 0:
|
372
|
+
vec4 = np.zeros((f.get_dimension(), ))
|
373
|
+
else:
|
374
|
+
swids = np.array(swids)
|
375
|
+
vec4 = np.sum(input_matrix[swids] / len(swids), 0)
|
376
|
+
|
377
|
+
self.assertTrue(np.isclose(vec1, vec2, atol=1e-5, rtol=0).all())
|
378
|
+
self.assertTrue(np.isclose(vec2, vec3, atol=1e-5, rtol=0).all())
|
379
|
+
self.assertTrue(np.isclose(vec3, vec4, atol=1e-5, rtol=0).all())
|
380
|
+
self.assertTrue(np.isclose(vec4, vec1, atol=1e-5, rtol=0).all())
|
381
|
+
|
382
|
+
def gen_test_unsupervised_get_words(self, kwargs):
|
383
|
+
# Check more corner cases of 0 vocab, empty file etc.
|
384
|
+
f = build_unsupervised_model(get_random_data(100), kwargs)
|
385
|
+
words1, freq1 = f.get_words(include_freq=True)
|
386
|
+
words2 = f.get_words(include_freq=False)
|
387
|
+
self.assertEqual(len(words1), len(words2))
|
388
|
+
self.assertEqual(len(words1), len(freq1))
|
389
|
+
|
390
|
+
def gen_test_supervised_get_words(self, kwargs):
|
391
|
+
f = build_supervised_model(get_random_data(100), kwargs)
|
392
|
+
words1, freq1 = f.get_words(include_freq=True)
|
393
|
+
words2 = f.get_words(include_freq=False)
|
394
|
+
self.assertEqual(len(words1), len(words2))
|
395
|
+
self.assertEqual(len(words1), len(freq1))
|
396
|
+
|
397
|
+
def gen_test_unsupervised_get_labels(self, kwargs):
|
398
|
+
f = build_unsupervised_model(get_random_data(100), kwargs)
|
399
|
+
labels1, freq1 = f.get_labels(include_freq=True)
|
400
|
+
labels2 = f.get_labels(include_freq=False)
|
401
|
+
words2 = f.get_words(include_freq=False)
|
402
|
+
self.assertEqual(len(labels1), len(labels2))
|
403
|
+
self.assertEqual(len(labels1), len(freq1))
|
404
|
+
self.assertEqual(len(labels1), len(words2))
|
405
|
+
for w1, w2 in zip(labels2, words2):
|
406
|
+
self.assertEqual(w1, w2)
|
407
|
+
|
408
|
+
def gen_test_supervised_get_labels(self, kwargs):
|
409
|
+
f = build_supervised_model(get_random_data(100), kwargs)
|
410
|
+
labels1, freq1 = f.get_labels(include_freq=True)
|
411
|
+
labels2 = f.get_labels(include_freq=False)
|
412
|
+
self.assertEqual(len(labels1), len(labels2))
|
413
|
+
self.assertEqual(len(labels1), len(freq1))
|
414
|
+
|
415
|
+
def gen_test_unsupervised_exercise_is_quant(self, kwargs):
|
416
|
+
f = build_unsupervised_model(get_random_data(100), kwargs)
|
417
|
+
gotError = False
|
418
|
+
try:
|
419
|
+
f.quantize()
|
420
|
+
except ValueError:
|
421
|
+
gotError = True
|
422
|
+
self.assertTrue(gotError)
|
423
|
+
|
424
|
+
def gen_test_supervised_exercise_is_quant(self, kwargs):
|
425
|
+
f = build_supervised_model(
|
426
|
+
get_random_data(1000, max_vocab_size=1000), kwargs
|
427
|
+
)
|
428
|
+
self.assertTrue(not f.is_quantized())
|
429
|
+
f.quantize()
|
430
|
+
self.assertTrue(f.is_quantized())
|
431
|
+
|
432
|
+
def gen_test_newline_predict_sentence(self, kwargs):
|
433
|
+
f = build_supervised_model(get_random_data(100), kwargs)
|
434
|
+
sentence = " ".join(get_random_words(20))
|
435
|
+
f.predict(sentence, k=5)
|
436
|
+
sentence += "\n"
|
437
|
+
gotError = False
|
438
|
+
try:
|
439
|
+
f.predict(sentence, k=5)
|
440
|
+
except ValueError:
|
441
|
+
gotError = True
|
442
|
+
self.assertTrue(gotError)
|
443
|
+
|
444
|
+
f = build_supervised_model(get_random_data(100), kwargs)
|
445
|
+
sentence = " ".join(get_random_words(20))
|
446
|
+
f.get_sentence_vector(sentence)
|
447
|
+
sentence += "\n"
|
448
|
+
gotError = False
|
449
|
+
try:
|
450
|
+
f.get_sentence_vector(sentence)
|
451
|
+
except ValueError:
|
452
|
+
gotError = True
|
453
|
+
self.assertTrue(gotError)
|
454
|
+
|
455
|
+
|
456
|
+
# Generate a supervised test case
|
457
|
+
# The returned function will be set as an attribute to a test class
|
458
|
+
def gen_sup_test(configuration, data_dir):
|
459
|
+
def sup_test(self):
|
460
|
+
def get_path_size(path):
|
461
|
+
path_size = subprocess.check_output(["stat", "-c", "%s",
|
462
|
+
path]).decode('utf-8')
|
463
|
+
path_size = int(path_size)
|
464
|
+
return path_size
|
465
|
+
|
466
|
+
def check(model, model_filename, test, lessthan, msg_prefix=""):
|
467
|
+
N_local_out, p1_local_out, r1_local_out = model.test(test["data"])
|
468
|
+
self.assertEqual(
|
469
|
+
N_local_out, test["n"], msg_prefix + "N: Want: " +
|
470
|
+
str(test["n"]) + " Is: " + str(N_local_out)
|
471
|
+
)
|
472
|
+
self.assertTrue(
|
473
|
+
p1_local_out >= test["p1"], msg_prefix + "p1: Want: " +
|
474
|
+
str(test["p1"]) + " Is: " + str(p1_local_out)
|
475
|
+
)
|
476
|
+
self.assertTrue(
|
477
|
+
r1_local_out >= test["r1"], msg_prefix + "r1: Want: " +
|
478
|
+
str(test["r1"]) + " Is: " + str(r1_local_out)
|
479
|
+
)
|
480
|
+
path_size = get_path_size(model_filename)
|
481
|
+
size_msg = str(test["size"]) + " Is: " + str(path_size)
|
482
|
+
if lessthan:
|
483
|
+
self.assertTrue(
|
484
|
+
path_size <= test["size"],
|
485
|
+
msg_prefix + "Size: Want at most: " + size_msg
|
486
|
+
)
|
487
|
+
else:
|
488
|
+
self.assertTrue(
|
489
|
+
path_size == test["size"],
|
490
|
+
msg_prefix + "Size: Want: " + size_msg
|
491
|
+
)
|
492
|
+
|
493
|
+
configuration["args"]["input"] = os.path.join(
|
494
|
+
data_dir, configuration["args"]["input"]
|
495
|
+
)
|
496
|
+
configuration["quant_args"]["input"] = configuration["args"]["input"]
|
497
|
+
configuration["test"]["data"] = os.path.join(
|
498
|
+
data_dir, configuration["test"]["data"]
|
499
|
+
)
|
500
|
+
configuration["quant_test"]["data"] = configuration["test"]["data"]
|
501
|
+
output = os.path.join(tempfile.mkdtemp(), configuration["dataset"])
|
502
|
+
print()
|
503
|
+
model = train_supervised(**configuration["args"])
|
504
|
+
model.save_model(output + ".bin")
|
505
|
+
check(
|
506
|
+
model,
|
507
|
+
output + ".bin",
|
508
|
+
configuration["test"],
|
509
|
+
False,
|
510
|
+
msg_prefix="Supervised: "
|
511
|
+
)
|
512
|
+
print()
|
513
|
+
model.quantize(**configuration["quant_args"])
|
514
|
+
model.save_model(output + ".ftz")
|
515
|
+
check(
|
516
|
+
model,
|
517
|
+
output + ".ftz",
|
518
|
+
configuration["quant_test"],
|
519
|
+
True,
|
520
|
+
msg_prefix="Quantized: "
|
521
|
+
)
|
522
|
+
|
523
|
+
return sup_test
|
524
|
+
|
525
|
+
|
526
|
+
def gen_unit_tests(verbose=0):
|
527
|
+
gen_funcs = [
|
528
|
+
func for func in dir(TestFastTextUnitPy)
|
529
|
+
if callable(getattr(TestFastTextUnitPy, func))
|
530
|
+
if func.startswith("gen_test_")
|
531
|
+
]
|
532
|
+
general_settings = [
|
533
|
+
{
|
534
|
+
"minn": 2,
|
535
|
+
"maxn": 4,
|
536
|
+
}, {
|
537
|
+
"minn": 0,
|
538
|
+
"maxn": 0,
|
539
|
+
"bucket": 0
|
540
|
+
}, {
|
541
|
+
"dim": 1
|
542
|
+
}, {
|
543
|
+
"dim": 5
|
544
|
+
}
|
545
|
+
]
|
546
|
+
supervised_settings = [
|
547
|
+
{
|
548
|
+
"minn": 2,
|
549
|
+
"maxn": 4,
|
550
|
+
}, {
|
551
|
+
"minn": 0,
|
552
|
+
"maxn": 0,
|
553
|
+
"bucket": 0
|
554
|
+
}, {
|
555
|
+
"dim": 1
|
556
|
+
}, {
|
557
|
+
"dim": 5
|
558
|
+
}, {
|
559
|
+
"dim": 5,
|
560
|
+
"loss": "hs"
|
561
|
+
}
|
562
|
+
]
|
563
|
+
unsupervised_settings = [
|
564
|
+
{
|
565
|
+
"minn": 2,
|
566
|
+
"maxn": 4,
|
567
|
+
}, {
|
568
|
+
"minn": 0,
|
569
|
+
"maxn": 0,
|
570
|
+
"bucket": 0
|
571
|
+
}, {
|
572
|
+
"dim": 1
|
573
|
+
}, {
|
574
|
+
"dim": 5,
|
575
|
+
"model": "cbow"
|
576
|
+
}, {
|
577
|
+
"dim": 5,
|
578
|
+
"model": "skipgram"
|
579
|
+
}
|
580
|
+
]
|
581
|
+
for gen_func in gen_funcs:
|
582
|
+
|
583
|
+
def build_test(test_name, kwargs=None):
|
584
|
+
if kwargs is None:
|
585
|
+
kwargs = {}
|
586
|
+
kwargs["verbose"] = verbose
|
587
|
+
|
588
|
+
def test(self):
|
589
|
+
return getattr(TestFastTextUnitPy,
|
590
|
+
"gen_" + test_name)(self, copy.deepcopy(kwargs))
|
591
|
+
|
592
|
+
return test
|
593
|
+
|
594
|
+
test_name = gen_func[4:]
|
595
|
+
if "_unsupervised_" in test_name:
|
596
|
+
for i, setting in enumerate(unsupervised_settings):
|
597
|
+
setattr(
|
598
|
+
TestFastTextUnitPy, test_name + "_" + str(i),
|
599
|
+
build_test(test_name, setting)
|
600
|
+
)
|
601
|
+
elif "_supervised_" in test_name:
|
602
|
+
for i, setting in enumerate(supervised_settings):
|
603
|
+
setattr(
|
604
|
+
TestFastTextUnitPy, test_name + "_" + str(i),
|
605
|
+
build_test(test_name, setting)
|
606
|
+
)
|
607
|
+
else:
|
608
|
+
for i, setting in enumerate(general_settings):
|
609
|
+
setattr(
|
610
|
+
TestFastTextUnitPy, test_name + "_" + str(i),
|
611
|
+
build_test(test_name, setting)
|
612
|
+
)
|
613
|
+
|
614
|
+
return TestFastTextUnitPy
|
615
|
+
|
616
|
+
|
617
|
+
def gen_tests(data_dir, verbose=1):
|
618
|
+
class TestFastTextPy(unittest.TestCase):
|
619
|
+
pass
|
620
|
+
|
621
|
+
i = 0
|
622
|
+
for configuration in get_supervised_models(verbose=verbose):
|
623
|
+
setattr(
|
624
|
+
TestFastTextPy,
|
625
|
+
"test_sup_" + str(i) + "_" + configuration["dataset"],
|
626
|
+
gen_sup_test(configuration, data_dir)
|
627
|
+
)
|
628
|
+
i += 1
|
629
|
+
return TestFastTextPy
|