If we talk about one sentence i.e. x.shape = [batch_size, sentence_length] after embedding i get x.shape = [batch_size, sentence_length, embedding_dim].
I want to convolve over words in this sentence.
So as it’s told in one of CNN tutorials in pytorch i need to remute and end up with [batch_size, embedding_dim, sentence_length] before convolution.
After convolution i’m getting strange shaped tensor  [1, 100, 118]. 1 is batch_size in my current setting but i don’t get where other dims came from as i have embedding_dim=300 and sentence_length=120.
It seems like i’m using it wrong. I know what convolutional layer is as i worked with it in tf but torch api seems hard to me.
Correct me if i’m using it wrong please.
Also here’s my updated code.
class CNNEncoder(nn.Module):
    def __init__(self, embed_dim: int, vocab_size: int):
        super(CNNEncoder, self).__init__()

        self.embed = nn.Embedding(vocab_size, embed_dim)
        self.conv1 = nn.Conv1d(embed_dim, 100, 3)
        self.pool = nn.AvgPool1d(1, 1)

    def forward(self, x):
        x.unsqueeze_(0)
        x = self.embed(x)
        x = x.permute(0, 2, 1)
        x = self.conv1(x)
        x = torch.tanh(x)
        x = self.pool(x)
        x.unsqueeze_(1)
        return x

P.S.
Main question is actually about using same model for sentence (shape [batch_size, sentence_length]) and for matrix of sentences (shape [K, N, sentence_length])
But i think i need to figure out first if i’m using this model right just for sentence and then deal with matrix question.