本文整理汇总了Python中tensorflow.contrib.rnn.python.ops.core_rnn_cell._linear方法的典型用法代码示例。如果您正苦于以下问题:Python core_rnn_cell._linear方法的具体用法?Python core_rnn_cell._linear怎么用?Python core_rnn_cell._linear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.contrib.rnn.python.ops.core_rnn_cell
的用法示例。
在下文中一共展示了core_rnn_cell._linear方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: linear
# 需要导入模块: from tensorflow.contrib.rnn.python.ops import core_rnn_cell [as 别名]
# 或者: from tensorflow.contrib.rnn.python.ops.core_rnn_cell import _linear [as 别名]
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
示例2: linear
# 需要导入模块: from tensorflow.contrib.rnn.python.ops import core_rnn_cell [as 别名]
# 或者: from tensorflow.contrib.rnn.python.ops.core_rnn_cell import _linear [as 别名]
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
示例3: _encode
# 需要导入模块: from tensorflow.contrib.rnn.python.ops import core_rnn_cell [as 别名]
# 或者: from tensorflow.contrib.rnn.python.ops.core_rnn_cell import _linear [as 别名]
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