Jenna Kwon
Jenna Kwon

Reputation: 1252

Vowpal Wabbit python wrapper empty prediction file

The prediction file when called from pyvw wrapper is empty. For example, I am doing something like,

vw = pyvw.vw(" -i cb.model --cb_explore 50 --cover 10 -p prediction.txt")
ex = vw.example(" | label label2")
vw.predict(ex)
vw.finish()
ex.finish() 

This creates prediction.txt but does not write anything to it.

I would greatly appreciate any guidance.

Thank you!

Upvotes: 0

Views: 386

Answers (1)

Montenegrodr
Montenegrodr

Reputation: 1636

This snippet might help you:

from vowpalwabbit import pyvw

def to_vw(clf, text, str_label):
    vw_example = str('{} |f {} '.format(str_label, text))
    return clf.example(vw_example)

clf = vw = pyvw.vw(
    loss_function='logistic', oaa=2,
    link='logistic', raw_predictions='output.txt'
)

ex = to_vw(clf, 'I like vowpal wabbit. But not that much.', '1')
clf.learn(ex)
clf.predict(ex, labelType=pyvw.pylibvw.vw.lMulticlass)

You should have the probabilities written in output.txt file.

Upvotes: 1

Related Questions