Skip to content

Why are all the slices across batch dimension concatenated in the forward process of the Tokenizer class? #4

@kangchengX

Description

@kangchengX

Hi, I am wondering why you concatenate the feature vectors of all the slices before passing them to gumbel_softmax(), i.e., in the code below

class Tokenizer(nn.Module):
    def __init__(self, rep_dim, vocab_size):
        super(Tokenizer, self).__init__()
        self.center = nn.Linear(rep_dim, vocab_size)

    def forward(self, x):
        bs, length, dim = x.shape
        probs = self.center(x.view(-1, dim))
        ret = F.gumbel_softmax(probs)
        indexes = ret.max(-1, keepdim=True)[1]
        return indexes.view(bs, length)

why is view(-1, dim) called to convert shape from (bs, length, dim) to (bs * length, dim)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions