本文整理汇总了Python中tree.loadWordMap函数的典型用法代码示例。如果您正苦于以下问题:Python loadWordMap函数的具体用法?Python loadWordMap怎么用?Python loadWordMap使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了loadWordMap函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: run
def run(args=None):
usage = "usage : %prog [options]"
parser = optparse.OptionParser(usage=usage)
parser.add_option("--test",action="store_true",dest="test",default=False)
# Optimizer
parser.add_option("--minibatch",dest="minibatch",type="int",default=30)
parser.add_option("--optimizer",dest="optimizer",type="string",
default="adagrad")
parser.add_option("--epochs",dest="epochs",type="int",default=50)
parser.add_option("--step",dest="step",type="float",default=1e-2)
parser.add_option("--outputDim",dest="outputDim",type="int",default=5)
parser.add_option("--wvecDim",dest="wvecDim",type="int",default=30)
parser.add_option("--outFile",dest="outFile",type="string",
default="models/test.bin")
parser.add_option("--inFile",dest="inFile",type="string",
default="models/test.bin")
parser.add_option("--data",dest="data",type="string",default="train")
(opts,args)=parser.parse_args(args)
# Testing
if opts.test:
test(opts.inFile,opts.data)
return
print "Loading data..."
# load training data
trees = tr.loadTrees()
opts.numWords = len(tr.loadWordMap())
rnn = nnet.RNN(opts.wvecDim,opts.outputDim,opts.numWords,opts.minibatch)
rnn.initParams()
sgd = optimizer.SGD(rnn,alpha=opts.step,minibatch=opts.minibatch,
optimizer=opts.optimizer)
for e in range(opts.epochs):
start = time.time()
print "Running epoch %d"%e
sgd.run(trees)
end = time.time()
print "Time per epoch : %f"%(end-start)
with open(opts.outFile,'w') as fid:
pickle.dump(opts,fid)
pickle.dump(sgd.costt,fid)
rnn.toFile(fid)
开发者ID:GuesPita,项目名称:semantic-rntn,代码行数:51,代码来源:runNNet.py
示例2: len
numGrad = (costP - cost)/epsilon
err = np.abs(dL[j][i] - numGrad)
#print "Analytic %.9f, Numerical %.9f, Relative Error %.9f"%(dL[j][i],numGrad,err)
err2+=err
count+=1
if 0.001 > err2/count:
print "Passed :)"
else:
print "Failed : Sum of Error = %.9f" % (err2/count)
if __name__ == '__main__':
import tree as treeM
train = treeM.loadTrees()
numW = len(treeM.loadWordMap())
wvecDim = 10
outputDim = 5
nn = RNTN(wvecDim,outputDim,numW,mbSize=4)
nn.initParams()
mbData = train[:1]
#cost, grad = nn.costAndGrad(mbData)
print "Numerical gradient check..."
nn.check_grad(mbData)
开发者ID:vineelpratap,项目名称:Polarity-prediction-using-RNTNs,代码行数:28,代码来源:rntn.py
示例3: run
def run( args = None):
usage = "usage : %prog [options]"
parser = optparse.OptionParser(usage=usage)
parser.add_option("--test",action="store_true",dest="test",default=False)
# Optimizer
parser.add_option("--minibatch",dest="minibatch",type="int",default=30)
parser.add_option("--optimizer",dest="optimizer",type="string",default="adagrad")
parser.add_option("--epochs",dest="epochs",type="int",default=50)
parser.add_option("--step",dest="step",type="float",default=1e-2)
parser.add_option("--middleDim",dest="middleDim",type="int",default=10)
parser.add_option("--outputDim",dest="outputDim",type="int",default=5)
parser.add_option("--wvecDim",dest="wvecDim",type="int",default=30)
# for DCNN only
parser.add_option("--ktop",dest="ktop",type="int",default=5)
parser.add_option("--m1",dest="m1",type="int",default=10)
parser.add_option("--m2",dest="m2",type="int",default=7)
parser.add_option("--n1",dest="n1",type="int",default=6)
parser.add_option("--n2",dest="n2",type="int",default=12)
parser.add_option("--outFile",dest="outFile",type="string",default="models/test.bin")
parser.add_option("--inFile",dest="inFile",type="string",default="models/test.bin")
parser.add_option("--data",dest="data",type="string",default="train")
parser.add_option("--model",dest="model",type="string",default="RNN")
(opts,args)=parser.parse_args(args)
# make this false if you dont care about your accuracies per epoch, makes things faster!
evaluate_accuracy_while_training = True
# Testing
if opts.test:
test(opts.inFile, opts.data, opts.model)
return
print "Loading data..."
train_accuracies = []
dev_accuracies = []
# load training data
trees = tr.loadTrees('train')
opts.numWords = len(tr.loadWordMap())
if (opts.model=='RNTN'):
nn = RNTN(opts.wvecDim,opts.outputDim,opts.numWords,opts.minibatch)
elif(opts.model=='RNN'):
nn = RNN(opts.wvecDim,opts.outputDim,opts.numWords,opts.minibatch)
elif(opts.model=='RNN2'):
nn = RNN2(opts.wvecDim,opts.middleDim,opts.outputDim,opts.numWords,opts.minibatch)
elif(opts.model=='RNN3'):
nn = RNN3(opts.wvecDim,opts.middleDim,opts.outputDim,opts.numWords,opts.minibatch)
elif(opts.model=='DCNN'):
nn = DCNN(opts.wvecDim,opts.ktop,opts.m1,opts.m2, opts.n1, opts.n2,0, opts.outputDim,opts.numWords, 2, opts.minibatch,rho=1e-4)
trees = cnn.tree2matrix(trees)
else:
raise '%s is not a valid neural network so far only RNTN, RNN, RNN2, RNN3, and DCNN'%opts.model
nn.initParams()
sgd = optimizer.SGD(nn, alpha=opts.step, minibatch=opts.minibatch, optimizer=opts.optimizer)
dev_trees = tr.loadTrees("dev")
for e in range(opts.epochs):
start = time.time()
print "Running epoch %d"%e
sgd.run(trees)
end = time.time()
print "Time per epoch : %f" %(end-start)
with open(opts.outFile,'w') as fid:
pickle.dump(opts,fid)
pickle.dump(sgd.costt,fid)
nn.toFile(fid)
if evaluate_accuracy_while_training:
print "testing on training set real quick"
train_accuracies.append(test(opts.outFile,"train",opts.model,trees))
print "testing on dev set real quick"
dev_accuracies.append(test(opts.outFile,"dev",opts.model,dev_trees))
# clear the fprop flags in trees and dev_trees
for tree in trees:
tr.leftTraverse(tree.root,nodeFn=tr.clearFprop)
for tree in dev_trees:
tr.leftTraverse(tree.root,nodeFn=tr.clearFprop)
print "fprop in trees cleared"
if evaluate_accuracy_while_training:
pdb.set_trace()
print train_accuracies
print dev_accuracies
开发者ID:ryu577,项目名称:base,代码行数:96,代码来源:runNNet.py
示例4: len
parser.add_option("--epochs",dest="epochs",type="int",default=50)
parser.add_option("--step",dest="step",type="float",default=1e-2)
parser.add_option("--outputDim",dest="outputDim",type="int",default=5)
parser.add_option("--wvecDim",dest="wvecDim",type="int",default=30)
parser.add_option("--outFile",dest="outFile",type="string",
default="models/distrntn.bin")
parser.add_option("--inFile",dest="inFile",type="string",
default="models/distrntn.bin")
parser.add_option("--data",dest="data",type="string",default="train")
(opts,args)=parser.parse_args(None)
print "Loading data..."
# load training data
trees = tr.loadTrees()
opts.numWords = len(tr.loadWordMap())
#setup the rntn
rnn = nnet.RNN(opts.wvecDim,opts.outputDim,opts.numWords,opts.minibatch)
rnn.initParams()
sgd = optimizer.SGD(rnn,alpha=opts.step,minibatch=opts.minibatch,
optimizer=opts.optimizer)
#setup spark
if mode == "local":
# Set heap space size for java
#os.environ["_JAVA_OPTIONS"] = "-Xmx1g"
conf = (SparkConf()
.setMaster("local[*]")
.setAppName(appname)
开发者ID:iron-fe,项目名称:rntn_on_Spark,代码行数:31,代码来源:distrntn.py
示例5: run
def run(args=None):
usage = "usage : %prog [options]"
parser = optparse.OptionParser(usage=usage)
parser.add_option("--test",action="store_true",dest="test",default=False)
# Optimizer
parser.add_option("--minibatch",dest="minibatch",type="int",default=30)
parser.add_option("--optimizer",dest="optimizer",type="string",
default="adagrad")
parser.add_option("--epochs",dest="epochs",type="int",default=50)
parser.add_option("--step",dest="step",type="float",default=1e-2)
parser.add_option("--middleDim",dest="middleDim",type="int",default=10)
parser.add_option("--outputDim",dest="outputDim",type="int",default=5)
parser.add_option("--wvecDim",dest="wvecDim",type="int",default=30)
# By @tiagokv, just to ease the first assignment test
parser.add_option("--wvecDimBatch",dest="wvecDimBatch",type="string",default="")
# for DCNN only
parser.add_option("--ktop",dest="ktop",type="int",default=5)
parser.add_option("--m1",dest="m1",type="int",default=10)
parser.add_option("--m2",dest="m2",type="int",default=7)
parser.add_option("--n1",dest="n1",type="int",default=6)
parser.add_option("--n2",dest="n2",type="int",default=12)
parser.add_option("--outFile",dest="outFile",type="string",
default="models/test.bin")
parser.add_option("--inFile",dest="inFile",type="string",
default="models/test.bin")
parser.add_option("--data",dest="data",type="string",default="train")
parser.add_option("--model",dest="model",type="string",default="RNN")
(opts,args)=parser.parse_args(args)
# make this false if you dont care about your accuracies per epoch, makes things faster!
evaluate_accuracy_while_training = True
# Testing
if opts.test:
test(opts.inFile,opts.data,opts.model)
return
print "Loading data..."
train_accuracies = []
dev_accuracies = []
# load training data
trees = tr.loadTrees('train')
opts.numWords = len(tr.loadWordMap())
if (opts.model=='RNTN'):
nn = RNTN(opts.wvecDim,opts.outputDim,opts.numWords,opts.minibatch)
elif(opts.model=='RNN'):
nn = RNN(opts.wvecDim,opts.outputDim,opts.numWords,opts.minibatch)
elif(opts.model=='RNN2'):
nn = RNN2(opts.wvecDim,opts.middleDim,opts.outputDim,opts.numWords,opts.minibatch)
elif(opts.model=='RNN3'):
nn = RNN3(opts.wvecDim,opts.middleDim,opts.outputDim,opts.numWords,opts.minibatch)
elif(opts.model=='DCNN'):
nn = DCNN(opts.wvecDim,opts.ktop,opts.m1,opts.m2, opts.n1, opts.n2,0, opts.outputDim,opts.numWords, 2, opts.minibatch,rho=1e-4)
trees = cnn.tree2matrix(trees)
else:
raise '%s is not a valid neural network so far only RNTN, RNN, RNN2, RNN3, and DCNN'%opts.model
nn.initParams()
sgd = optimizer.SGD(nn,alpha=opts.step,minibatch=opts.minibatch,
optimizer=opts.optimizer)
# assuring folder for plots exists
if( os.path.isdir('plots') == False ): os.makedirs('test')
if( os.path.isdir('plots/' + opts.model ) == False ): os.makedirs('plots/' + opts.model)
dev_trees = tr.loadTrees("dev")
for e in range(opts.epochs):
start = time.time()
print "Running epoch %d"%e
sgd.run(trees)
end = time.time()
print "Time per epoch : %f"%(end-start)
with open(opts.outFile,'w') as fid:
pickle.dump(opts,fid)
pickle.dump(sgd.costt,fid)
nn.toFile(fid)
if evaluate_accuracy_while_training:
print "testing on training set real quick"
train_accuracies.append(test(opts.outFile,"train",opts.model,trees))
print "testing on dev set real quick"
dev_accuracies.append(test(opts.outFile,"dev",opts.model,dev_trees))
# clear the fprop flags in trees and dev_trees
for tree in trees:
tr.leftTraverse(tree.root,nodeFn=tr.clearFprop)
for tree in dev_trees:
tr.leftTraverse(tree.root,nodeFn=tr.clearFprop)
print "fprop in trees cleared"
#.........这里部分代码省略.........
开发者ID:tiagokv,项目名称:cs224d,代码行数:101,代码来源:runNNet.py
示例6: prnt
if __name__ == '__main__' and __package__ is None:
from os import sys, path
sys.path.append(path.dirname(path.dirname(path.abspath('__file__'))))
sys.dont_write_bytecode = True
###############################
# Take a peek at how the tree works.
###############################
import tree as treeM
train = treeM.loadTrees()
word_to_id = treeM.loadWordMap()
id_to_word = {}
for i in word_to_id:
id_to_word[word_to_id[i]] = i
treeTxt = ""
def prnt(node):
global treeTxt
if node.isLeaf:
#print(id_to_word[node.word], end = " ")
treeTxt = treeTxt + id_to_word[node.word] + " "
return 0
else:
treeTxt = treeTxt + "("
prnt(node.left)
prnt(node.right)
开发者ID:ryu577,项目名称:base,代码行数:29,代码来源:main.py
示例7: run
def run(args=None):
usage = "usage : %prog [options]"
parser = optparse.OptionParser(usage=usage)
parser.add_option("--test",action="store_true",dest="test",default=False)
# Optimizer
parser.add_option("--minibatch",dest="minibatch",type="int",default=30)
parser.add_option("--optimizer",dest="optimizer",type="string",
default="adagrad")
parser.add_option("--epochs",dest="epochs",type="int",default=50)
parser.add_option("--step",dest="step",type="float",default=1e-2)
parser.add_option("--init",dest="init",type="float",default=0.01)
parser.add_option("--outputDim",dest="outputDim",type="int",default=5)
parser.add_option("--wvecDim",dest="wvecDim",type="int",default=30)
parser.add_option("--rho",dest="rho",type="float",default=1e-6)
parser.add_option("--outFile",dest="outFile",type="string",
default="models/test.bin")
parser.add_option("--inFile",dest="inFile",type="string",
default="models/test.bin")
parser.add_option("--data",dest="data",type="string",default="train")
parser.add_option("--model",dest="model",type="string",default="RNTN")
parser.add_option("--maxTrain",dest="maxTrain", type="int", default=-1)
parser.add_option("--activation",dest="acti", type="string", default="tanh")
parser.add_option("--partial",action="store_true",dest="partial",default=False)
parser.add_option("--w2v",dest="w2vmodel", type="string")
(opts,args)=parser.parse_args(args)
# make this false if you dont care about your accuracies per epoch, makes things faster!
evaluate_accuracy_while_training = True
# Testing
if opts.test:
cmfile = opts.inFile + ".confusion_matrix-" + opts.data + ".png"
test(opts.inFile,opts.data,opts.model,acti=opts.acti)
return
print "Loading data..."
embedding = None
wordMap = None
if opts.w2vmodel is not None:
print "Loading pre-trained word2vec model from %s" % opts.w2vmodel
w2v = models.Word2Vec.load(opts.w2vmodel)
embedding, wordMap = readW2v(w2v,opts.wvecDim)
train_accuracies = []
train_rootAccuracies = []
dev_accuracies = []
dev_rootAccuracies = []
# load training data
trees = tr.loadTrees('train',wordMap=wordMap)[:opts.maxTrain] #train.full.15
if opts.maxTrain > -1:
print "Training only on %d trees" % opts.maxTrain
opts.numWords = len(tr.loadWordMap())
if opts.partial==True:
print "Only partial feedback"
if (opts.model=='RNTN'):
nn = RNTN(wvecDim=opts.wvecDim,outputDim=opts.outputDim,numWords=opts.numWords,
mbSize=opts.minibatch,rho=opts.rho, acti=opts.acti, init=opts.init, partial=opts.partial)
else:
raise '%s is not a valid neural network so far only RNTN, RNN'%opts.model
nn.initParams(embedding=embedding)
sgd = optimizer.SGD(nn,alpha=opts.step,minibatch=opts.minibatch,
optimizer=opts.optimizer)
dev_trees = tr.loadTrees("dev") #dev.full.15
for e in range(opts.epochs):
start = time.time()
print "Running epoch %d"%e
sgd.run(trees)
end = time.time()
print "Time per epoch : %f"%(end-start)
with open(opts.outFile,'w') as fid:
pickle.dump(opts,fid)
pickle.dump(sgd.costt,fid)
nn.toFile(fid)
if evaluate_accuracy_while_training:
print "testing on training set"
acc, sacc = test(opts.outFile,"train",opts.model,trees, acti=opts.acti)
train_accuracies.append(acc)
train_rootAccuracies.append(sacc)
print "testing on dev set"
dacc, dsacc = test(opts.outFile,"dev",opts.model,dev_trees, acti=opts.acti)
dev_accuracies.append(dacc)
#.........这里部分代码省略.........
开发者ID:juliakreutzer,项目名称:wtfrnn,代码行数:101,代码来源:runNNet.py
示例8: run
def run(args=None):
usage = "usage : %prog [options]"
parser = optparse.OptionParser(usage=usage)
parser.add_option("--test",action="store_true",dest="test",default=False)
# Optimizer
parser.add_option("--minibatch",dest="minibatch",type="int",default=30)
parser.add_option("--optimizer",dest="optimizer",type="string",
default="adagrad")
parser.add_option("--epochs",dest="epochs",type="int",default=50)
parser.add_option("--step",dest="step",type="float",default=1e-2)
parser.add_option("--rho",dest="rho",type="float",default=1e-4)
parser.add_option("--middleDim",dest="middleDim",type="int",default=10)
parser.add_option("--outputDim",dest="outputDim",type="int",default=3)
parser.add_option("--wvecDim",dest="wvecDim",type="int",default=30)
# for DCNN only
parser.add_option("--ktop",dest="ktop",type="int",default=5)
parser.add_option("--m1",dest="m1",type="int",default=10)
parser.add_option("--m2",dest="m2",type="int",default=7)
parser.add_option("--n1",dest="n1",type="int",default=6)
parser.add_option("--n2",dest="n2",type="int",default=12)
parser.add_option("--outFile",dest="outFile",type="string",
default="models/test.bin")
parser.add_option("--inFile",dest="inFile",type="string",
default="models/test.bin")
parser.add_option("--data",dest="data",type="string",default="train")
parser.add_option("--model",dest="model",type="string",default="RNN")
parser.add_option("--pretrain",dest="pretrain",default=False)
parser.add_option("--dropout",dest="dropout",default=False)
(opts,args)=parser.parse_args(args)
# make this false if you dont care about your accuracies per epoch
evaluate_accuracy_while_training = True
# Testing
if opts.test:
test(opts.inFile,opts.data,opts.model,e=1000)
return
print "Loading data..."
train_accuracies = []
dev_accuracies = []
# load training data
trees = tr.loadTrees('train')
opts.numWords = len(tr.loadWordMap())
if (opts.model=='RNTN'):
nn = RNTN(opts.wvecDim,opts.outputDim,opts.numWords,opts.minibatch,opts.pretrain,opts.dropout,opts.rho)
elif(opts.model=='RNN'):
nn = RNN(opts.wvecDim,opts.outputDim,opts.numWords,opts.minibatch,opts.pretrain,opts.dropout,opts.rho)
elif(opts.model=='RNN2'):
nn = RNN2(opts.wvecDim,opts.middleDim,opts.outputDim,opts.numWords,opts.minibatch,opts.pretrain,opts.dropout,opts.rho)
elif(opts.model=='RNN2TANH'):
nn = RNN2(opts.wvecDim,opts.middleDim,opts.outputDim,opts.numWords,opts.minibatch,opts.pretrain,opts.dropout,opts.rho)
elif(opts.model=='RNN3'):
nn = RNN3(opts.wvecDim,opts.middleDim,opts.outputDim,opts.numWords,opts.minibatch,opts.pretrain,opts.dropout,opts.rho)
elif(opts.model=='DCNN'):
nn = DCNN(opts.wvecDim,opts.ktop,opts.m1,opts.m2, opts.n1, opts.n2,0, opts.outputDim,opts.numWords, 2, opts.minibatch,rho=1e-4)
trees = cnn.tree2matrix(trees)
else:
raise '%s is not a valid neural network so far only RNTN, RNN, RNN2, and DCNN'%opts.model
nn.initParams()
sgd = optimizer.SGD(nn,alpha=opts.step,minibatch=opts.minibatch,
optimizer=opts.optimizer)
for e in range(opts.epochs):
start = time.time()
print "Running epoch %d"%e
sgd.run(trees)
end = time.time()
print "Time per epoch : %f"%(end-start)
with open(opts.outFile,'w') as fid:
pickle.dump(opts,fid)
pickle.dump(sgd.costt,fid)
nn.toFile(fid)
if evaluate_accuracy_while_training:
print "testing on training set real quick"
train_accuracies.append(test(opts.outFile,"train",opts.model,trees,e))
print "testing on dev set real quick"
dev_accuracies.append(test(opts.outFile,"dev",opts.model,e=e))
if e%10==0:
if evaluate_accuracy_while_training:
print train_accuracies
print dev_accuracies
plt.figure()
plt.plot(train_accuracies,label = 'Train')
plt.plot(dev_accuracies,label = 'Dev')
plt.legend()
plt.savefig('temp/train_dev_accuracies_'+str(opts.model)+'_middle_'+str(opts.middleDim)+'.png')
#.........这里部分代码省略.........
开发者ID:yucca43,项目名称:NNproject,代码行数:101,代码来源:runNNet.py
示例9: run
def run(args=None):
usage = "usage : %prog [options]"
parser = optparse.OptionParser(usage=usage)
parser.add_option("--test",action="store_true",dest="test",default=False)
# Optimizer
parser.add_option("--minibatch",dest="minibatch",type="int",default=30)
parser.add_option("--optimizer",dest="optimizer",type="string",
default="adagrad")
parser.add_option("--epochs",dest="epochs",type="int",default=50)
parser.add_option("--step",dest="step",type="float",default=1e-2)
parser.add_option("--wvecDim",dest="wvecDim",type="int",default=30)
parser.add_option("--outputDim",dest="outputDim",type="int",default=2)
parser.add_option("--alpha",dest="alpha",type="int",default=0.2)
parser.add_option("--outFile",dest="outFile",type="string",
default="models/test.bin")
parser.add_option("--inFile",dest="inFile",type="string",
default="models/test.bin")
parser.add_option("--data",dest="data",type="string",default="brae.pos")
parser.add_option("--dev",dest="dev",type="string",default="brae.dev")
parser.add_option("--wordMap",dest="map",type="string",default="brae.tot")
(opts,args)=parser.parse_args(args)
# make this false if you dont care about your accuracies per epoch, makes things faster!
evaluate_accuracy_while_training = True
# Testing
if opts.test:
test(opts.inFile,opts.data)
return
print "Loading data..."
train_accuracies = []
dev_accuracies = []
trees = tr.printtree(opts.data)
opts.numWords = len(tr.loadWordMap(opts.map))
nn = RNN(opts.wvecDim,opts.outputDim,opts.numWords,opts.alpha,opts.minibatch)
nn.initParams()
sgd = optimizer.SGD(nn,alpha=opts.step,minibatch=opts.minibatch,
optimizer=opts.optimizer)
dev_trees = tr.printtree(opts.dev)
for e in range(opts.epochs):
start = time.time()
print "Running epoch %d"%e
sgd.run(trees)
end = time.time()
print "Time per epoch : %f"%(end-start)
with open(opts.outFile,'w') as fid:
pickle.dump(opts,fid)
pickle.dump(sgd.costt,fid)
nn.toFile(fid)
if evaluate_accuracy_while_training:
print "testing on training set real quick"
train_accuracies.append(test(opts.outFile,opts.data,trees))
print "testing on dev set real quick"
dev_accuracies.append(test(opts.outFile,opts.dev,dev_trees))
if evaluate_accuracy_while_training:
pdb.set_trace()
print train_accuracies
print dev_accuracies
开发者ID:successar,项目名称:RAE,代码行数:72,代码来源:runNNet.py
注:本文中的tree.loadWordMap函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论