Foundations to Frontier
Tests
D. Classical Machine Learning › D13 Recommender Systems

Content-Based Filtering

Content-based recommenders suggest items similar to those a user already liked, judging similarity from the items' own descriptions: text, tags, genres, specifications or learned embeddings. Each item becomes a feature vector (classically TF-IDF over its words), each user becomes a profile vector built from the items they liked (an average, or Rocchio's weighted difference of liked and disliked items, or a per-user classifier), and recommendations are the unseen items closest to the profile, usually by cosine similarity. The approach needs no other users, so it handles new items immediately and explains itself through shared features, but it can only recommend more of what the user has already shown, it depends entirely on the quality of the item features, and new users with no history get nothing useful. This page covers TF-IDF item representations, profile construction, cosine scoring, evaluation by precision, recall and coverage, over-specialisation, and hybrids with popularity and collaborative signals. In the exercises you build a TF-IDF content recommender; then you measure its accuracy, catalogue coverage and narrowing over a user's history against popularity and a hybrid.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

More of what you liked

If you enjoyed two documentaries about space engineering, a helpful friend might suggest a third one about Mars rovers, because it is about the same things. A content-based recommender does exactly that. It describes every item by its features (words, tags, genres), sums up what you liked into a profile, and suggests the items whose descriptions best match that profile. It never needs to know what anyone else watched.

Content-based recommendation: like a few, get similar ones
profile (top tags): space 0.71, engineering 0.52, robots 0.35, physics 0.33
Moon Landing Files · cosine 0.73 · score 0.73 · shares: space, engineering
Exoplanet Hunt · cosine 0.56 · score 0.56 · shares: space, physics
Robot Hands · cosine 0.47 · score 0.47 · shares: robots, engineering
Deep Sea Robots · cosine 0.44 · score 0.44 · shares: robots, engineering
Jet Age · cosine 0.26 · score 0.26 · shares: engineering
Cathedral Builders · cosine 0.25 · score 0.25 · shares: engineering
Every recommendation can be explained by the tags it shares with what you liked, and a brand-new item with tags but no viewers can be recommended at once: no cold start for items. The flip side is over-specialisation: like only space films and you only ever see space films, so nothing from outside your profile can surprise you. Blending in popularity broadens the list but pushes everyone toward the same hits.
Why engineers care

Content-based matching powers document and procedure recommendation in maintenance manuals, similar-incident retrieval for safety reports, part and supplier suggestions from specifications, and the “related items” lists of technical libraries. It works from day one, before any usage data exists, and every suggestion can be justified by shared features, which matters in regulated settings.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Content-based filtering recommends items…
  2. 2. A brand-new item with a description but no ratings can be recommended…
  3. 3. A typical weakness is…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

Vectors, profiles and cosine by hand

TF-IDF. An item’s weight for word w is tf(w) × idf(w), where tf counts occurrences in the item’s text. The smoothed idf(w) = log((1 + n)/(1 + df)) + 1 down-weights words that appear in many items (df = number of items containing w).

  • A word in all 10 of 10 items has idf 1.
  • A word in 1 of 9 items has idf log 5 + 1 = 2.61.

Normalise each item vector to unit length.

Cosine similarity. cos(a, b) = a·b/(‖a‖‖b‖). For (1, 0) and (1, 1) it is 1/√2 = 0.707. Parallel vectors give 1, and vectors with no shared words give 0.

User profile.

  • Average: the mean of the liked items’ vectors, normalised.
  • Rocchio: p = α·mean(liked) − β·mean(disliked), which moves away from disliked content.
  • Per-user classifier: logistic regression or naive Bayes on liked versus not-liked item features.

Evaluation. Hold out some of each user’s likes and recommend k items from the rest.

  • precision@k = hits/k and recall@k = hits/|held out|. Recommending 5, 3, 9, 1 against held-out 3, 1, 7, 8 gives precision@4 = recall@4 = 0.5.
  • Coverage: the fraction of the catalogue recommended to anyone. Three users receiving (1, 2), (2, 3) and (1, 3) out of 10 items give coverage 0.3.

The steps in plain English:

  1. Build item vectors: TF-IDF of text and tags, one-hot categorical attributes, scaled numeric attributes, or pretrained embeddings.
  2. Build each user’s profile from their positive (and negative) interactions.
  3. Score unseen items by cosine similarity to the profile and recommend the top k.
  4. Evaluate on held-out interactions with precision, recall, coverage and diversity, against popularity and random baselines.
📝 Quick check (Level 1)
0/3 answered
  1. 1. IDF gives the highest weight to words that are…
  2. 2. Cosine similarity of two vectors with no shared non-zero features is…
  3. 3. Rocchio's profile subtracts…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 30 minUndergraduate students and practising engineers.

Strengths, limits and hybrids

Strengths.

  • No item cold start: any described item can be scored.
  • User independence: one user’s recommendations do not depend on others’ data, which helps privacy and niche tastes.
  • Transparency: “recommended because it shares space, engineering”.

Limits.

  • Over-specialisation: the profile is a centroid of past likes, so the top-ranked items cluster around the dominant interest. Secondary interests are under-served, and there is no serendipity.
  • Feature dependence: if two items with similar descriptions differ in quality or style, the recommender cannot tell.
  • New users: with no history there is no profile.

Hybrids. Mix content scores with popularity, which helps new users and quality, or with collaborative filtering, which helps quality and serendipity. Simple weighted blends often beat either part alone.

Exercise 1 (240 items, each described by genre words plus shared filler words):

  • a user who liked 10 items of one genre received top-10 recommendations with precision 1.00, against 0.12 for random guessing;
  • all ten recommendations came from the liked genre, which is accurate here but already shows the narrowing.
from sklearn.feature_extraction.text import TfidfVectorizer
X = TfidfVectorizer(stop_words="english").fit_transform(item_texts)    # rows L2-normalised by default
profile = np.asarray(X[liked].mean(axis=0)); scores = X @ profile.T   # cosine to the profile, up to its norm
🐍 Exercise 1: a TF-IDF content recommender
Build L2-normalised TF-IDF item vectors from word lists, a mean-of-liked user profile, cosine scoring of unseen items, and precision@k on held-out likes.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Over-specialisation arises because the profile is…
  2. 2. Content-based methods cannot distinguish items that…
  3. 3. A popularity blend mainly helps…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Vector-space model. TF-IDF with cosine similarity comes from information retrieval (Salton, 1975). A user profile is a “query” and items are “documents”. IDF approximates a word’s informativeness, roughly −log P(word appears).

Learning profiles. Treating each user’s likes as positive examples gives a per-user classifier. Naive Bayes, Rocchio and linear models are classic choices. With little data per user, regularisation, or sharing parameters across users, is essential, which leads toward hybrid and collaborative models.

Modern content features. Pretrained text, image or audio embeddings replace TF-IDF and capture meaning beyond exact word overlap. Two-tower models learn item and user encoders jointly from interaction data, blurring the line between content-based and collaborative methods.

Evaluation pitfalls. Random hold-out leaks the future; prefer time-based splits. Precision falls as the held-out set shrinks, so compare against baselines on the same split. Report coverage and diversity alongside accuracy.

Interview questions.

  • How do you recommend items that have just been added to the catalogue? Use content features, or a hybrid that falls back on content for items without interactions.
  • How do you reduce filter bubbles in a content-based system? Re-rank for diversity (maximal marginal relevance), keep several interest profiles per user, inject exploration, and blend in collaborative or popularity signals.
📝 Quick check (Level 3)
0/3 answered
  1. 1. TF-IDF and cosine similarity come from…
  2. 2. Maximal marginal relevance re-ranks to…
  3. 3. Two-tower models learn…

Level 4: Expert

★★★★★ Expert⏱ 25 minResearchers: original papers and open problems.

Accuracy, coverage and narrowing

History.

  • G. Salton, A. Wong and C. Yang (1975) introduced the vector-space model.
  • J. Rocchio (1971) introduced relevance feedback.
  • M. Pazzani and D. Billsus (1997, 2007) applied learned user profiles to content-based recommendation.
  • P. Lops, M. de Gemmis and G. Semeraro (2011) surveyed the field.
  • Modern systems combine content embeddings with collaborative signals.

Exercise 2. 400 items in 8 genres, with TF-IDF text and a skewed quality factor. 300 users each have a main genre (70% of their likes) and a second genre (30%), with 40 likes each. The first h likes train the profile, and the rest are held out. Each cell shows precision@10, then catalogue coverage, then the share of recommendations from the user’s second genre.

likes used content-based popularity hybrid random
2 0.324, 0.99, 0.26 0.245, 0.03, 0.11 0.393, 0.97, 0.26 0.089, 1.00, 0.12
5 0.349, 0.98, 0.21 0.225, 0.04, 0.12 0.442, 0.95, 0.22 0.081, 1.00, 0.12
10 0.328, 0.93, 0.13 0.187, 0.04, 0.10 0.441, 0.89, 0.13 0.071, 1.00, 0.11
20 0.263, 0.86, 0.07 0.116, 0.04, 0.08 0.362, 0.82, 0.09 0.050, 1.00, 0.11

Content-based precision divided by random precision was 3.7, 4.3, 4.6 and 5.2 for 2, 5, 10 and 20 likes.

  • The hybrid (content + 0.3 × popularity) was most accurate at every history length. Content found the right genre, and popularity found the good items within it.
  • Popularity gave everyone almost the same list: 3–4% catalogue coverage, against 82–99% for content-based methods.
  • Content-based recommendations narrowed as the history grew. The second genre made up 30% of each user’s likes, but only 26% of recommendations after 2 likes and 7% after 20. The centroid profile settled firmly on the main genre.
  • Raw precision fell for long histories because fewer likes remained to be found. Relative to random, content-based accuracy kept improving, from 3.7× to 5.2×.
🐍 Exercise 2 (research): accuracy, coverage and narrowing
Simulate users with a main and a second genre, and compare content-based, popularity, hybrid and random recommenders by precision@10, catalogue coverage and the share of recommendations from the second genre, for 2–20 training likes.

Content-based recommendation in AI, robotics and aerospace

  • Maintenance documentation: suggest procedures, service bulletins and past work orders similar to the current fault description.
  • Safety-report retrieval: find similar incident narratives for investigators, with explanations via shared terms.
  • Engineering reuse: recommend existing designs, parts or test cases with similar specifications.

References

  1. G. Salton, A. Wong, C. S. Yang (1975). “A vector space model for automatic indexing.” Communications of the ACM 18(11).
  2. M. J. Pazzani, D. Billsus (2007). “Content-based recommendation systems.” In The Adaptive Web, Springer.
  3. P. Lops, M. de Gemmis, G. Semeraro (2011). “Content-based recommender systems: state of the art and trends.” In Recommender Systems Handbook, Springer.
  4. J. Carbonell, J. Goldstein (1998). “The use of MMR, diversity-based reranking for reordering documents and producing summaries.” Proc. ACM SIGIR.