使用最大池层减少张量的维度

Reduce the dimension of a tensor using max-pooling layer

我的问题很简单:

如何使用最大池化层将列表或张量的维数减少到列表中的 512 个元素:

我正在尝试以下代码:

    input_ids = tokenizer.encode(question, text)
    print(input_ids) # input_ids is a list of 700 elements
    m = nn.AdaptiveMaxPool1d(512)
    input_ids = m(torch.tensor([[input_ids]])) # convert the list to tensor and apply max-pooling layer

但是我收到以下错误:

RuntimeError: "adaptive_max_pool2d_cpu" not implemented for 'Long'

所以,请帮忙找出错误所在

问题出在您的 input_ids 上。您正在将 long 类型的张量传递给 Adaptive MaxPool1d,只需将其转换为 float。

    input_ids = tokenizer.encode(question, text)
    print(input_ids) # input_ids is a list of 700 elements
    m = nn.AdaptiveMaxPool1d(512)
    input_ids = m(torch.tensor([[input_ids]]).float()) #