Java API for Vowpal Wabbit?

2020-07-13 11:47发布

I am trying to use Vowpal Wabbit through Java. I have downloaded and successfully compiled the code from GitHub. The command line tool works fine. After having a quick look at the repository (especially here), I can only assume that using it through Java is supposed to be already possible, and I don't really want to reinvent the wheel.

A wrapper around Vowpal Wabbit that allows use through Java. This wrapper is designed to be self contained. Because of the use of JNI, a number of platforms are supported in this JAR.

I have added the maven dependency (found here) to my project, but without any kind of document, I don't really know where to start. I have seen in another question that it seems to be possible to use VW with Java, but the guy only uses Runtime.getRuntime.exec() to call his bash command, and I can't find any documentation about any other way of doing (and there are only 2 questions mixing VW and Java on SO, which doesn't help). I am new to JNI, so most likely there is something easy that I don't see. To be perfectly clear, my questions are :

  • Should I just make a valid vw command and use it through Runtime.getRuntime.exec()? This doesn't seem to be the spirit of JNI, for there is no need for any wrapper/library for this. Plus, this doesn't make it very portable.
  • Where (the hell) is the (Java API) documentation ?

Any kind of help or guidance would be welcome.

6条回答
Evening l夕情丶
2楼-- · 2020-07-13 11:57

I don't think this adds a lot, but none of the previous answers really provided a clear answer. Like @Macchiatow mentioned, to use the Java wrapper which comes with Vowpal Wabbit, you would:

  1. (on the project root dir) make all java or make java
  2. cd into java and verify the installation with mvn test
  3. you'd then mvn install to have the Java API jarred up and placed in your local maven repository. Supposedly this builds the JNI parts on your machine, so as to fit the C/C++ libraries of your platform if you have the necessary native C/C++ libraries installed and available to the make command.
  4. you'd supposedly be able to include the vowpal package/s from those jars in the build tool used in your own project (ant/maven/boot/leiningen/sbt/etc. as in here).

For more background maybe see the Vowpal Wabbit Java readme. I think what it tries to say there, is that if you want a ready made jar from maven central, you should make sure it's the same vowpal version you're using, but without knowing more I'd guess if you built it like above, you are by definition using the same version.

I've had the above process work off a fresh clone, with Ubuntu 16.04 and Java 8.

查看更多
三岁会撩人
3楼-- · 2020-07-13 12:04

You may checkout vowpal wabbit JNI wrapper we've built in Indeed: https://github.com/indeedeng/vowpal-wabbit-java.

We wrote integration test that can work as usage examples and we wrote API documentation as well. Check "using the library" section of README.

Hope this will help.

查看更多
我命由我不由天
4楼-- · 2020-07-13 12:04

There is indeed Java JNI wrapper to have a basic access to VW. By basic I mean to teach your model and to predict probability later on. They also provide Python library that can do far more than wrapper for Java. Recently I was forced to expose few more VW methods to Java by extending code provided.

Back to the questions:

  • Rather use the vw-jni artifact available in central maven repo and clone their code and run make all java. I some cases compiling code yourself will be the only solution, as for example provided artifact won't run on OpenSuse (my case)
  • Code available pretty straight forward. VWLearners::create is a factory to get an instance of VW from Java.
查看更多
神经病院院长
5楼-- · 2020-07-13 12:05

I was one of the two primary authors of the VW JNI wrapper. Since the posting of this question the interface has significantly changed. We now encourage users to compile the native side on their own and provide it on the java.library.path. We have updated the README significantly to show how to use the library from Java.

I totally agree with your criticism that we have not published the Java API. I will work on that the next time I modify this code. In the meantime please feel free to clone the library and run mvn install and you can generate the Java API docs yourself. They should be quite detailed as we spent a lot of effort writing detailed docs.

查看更多
爷、活的狠高调
6楼-- · 2020-07-13 12:09

This link may be of some help with regards to setting up a JNI wrapper.

查看更多
霸刀☆藐视天下
7楼-- · 2020-07-13 12:15

I wasn't able to find Java API documentation anywhere, but Java code seems well documented - did you maybe try generating Javadoc yourself from the code?

查看更多
登录 后发表回答