-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
mini_vw.py
37 lines (28 loc) · 919 Bytes
/
mini_vw.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from __future__ import print_function
import sys
from vowpalwabbit import pyvw
learnFromStrings = False
# this is a stupid program that basically mimics vw's behavior,
# mostly for the purpose of speed comparisons
def mini_vw(inputFile, numPasses, otherArgs):
vw = pyvw.vw(otherArgs)
for p in range(numPasses):
print('pass', (p+1))
h = open(inputFile, 'r')
for l in h.readlines():
if learnFromStrings:
vw.learn(l)
else:
ex = vw.example(l)
vw.learn(ex)
ex.finish()
h.close()
vw.finish()
if __name__ == '__main__':
if len(sys.argv) < 3:
print('usage: mini_vw.py (inputFile) (#passes) (...other VW args...)')
exit()
inputFile = sys.argv[1]
numPasses = int(sys.argv[2])
otherArgs = ' '.join(sys.argv[3:])
mini_vw(inputFile, numPasses, otherArgs)