Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Training on datasets without y attribute (ex: unsupervised-learning) throws AttributeError #3836

Open
arunppsg opened this issue Feb 15, 2024 · 0 comments · May be fixed by #3847
Open

Training on datasets without y attribute (ex: unsupervised-learning) throws AttributeError #3836

arunppsg opened this issue Feb 15, 2024 · 0 comments · May be fixed by #3847

Comments

@arunppsg
Copy link
Contributor

To Reproduce

import csv
import deepchem as dc
from deepchem.models.torch_models import InfoGraphModel

# Generate sample dataset without y value
with open('smiles.csv', 'w', newline='') as csvfile:
    fieldnames = ['smiles']
    writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
    writer.writeheader()
    for i in range(100):
        writer.writerow({'smiles': 'Cc1[nH]ccc1C(=O)N[C@@H](C)CNC(=O)c1cccc2[nH]ccc21'})

featurizer = dc.feat.MolGraphConvFeaturizer(use_edges=True)

loader = dc.data.CSVLoader([], feature_field='smiles', featurizer=featurizer)
dataset = loader.create_dataset('smiles.csv', data_dir='temp-dir')

# Fit on model
loss = model.fit(dataset, nb_epoch=1)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[4], line 1
----> 1 loss = model.fit(dataset, nb_epoch=1)

...

File ~/deepchem/models/torch_models/torch_model.py:921, in <listcomp>(.0)
    918 input_tensors = [torch.as_tensor(x, device=self.device) for x in inputs]
    919 if labels is not None:
    920     labels = [
--> 921         x.astype(np.float32) if x.dtype == np.float64 else x
    922         for x in labels
    923     ]
    924     label_tensors = [
    925         torch.as_tensor(x, device=self.device) for x in labels
    926     ]
    927 else:

AttributeError: 'NoneType' object has no attribute 'dtype'

Potential Solution

Adding a check for y values before this line

yield ([X_b], [y_b], [w_b])

to return None for y when it is None instead of returning [None].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant