Python tensorflow.contrib.rnn.python.ops.core_rnn_cell._linear() Examples
The following are 3
code examples of tensorflow.contrib.rnn.python.ops.core_rnn_cell._linear().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
tensorflow.contrib.rnn.python.ops.core_rnn_cell
, or try the search function
.
Example #1
Source File: deeppyramid_utils.py From BERT with Apache License 2.0 | 6 votes |
def linear(args, output_size, bias, bias_start=0.0, scope=None, squeeze=False, wd=0.0, input_keep_prob=1.0, is_train=None): with tf.variable_scope(scope or "linear"): if args is None or (nest.is_sequence(args) and not args): raise ValueError("`args` must be specified") if not nest.is_sequence(args): args = [args] flat_args = [flatten(arg, 1) for arg in args] # if input_keep_prob < 1.0: assert is_train is not None flat_args = [tf.cond(is_train, lambda: tf.nn.dropout(arg, input_keep_prob), lambda: arg) for arg in flat_args] flat_out = _linear(flat_args, output_size, bias) out = reconstruct(flat_out, args[0], 1) if squeeze: out = tf.squeeze(out, [len(args[0].get_shape().as_list())-1]) return out
Example #2
Source File: nn.py From BERT with Apache License 2.0 | 6 votes |
def linear(args, output_size, bias, bias_start=0.0, scope=None, squeeze=False, wd=0.0, input_keep_prob=1.0, is_train=None): with tf.variable_scope(scope or "linear"): if args is None or (nest.is_sequence(args) and not args): raise ValueError("`args` must be specified") if not nest.is_sequence(args): args = [args] flat_args = [flatten(arg, 1) for arg in args] # if input_keep_prob < 1.0: assert is_train is not None flat_args = [tf.cond(is_train, lambda: tf.nn.dropout(arg, input_keep_prob), lambda: arg) for arg in flat_args] flat_out = _linear(flat_args, output_size, bias) out = reconstruct(flat_out, args[0], 1) if squeeze: out = tf.squeeze(out, [len(args[0].get_shape().as_list())-1]) if wd: add_wd(wd) return out
Example #3
Source File: embed_compress.py From neuralcompressor with MIT License | 5 votes |
def _encode(self, input_matrix, word_ids, embed_size): input_embeds = tf.nn.embedding_lookup(input_matrix, word_ids, name="input_embeds") M, K = self.M, self.K with tf.variable_scope("h"): h = tf.nn.tanh(_linear(input_embeds, M * K/2, True)) with tf.variable_scope("logits"): logits = _linear(h, M * K, True) logits = tf.log(tf.nn.softplus(logits) + 1e-8) logits = tf.reshape(logits, [-1, M, K], name="logits") return input_embeds, logits