Coder Social home page Coder Social logo

turtle's Introduction

# turtle - load readable_model from vowpal wabbit and serve it from java

## example train a model

$ vw -d /path/to/dataset/dataset --readable_model readable_model.txt

##  readable_model.txt looks like:
...
6163:0.0624969
7472:-0.12023
42847:-0.0421919
49960:-0.12023
51692:0.0624969
55432:-0.0421919
...

using https://gist.github.com/luoq/b4c374b5cbabe3ae76ffacdac22750af,
and some logic to produce the same buckets for the same feature combinations

## java code
add the dependency in pom.xml
<dependency>
    <groupId>bz.turtle</groupId>
    <artifactId>readable</artifactId>
    <version>2.0.11-BETA</version>
</dependency>

import bz.turtle.readable.*;

ReadableModel m = new ReadableModel("directory/of/readable_model.txt"); // .txt.gz also works


// this will load the model creating only float[] array with same size as 2**bits(-b from vw)
// it uses same algorithm to compute hash buckets as vw and then returns the inner product

m.predict(
          new Doc(
              new Namespace(
                  "your-namespace",
                  new Feature("a",1.0),
                  new Feature("b",1.0),
                  new Feature("c",1.0))));
// value 1.0 is default

## make sure it works
if you want to make sure your parameters are supported, in the repeatable_model.txt
add test.txt and predictions.txt (using -p from vw) and it will automatically
test if turtle gets the same predictions as the wabbit.

if you pass file to ReadableModel it will just try to load the file


check out resources/test for more examples


## known bugs

* -q ::
  the way vw does permutation is different, and it produces different results

## thanks

* Lucas Bernardi
* Tarek Sheasha
* Denis Bilenko

wouldn't have happened without the help of those guys

## todo

* more tests
* verify the checksum of the model
* support for --cubic
* support for ngrams and skips
* support for --lrq

turtle's People

Contributors

fbarrios avatar jackdoe avatar lucjb avatar tsheasha avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

turtle's Issues

Broken JDK compatibility

The releases 2.0.7-BETA and above are no longer compatible with the JDK I'm using. This is the Java version:

java version "1.8.0_92"
Java(TM) SE Runtime Environment (build 1.8.0_92-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.92-b14, mixed mode)

And this is the error I get with 2.0.7-BETA:

java.lang.NoSuchMethodError: java.nio.CharBuffer.clear()Ljava/nio/CharBuffer;

	at bz.turtle.readable.input.Feature.setByteBuffer(Feature.java:236)
	at bz.turtle.readable.input.Feature.setName(Feature.java:197)
	at bz.turtle.readable.input.Feature.<init>(Feature.java:54)
	at bz.turtle.readable.input.Feature.<init>(Feature.java:45)

And with 2.0.9-BETA I get a different, but similar one:

java.lang.NoSuchMethodError: java.nio.CharBuffer.position(I)Ljava/nio/CharBuffer;

	at bz.turtle.readable.input.Feature.setByteBuffer(Feature.java:230)
	at bz.turtle.readable.input.Feature.setName(Feature.java:190)
	at bz.turtle.readable.input.Feature.<init>(Feature.java:47)
	at bz.turtle.readable.input.Feature.<init>(Feature.java:38)

It's worth noting that if I build the project myself on this JDK, it works correctly, so it seems to be some cross-version incompatibility.

--predictions vs --raw_predictions

FWIW, it looks like it computes raw predictions (vw -r) rather than predictions (vw -p).

For binary classification, raw prediction is dot product, normal prediction is clipped dot product (+ link function if one is provided).

Compare:

$ printf -- '-2 | neg \n 2 | pos \n | pos pos pos pos pos pos pos pos pos pos' | vw --readable_model read.txt --quiet -r /dev/stdout
0
-0.297751
3.034739

$ printf -- '-2 | neg \n 2 | pos \n | pos pos pos pos pos pos pos pos pos pos' | vw --readable_model read.txt --quiet -p /dev/stdout
0
-0.297751
>>> 2 <<<

Clipping boundaries are saved in the model:

$ head read.txt | grep label
Min label:-2
Max label:2

For oaa, regular prediction is class label (calculated as argmax), raw prediction is array of raw scores for each individual model.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.