Skip to content

Compile Facebook FastText to a Linux dynamic library(so), and expose three functions for JNA to invoke

Notifications You must be signed in to change notification settings

hittlle/fasttext-java-wrapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 

Repository files navigation

1, Why this? Facebook fasttext is an excellent text classification tool, and I love it. You know what? I tried scikit-learn SVM, Random Forest and Logistic Regression algorithms to train multiclass classification models for short texts, and fasttext turned out to be the best in my environment. After the training and tuning phases, I started to integrate the model into my backend service. My backend service is Java based, but fasttext is written in C++ 11. So I had to turn to JNI or JNA for help. I chosed JNA for its simplicity. And I also modified the fasttext source code to expose three C-sytle functions (extern "C") for JNA. That's it.

2, How to build the dynamic library and run the test? Just execute

bash build.sh

and you'll find the libfasttext.so dynamic library, and you can run the test this way

javac -cp "jna-5.3.0.jar:." FastTextJNAWrapper.java

java -cp "jna-5.3.0.jar:." FastTextJNAWrapper

About

Compile Facebook FastText to a Linux dynamic library(so), and expose three functions for JNA to invoke

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published