Vowpal Wabbit无需写入磁盘即可执行 [英] Vowpal Wabbit execute without writing to disk

查看:133
本文介绍了Vowpal Wabbit无需写入磁盘即可执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用以下方式编写了一个执行Vowpal Wabbit的java代码:

I wrote a java code to execute Vowpal Wabbit in the following way:

 System.out.println("Executing command " + command);
        final Runtime r = Runtime.getRuntime();
        final Process p = r.exec(command);
        System.out.println("waiting for the process");
        try (final BufferedReader b = new BufferedReader(new InputStreamReader(p.getInputStream()))) {
            String line;

            while ((line = b.readLine()) != null) {
                final T lineResult = textParser.parseLine(line);
                parserResultCombiner.addToCombiner(lineResult);
            }
        }
        p.waitFor();
        System.out.println("done");
}

其中命令是


vw -d input.txt --loss_function = logistic -f model.vw

vw -d input.txt --loss_function=logistic -f model.vw

这样做的缺点是需要写入磁盘。经过一番搜索,我了解到vowpal wabbit支持从标准输入中读取数据
R中的示例

The disadvantage of this is that it requires writing to disk. After some searching, I learned that vowpal wabbit supports reading data from standard input example in R

我在Java 1.8中找不到任何完成此任务的示例。任何人都可以和我分享吗?

I could not find any example to accomplish this in Java 1.8. Could anyone share one with me?

推荐答案

你需要在守护进程模式下启动vw。这将启动一个侦听指定端口的进程。

You need to start vw in daemon mode. This starts a process that listens on the port specified.

$ vw -i model.vw  -t --daemon --quiet --port 26542

守护程序启动后,您可以发送样本以使用套接字调用进行预测

Once the daemon has started, you can send samples to predict using socket calls

$ echo " abc-example| a b c" | netcat localhost 26542
0.000000 abc-example

$ echo " xyz-example| x y z" | netcat localhost 26542
1.000000 xyz-example

source:
https://github.com/JohnLangford/vowpal_wabbit/wiki/daemon-example

最近,他们使用jni
推送了与vw交互的代码的java版本 https://github.com/JohnLangford/vowpal_wabbit/tree/master/java

Recently they pushed a java version of the code that interacts with vw using jni https://github.com/JohnLangford/vowpal_wabbit/tree/master/java

这篇关于Vowpal Wabbit无需写入磁盘即可执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆