Repository: PaccMann/paccmann_datasets

Issue:
Shape of tensors returned by SMILES_dataset
The `SMILESDataset` class currently returns per default tensors of shape `sequence_length x 1`. This is not ideal since the additional dimension is not understood by most models per default.
As a workaround, we use `torch.squeeze()` in the code that currently uses `SMILESDataset ` objects.

Writing methods that want to use models and loaders generically (like the uncertainity estimation functions in `paccmann_predictor`) causes problems then.

Check `test_smiles_eager_dataset.py`  for the details. 

Discussion:

Patch:
diff --git a/pytoda/smiles/transforms.py b/pytoda/smiles/transforms.py
index 6a9288f..a40439f 100644
--- a/pytoda/smiles/transforms.py
+++ b/pytoda/smiles/transforms.py
@@ -95,7 +95,7 @@ class ToTensor(Transform):
         """
         return torch.tensor(
             token_indexes, dtype=self.dtype, device=self.device
-        ).view(-1, 1)
+        ).view(-1, 1).squeeze()
 
 
 class RemoveIsomery(Transform):


Test patch:
diff --git a/pytoda/datasets/tests/test_drug_sensitivity_eager_dataset.py b/pytoda/datasets/tests/test_drug_sensitivity_eager_dataset.py
index f3033fb..10861c0 100644
--- a/pytoda/datasets/tests/test_drug_sensitivity_eager_dataset.py
+++ b/pytoda/datasets/tests/test_drug_sensitivity_eager_dataset.py
@@ -111,10 +111,7 @@ class TestDrugSensitivityDataset(unittest.TestCase):
                     np.testing.assert_almost_equal(
                         token_indexes_tensor.numpy(),
                         np.array(
-                            [
-                                [padding_index], [padding_index], [c_index],
-                                [o_index]
-                            ]
+                            [padding_index, padding_index, c_index, o_index]
                         )
                     )
                     np.testing.assert_almost_equal(
@@ -176,7 +173,7 @@ class TestDrugSensitivityDataset(unittest.TestCase):
                             ic50_batch
                         )
                     ) in enumerate(data_loader):
-                        self.assertEqual(token_indexes_batch.size(), (2, 4, 1))
+                        self.assertEqual(token_indexes_batch.size(), (2, 4))
                         self.assertEqual(gene_expression_batch.size(), (2, 4))
                         self.assertEqual(ic50_batch.size(), (2, 1))
                         if batch_index > 4:
diff --git a/pytoda/datasets/tests/test_drug_sensitivity_lazy_dataset.py b/pytoda/datasets/tests/test_drug_sensitivity_lazy_dataset.py
index cbd7c76..8043634 100644
--- a/pytoda/datasets/tests/test_drug_sensitivity_lazy_dataset.py
+++ b/pytoda/datasets/tests/test_drug_sensitivity_lazy_dataset.py
@@ -111,10 +111,7 @@ class TestDrugSensitivityDataset(unittest.TestCase):
                     np.testing.assert_almost_equal(
                         token_indexes_tensor.numpy(),
                         np.array(
-                            [
-                                [padding_index], [padding_index], [c_index],
-                                [o_index]
-                            ]
+                            [padding_index, padding_index, c_index, o_index]
                         )
                     )
                     np.testing.assert_almost_equal(
@@ -176,7 +173,7 @@ class TestDrugSensitivityDataset(unittest.TestCase):
                             ic50_batch
                         )
                     ) in enumerate(data_loader):
-                        self.assertEqual(token_indexes_batch.size(), (2, 4, 1))
+                        self.assertEqual(token_indexes_batch.size(), (2, 4))
                         self.assertEqual(gene_expression_batch.size(), (2, 4))
                         self.assertEqual(ic50_batch.size(), (2, 1))
                         if batch_index > 4:
diff --git a/pytoda/datasets/tests/test_smiles_eager_dataset.py b/pytoda/datasets/tests/test_smiles_eager_dataset.py
index 2479c3c..7c79c5b 100644
--- a/pytoda/datasets/tests/test_smiles_eager_dataset.py
+++ b/pytoda/datasets/tests/test_smiles_eager_dataset.py
@@ -169,7 +169,7 @@ class TestSMILESDatasetEagerBackend(unittest.TestCase):
                     smiles_dataset, batch_size=4, shuffle=True
                 )
                 for batch_index, batch in enumerate(data_loader):
-                    self.assertEqual(batch.shape, (4, 4, 1))
+                    self.assertEqual(batch.shape, (4, 4))
                     if batch_index > 10:
                         break
 
diff --git a/pytoda/datasets/tests/test_smiles_lazy_dataset.py b/pytoda/datasets/tests/test_smiles_lazy_dataset.py
index 01b5929..d2791f3 100644
--- a/pytoda/datasets/tests/test_smiles_lazy_dataset.py
+++ b/pytoda/datasets/tests/test_smiles_lazy_dataset.py
@@ -169,7 +169,7 @@ class TestSMILESDatasetLazyBackend(unittest.TestCase):
                     smiles_dataset, batch_size=4, shuffle=True
                 )
                 for batch_index, batch in enumerate(data_loader):
-                    self.assertEqual(batch.shape, (4, 4, 1))
+                    self.assertEqual(batch.shape, (4, 4))
                     if batch_index > 10:
                         break