當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。