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