我编写了一个java代码来按以下方式执行Vowpal Wabbit:
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
这样做的缺点是需要写入磁盘。经过一番搜索,我了解到Vowpal wabbit支持从标准输入读取数据 example in R
我找不到任何在 Java 1.8 中完成此操作的示例。谁能和我分享一份吗?
最佳答案
您需要以守护程序模式启动 vw。这将启动一个监听指定端口的进程。
$ vw -i model.vw -t --daemon --quiet --port 26542
守护进程启动后,您可以使用套接字调用发送样本进行预测
$ 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
来源: https://github.com/JohnLangford/vowpal_wabbit/wiki/daemon-example
最近他们推送了一个java版本的代码,使用jni与vw交互 https://github.com/JohnLangford/vowpal_wabbit/tree/master/java
关于java - Vowpal Wabbit 执行而不写入磁盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26491666/