本文整理匯總了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
示例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
示例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()
示例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}