def __getitem__(self, index): """ Returns the _transformed_ item from the dataset Args: index (int): Returns: (tuple): * example (ndarray): vector representation of a training sample * label (string): the class label * length (int): the length (tokens) of the sentence * index (int): the index of the dataitem in the dataset. It is useful for getting the raw input for visualizations. """ sample, label = self.data[index], self.labels[index] # transform the sample and the label, # in order to feed them to the model sample = vectorize(sample, self.char2idx, self.max_length) if self.label_transformer is not None: label = self.label_transformer.transform(label) if isinstance(label, (list, tuple)): label = numpy.array(label) return sample, label, len(self.data[index]), index
def __getitem__(self, index): """ Returns the _transformed_ item from the dataset Args: index (int): Returns: (tuple): * example (ndarray): vector representation of a training example * label (int): the class label * length (int): the length (tokens) of the sentence Examples: For an `index` where: :: self.data[index] = ['this', 'is', 'really', 'simple'] self.target[index] = "neutral" the function will have to return return: :: example = [ 533 3908 1387 649 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] label = 1 """ sample, label = self.data[index], self.labels[index] length = min(self.max_length, len(sample)) sample = vectorize(sample, self.word2idx, self.max_length) return sample, label, length