Get startedGet started for free

TED talk recommender

In this exercise, we will build a recommendation system that suggests TED Talks based on their transcripts. You have been given a get_recommendations() function that takes in the title of a talk, a similarity matrix and an indices series as its arguments, and outputs a list of most similar talks. indices has already been provided to you.

You have also been given a transcripts series that contains the transcripts of around 500 TED talks. Your task is to generate a cosine similarity matrix for the tf-idf vectors of the talk transcripts.

Consequently, we will generate recommendations for a talk titled '5 ways to kill your dreams' by Brazilian entrepreneur Bel Pesce.

This exercise is part of the course

Feature Engineering for NLP in Python

View Course

Exercise instructions

  • Initialize a TfidfVectorizer with English stopwords. Name it tfidf.
  • Construct tfidf_matrix by fitting and transforming transcripts.
  • Generate the cosine similarity matrix cosine_sim using tfidf_matrix.
  • Use get_recommendations() to generate recommendations for '5 ways to kill your dreams'.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Initialize the TfidfVectorizer 
tfidf = ____

# Construct the TF-IDF matrix
tfidf_matrix = ____

# Generate the cosine similarity matrix
cosine_sim = ____
 
# Generate recommendations 
print(get_recommendations(____, ____, indices))
Edit and Run Code