MCPcopy Create free account
hub / github.com/google-research/language / model_function

Function model_function

language/labs/memory/run_models.py:116–236  ·  view source on GitHub ↗

A generic model, satisfying the tf.Estimator API. Args: features: Dictionary of input tensors. Key "seqs": For the pattern task: [batch_size, seq_len, pattern_size] Sequences of patterns, where `seq_len` is the length of a sequence (including the quer

(features, labels, mode)

Source from the content-addressed store, hash-verified

114
115
116def model_function(features, labels, mode):
117 """A generic model, satisfying the tf.Estimator API.
118
119 Args:
120 features: Dictionary of input tensors.
121 Key "seqs":
122 For the pattern task: <tf.float32>[batch_size, seq_len, pattern_size]
123 Sequences of patterns, where `seq_len` is the length of a sequence
124 (including the query pattern) and `pattern_size` is the dimensionality
125 of each pattern.
126 For the symbolic task: <tf.int32>[batch_size, seq_len]
127 Sequences of encoded kv pairs.
128 Key "targets": same as `labels` arg.
129 labels:
130 For the pattern task: <tf.int32>[batch_size, pattern_size]
131 The correct pattern to retrieve for the degraded query.
132 For the symbolic task: <tf.int32>[batch_size]
133 The correct value to retrieve for the given key.
134 mode: One of the keys from tf.estimator.ModeKeys
135
136 Returns:
137 final_out: retrieved pattern for the degraded query.
138
139 Raises:
140 NameError: If FLAGS.model_name is not one of "vanilla_rnn", "vanilla_lstm",
141 "rnn_attention", "rnn_fast_weights", "rnn_differentiable_plasticity," or if
142 FLAGS.task_name is not "pattern" or "symbolic".
143 """
144 seqs = features["seqs"]
145
146 if FLAGS.task_name == "symbolic":
147 # seqs: <tf.int32>[FLAGS.batch_size, len(seqs), SYMBOLIC_VOCAB_SIZE]
148 # where len(seqs) == 2 * FLAGS.num_sets_per_sequence as each set is a
149 # key-value pair to put into memory.
150 # labels: <tf.int32>[FLAGS.batch_size, SYMBOLIC_VOCAB_SIZE]
151 seqs = tf.one_hot(seqs, SYMBOLIC_VOCAB_SIZE)
152 labels = tf.one_hot(labels, SYMBOLIC_VOCAB_SIZE)
153
154 # Forward pass through model
155 # preds: <float32>[FLAGS.batch_size, FLAGS.pattern_size]
156 if FLAGS.model_name == "vanilla_rnn":
157 preds = vanilla_rnn(seqs, hidden_size=FLAGS.hidden_size)
158 elif FLAGS.model_name == "vanilla_lstm":
159 preds = vanilla_lstm(seqs, hidden_size=FLAGS.hidden_size)
160 elif FLAGS.model_name == "rnn_attention":
161 preds = rnn_attention(
162 seqs, batch_size=FLAGS.batch_size, hidden_size=FLAGS.hidden_size)
163 elif FLAGS.model_name == "rnn_fast_weights":
164 preds = rnn_fast_weights(
165 seqs,
166 batch_size=FLAGS.batch_size,
167 hidden_size=FLAGS.hidden_size,
168 fast_steps=FLAGS.fast_steps,
169 fast_decay_rate=FLAGS.fast_decay_rate,
170 fast_lr=FLAGS.fast_lr,
171 )
172 elif FLAGS.model_name == "rnn_differentiable_plasticity":
173 preds = rnn_differentiable_plasticity(

Callers 1

Calls 8

vanilla_rnnFunction · 0.90
vanilla_lstmFunction · 0.90
rnn_attentionFunction · 0.90
rnn_fast_weightsFunction · 0.90
rnn_explicit_memFunction · 0.90
hamming_lossFunction · 0.90
apply_gradientsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…