def __init__(self):
    super(CNN,self).__init__()
    self.voacb_size=5304
    self.batch_size=1
    self.num_filters=3
    self.word_embed=torch.load("word2vec.pkl")
    self.in_channel=1
    self.filter_sizes=[1,2,3]
    self.embedding_length=200
    self.number_classes=4
    self.embed = nn.Embedding(self.voacb_size + 1, self.embedding_length)
    #self.embed.weight.data.copy_(torch.from_numpy(self.word_embed.weight.data))
    #self.embed.weight.requires_grad=False
    self.conv1=nn.ModuleList([nn.Conv2d(in_channels=self.in_channel,out_channels=self.num_filters,kernel_size=(x,self.embedding_length)) for x in self.filter_sizes])
    self.dropout=nn.Dropout(p=0.5)
    self.fc=nn.Linear(self.num_filters*len(self.filter_sizes),self.number_classes)


def forward(self,input_x):
    x = self.embed(input_x)
    x=x.unsqueeze(1)
    x = [F.relu(conv(x)).squeeze(3) for conv in self.conv1]
    x = [F.max_pool1d(i, i.size(2)).squeeze(2) for i in x]
    x = torch.cat(x, 1)
    x = self.dropout(x)  # (batch_size,len(kernel_sizes)*num_kernels)
    logit = self.fc(x)  # (batch_size, num_aspects)
    return logit

This is what I’m doing I believe that I am using the cross_entropy loss as my loss function. The loss function is defined in my train function. Please let me know if you want to have a look at it.