deepspeech.pytorch icon indicating copy to clipboard operation
deepspeech.pytorch copied to clipboard

SequenceWise Operation

Open igor17400 opened this issue 11 months ago • 0 comments

Hi there,

Could please someone provide an explanation for the necessity of the SequenceWise operation?

Additionally, if possible, could explain how this operation is similar to TimeDistributed layer from Keras, as discussed in this thread?

class SequenceWise(nn.Module):
    def __init__(self, module):
        """
        Collapses input of dim T*N*H to (T*N)*H, and applies to a module.
        Allows handling of variable sequence lengths and minibatch sizes.
        :param module: Module to apply input to.
        """
        super(SequenceWise, self).__init__()
        self.module = module

    def forward(self, x):
        t, n = x.size(0), x.size(1)
        x = x.view(t * n, -1)
        x = self.module(x)
        x = x.view(t, n, -1)
        return x

    def __repr__(self):
        tmpstr = self.__class__.__name__ + ' (\n'
        tmpstr += self.module.__repr__()
        tmpstr += ')'
        return tmpstr

igor17400 avatar Mar 12 '24 07:03 igor17400