Hello,
I am only beginning with pytorch and I am stuck with the problem of processing sequences with variable length.
My task is to take two sequences and infer how similar are they.
I have came up with something like this. q1 and q2 are just list of integer word indices.
 def SimilarityModule(nn.Module)
     def __init__():
         self.embedding = nn.Embedding(...)
     ....
    def forward(self, q1, q2):
        q1_embeds = self.embeddings(q1)
        q2_embeds = self.embeddings(q2)
        #mean over whole sequence
        q1_repre = torch.mean( q1_embeds, 0 ) 
        q2_repre = torch.mean( q2_embeds, 0 )

        dot_product = torch.dot( q1_repre, q2_repre ) / torch.norm( q1_repre, 2 ) / torch.norm( q1_repre, 2 )

        return dot_product

I can run the model on one sample:
similarity = model( q1, q2)
I have a question how properly create a batch of the sequences with variable length and feed it to the module? Thank you in advance for help!