Welcome to mirror list, hosted at ThFree Co, Russian Federation.

mini_vw.py « python - github.com/moses-smt/vowpal_wabbit.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0d82fe2c344bc7d2ffceb2e40e9fa7f3dd8866d8 (plain)
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
import sys
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)