-
Notifications
You must be signed in to change notification settings - Fork 6
/
test.py
66 lines (53 loc) · 1.75 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import tensorflow as tf
import numpy as np
# lookup_table = np.reshape(range(16),newshape=[4,4])
# inputs = tf.convert_to_tensor(np.array([[[0,1],[0,2]],[[1,3],[2,3]]]))
# # output = tf.nn.embedding_lookup(lookup_table, inputs)
# position_ind = tf.tile(tf.expand_dims(tf.range(10), 0), [100, 1])
# T_q = 3
# T_k = 4
# w = 0.1
# b = -0.2
# Nq = 4
#
# Dis_M = np.zeros(shape=[T_q, T_k])
# for i in range(T_q):
# for j in range(T_k):
# Dis_M[i][j] = -abs(w * (i - j) ** 2 + b)
# dis_M = tf.convert_to_tensor(Dis_M)
# dis_M = tf.concat(tf.tile(tf.expand_dims(dis_M, 0), [Nq, 1, 1]),axis=0)
#
# dis_split = tf.split(dis_M, Nq)
#
#
# with tf.Session() as sess:
# with tf.variable_scope("interaction-1", reuse=False):
# with tf.variable_scope("sub-layer"):
# shift = tf.convert_to_tensor(8,name="shift")
#
# with tf.variable_scope("interaction 1", reuse=True):
# with tf.variable_scope("sub-layer"):
# shift1 = tf.get_variable("shift")
# assert shift == shift1
import Model
inputX_word = np.random.rand(64,100,128)
inputX_char = np.random.rand(64,100,30)
inputY_word = np.random.rand(64,100,128)
inputY_char = np.random.rand(64,100,30)
input_y = [[0, 1] for _ in range(64)]
model = Model.GaussionTransformer()
feed_dict = {
model.inputX_word: inputX_word,
model.inputX_char: inputX_char,
model.inputY_word: inputY_word,
model.inputY_char: inputY_char,
model.y: input_y,
model.dropout_rate: 0.8,
model.is_training: True
}
with tf.Session() as sess:
writer = tf.summary.FileWriter("logs/", sess.graph)
sess.run(tf.global_variables_initializer())
writer.add_graph(sess.graph)
y = sess.run(model.pred_y, feed_dict=feed_dict)
print(y)