Adding movie year to the movielens model

Hi all!,

I was trying to add the movie year from the movie titles to the movielens model from lesson 5 but I get a cuda error:
“reduce failed to synchorinze”

I found a topic about this saying that this was discussed in lesson 7 but that was of V1 of the course so it’s still using keras.

Here’s the code for the model:

class MininetConts(nn.Module):
def __init__(self, n_users, n_movies, n_conts, nh=10, d1=0.05, d2=0.5):
    super().__init__()
    self.u, self.m = emb(n_users, n_factors), emb(n_movies, n_factors)
    self.lin1 = nn.Linear(n_factors * 2 + n_conts, nh)
    self.lin_out = nn.Linear(nh, 1)
    self.d1 = nn.Dropout(d1)
    self.d2 = nn.Dropout(d2)

def forward(self, cats, conts):
    users, movies = cats[:,0], cats[:,1]
    u_emb, m_emb = self.u(users), self.m(movies)
    inpt = torch.cat([u_emb, m_emb, conts], 1) # dim=1 because we want them side by side
    x = self.d1(inpt)
    x = self.lin1(x)
    x = F.relu(x)
    x = self.d2(x)
    x = self.lin_out(x)
    return F.sigmoid(x) * (max_rating-min_rating) + min_rating

I looked at the shape of inpt which seems to make sense. Also the datatypes should be correct float32 for the year and target. Also this looks right to me:

it = iter(data.trn_dl)
*xs,yt = next(it)
xs[0].shape, xs[1].shape, yt.shape
output: (torch.Size([64, 2]), torch.Size([64, 1]), torch.Size([64, 1]))

Any ideas what I’m doing wrong? Thanks!

Just for future reference: There turned out to be nothing wrong with the model but the proc_df function I used also affected my userId and movieId which I wasn’t aware of :).

Nice idea. I can’t see anything wrong with your approach on first glance, and I haven’t seen that error before. You may need to share your notebook so we can see all the steps. Also, try using the python debugger to step through forward().

Thanks for the reply! Yeah the model is working now!

I was using the proc_df() to normalize the movie years but this also updates the user ID and movieId and thereby tried to look up embeddings for indexes that did not exist.

1 Like

Did adding the year help?

Not really!

Leaving the settings as in your notebook: running 3 epochs with lr 1e-3, then 3 with 1e-5 only the very first epoch has a slightly better loss (.803 vs .811). After the 2nd epoch this advantage disappears.

Which would make sense to me because if the movie year is important (there surely could be people who love old films instead of new ones) it would easily show up in one of our 50 features after some training right?

That sounds right :slight_smile: