Hi Piotr,
Thanks – so the code is a bit unusual, but here we are
## this is all Keras that I'm trying to understand
class MaskedConvolution1D(Convolution1D):
    def __init__(self, *args, **kwargs):
        super(MaskedConvolution1D, self).__init__(*args, **kwargs)

    def compute_mask(self, input, input_mask=None):
        return input_mask

    def call(self, x, mask=None):
        assert mask is not None
        mask = K.expand_dims(mask, axis=-1)
        x = super(MaskedConvolution1D, self).call(x)
        return x * K.cast(mask, K.floatx())

class MaskingByLambda(Layer):
    def __init__(self, func, **kwargs):
        self.supports_masking = True
        self.mask_func = func
        super(MaskingByLambda, self).__init__(**kwargs)

    def compute_mask(self, input, input_mask=None):
        return self.mask_func(input, input_mask)

    def call(self, x, mask=None):
        exd_mask = K.expand_dims(self.mask_func(x, mask), axis=-1)
        return x * K.cast(exd_mask, K.floatx())

def lambda_func(tensor):
    return lambda input, mask: tensor

def model(length):
    input = Input(shape=(length, n_features))
    mask = Input(shape=(length,))
    seq = MaskingByLambda(lambda_func(mask))(input)
    conv = MaskedConvolution1D(28, 3, padding='same', activation='relu')(seq)

The dataset I’m working on is a set of sequences, such as:
x = ["This is a sentence", "This is another longer sentence", "Short sentence", "AHHH!"]

This is then tokenised into a 1-0 encoded tensor to be fed into the Conv1D layer. I’m just wondering most importantly how a nn.Conv1d can handle variable length sequences, and how it can replicate the functionality of the MaskedConvolution1D implementation above.
Thanks!!