I am trying to implement a simple custom nn.Module which multiplies a sparse input matrix with a dense matrix. Following is the code snippet -
class CustomEmbedding(torch.nn.Module):
def init(self, num_embeddings, embedding_dim):
super(CustomEmbedding, self).init()
self.num_embeddings = num_embeddings
self.embedding_dim = embedding_dim
self.weight = torch.nn.Parameter(torch.Tensor(num_embeddings, embedding_dim))
self.reset_parameters()
def reset_parameters(self):
self.weight.data.normal_(0, 1)
def forward(self, input):
return torch.mm(input,self.weight)
However, I am getting the following run time error -
RuntimeError: Expected object of type Variable[torch.sparse.FloatTensor] but found type Variable[torch.FloatTensor] for argument #1 ‘mat2’
Any idea why this might be happening?