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


Python ndarray.max方法代码示例

本文整理汇总了Python中mxnet.ndarray.max方法的典型用法代码示例。如果您正苦于以下问题:Python ndarray.max方法的具体用法?Python ndarray.max怎么用?Python ndarray.max使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mxnet.ndarray的用法示例。


在下文中一共展示了ndarray.max方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: pad_packed_tensor

# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import max [as 别名]
def pad_packed_tensor(input, lengths, value, l_min=None):
    old_shape = input.shape
    if isinstance(lengths, nd.NDArray):
        max_len = as_scalar(input.max())
    else:
        max_len = builtins.max(lengths)

    if l_min is not None:
        max_len = builtins.max(max_len, l_min)

    batch_size = len(lengths)
    ctx = input.context
    dtype = input.dtype
    x = nd.full((batch_size * max_len, *old_shape[1:]), value, ctx=ctx, dtype=dtype)
    index = []
    for i, l in enumerate(lengths):
        index.extend(range(i * max_len, i * max_len + l))
    index = nd.array(index, ctx=ctx)
    return scatter_row(x, index, input).reshape(batch_size, max_len, *old_shape[1:]) 
开发者ID:dmlc,项目名称:dgl,代码行数:21,代码来源:tensor.py

示例2: log_sum_exp

# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import max [as 别名]
def log_sum_exp(vec):
    max_score = nd.max(vec).asscalar()
    return nd.log(nd.sum(nd.exp(vec - max_score))) + max_score

# Model 
开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:7,代码来源:lstm_crf.py

示例3: _viterbi_decode

# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import max [as 别名]
def _viterbi_decode(self, feats):
        backpointers = []

        # Initialize the viterbi variables in log space
        vvars = nd.full((1, self.tagset_size), -10000.)
        vvars[0, self.tag2idx[START_TAG]] = 0

        for feat in feats:
            bptrs_t = []  # holds the backpointers for this step
            viterbivars_t = []  # holds the viterbi variables for this step

            for next_tag in range(self.tagset_size):
                # next_tag_var[i] holds the viterbi variable for tag i at the
                # previous step, plus the score of transitioning
                # from tag i to next_tag.
                # We don't include the emission scores here because the max
                # does not depend on them (we add them in below)
                next_tag_var = vvars + self.transitions.data()[next_tag]
                best_tag_id = argmax(next_tag_var)
                bptrs_t.append(best_tag_id)
                viterbivars_t.append(next_tag_var[0, best_tag_id])
            # Now add in the emission scores, and assign vvars to the set
            # of viterbi variables we just computed
            vvars = (nd.concat(*viterbivars_t, dim=0) + feat).reshape((1, -1))
            backpointers.append(bptrs_t)

        # Transition to STOP_TAG
        terminal_var = vvars + self.transitions.data()[self.tag2idx[STOP_TAG]]
        best_tag_id = argmax(terminal_var)
        path_score = terminal_var[0, best_tag_id]

        # Follow the back pointers to decode the best path.
        best_path = [best_tag_id]
        for bptrs_t in reversed(backpointers):
            best_tag_id = bptrs_t[best_tag_id]
            best_path.append(best_tag_id)
        # Pop off the start tag (we dont want to return that to the caller)
        start = best_path.pop()
        assert start == self.tag2idx[START_TAG]  # Sanity check
        best_path.reverse()
        return path_score, best_path 
开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:43,代码来源:lstm_crf.py

示例4: max

# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import max [as 别名]
def max(input, dim):
    return nd.max(input, axis=dim) 
开发者ID:dmlc,项目名称:dgl,代码行数:4,代码来源:tensor.py

示例5: reduce_max

# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import max [as 别名]
def reduce_max(input):
    return input.max() 
开发者ID:dmlc,项目名称:dgl,代码行数:4,代码来源:tensor.py

示例6: hybrid_forward

# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import max [as 别名]
def hybrid_forward(self, F, preds, label):
        label = label.astype('float32')
        dist = F.sqrt(F.sum(F.square(preds), axis=1))

        return label * F.square(dist) + (1 - label) * F.square(F.max(self._m - dist, 0)) 
开发者ID:aws-samples,项目名称:d-SNE,代码行数:7,代码来源:custom_layers.py

示例7: log_sum_exp

# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import max [as 别名]
def log_sum_exp(vec):
    max_score = nd.max(vec).asscalar()
    return nd.log(nd.sum(nd.exp(vec - max_score))) + max_score 
开发者ID:fierceX,项目名称:NER_BiLSTM_CRF_Chinese,代码行数:5,代码来源:model.py

示例8: _viterbi_decode

# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import max [as 别名]
def _viterbi_decode(self, feats):
        backpointers = []

        # Initialize the viterbi variables in log space
        vvars = nd.full((1, self.tagset_size), -10000.)
        vvars[0, self.tag2idx[START_TAG]] = 0

        for feat in feats:
            bptrs_t = []  # holds the backpointers for this step
            viterbivars_t = []  # holds the viterbi variables for this step

            for next_tag in range(self.tagset_size):
                # next_tag_var[i] holds the viterbi variable for tag i at the
                # previous step, plus the score of transitioning
                # from tag i to next_tag.
                # We don't include the emission scores here because the max
                # does not depend on them (we add them in below)
                next_tag_var = vvars + self.transitions[next_tag]
                best_tag_id = argmax(next_tag_var)
                bptrs_t.append(best_tag_id)
                viterbivars_t.append(next_tag_var[0, best_tag_id])
            # Now add in the emission scores, and assign vvars to the set
            # of viterbi variables we just computed
            vvars = (nd.concat(*viterbivars_t, dim=0) + feat).reshape((1, -1))
            backpointers.append(bptrs_t)

        # Transition to STOP_TAG
        terminal_var = vvars + self.transitions[self.tag2idx[STOP_TAG]]
        best_tag_id = argmax(terminal_var)
        path_score = terminal_var[0, best_tag_id]

        # Follow the back pointers to decode the best path.
        best_path = [best_tag_id]
        for bptrs_t in reversed(backpointers):
            best_tag_id = bptrs_t[best_tag_id]
            best_path.append(best_tag_id)
        # Pop off the start tag (we dont want to return that to the caller)
        start = best_path.pop()
        assert start == self.tag2idx[START_TAG]  # Sanity check
        best_path.reverse()
        return path_score, best_path 
开发者ID:mahyarnajibi,项目名称:SNIPER-mxnet,代码行数:43,代码来源:lstm_crf.py


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