TED Talk 推薦器
在這個練習中,你將建立一個根據逐字稿內容來推薦 TED Talk 的系統。你已獲得一個 get_recommendations() 函式,它接收演講標題、相似度矩陣與 indices 序列作為引數,並輸出最相似演講的清單。indices 已經替你準備好。
你同時也拿到了一個 transcripts 序列,裡面包含大約 500 場 TED Talk 的逐字稿。你的任務是為這些逐字稿的 tf-idf 向量建立一個餘弦相似度矩陣。
最後,我們會為巴西創業家 Bel Pesce 的演講「5 ways to kill your dreams」產生推薦結果。
本練習屬於課程
Python 中文本特徵工程
練習說明
- 以英文停用詞初始化
TfidfVectorizer,將其命名為tfidf。 - 對
transcripts進行 fit 與 transform,建立tfidf_matrix。 - 使用
tfidf_matrix產生餘弦相似度矩陣cosine_sim。 - 使用
get_recommendations()為「5 ways to kill your dreams」產生推薦。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Initialize the TfidfVectorizer
tfidf = ____
# Construct the TF-IDF matrix
tfidf_matrix = ____
# Generate the cosine similarity matrix
cosine_sim = ____
# Generate recommendations
print(get_recommendations(____, ____, indices))