本文整理匯總了Python中tflearn.embedding方法的典型用法代碼示例。如果您正苦於以下問題:Python tflearn.embedding方法的具體用法?Python tflearn.embedding怎麽用?Python tflearn.embedding使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tflearn
的用法示例。
在下文中一共展示了tflearn.embedding方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _create_model
# 需要導入模塊: import tflearn [as 別名]
# 或者: from tflearn import embedding [as 別名]
def _create_model(self):
reset_default_graph()
net = input_data([None, SEQUENCE_LEN])
net = embedding(net, input_dim=len(self._vocab.vocabulary_),
output_dim=WORD_FEATURE_DIM)
net = lstm(net, DOC_FEATURE_DIM, dropout=0.8)
net = fully_connected(net, 2, activation='softmax')
net = regression(net, optimizer='adam', learning_rate=0.001,
loss='categorical_crossentropy')
return DNN(net)
示例2: test_recurrent_layers
# 需要導入模塊: import tflearn [as 別名]
# 或者: from tflearn import embedding [as 別名]
def test_recurrent_layers(self):
X = [[1, 3, 5, 7], [2, 4, 8, 10], [1, 5, 9, 11], [2, 6, 8, 0]]
Y = [[0., 1.], [1., 0.], [0., 1.], [1., 0.]]
with tf.Graph().as_default():
g = tflearn.input_data(shape=[None, 4])
g = tflearn.embedding(g, input_dim=12, output_dim=4)
g = tflearn.lstm(g, 6)
g = tflearn.fully_connected(g, 2, activation='softmax')
g = tflearn.regression(g, optimizer='sgd', learning_rate=1.)
m = tflearn.DNN(g)
m.fit(X, Y, n_epoch=300, snapshot_epoch=False)
self.assertGreater(m.predict([[5, 9, 11, 1]])[0][1], 0.9)