odats
(Oleh Dats)
July 26, 2020, 10:17am
1
I have input vectors with different size: [1,0,1], [1,0,1,1,1,1]…
Is there a way to add additional NN layer that Pads vectors on the right side with 2?
[1,0,1] -> [1,0,1,2,2,2,2,2]
[1,0,1,1,1,1] -> [1,0,1,1,1,1,2,2]
MAX_STRING_SIZE = 8
model = torch.nn.Sequential(
torch.nn.Linear(MAX_STRING_SIZE, 1),
torch.nn.Sigmoid()
)
torch.nn.functional.
pad
( input , pad , mode=‘constant’ , value=2 )
you can also try
tensor1 = torch.Tensor([1,0,2])
max_seq_len = 7
tensor2 = torch.ones(max_seq_len)*2
tensor1 = torch.cat((tensor1,tensor2))[:max_seq_len]
change the max_seq_len to get padding till different sizes
odats
(Oleh Dats)
July 27, 2020, 4:52pm
3
How to use it with batches?
tensor1 = torch.Tensor([[1,0,2],[1,0,2,1,0,2]])