{"id":13779041,"url":"https://github.com/mwydmuch/extremeText","last_synced_at":"2025-05-11T12:32:40.492Z","repository":{"id":57427816,"uuid":"65775764","full_name":"mwydmuch/extremeText","owner":"mwydmuch","description":"Library for fast text representation and extreme classification.","archived":false,"fork":true,"pushed_at":"2020-12-20T18:22:50.000Z","size":41742,"stargazers_count":150,"open_issues_count":6,"forks_count":16,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-09-14T22:29:11.299Z","etag":null,"topics":["extreme-classification","extreme-multi-label-cassification","extremetext","fasttext","machine-learning","multi-label-classification","text-classification"],"latest_commit_sha":null,"homepage":"","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"facebookresearch/fastText","license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mwydmuch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-08-16T01:04:26.000Z","updated_at":"2024-06-02T06:51:08.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/mwydmuch/extremeText","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mwydmuch%2FextremeText","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mwydmuch%2FextremeText/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mwydmuch%2FextremeText/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mwydmuch%2FextremeText/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mwydmuch","download_url":"https://codeload.github.com/mwydmuch/extremeText/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225049022,"owners_count":17412911,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["extreme-classification","extreme-multi-label-cassification","extremetext","fasttext","machine-learning","multi-label-classification","text-classification"],"created_at":"2024-08-03T18:01:00.347Z","updated_at":"2024-11-17T14:31:09.871Z","avatar_url":"https://github.com/mwydmuch.png","language":"HTML","funding_links":[],"categories":["Text Classification"],"sub_categories":[],"readme":"# extremeText\n\nextremeText is an extension of [fastText](https://github.com/facebookresearch/fastText) library for multi-label classification including extreme cases with hundreds of thousands and millions of labels.\n\nextremeText implements:\n\n* Probabilistic Labels Tree (PLT) loss for extreme multi-Label classification with top-down hierarchical clustering (k-means) for tree building,\n* sigmoid loss for multi-label classification,\n* L2 regularization for all losses,\n* ensemble of loss layers with bagging,\n* calculation of hidden (document) vector as a weighted average of the word vectors,\n* calculation of TF-IDF weights for words.\n\n## Installation\n\n### Building executable\n\nextremeText like fastText can be build as executable using Make (recommended) or/and CMake:\n\n```\n$ git clone https://github.com/mwydmuch/extremeText.git\n$ cd extremeText\n(optional) $ cmake .\n$ make\n```\n\nThis will produce object files for all the classes as well as the main binary `extremetext`.\n\n### Python package\n\nThe easiest way to get extremeText is to use [pip](https://pip.pypa.io/en/stable/).\n\n```\n$ pip install extremetext\n```\n\nInstalling on MacOS may require setting `MACOSX_DEPLOYMENT_TARGET=10.9` first:\n```\n$ export MACOSX_DEPLOYMENT_TARGET=10.9\n$ pip install extremetext\n```\n\nThe latest version of extremeText can be build from sources using pip or alternatively setuptools.\n\n```\n$ git clone https://github.com/mwydmuch/extremeText.git\n$ cd extremeText\n$ pip install .\n(or) $ python setup.py install\n```\n\nNow you can import this library with:\n\n```\nimport extremeText\n```\n\n## Usage\n\nextremeText adds new options for fastText supervised command:\n\n```\n$ ./extremetext supervised\n\nNew losses for multi-label classification:\n  -loss sigmoid       \n  -loss plt           (Probabilistic Labels Tree)\n\nWith the following optional arguments:\n  General:\n  -l2                 L2 regularization (default = 0)\n  -tfidfWeights       calculate TF-IDF weights for words\n  -wordsWeights       read word weights from file (format: \u003cword\u003e:\u003cweights\u003e)\n  -weight             document weight prefix (default = __weight__; format: \u003cweight prefix\u003e:\u003cdocument weight\u003e)\n  -tag                tags prefix (default = __tag__), tags are ignored words, that are outputed with prediction\n  -eosWeight          weight of EOS token (default = 1.0)\n  -freezeVectors      freeze pretrained word vectors for supervised learning\n  \n  PLT (Probabilistic Labels Tree):\n  -treeType           type of PLT: complete, huffman, kmeans (default = kmeans)\n  -arity              arity of PLT (default = 2)\n  -maxLeaves          maximum number of leaves (labels) in one internal node of PLT (default = 100)\n  -kMeansEps          stopping criteria for k-means clustering (default = 0.001)\n  \n  Ensemble:\n  -ensemble           size of the ensemble (default = 1)\n  -bagging            bagging ratio (default = 1.0)\n```\n\nextremeText also adds new commands and makes other to work in parallel:\n```\n$ ./extremetext predict[-prob] \u003cmodel\u003e \u003ctest-data\u003e [\u003ck\u003e] [\u003cth\u003e] [\u003coutput\u003e] [\u003cthread\u003e]\n$ ./extremetext get-prob \u003cmodel\u003e \u003cinput\u003e [\u003cth\u003e] [\u003coutput\u003e] [\u003cthread\u003e]\n```\n\n## Reference\n\nPlease cite below work if using this code for extreme classification.\n\nM. Wydmuch, K. Jasinska, M. Kuznetsov, R. Busa-Fekete, K. Dembczyński. [*A no-regret generalization of hierarchical softmax to extreme multi-label classification*](http://papers.nips.cc/paper/7872-a-no-regret-generalization-of-hierarchical-softmax-to-extreme-multi-label-classification). Advances in Neural Information Processing Systems 31, 2018.\n\n## TODO\n* Merge with the latest changes from fastText.\n* Rewrite vanilla fastText losses as extremeText loss layers to support all new features. \n\n---\n\n# fastText original README.md\n\n## Table of contents\n\n* [Introduction](#introduction)\n* [Resources](#resources)\n   * [Models](#models)\n   * [Supplementary data](#supplementary-data)\n   * [FAQ](#faq)\n   * [Cheatsheet](#cheatsheet)\n* [Requirements](#requirements)\n* [Building fastText](#building-fasttext)\n   * [Getting the source code](#getting-the-source-code)\n   * [Building fastText using make (preferred)](#building-fasttext-using-make-preferred)\n   * [Building fastText using cmake](#building-fasttext-using-cmake)\n   * [Building fastText for Python](#building-fasttext-for-python)\n* [Example use cases](#example-use-cases)\n   * [Word representation learning](#word-representation-learning)\n   * [Obtaining word vectors for out-of-vocabulary words](#obtaining-word-vectors-for-out-of-vocabulary-words)\n   * [Text classification](#text-classification)\n* [Full documentation](#full-documentation)\n* [References](#references)\n   * [Enriching Word Vectors with Subword Information](#enriching-word-vectors-with-subword-information)\n   * [Bag of Tricks for Efficient Text Classification](#bag-of-tricks-for-efficient-text-classification)\n   * [FastText.zip: Compressing text classification models](#fasttextzip-compressing-text-classification-models)\n* [Join the fastText community](#join-the-fasttext-community)\n* [License](#license)\n\n## Introduction\n\n[fastText](https://fasttext.cc/) is a library for efficient learning of word representations and sentence classification.\n\n## Resources\n\n### Models\n- Recent state-of-the-art [English word vectors](https://fasttext.cc/docs/en/english-vectors.html).\n- Word vectors for [157 languages trained on Wikipedia and Crawl](https://github.com/facebookresearch/fastText/blob/master/docs/crawl-vectors.md).\n- Models for [language identification](https://fasttext.cc/docs/en/language-identification.html#content) and [various supervised tasks](https://fasttext.cc/docs/en/supervised-models.html#content).\n\n### Supplementary data\n- The preprocessed [YFCC100M data](https://fasttext.cc/docs/en/dataset.html#content) used in [2].\n\n### FAQ\n\nYou can find [answers to frequently asked questions](https://fasttext.cc/docs/en/faqs.html#content) on our [website](https://fasttext.cc/).\n\n### Cheatsheet\n\nWe also provide a [cheatsheet](https://fasttext.cc/docs/en/cheatsheet.html#content) full of useful one-liners.\n\n## Requirements\n\nWe are continously building and testing our library, CLI and Python bindings under various docker images using [circleci](https://circleci.com/).\n\nGenerally, **fastText** builds on modern Mac OS and Linux distributions.\nSince it uses some C++11 features, it requires a compiler with good C++11 support.\nThese include :\n\n* (g++-4.7.2 or newer) or (clang-3.3 or newer)\n\nCompilation is carried out using a Makefile, so you will need to have a working **make**.\nIf you want to use **cmake** you need at least version 2.8.9.\n\nOne of the oldest distributions we successfully built and tested the CLI under is [Debian wheezy](https://www.debian.org/releases/wheezy/).\n\nFor the word-similarity evaluation script you will need:\n\n* Python 2.6 or newer\n* NumPy \u0026 SciPy\n\nFor the python bindings (see the subdirectory python) you will need:\n\n* Python version 2.7 or \u003e=3.4\n* NumPy \u0026 SciPy\n* [pybind11](https://github.com/pybind/pybind11)\n\nOne of the oldest distributions we successfully built and tested the Python bindings under is [Debian jessie](https://www.debian.org/releases/jessie/).\n\nIf these requirements make it impossible for you to use fastText, please open an issue and we will try to accommodate you.\n\n## Building fastText\n\nWe discuss building the latest stable version of fastText.\n\n### Getting the source code\n\nYou can find our [latest stable release](https://github.com/facebookresearch/fastText/releases/latest) in the usual place.\n\nThere is also the master branch that contains all of our most recent work, but comes along with all the usual caveats of an unstable branch. You might want to use this if you are a developer or power-user.\n\n### Building fastText using make (preferred)\n\n```\n$ wget https://github.com/facebookresearch/fastText/archive/v0.1.0.zip\n$ unzip v0.1.0.zip\n$ cd fastText-0.1.0\n$ make\n```\n\nThis will produce object files for all the classes as well as the main binary `fasttext`.\nIf you do not plan on using the default system-wide compiler, update the two macros defined at the beginning of the Makefile (CC and INCLUDES).\n\n### Building fastText using cmake\n\nFor now this is not part of a release, so you will need to clone the master branch.\n\n```\n$ git clone https://github.com/facebookresearch/fastText.git\n$ cd fastText\n$ mkdir build \u0026\u0026 cd build \u0026\u0026 cmake ..\n$ make \u0026\u0026 make install\n```\n\nThis will create the fasttext binary and also all relevant libraries (shared, static, PIC).\n\n### Building fastText for Python\n\nFor now this is not part of a release, so you will need to clone the master branch.\n\n```\n$ git clone https://github.com/facebookresearch/fastText.git\n$ cd fastText\n$ pip install .\n```\n\nFor further information and introduction see python/README.md\n\n## Example use cases\n\nThis library has two main use cases: word representation learning and text classification.\nThese were described in the two papers [1](#enriching-word-vectors-with-subword-information) and [2](#bag-of-tricks-for-efficient-text-classification).\n\n### Word representation learning\n\nIn order to learn word vectors, as described in [1](#enriching-word-vectors-with-subword-information), do:\n\n```\n$ ./fasttext skipgram -input data.txt -output model\n```\n\nwhere `data.txt` is a training file containing `UTF-8` encoded text.\nBy default the word vectors will take into account character n-grams from 3 to 6 characters.\nAt the end of optimization the program will save two files: `model.bin` and `model.vec`.\n`model.vec` is a text file containing the word vectors, one per line.\n`model.bin` is a binary file containing the parameters of the model along with the dictionary and all hyper parameters.\nThe binary file can be used later to compute word vectors or to restart the optimization.\n\n### Obtaining word vectors for out-of-vocabulary words\n\nThe previously trained model can be used to compute word vectors for out-of-vocabulary words.\nProvided you have a text file `queries.txt` containing words for which you want to compute vectors, use the following command:\n\n```\n$ ./fasttext print-word-vectors model.bin \u003c queries.txt\n```\n\nThis will output word vectors to the standard output, one vector per line.\nThis can also be used with pipes:\n\n```\n$ cat queries.txt | ./fasttext print-word-vectors model.bin\n```\n\nSee the provided scripts for an example. For instance, running:\n\n```\n$ ./word-vector-example.sh\n```\n\nwill compile the code, download data, compute word vectors and evaluate them on the rare words similarity dataset RW [Thang et al. 2013].\n\n### Text classification\n\nThis library can also be used to train supervised text classifiers, for instance for sentiment analysis.\nIn order to train a text classifier using the method described in [2](#bag-of-tricks-for-efficient-text-classification), use:\n\n```\n$ ./fasttext supervised -input train.txt -output model\n```\n\nwhere `train.txt` is a text file containing a training sentence per line along with the labels.\nBy default, we assume that labels are words that are prefixed by the string `__label__`.\nThis will output two files: `model.bin` and `model.vec`.\nOnce the model was trained, you can evaluate it by computing the precision and recall at k (P@k and R@k) on a test set using:\n\n```\n$ ./fasttext test model.bin test.txt k\n```\n\nThe argument `k` is optional, and is equal to `1` by default.\n\nIn order to obtain the k most likely labels for a piece of text, use:\n\n```\n$ ./fasttext predict model.bin test.txt k\n```\n\nor use `predict-prob` to also get the probability for each label\n\n```\n$ ./fasttext predict-prob model.bin test.txt k\n```\n\nwhere `test.txt` contains a piece of text to classify per line.\nDoing so will print to the standard output the k most likely labels for each line.\nThe argument `k` is optional, and equal to `1` by default.\nSee `classification-example.sh` for an example use case.\nIn order to reproduce results from the paper [2](#bag-of-tricks-for-efficient-text-classification), run `classification-results.sh`, this will download all the datasets and reproduce the results from Table 1.\n\nIf you want to compute vector representations of sentences or paragraphs, please use:\n\n```\n$ ./fasttext print-sentence-vectors model.bin \u003c text.txt\n```\n\nThis assumes that the `text.txt` file contains the paragraphs that you want to get vectors for.\nThe program will output one vector representation per line in the file.\n\nYou can also quantize a supervised model to reduce its memory usage with the following command:\n\n```\n$ ./fasttext quantize -output model\n```\nThis will create a `.ftz` file with a smaller memory footprint. All the standard functionality, like `test` or `predict` work the same way on the quantized models:\n```\n$ ./fasttext test model.ftz test.txt\n```\nThe quantization procedure follows the steps described in [3](#fasttextzip-compressing-text-classification-models). You can\nrun the script `quantization-example.sh` for an example.\n\n\n## Full documentation\n\nInvoke a command without arguments to list available arguments and their default values:\n\n```\n$ ./fasttext supervised\nEmpty input or output path.\n\nThe following arguments are mandatory:\n  -input              training file path\n  -output             output file path\n\nThe following arguments are optional:\n  -verbose            verbosity level [2]\n\nThe following arguments for the dictionary are optional:\n  -minCount           minimal number of word occurences [1]\n  -minCountLabel      minimal number of label occurences [0]\n  -wordNgrams         max length of word ngram [1]\n  -bucket             number of buckets [2000000]\n  -minn               min length of char ngram [0]\n  -maxn               max length of char ngram [0]\n  -t                  sampling threshold [0.0001]\n  -label              labels prefix [__label__]\n\nThe following arguments for training are optional:\n  -lr                 learning rate [0.1]\n  -lrUpdateRate       change the rate of updates for the learning rate [100]\n  -dim                size of word vectors [100]\n  -ws                 size of the context window [5]\n  -epoch              number of epochs [5]\n  -neg                number of negatives sampled [5]\n  -loss               loss function {ns, hs, softmax} [softmax]\n  -thread             number of threads [12]\n  -pretrainedVectors  pretrained word vectors for supervised learning []\n  -saveOutput         whether output params should be saved [0]\n\nThe following arguments for quantization are optional:\n  -cutoff             number of words and ngrams to retain [0]\n  -retrain            finetune embeddings if a cutoff is applied [0]\n  -qnorm              quantizing the norm separately [0]\n  -qout               quantizing the classifier [0]\n  -dsub               size of each sub-vector [2]\n```\n\nDefaults may vary by mode. (Word-representation modes `skipgram` and `cbow` use a default `-minCount` of 5.)\n\n## References\n\nPlease cite [1](#enriching-word-vectors-with-subword-information) if using this code for learning word representations or [2](#bag-of-tricks-for-efficient-text-classification) if using for text classification.\n\n### Enriching Word Vectors with Subword Information\n\n[1] P. Bojanowski\\*, E. Grave\\*, A. Joulin, T. Mikolov, [*Enriching Word Vectors with Subword Information*](https://arxiv.org/abs/1607.04606)\n\n```\n@article{bojanowski2017enriching,\n  title={Enriching Word Vectors with Subword Information},\n  author={Bojanowski, Piotr and Grave, Edouard and Joulin, Armand and Mikolov, Tomas},\n  journal={Transactions of the Association for Computational Linguistics},\n  volume={5},\n  year={2017},\n  issn={2307-387X},\n  pages={135--146}\n}\n```\n\n### Bag of Tricks for Efficient Text Classification\n\n[2] A. Joulin, E. Grave, P. Bojanowski, T. Mikolov, [*Bag of Tricks for Efficient Text Classification*](https://arxiv.org/abs/1607.01759)\n\n```\n@InProceedings{joulin2017bag,\n  title={Bag of Tricks for Efficient Text Classification},\n  author={Joulin, Armand and Grave, Edouard and Bojanowski, Piotr and Mikolov, Tomas},\n  booktitle={Proceedings of the 15th Conference of the European Chapter of the Association for Computational Linguistics: Volume 2, Short Papers},\n  month={April},\n  year={2017},\n  publisher={Association for Computational Linguistics},\n  pages={427--431},\n}\n```\n\n### FastText.zip: Compressing text classification models\n\n[3] A. Joulin, E. Grave, P. Bojanowski, M. Douze, H. Jégou, T. Mikolov, [*FastText.zip: Compressing text classification models*](https://arxiv.org/abs/1612.03651)\n\n```\n@article{joulin2016fasttext,\n  title={FastText.zip: Compressing text classification models},\n  author={Joulin, Armand and Grave, Edouard and Bojanowski, Piotr and Douze, Matthijs and J{\\'e}gou, H{\\'e}rve and Mikolov, Tomas},\n  journal={arXiv preprint arXiv:1612.03651},\n  year={2016}\n}\n```\n\n(\\* These authors contributed equally.)\n\n\n## Join the fastText community\n\n* Facebook page: https://www.facebook.com/groups/1174547215919768\n* Google group: https://groups.google.com/forum/#!forum/fasttext-library\n* Contact: [egrave@fb.com](mailto:egrave@fb.com), [bojanowski@fb.com](mailto:bojanowski@fb.com), [ajoulin@fb.com](mailto:ajoulin@fb.com), [tmikolov@fb.com](mailto:tmikolov@fb.com)\n\nSee the CONTRIBUTING file for information about how to help out.\n\n## License\n\nfastText is BSD-licensed. We also provide an additional patent grant.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmwydmuch%2FextremeText","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmwydmuch%2FextremeText","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmwydmuch%2FextremeText/lists"}