Advertisement
Guest User

Untitled

a guest
Feb 21st, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. # This is a stack of res conns
  2. def skip_conns(inputs, wsz_all, n):
  3. for i in range(n):
  4. with tf.variable_scope("skip-%d" % i):
  5. W_p = tf.get_variable("W_p", [wsz_all, wsz_all])
  6. b_p = tf.get_variable("B_p", [1, wsz_all], initializer=tf.constant_initializer(0.0))
  7. proj = tf.nn.relu(tf.matmul(inputs, W_p) + b_p, "relu")
  8.  
  9. inputs = inputs + proj
  10. return inputs
  11.  
  12. # This is a stack of highway conns.
  13. def highway_conns(inputs, wsz_all, n):
  14. for i in range(n):
  15. with tf.variable_scope("highway-%d" % i):
  16. W_p = tf.get_variable("W_p", [wsz_all, wsz_all])
  17. b_p = tf.get_variable("B_p", [1, wsz_all], initializer=tf.constant_initializer(0.0))
  18. proj = tf.nn.relu(tf.matmul(inputs, W_p) + b_p, "relu-proj")
  19.  
  20. W_t = tf.get_variable("W_t", [wsz_all, wsz_all])
  21. b_t = tf.get_variable("B_t", [1, wsz_all], initializer=tf.constant_initializer(-2.0))
  22. transform = tf.nn.sigmoid(tf.matmul(inputs, W_t) + b_t, "sigmoid-transform")
  23.  
  24. inputs = tf.multiply(transform, proj) + tf.multiply(inputs, 1 - transform)
  25. return inputs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement