當前位置: 首頁>>代碼示例>>Python>>正文


Python Parameters.parameter_count方法代碼示例

本文整理匯總了Python中theano_toolkit.parameters.Parameters.parameter_count方法的典型用法代碼示例。如果您正苦於以下問題:Python Parameters.parameter_count方法的具體用法?Python Parameters.parameter_count怎麽用?Python Parameters.parameter_count使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在theano_toolkit.parameters.Parameters的用法示例。


在下文中一共展示了Parameters.parameter_count方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: make_functions

# 需要導入模塊: from theano_toolkit.parameters import Parameters [as 別名]
# 或者: from theano_toolkit.parameters.Parameters import parameter_count [as 別名]
def make_functions(
        input_size, output_size, mem_size, mem_width, hidden_sizes=[100]):

    start_time = time.time()

    input_seqs  = T.btensor3('input_sequences')
    output_seqs = T.btensor3('output_sequences')

    P = Parameters()
    process = model.build(P,
            input_size, output_size, mem_size, mem_width, hidden_sizes[0])
    outputs = process(T.cast(input_seqs,'float32'))
    output_length = (input_seqs.shape[1] - 2) // 2

    Y = output_seqs[:,-output_length:,:-2]
    Y_hat = T.nnet.sigmoid(outputs[:,-output_length:,:-2])

    cross_entropy = T.mean(T.nnet.binary_crossentropy(Y_hat,Y))
    bits_loss = cross_entropy * (Y.shape[1] * Y.shape[2]) / T.log(2)

    params = P.values()

    cost = cross_entropy # + 1e-5 * sum(T.sum(T.sqr(w)) for w in params)

    print "Computing gradients",
    grads = T.grad(cost, wrt=params)
    grads = updates.clip_deltas(grads, np.float32(clip_length))

    print "Done. (%0.3f s)"%(time.time() - start_time)
    start_time = time.time()
    print "Compiling function",
    P_learn = Parameters()

    update_pairs = updates.rmsprop(
                params, grads,
                learning_rate=1e-4,
                P=P_learn
            )

    train = theano.function(
            inputs=[input_seqs, output_seqs],
            outputs=cross_entropy,
            updates=update_pairs,
        )

    test = theano.function(
            inputs=[input_seqs, output_seqs],
            outputs=bits_loss
        )

    print "Done. (%0.3f s)"%(time.time() - start_time)
    print P.parameter_count()
    return P, P_learn, train, test
開發者ID:shawntan,項目名稱:neural-turing-machines,代碼行數:55,代碼來源:train_copy.py

示例2: attention

# 需要導入模塊: from theano_toolkit.parameters import Parameters [as 別名]
# 或者: from theano_toolkit.parameters.Parameters import parameter_count [as 別名]
				word_rep_size = 128,
				stmt_hidden_size = 128,
				diag_hidden_size = 128,
				vocab_size  = vocab_size,
				output_size = vocab_size,
				map_fun_size = 128,
				evidence_count = evidence_count
				)

		output_evds,output_ans = attention(story,idxs,qstn)
		cross_entropy = -T.log(output_ans[ans_lbl]) \
				+ -T.log(output_evds[0][ans_evds[0]]) \
				+ -T.log(output_evds[1][ans_evds[1]]) 
		#cost += -T.log(ordered_probs(output_evds,ans_e.vds)) 
		print "Done."
		print "Parameter count:", P.parameter_count()

		print "Calculating gradient expression...",
		params = P.values()
		cost = cross_entropy
		grads = T.grad(cost,wrt=params)
		print "Done."

		inputs = [story,idxs,qstn,ans_lbl,ans_evds]
		outputs = cross_entropy
		pickle.dump(
				(inputs,outputs,params,grads),
				open("compute_tree.pkl","wb"),2
				)

		print "Compiling native...",
開發者ID:wavelets,項目名稱:neural-qa,代碼行數:33,代碼來源:train.py


注:本文中的theano_toolkit.parameters.Parameters.parameter_count方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。