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


Python nd.batch_dot方法代码示例

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


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

示例1: forward

# 需要导入模块: from mxnet import nd [as 别名]
# 或者: from mxnet.nd import batch_dot [as 别名]
def forward(self, feature, data):
        """ Forward process of a MetaDense layer

        Parameters
        ----------
        feature: NDArray with shape [n, d]
        data: NDArray with shape [n, b, input_hidden_size]

        Returns
        -------
        output: NDArray with shape [n, b, output_hidden_size]
        """
        weight = self.w_mlp(feature) # [n, input_hidden_size * output_hidden_size]
        weight = nd.reshape(weight, (-1, self.input_hidden_size, self.output_hidden_size))
        bias = nd.reshape(self.b_mlp(feature), shape=(-1, 1, 1)) # [n, 1, 1]
        return nd.batch_dot(data, weight) + bias 
开发者ID:panzheyi,项目名称:ST-MetaNet,代码行数:18,代码来源:basic_structure.py

示例2: batch_attention

# 需要导入模块: from mxnet import nd [as 别名]
# 或者: from mxnet.nd import batch_dot [as 别名]
def batch_attention(encoder,decoder):
    attention = nd.softmax(nd.batch_dot(encoder,nd.transpose(decoder,axes = (0,2,1))),axis=1)
    new_decoder = nd.batch_dot(attention,nd.transpose(encoder,axes=(0,1,2)))
    return new_decoder 
开发者ID:NonvolatileMemory,项目名称:AAAI_2019_EXAM,代码行数:6,代码来源:TextEXAM_multi-label.py

示例3: bmm_maybe_select

# 需要导入模块: from mxnet import nd [as 别名]
# 或者: from mxnet.nd import batch_dot [as 别名]
def bmm_maybe_select(A, B, index):
    """Slice submatrices of A by the given index and perform bmm.

    B is a 3D tensor of shape (N, D1, D2), which can be viewed as a stack of
    N matrices of shape (D1, D2). The input index is an integer vector of length M.
    A could be either:
    (1) a dense tensor of shape (M, D1),
    (2) an integer vector of length M.
    The result C is a 2D matrix of shape (M, D2)

    For case (1), C is computed by bmm:
    ::

        C[i, :] = matmul(A[i, :], B[index[i], :, :])

    For case (2), C is computed by index select:
    ::

        C[i, :] = B[index[i], A[i], :]

    Parameters
    ----------
    A : mxnet.NDArray
        lhs tensor
    B : mxnet.NDArray
        rhs tensor
    index : mxnet.NDArray
        index tensor

    Returns
    -------
    C : mxnet.NDArray
        return tensor
    """
    if A.dtype in (np.int32, np.int64) and len(A.shape) == 1:
        return B[index, A, :]
    else:
        BB = nd.take(B, index, axis=0)
        return nd.batch_dot(A.expand_dims(1), BB).squeeze() 
开发者ID:dmlc,项目名称:dgl,代码行数:41,代码来源:utils.py

示例4: bdd_message_func

# 需要导入模块: from mxnet import nd [as 别名]
# 或者: from mxnet.nd import batch_dot [as 别名]
def bdd_message_func(self, edges):
        """Message function for block-diagonal-decomposition regularizer"""
        ctx = edges.src['h'].context
        if edges.src['h'].dtype in (np.int32, np.int64) and len(edges.src['h'].shape) == 1:
            raise TypeError('Block decomposition does not allow integer ID feature.')
        weight = self.weight.data(ctx)[edges.data['type'], :].reshape(
            -1, self.submat_in, self.submat_out)
        node = edges.src['h'].reshape(-1, 1, self.submat_in)
        msg = nd.batch_dot(node, weight).reshape(-1, self.out_feat)
        if 'norm' in edges.data:
            msg = msg * edges.data['norm']
        return {'msg': msg} 
开发者ID:dmlc,项目名称:dgl,代码行数:14,代码来源:relgraphconv.py


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