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

Function predict

language/boolq/run_recurrent_model_boolq.py:319–386  ·  view source on GitHub ↗

Compute the class logit predictions. Args: is_train: bool, are we in train mode embeddings: `embedding_utils.PretrainedWordEmbeddings` to embed with premise_tensors: batched premise tensors from `build_tensorize_text_fn` hypothesis_tensors: batched hypothesis tensors from `b

(is_train, embeddings, premise_tensors, hypothesis_tensors)

Source from the content-addressed store, hash-verified

317
318
319def predict(is_train, embeddings, premise_tensors, hypothesis_tensors):
320 """Compute the class logit predictions.
321
322 Args:
323 is_train: bool, are we in train mode
324 embeddings: `embedding_utils.PretrainedWordEmbeddings` to embed with
325 premise_tensors: batched premise tensors from `build_tensorize_text_fn`
326 hypothesis_tensors: batched hypothesis tensors from
327 `build_tensorize_text_fn`
328
329 Returns:
330 logits: <tf.float32>[batch, 3] Scores for each class (for checkpoint
331 comparability, the BoolQ models also produce a neutral logit)
332 """
333 with tf.variable_scope("embed"):
334 premise = embed_text(premise_tensors, embeddings)
335 premise_lens = premise_tensors["len"]
336 with tf.variable_scope("embed", reuse=True):
337 hypothesis = embed_text(hypothesis_tensors, embeddings)
338 hypothesis_len = hypothesis_tensors["len"]
339
340 e_drop = FLAGS.embed_dropout_rate
341 premise = variational_dropout(premise, e_drop, is_train)
342 hypothesis = variational_dropout(hypothesis, e_drop, is_train)
343
344 with tf.variable_scope("embed/encode-text/layer-1"):
345 premise = apply_highway_lstm(premise, premise_lens)
346 with tf.variable_scope("embed/encode-text/layer-1", reuse=True):
347 hypothesis = apply_highway_lstm(hypothesis, hypothesis_len)
348
349 with tf.variable_scope("fuse"):
350 with tf.variable_scope("attention"):
351 atten = compute_attention(premise, hypothesis)
352 atten = mask_attention(atten, premise_lens, hypothesis_len)
353
354 attended_h = tf.matmul(tf.nn.softmax(atten), hypothesis)
355 attended_p = tf.matmul(
356 tf.nn.softmax(tf.transpose(atten, [0, 2, 1])), premise)
357 premise = tf.concat([premise, attended_h, attended_h * premise], 2)
358 hypothesis = tf.concat([hypothesis, attended_p, attended_p * hypothesis], 2)
359
360 with tf.variable_scope("post-process/layer-0"):
361 premise = apply_highway_lstm(premise, premise_lens)
362 with tf.variable_scope("post-process/layer-0", reuse=True):
363 hypothesis = apply_highway_lstm(hypothesis, hypothesis_len)
364
365 drop = FLAGS.dropout_rate
366 premise = variational_dropout(premise, drop, is_train)
367 hypothesis = variational_dropout(hypothesis, drop, is_train)
368
369 with tf.variable_scope("pool/atten-pool"):
370 premise = pool(premise, premise_lens)
371 with tf.variable_scope("pool/atten-pool", reuse=True):
372 hypothesis = pool(hypothesis, hypothesis_len)
373
374 joint_embed = tf.concat([premise, hypothesis], 1)
375 with tf.variable_scope("post-processs-pooled/layer-1"):
376 joint_embed = tf.layers.dense(

Callers 2

model_functionFunction · 0.85
evaluateFunction · 0.85

Calls 7

embed_textFunction · 0.85
variational_dropoutFunction · 0.85
apply_highway_lstmFunction · 0.85
compute_attentionFunction · 0.85
mask_attentionFunction · 0.85
poolFunction · 0.85
dropoutFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…