I have the code written for part highlighted in blue, need to add the red part.
class BiDir(torch.nn.Module):
def init(self, weights, emb_dim, hid_dim, rnn_num_layers=2):
super().init()
#Embedding layers using glove as the pretrained weights
self.embedding = nn.Embedding.from_pretrained(weights)
#Bidirectional GRU module for forward pass with 2 hidden layers
self.rnn = torch.nn.GRU(emb_dim, hid_dim, bidirectional=True, num_layers=rnn_num_layers)
self.l1 = torch.nn.Linear(hid_dim * 2 * rnn_num_layers, 256)
self.l2 = torch.nn.Linear(256, 2)
def forward(self, samples):
    
    #Forward Pass        
    embedded = self.embedding(samples)
    _, last_hidden = self.rnn(embedded)
    hidden_list = [last_hidden[i, :, :] for i in range(last_hidden.shape[0])]
    #Calculating the loss
    encoded = torch.cat(hidden_list, dim=1)
    #RELU and Sigmoid Activation Function
    encoded = torch.nn.functional.relu(self.l1(encoded))
    encoded = torch.sigmoid(torch.FloatTensor(self.l2(encoded)))

    return encoded