With the role of permute in mind we could see what first permute does is reordering the concatenate tensor for it to fit the inputs format of self.W, i.e with batch as first dimension and the second permute does similar thing because we want to max pool the linear_output along the sequence and F.max_pool1d will pool along the last dimension. Print("Original size:\n\n".format(re_var.size(), re_var)) What permute function does is rearranges the original tensor according to the desired ordering, note permute is different from reshape function, because when apply permute, the elements in tensor follow the index you provide where in reshape it's not. Similar implementations of RCNN use permute or transpose. class (dims: Listint) source This module returns a view of the tensor input with its dimensions permuted. Max_out_features = self.dropout(max_out_features) torch is definitely installed, otherwise other operations made with torch wouldn’t work, too. But I get the following error: AttributeError: module torch has no attribute permute. # max_out_features.shape = (batch_size, hidden_size_linear) I tried to run the code below for training a sequence tagging model (didn’t list all of the code because it works fine). Max_out_features = F.max_pool1d(linear_output, linear_output.shape).squeeze(2) Linear_output = linear_output.permute(0,2,1) # Reshaping fot max_pool # linear_output.shape = (batch_size, seq_len, hidden_size_linear) # final_features.shape = (batch_size, seq_len, embed_size + 2*hidden_size) The model was implemented with PyTorch and all experiments were run on an NVidia. Input_features = torch.cat(, 2).permute(1,0,2) Permute Me Softly: Learning Soft Permutations for Graph Representations. W, C) -> (C, H, W) tensor tensor.permute(2, 0, 1) elif len(inputshape) 4: (B, H. # lstm_out.shape = (seq_len, batch_size, 2 * hidden_size) Tensor: Converts a numpy image to a PyTorch 4d tensor image. Lstm_out, (h_n,c_n) = self.lstm(embedded_sent) # embedded_sent.shape = (seq_len, batch_size, embed_size) The second is after a linear layer and before a max pooling layer.Ĭould you please explain why the permutation is necessary or useful? The first is after the LSTM layer and before tanh. There are two points where the dimensions of tensors are permuted using the permute function. I am looking at an implementation of RCNN for text classification using PyTorch.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |