def cross_validate_one(idx): global gdata (M,b,trainlist,threads)=gdata if idx==0: (M2,b2)=testGrad(M,b,trainlist,idx) res=0 else: random.shuffle(trainlist) trainvalborder=len(trainlist)*(threads-2)/(threads-1) (M2,b2)=testGrad(M,b,trainlist[:trainvalborder],idx) print 'MMR after unigram learning train(idx=',idx,'):',mrr(M2,b2,trainlist) res=mrr(M2,b2,trainlist[trainvalborder:]) print 'MMR after unigram learning val(idx=',idx,'):',res return (res,M2,b2)
def cross_validate_one(idx): global gdata (M, b, trainlist, threads) = gdata if idx == 0: (M2, b2) = testGrad(M, b, trainlist, idx) res = 0 else: random.shuffle(trainlist) trainvalborder = len(trainlist) * (threads - 2) / (threads - 1) (M2, b2) = testGrad(M, b, trainlist[:trainvalborder], idx) print 'MMR after unigram learning train(idx=', idx, '):', mrr( M2, b2, trainlist) res = mrr(M2, b2, trainlist[trainvalborder:]) print 'MMR after unigram learning val(idx=', idx, '):', res return (res, M2, b2)
def trainMb(trainlist, ans1, ans0): """Unigram training from saved Qlist files, returns Mb weights. You can play with the learning constants in trainConsts() of basicgrad.py""" t0 = time.time() M = np.random.normal(0, 0.01, (GLOVELEN, GLOVELEN)) b = -0.0001 # M=np.loadtxt('data/M58prop') # b=np.loadtxt('data/b58prop') mrrs, crossmrr, M, b = cross_validate_all(M, b, trainlist) t1 = time.time() print "time spent training =", t1 - t0 print "MRR after crossvalidation=", crossmrr # XXX: This has a sideeffect, setting resolutions in trainlist trainmrr = mrr(M, b, trainlist) print 'Mb MRR on train:', trainmrr l, alpha = trainConsts() results = [crossmrr, mrrs, l, alpha, trainmrr] return (M, b, results)
def trainMb(trainlist,ans1,ans0): """Unigram training from saved Qlist files, returns Mb weights. You can play with the learning constants in trainConsts() of basicgrad.py""" t0=time.time() M=np.random.normal(0,0.01,(GLOVELEN,GLOVELEN)) b=-0.0001 # M=np.loadtxt('data/M58prop') # b=np.loadtxt('data/b58prop') mrrs,crossmrr,M,b=cross_validate_all(M,b,trainlist) t1=time.time() print "time spent training =",t1-t0 print "MRR after crossvalidation=",crossmrr # XXX: This has a sideeffect, setting resolutions in trainlist trainmrr=mrr(M,b,trainlist) print 'Mb MRR on train:', trainmrr l,alpha=trainConsts() results=[crossmrr,mrrs,l,alpha,trainmrr] return (M,b,results)