import torch


def collate_fn(batch):
    """Collates a batch of padded variable length inputs"""

    ids, inputs, labels, texts = zip(*batch)
    labels = torch.tensor(labels)

    # get sequence lengths
    lengths = torch.tensor([x.shape[0] for x in inputs])

    # padding
    inputs = torch.nn.utils.rnn.pad_sequence(inputs, batch_first=True)

    return ids, inputs, labels, texts, lengths