Skip to content

Instantly share code, notes, and snippets.

@lazuxd
Created July 19, 2021 19:03
Show Gist options
  • Save lazuxd/90a5b57983d291cf4d8452f3be334050 to your computer and use it in GitHub Desktop.
Save lazuxd/90a5b57983d291cf4d8452f3be334050 to your computer and use it in GitHub Desktop.
class Model:
def __init__(self,
vocabulary: list,
inter_time_step_size: int,
unit_type: str,
depth: int):
# unit_type can be one of: 'gru' or 'lstm'
# depth >= 1
self._init(vocabulary, inter_time_step_size, unit_type, depth)
self.weights = (self._init_gru() if unit_type == 'gru'
else self._init_lstm())
# weights and bias used to compute y (the softmax predictions)
self.wy = tf.Variable(tf.random.normal(
stddev=sqrt(2.0/(self.inter_time_step_size+self.vocab_size)),
shape=(self.inter_time_step_size, self.vocab_size),
dtype=tf.double))
self.by = tf.Variable(tf.random.normal(
stddev=sqrt(2.0/(1+self.vocab_size)),
shape=(1, self.vocab_size),
dtype=tf.double))
self.weights.extend([self.wy, self.by])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment