yes you can , like this :
class Encoder(nn.Module):
    def __init__(self, vocab_size, embedding_size, hidden_size,n_layers=1, dropout=0.3):
        super(Encoder, self).__init__()
        assert hidden_size % 2 == 0
        self.embedding = nn.Embedding(vocab_size, embedding_size)
        self.gru = nn.GRU(embedding_size, hidden_size//2, n_layers,dropout=dropout, bidirectional=True)

    def forward(self, src_batch, hidden=None):
        src_embeddings = self.embedding(src_batch)
        outputs, hidden = self.gru(src_embeddings, hidden)

        return outputs, hidden