小编bei*_*ner的帖子

当索引张量不同维度时,如何向量化索引和计算?

我正在尝试在 Pytorch 中矢量化以下 for 循环。我很高兴只对内部 for 循环进行矢量化,但完成整个批次也很棒。

# B: the batch size
# N: the number of training examples 
# dim: the dimension of each feature vector
# K: the number of discrete labels. each vector has a single label
# delta: margin for hinge loss

batch_data = torch.tensor(...)  # Tensor of shape [B x N x d]
batch_labels = torch.tensor(...)  # Tensor of shape [B x N x 1], each element is one of K labels (ints)

batch_losses = …
Run Code Online (Sandbox Code Playgroud)

python vectorization pytorch

6
推荐指数
1
解决办法
846
查看次数

标签 统计

python ×1

pytorch ×1

vectorization ×1