def test_format_of_x(self): dataset = SequencesDataset() x, y = dataset[0] self.assertIsInstance(x, torch.FloatTensor) self.assertEqual(len(x.shape), 2) self.assertGreater(x.shape[0], 8) self.assertEqual(x.shape[1], 1)
def test_train_one_epoch(self): dataset = SequencesDataset(set_size=10) mean_loss = self.interface.train_one_epoch(dataset, weight_decay=0, learning_rate=0.02, shuffle=False) self.assertIsInstance(mean_loss, float)
def test_performance_on_samples(self): dataset = SequencesDataset(set_size=10) performance = self.interface.performance_on_samples(dataset) sample = performance[0] # raw_sample = dataset[0] self.assertIsInstance(sample.x, torch.FloatTensor) self.assertEqual(len(sample.x.shape), 2) self.assertGreater(sample.x.shape[0], 8) self.assertEqual(sample.x.shape[1], 1) self.assertIsInstance(sample.loss, float) self.assertIsInstance(sample.actual_y, float) self.assertIsInstance(sample.predicted_y, float)
def test___preprocessed_batch__(self): batch_size = 5 batch = SequencesDataset(set_size=batch_size)[:batch_size] x, y, normalization_factors, normalization_offsets = self.interface.__preprocessed_batch__( batch) self.assertIsInstance(x, torch.nn.utils.rnn.PackedSequence) x_unpacked, x_lengths = torch.nn.utils.rnn.pad_packed_sequence( x, batch_first=True) self.assertEqual(x_unpacked.shape[0], batch_size) self.assertGreater(x_unpacked.shape[1], 8) self.assertEqual(x_unpacked.shape[2], 1) self.assertIsInstance(y, torch.FloatTensor) # y_unpacked, y_lengths = torch.nn.utils.rnn.pad_packed_sequence(y, batch_first=True) self.assertEqual(y.shape, (batch_size, 1)) self.assertFalse(y.requires_grad) self.assertIsInstance(normalization_factors, torch.FloatTensor) self.assertEqual(normalization_factors.shape, (batch_size, )) self.assertIsInstance(normalization_offsets, torch.FloatTensor) self.assertEqual(normalization_offsets.shape, (batch_size, ))
def test___len__(self): dataset = SequencesDataset() self.assertEqual(len(dataset), 50000)
def test_format_of_y(self): dataset = SequencesDataset() x, y = dataset[0] self.assertIsInstance(y, torch.FloatTensor) self.assertEqual(y.shape, (1, 1))
def test___getitem__(self): dataset = SequencesDataset() samples = dataset[:2] self.assertIsInstance(samples[0], tuple) self.assertIsInstance(samples[1], tuple)
import dataset_parties from datasets.sequences_dataset import SequencesDataset dataset = SequencesDataset() train_set, dev_set, test_set = dataset_parties.ng_style(dataset)
def test_performance_on_set(self): dataset = SequencesDataset(set_size=10) performance = self.interface.performance_on_set(dataset) self.assertIsInstance(performance, float)