# Lesson 7 official topic

Hey lesson 7 crew.
I published a quick recap of this lesson along with a quiz (questions I created myself).
Also included is my per-lesson tenacious animal for your viewing pleasure

I was trying to implement multi-target classification with the titanic dataset, I seem to be getting two different predictions, but something doesn’t seem quite right about how I’ve tried to implement it, but cant quite figure out what.

Hi,

The first thing we can do to make this model a little bit better is to force those predictions to be between 0 and 5. For this, we just need to use sigmoid_range , like in <>. One thing we discovered empirically is that it’s better to have the range go a little bit over 5, so we use (0, 5.5):

This is snippet from 08_collab, from where do we arrive at 5 ? What does that range mean ?

The code related to the snippet.

class DotProduct(Module):
def init(self, n_users, n_movies, n_factors, y_range=(0,5.5)):
self.user_factors = Embedding(n_users, n_factors)
self.movie_factors = Embedding(n_movies, n_factors)
self.y_range = y_range

def forward(self, x):
users = self.user_factors(x[:,0])
movies = self.movie_factors(x[:,1])
return sigmoid_range((users * movies).sum(dim=1), *self.y_range)

Thanks

That 5 corresponds to the maximum rating of 5 that someone can give a movie. I found a snippet in the lesson 7 video where he talks about it. Since sigmoid never outputs 1 (except at positive infinity), the maximum value of the range is 5.5 so that a sigmoid output of 5 is possible.

1 Like

I loved lesson 7! A bit bummed I discovered this course 1-2 years late, but better now than never :). Anyways I wanted to extend this method to produce personalized recommendations for me, based on the movie ratings I noted in letterboxd for the movies that are part of the data set. If anyone is curious: Kaggle notebook, writeup. Thanks a lot for the amazing course !

2 Likes

Hi, great lesson!
I am doing collaborative filtering with anime dataset.
First, I created a model and exported it as pkl.
Next I created app.py file with dls, learn (from my .pkl) and defined function:
def find_similar_animes(anime_name, learn, dls, top_n=5) …
where anime_name should be selected from the list (name of the anime from anime dataframe).
the output of find_similar_anime function is

similar_animes = [dls.classes[‘name’][i] for i in top_indices].

When I provide anime name to anime_name and run it in notebook -I am getting the result - 5 similar animes:

anime_name = “Durarara!!”
similar_animes = find_similar_animes(anime_name, learn, dls)
print(f"Top 5 similar animes to ‘{anime_name}’:“)
for i, movie in enumerate(similar_animes, 1):
print(f”{i}. {movie}").

The output is:
Top 5 similar animes to ‘Durarara!!’:

1. Gintama Movie: Shinyaku Benizakura-hen
2. Haikyuu!! Second Season
3. Major S1
4. Gin no Saji
5. Steins;Gate: Kyoukaimenjou no Missing Link - Divide By Zero.

Which is great! I stumble into an issue when trying to create Gradio interface.

interface = gr.Interface(
fn=find_similar_animes,
inputs=gr.Dropdown(choices=list(anime[‘name’]), label=“Select Anime”),
outputs = gr.Textbox(),
title=“Find Similar Animes”,
description=“Select an anime from the dropdown list to find similar animes.”
)
interface.launch()

The gradio creates interface, where I can pick anime name from the drop down, but the output shows an error:

How can I define the output, so it is displayed as a list of recommended animes?

It’s been just 11 min out of allocated 30 Hours. That I got an error stating:
“OutOfMemoryError: CUDA out of memory. Tried to allocate 20.00 MiB. GPU 0 has a total capacty of 14.75 GiB of which 1.06 MiB is free. Process 2355 has 14.74 GiB memory in use. Of the allocated memory 14.50 GiB is allocated by PyTorch, and 62.92 MiB is reserved by PyTorch but unallocated. If reserved but unallocated memory is large try setting max_split_size_mb to avoid fragmentation. See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF”.

I have just trained 2 models with Images size of 1000 and epoch = 1 . GPU was T4*2.

This is so strange and awesome! I’m a huge anime fan and I’ve been doing a similar project on the same dataset!

For me i had to set timm to:

"timm==0.6.2.dev0"