All Projects → vinhkhuc → Jfasttext

vinhkhuc / Jfasttext

Licence: other
Java interface for fastText

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Jfasttext

overview-and-benchmark-of-traditional-and-deep-learning-models-in-text-classification
NLP tutorial
Stars: ✭ 41 (-78.76%)
Mutual labels:  text-classification, word-embeddings
Lbl2Vec
Lbl2Vec learns jointly embedded label, document and word vectors to retrieve documents with predefined topics from an unlabeled document corpus.
Stars: ✭ 25 (-87.05%)
Mutual labels:  text-classification, word-embeddings
Shallowlearn
An experiment about re-implementing supervised learning models based on shallow neural network approaches (e.g. fastText) with some additional exclusive features and nice API. Written in Python and fully compatible with Scikit-learn.
Stars: ✭ 196 (+1.55%)
Mutual labels:  text-classification, word-embeddings
Meta
A Modern C++ Data Sciences Toolkit
Stars: ✭ 600 (+210.88%)
Mutual labels:  text-classification, word-embeddings
Neuronblocks
NLP DNN Toolkit - Building Your NLP DNN Models Like Playing Lego
Stars: ✭ 1,356 (+602.59%)
Mutual labels:  text-classification, model-compression
Kadot
Kadot, the unsupervised natural language processing library.
Stars: ✭ 108 (-44.04%)
Mutual labels:  text-classification, word-embeddings
Naive-Resume-Matching
Text Similarity Applied to resume, to compare Resumes with Job Descriptions and create a score to rank them. Similar to an ATS.
Stars: ✭ 27 (-86.01%)
Mutual labels:  text-classification, word-embeddings
Concise Ipython Notebooks For Deep Learning
Ipython Notebooks for solving problems like classification, segmentation, generation using latest Deep learning algorithms on different publicly available text and image data-sets.
Stars: ✭ 23 (-88.08%)
Mutual labels:  text-classification, word-embeddings
Textblob Ar
Arabic support for textblob
Stars: ✭ 60 (-68.91%)
Mutual labels:  text-classification, word-embeddings
Fastrtext
R wrapper for fastText
Stars: ✭ 103 (-46.63%)
Mutual labels:  text-classification, word-embeddings
Fasttext.js
FastText for Node.js
Stars: ✭ 127 (-34.2%)
Mutual labels:  text-classification, word-embeddings
Xcrash
🔥 xCrash provides the Android app with the ability to capture java crash, native crash and ANR. No root permission or any system permissions are required.
Stars: ✭ 2,689 (+1293.26%)
Mutual labels:  jni
Fastnlp
fastNLP: A Modularized and Extensible NLP Framework. Currently still in incubation.
Stars: ✭ 2,441 (+1164.77%)
Mutual labels:  text-classification
Sifrank zh
基于预训练模型的中文关键词抽取方法(论文SIFRank: A New Baseline for Unsupervised Keyphrase Extraction Based on Pre-trained Language Model 的中文版代码)
Stars: ✭ 175 (-9.33%)
Mutual labels:  word-embeddings
Kd lib
A Pytorch Knowledge Distillation library for benchmarking and extending works in the domains of Knowledge Distillation, Pruning, and Quantization.
Stars: ✭ 173 (-10.36%)
Mutual labels:  model-compression
Hdltex
HDLTex: Hierarchical Deep Learning for Text Classification
Stars: ✭ 191 (-1.04%)
Mutual labels:  text-classification
Sand
Using JNI to achieve Sobel operator image edge detection使用JNI实现Sobel算子图像边缘检测,支持kotlin https://github.com/Jomes/sand
Stars: ✭ 186 (-3.63%)
Mutual labels:  jni
Spark Nlp
State of the Art Natural Language Processing
Stars: ✭ 2,518 (+1204.66%)
Mutual labels:  text-classification
Scapix
Scapix Language Bridge
Stars: ✭ 171 (-11.4%)
Mutual labels:  jni
Lftm
Improving topic models LDA and DMM (one-topic-per-document model for short texts) with word embeddings (TACL 2015)
Stars: ✭ 168 (-12.95%)
Mutual labels:  word-embeddings

Build Status

Table of Contents

Introduction

JFastText is a Java wrapper for Facebook's fastText, a library for efficient learning of word embeddings and fast sentence classification. The JNI interface is built using javacpp.

The library provides full fastText's command line interface. It also provides the API for loading trained model from file to do label prediction in memory. Model training and quantization are supported via the command line interface.

JFastText is ideal for building fast text classifiers in Java.

Maven Dependency

<dependency>
  <groupId>com.github.vinhkhuc</groupId>
  <artifactId>jfasttext</artifactId>
  <version>0.4</version>
</dependency>

The Jar package on Maven Central is bundled with precompiled fastText library for Windows, Linux and MacOSX 64bit.

Building

C++ compiler (g++ on Mac/Linux or cl.exe on Windows) is required to compile fastText's code.

git clone --recursive https://github.com/vinhkhuc/JFastText
cd JFastText
mvn package

Quick Application - Language Identification

JFastText can use FastText's pretrained models directly. Language identification models can be downloaded here. In this quick example, we will use the quantized model which is super small and a bit less accurate than the original model.

$ wget -q https://s3-us-west-1.amazonaws.com/fasttext-vectors/supervised_models/lid.176.ftz \
    && { echo "This is English"; echo "Xin chào"; echo "Привет"; } \
    | java -jar target/jfasttext-*-jar-with-dependencies.jar predict lid.176.ftz -
__label__en
__label__vi
__label__ru

Detailed Examples

Examples on how to use JFastText can be found at examples/api and examples/cmd.

API

Initialization

import com.github.jfasttext.JFastText;
...
JFastText jft = new JFastText();

Word embedding learning

jft.runCmd(new String[] {
        "skipgram",
        "-input", "src/test/resources/data/unlabeled_data.txt",
        "-output", "src/test/resources/models/skipgram.model",
        "-bucket", "100",
        "-minCount", "1"
});

Text classification

// Train supervised model
jft.runCmd(new String[] {
        "supervised",
        "-input", "src/test/resources/data/labeled_data.txt",
        "-output", "src/test/resources/models/supervised.model"
});

// Load model from file
jft.loadModel("src/test/resources/models/supervised.model.bin");

// Do label prediction
String text = "What is the most popular sport in the US ?";
JFastText.ProbLabel probLabel = jft.predictProba(text);
System.out.printf("\nThe label of '%s' is '%s' with probability %f\n",
        text, probLabel.label, Math.exp(probLabel.logProb));

FastText's Command Line

FastText's command line interface can be accessed as follows:

$ java -jar target/jfasttext-*-jar-with-dependencies.jar
usage: fasttext <command> <args>

The commands supported by fasttext are:

  supervised              train a supervised classifier
  quantize                quantize a model to reduce the memory usage
  test                    evaluate a supervised classifier
  predict                 predict most likely labels
  predict-prob            predict most likely labels with probabilities
  skipgram                train a skipgram model
  cbow                    train a cbow model
  print-word-vectors      print word vectors given a trained model
  print-sentence-vectors  print sentence vectors given a trained model
  print-ngrams            print ngrams given a trained model and word
  nn                      query for nearest neighbors
  analogies               query for analogies
  dump                    dump arguments,dictionary,input/output vectors

For example:

$ java -jar target/jfasttext-*-jar-with-dependencies.jar quantize -h

License

BSD

References

(From fastText's references)

Please cite 1 if using this code for learning word representations or 2 if using for text classification.

Enriching Word Vectors with Subword Information

[1] P. Bojanowski*, E. Grave*, A. Joulin, T. Mikolov, Enriching Word Vectors with Subword Information

@article{bojanowski2016enriching,
  title={Enriching Word Vectors with Subword Information},
  author={Bojanowski, Piotr and Grave, Edouard and Joulin, Armand and Mikolov, Tomas},
  journal={arXiv preprint arXiv:1607.04606},
  year={2016}
}

Bag of Tricks for Efficient Text Classification

[2] A. Joulin, E. Grave, P. Bojanowski, T. Mikolov, Bag of Tricks for Efficient Text Classification

@article{joulin2016bag,
  title={Bag of Tricks for Efficient Text Classification},
  author={Joulin, Armand and Grave, Edouard and Bojanowski, Piotr and Mikolov, Tomas},
  journal={arXiv preprint arXiv:1607.01759},
  year={2016}
}

FastText.zip: Compressing text classification models

[3] A. Joulin, E. Grave, P. Bojanowski, M. Douze, H. Jégou, T. Mikolov, FastText.zip: Compressing text classification models

@article{joulin2016fasttext,
  title={FastText.zip: Compressing text classification models},
  author={Joulin, Armand and Grave, Edouard and Bojanowski, Piotr and Douze, Matthijs and J{\'e}gou, H{\'e}rve and Mikolov, Tomas},
  journal={arXiv preprint arXiv:1612.03651},
  year={2016}
}

(* These authors contributed equally.)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].