(sentences, conversation_length, sentence_length, vocab, batch_size=100, data=None, shuffle=True)
return data_loader
Load DataLoader of given DialogDataset
Load DataLoader of given DialogDataset
Load DataLoader of given DialogDataset
def get_loader(sentences, conversation_length, sentence_length, vocab, batch_size=100, data=None, shuffle=True):
    """Load DataLoader of given DialogDataset"""

    def collate_fn(data):
        """
        Collate list of data in to batch

        Args:
            data: list of tuple(source, target, conversation_length, source_length, target_length)
        Return:
            Batch of each feature
            - source (LongTensor): [batch_size, max_conversation_length, max_source_length]
            - target (LongTensor): [batch_size, max_conversation_length, max_source_length]
            - conversation_length (np.array): [batch_size]
            - source_length (LongTensor): [batch_size, max_conversation_length]
        """
        # Sort by conversation length (descending order) to use 'pack_padded_sequence'
        data.sort(key=lambda x: x[1], reverse=True)

        # Separate
        sentences, conversation_length, sentence_length = zip(*data)

        # return sentences, conversation_length, sentence_length.tolist()
        return sentences, conversation_length, sentence_length

    dataset = DialogDataset(sentences, conversation_length,
                            sentence_length, vocab, data=data)

    data_loader = DataLoader(
        dataset=dataset,
        batch_size=batch_size,
        shuffle=shuffle,
        collate_fn=collate_fn)

    return data_loader
def get_loader ( sentences , conversation_length , sentence_length , vocab , batch_size = 100 , data = None , shuffle = True ) : def collate_fn ( data ) : """
        Collate list of data in to batch

        Args:
            data: list of tuple(source, target, conversation_length, source_length, target_length)
        Return:
            Batch of each feature
            - source (LongTensor): [batch_size, max_conversation_length, max_source_length]
            - target (LongTensor): [batch_size, max_conversation_length, max_source_length]
            - conversation_length (np.array): [batch_size]
            - source_length (LongTensor): [batch_size, max_conversation_length]
        """ # Sort by conversation length (descending order) to use 'pack_padded_sequence' data . sort ( key = lambda x : x [ 1 ] , reverse = True ) # Separate sentences , conversation_length , sentence_length = zip ( * data ) # return sentences, conversation_length, sentence_length.tolist() return sentences , conversation_length , sentence_length dataset = DialogDataset ( sentences , conversation_length , sentence_length , vocab , data = data ) data_loader = DataLoader ( dataset = dataset , batch_size = batch_size , shuffle = shuffle , collate_fn = collate_fn ) return data_loader