GokuMohandas / Made-With-ML

Learn how to design, develop, deploy and iterate on production-grade ML applications.
https://madewithml.com
MIT License
37.51k stars 5.95k forks source link

error in 10_Utilities #194

Closed kumar-mahendra closed 3 years ago

kumar-mahendra commented 3 years ago

class Dataset 's method collate_fn needs a little change as otherwise following error in thrown when creating dataloader

ValueError: setting an array element with a sequence

Given Code

"""Processing on a batch."""
    # Get inputs
    batch = np.array(batch, dtype=object)
    X = batch[:, 0]    # This line execution throws above error 
    y = np.stack(batch[:, 1], axis=0)

Suggested solution

"""Processing on a batch."""
    # Get inputs
    batch = np.array(batch, dtype=object)
    X = np.stack(batch[:, 0] ,axis=0) 
    y = np.stack(batch[:, 1], axis=0)
GokuMohandas commented 3 years ago

Nice catch Kumar! Since our inputs are of the same length I have to stack them here. In subsequent lessons with variable sequence lengths within a batch, we have to use batch[:, i]. I'll push this fix later today.