Back to Research Journal
NLP6 min read

Building a Movie Recommendation Engine

How I built a content-based movie recommendation system that suggests 5 similar movies instantly using NLP techniques and vector cosine similarity.

Golam Monayem

Golam Monayem

2026-07-20 • Dhaka, Bangladesh

Building a Movie Recommendation Engine - Cover

What I Built

Recommendation engines power the discovery mechanisms behind Netflix, Spotify, and Amazon. In this project, I built a content-based recommendation system that takes any movie title you input and instantly recommends the top 5 most similar titles using Natural Language Processing.

To make it interactive and user-friendly, I built a dynamic frontend using Streamlit connected to the TMDB API for fetching real-time movie posters.

How It Works Under The Hood

Content-based filtering relies on finding similarities between items based on their descriptive metadata rather than user behavior history.

  1. Data Ingestion: Processed the TMDB 5000 movies dataset containing metadata for over 5,000 films.
  2. Feature Fusion: Extracted and consolidated critical metadata fields—including genres, plot keywords, top 3 cast members, director, and storyline synopsis—into a unified textual tag string.
  3. Text Preprocessing: Applied PorterStemmer to normalize word variations (e.g., 'actions', 'acting' -> 'act') and stripped common English stop words.
  4. Vectorization: Transformed tags into a 5,000-dimensional bag-of-words matrix using CountVectorizer.
  5. Cosine Distance: Computed pairwise cosine similarity across all vectors to find angular proximity.
python
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.metrics.pairwise import cosine_similarity

# Vectorize combined tags
cv = CountVectorizer(max_features=5000, stop_words='english')
vector = cv.fit_transform(new_df['tags']).toarray()

# Compute angular similarity matrix
similarity = cosine_similarity(vector)

The Magic of Cosine Similarity

Why cosine similarity instead of Euclidean distance? In high-dimensional text vector spaces, document length variations can distort Euclidean distance. Cosine similarity evaluates the angle between vectors rather than their magnitudes:

$$\text{Cosine Similarity}(A, B) = \frac{A \cdot B}{\|A\| \|B\|}$$

If two movies share common themes, their vectors point in nearly the identical direction in vector space, resulting in a score close to 1.0.

What I Learned

  • Feature engineering quality has an exponential impact on recommendation relevance.
  • Preprocessing and stemming text significantly reduces noise in vector spaces.
  • Streamlit allows rapid deployment of intuitive data science web applications without complex frontend boilerplate.
Sometimes the most elegant mathematical formulation outperforms complex black-box architectures.
Golam Monayem
About the Author

Golam Monayem

Machine Learning Engineer & Visual Designer based in Dhaka, Bangladesh. Studying CSE at Presidency University, team member at Wice BD, and building production-grade AI systems.