当前位置: 首页>>代码示例>>Python>>正文


Python core_rnn_cell._linear方法代码示例

本文整理汇总了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 
开发者ID:yyht,项目名称:BERT,代码行数:21,代码来源:deeppyramid_utils.py

示例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 
开发者ID:yyht,项目名称:BERT,代码行数:23,代码来源:nn.py

示例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 
开发者ID:zomux,项目名称:neuralcompressor,代码行数:14,代码来源:embed_compress.py


注:本文中的tensorflow.contrib.rnn.python.ops.core_rnn_cell._linear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。