I’m trying to select a number of data from a universal tensor (encoder_outputs
) according to the start and end boundaries by two index tensors. Take the below as an example:
# print(start_pre_ids)
tensor([[[ 564, 258, 1239, 528, 579, 0, 183, 1088, 899, 76],
[1309, 1379, 1766, 1414, 1694, 1648, 1731, 1610, 1856, 1435],
[1933, 2106, 2030, 1967, 1885, 2242, 2034, 2071, 1902, 2102],
[2636, 3704, 3267, 2589, 3293, 3497, 3450, 3122, 3347, 0],
[3939, 4064, 3823, 3872, 3813, 4296, 4538, 4501, 4398, 0],
[4830, 4890, 4837, 4621, 4808, 4911, 4655, 4928, 4787, 4981],
[5473, 6525, 5710, 6403, 5414, 5436, 6358, 5012, 0, 0],
[7025, 6866, 7171, 6733, 6712, 7215, 7279, 0, 0, 0],
[7507, 7643, 7533, 7741, 7428, 7597, 7390, 7414, 7710, 0],
[7869, 7790, 8143, 8021, 7821, 8013, 8168, 7886, 7900, 8079]]],
device='cuda:0')
# print(end_pre_ids)
tensor([[[ 592, 310, 1271, 543, 629, 80, 221, 1115, 938, 98],
[1379, 1414, 1806, 1430, 1729, 1669, 1738, 1639, 1923, 1503],
[1937, 2152, 2047, 2030, 1919, 2273, 2038, 2161, 1933, 2174],
[2659, 3725, 3334, 2643, 3343, 3529, 3483, 3167, 3419, 0],
[3945, 4112, 3825, 3947, 3843, 4306, 4665, 4589, 4413, 0],
[4852, 4911, 4890, 4628, 4842, 4932, 4787, 4981, 4804, 5012],
[5556, 6576, 5748, 6420, 5422, 5492, 6406, 5033, 0, 0],
[7063, 6927, 7252, 6793, 6786, 7259, 7300, 0, 0, 0],
[7556, 7689, 7600, 7767, 7465, 7611, 7454, 7438, 7741, 0],
[7917, 7903, 8174, 8085, 7846, 8021, 8182, 7909, 7917, 8137]]],
device='cuda:0')
When I’m doing encoder_outputs[:, start_pre_ids:end_pre_ids]
, I’m getting this error:
*** TypeError: only integer tensors of a single element can be converted to an index
Is there a way that I can select from encoder_outputs
based off the start_pre_ids
and end_pre_ids
? The encoder_outputs
’s shape is: [1, 8192, 1024]