AI Wiki中文/EN

Content-based recommendation: what can the item description tell you?

基于内容的推荐

Fit an interpretable ridge profile, rank unseen items and expose indistinguishable metadata.

On this pageIntuitionMathematics & methodImplementationLimitationsExercisesResearch connections

Recommend a new article before anyone clicks it

A newly published science article has no readers yet, but its topic and length are known. An item-neighborhood recommender lacks co-ratings for it. A content model can compare its attributes with a reader’s learned profile immediately. The reader, however, still needs a profile: a new item and a new user are different cold-start problems.

Content-based recommendation represents items through attributes and learns what those attributes mean for a particular user. Attributes may be structured fields or text features. Pazzani and Billsus describe representations, profiles and learning approaches, including linear regression and Rocchio-style profiles. PDF 2–3, 5–7 and 10–12 Koren and colleagues contrast this route with interaction-based methods. PDF 2

Here we fit a separate linear ridge profile for one reader. It is an explicit example within that family, not an implementation of every algorithm in the chapter. Collaborative filtering obtains its evidence from other users’ responses; this profile learns only from this user’s labels and the item attributes.

Identical item attributes tie, and negative model scores expose the probability interpretation error.
Identical item attributes tie, and negative model scores expose the probability interpretation error.

Turn a description into a score you can inspect

Let an item have d numeric attributes x. Scaling matters: a text-length field measured in characters could otherwise dwarf binary topic fields. Our example uses four binary attributes and normalizes each item’s vector:

x~={x/∥x∥2,∥x∥2>0,0,∥x∥2=0.\widetilde x=\begin{cases}x/\|x\|_2,&\|x\|_2>0,\\0,&\|x\|_2=0.\end{cases}

Normalization gives nonzero vectors unit length; it does not guarantee that the chosen attributes capture what the user values. In this example the coordinates mean science, music, gardening and long-form content. They are authored tags, not attributes extracted by a language model.

For user u, a scalar intercept b_u and d weights w_u give the score:

s(u,i)=bu+wu⊤x~i.s(u,i)=b_u+w_u^\top\widetilde x_i.

The labels are +1 for an authored like and −1 for an authored dislike. We fit n labeled items with squared error and a positive penalty on weights, leaving the intercept unpenalized:

J(bu,wu)=∑i=1n(yi−bu−wu⊤x~i)2+λ∥wu∥22,λ>0.J(b_u,w_u)=\sum_{i=1}^{n}(y_i-b_u-w_u^\top\widetilde x_i)^2+\lambda\|w_u\|_2^2,\qquad\lambda>0.

This is our ridge choice for a linear profile; the source chapter discusses linear regression profiles but does not supply this particular fixture and penalty. PDF 10–11 The score is unbounded. A negative value or a value above 1 is possible, so do not display it as a percentage probability without a separate probabilistic model and calibration check.

Stack rows (1,x-tilde) into A, and write theta=(b_u,w_u). Setting the quadratic derivative to zero yields:

(A⊤A+diag⁡(0,λ,…,λ))θ=A⊤y.\left(A^\top A+\operatorname{diag}(0,\lambda,\ldots,\lambda)\right)\theta=A^\top y.

With at least one labeled item and positive lambda, the system is positive definite: any nonzero weight direction receives a penalty, and a pure intercept direction has nonzero contribution from the data. With no labels we reject fitting rather than invent a profile.

The explanation for an item is an exact additive decomposition of the model’s score:

s(u,i)=bu+∑j=1dwujx~ij⏟feature contribution.s(u,i)=b_u+\sum_{j=1}^{d}\underbrace{w_{uj}\widetilde x_{ij}}_{\text{feature contribution}}.

A positive contribution says how this fitted model used a feature. It does not prove that the feature caused the user’s preference. Correlated attributes and omitted information can produce different interpretations.

The model cannot see a difference you did not encode

Use Python 3.12 and NumPy 1.26.4. The complete original example has nine items with four attributes. The first four labels are [1,1,−1,−1], and lambda is 0.2. Items 4 and 8 deliberately share identical attributes even though their real-world quality could differ.

"""Original item-attribute ridge profile; scores are not calibrated probabilities."""
import json
import numpy as np


def normalize(features):
    x=np.asarray(features,float)
    if x.ndim!=2 or x.shape[1]==0 or not np.isfinite(x).all():raise ValueError('finite item-feature matrix required')
    lengths=np.linalg.norm(x,axis=1,keepdims=True)
    return np.divide(x,lengths,out=np.zeros_like(x),where=lengths>0)


def fit(features,labels,regularization=.2):
    x=normalize(features);y=np.asarray(labels,float)
    if len(x)==0 or y.shape!=(len(x),) or not np.isfinite(y).all() or not np.isfinite(regularization) or regularization<=0:
        raise ValueError('nonempty labeled profile and positive regularization required')
    design=np.column_stack([np.ones(len(x)),x]);penalty=np.diag([0.]+[regularization]*x.shape[1])
    return np.linalg.solve(design.T@design+penalty,design.T@y)


def predict(features,model):
    x=normalize(features);w=np.asarray(model,float)
    if w.shape!=(x.shape[1]+1,) or not np.isfinite(w).all():raise ValueError('compatible finite profile required')
    return w[0]+x@w[1:]


def explain(features,model):
    x=normalize(features);predict(features,model)
    return dict(intercept=float(model[0]),contributions=(x*model[1:]).tolist())


def recommend(features,model,seen,k=3):
    scores=predict(features,model)
    if not isinstance(k,int) or k<0 or any(i<0 or i>=len(scores) for i in seen):raise ValueError('valid history and nonnegative k required')
    return sorted([i for i in range(len(scores)) if i not in seen],key=lambda i:(-scores[i],i))[:k]


def demo():
    # Attributes: science, music, gardening, long. IDs 4 and 8 have identical metadata.
    x=np.array([[1,0,0,1],[1,0,0,0],[0,1,0,1],[0,0,1,0],[1,0,0,1],[0,1,0,0],[0,0,0,1],[0,0,1,1],[1,0,0,1]],float)
    model=fit(x[:4],[1,1,-1,-1]);scores=predict(x,model)
    return dict(features=x.tolist(),profile=model.tolist(),scores=scores.tolist(),
                recommendations=recommend(x,model,{0,1,2,3}),explanation=explain(x,model),
                indistinguishable=[float(scores[4]),float(scores[8])],
                zero_feature_score=float(predict(np.zeros((1,4)),model)[0]))


if __name__=='__main__':print(json.dumps(demo(),allow_nan=False))

The fitted intercept is about −0.336734. Weights for science, music, gardening and long-form content are approximately [1.283121,−0.813774,−0.552722,0.201283]. Excluding the four training items, the top three IDs are [4,8,6]. New items 4 and 8 both score 0.712899; their tie is resolved by ID. Item 5 scores −1.150508, a direct counterexample to interpreting the score as a probability.

An all-zero feature vector receives the intercept, −0.336734. It supplies no feature evidence, rather than representing a mysteriously average article. Tests verify that contributions plus the intercept reconstruct every score, that identical vectors tie, and that consumed items are excluded. A separate hand example with features (1,0) and (0,1), labels +1 and −1, and lambda=1 gives intercept 0 and weights (0.5,−0.5).

For n labeled items and d dense features, forming the normal equations costs O(n d²), solving costs O(d³), and storing the labeled design costs O(n d). Scoring N items costs O(N d); this implementation sorts every score in O(N log N). It fits one profile. Fitting a separate model for many users multiplies training and storage requirements; large sparse text features usually need sparse or iterative methods instead of this dense solve.

A profile sees attributes, not the whole item

If two items have the same vector, any deterministic model using only that vector must score them alike for the same user. More optimization cannot distinguish them. Better attributes or additional collaborative evidence may help; adding arbitrary ID features alone supplies no learned evidence for an unseen ID.

Content profiles may keep returning familiar attributes and miss a new interest. The chapter discusses representation limits and combining other evidence. PDF 16 Explicitly reserve exploration opportunities and assess their outcomes; the present greedy scorer does not implement exploration. User cold start remains unresolved, and item cold start is manageable only when usable attributes exist.

There is no held-out quality evaluation in this nine-item demonstration. The known labels train a profile; the reported scores show its consequences. A deployment exercise should freeze feature construction and its vocabulary on training data, evaluate on later labeled items, compare with a popularity baseline, and check whether metadata available at recommendation time differs from later edited metadata.

Ask what the representation leaves out

  1. Which cold-start case can this profile address directly? Answer: A new item with known usable attributes for a user who already has a fitted profile. A user with no labels still needs another policy.
  2. For the two orthogonal items and lambda=1 hand example, what are the weights? Answer: (0.5,−0.5), with intercept 0. The penalty shrinks the unregularized weights toward zero.
  3. Why do items 4 and 8 tie? Answer: Their normalized vectors are identical. The same intercept and weights produce identical scores; unencoded quality differences cannot affect the calculation.
  4. Is a positive science contribution proof that adding a science tag would make the reader like an article? Answer: No. It explains this prediction algebraically, not a causal intervention. Tags can correlate with other properties and may be incomplete or misleading.

A family of methods with a disclosed concrete choice

The chapter’s recorded text sections support attributes, profiles, linear prediction and representation limitations; its figures were not visually reviewed. The Koren overview supports the comparison with collaborative evidence. Normalization, ridge fitting, authored labels and the feature-contribution display are this article’s original worked design. No upstream recommender code or reader data were copied. Try adding an attribute that distinguishes items 4 and 8, then determine what extra labeled evidence is needed to learn its weight.

Make a prediction, then check

Can this profile distinguish items with identical feature vectors?

Choose one answer

Learning objectives

  • Separate item cold start from user cold start and decompose a linear recommendation score.
  • Run the original example, check its numerical result and explain one failure condition.

Prerequisites & connections

Explore related knowledge →

References

  1. Content-based Recommendation Systems
    Michael J. Pazzani; Daniel Billsus · 2007
  2. Matrix Factorization Techniques for Recommender Systems
    Yehuda Koren; Robert Bell; Chris Volinsky · 2009

Version1 · Editorial status: Recorded technical checks completed

View technical check record (AI)

Codex · 2026-09-23 · Single AI author. Scoped reading: Physical PDF 1 identity and 2–3, 5–7, 10–12, 16 text: item features, profiles, linear regression, Rocchio and limits. Figures not visually reviewed. Physical PDF 1 identity, 2–4 methods text; viewed page 4 equations. Observed ratings, biases, SGD/ALS. No benchmark reproduction. 5 paired equations and four explained exercises. Checked ridge profile, unpenalized intercept, exact feature contributions, hand solution, identical metadata ties, negative score and zero features. No held-out quality or causal interpretation.

  • Checked ridge profile, unpenalized intercept, exact feature contributions, hand solution, identical metadata ties, negative score and zero features. No held-out quality or causal interpretation.
  • Four computed SVG variants per topic;11 numeric/geometry tests and36 responsive cases passed. Twelve selected captures visually checked;11 current images match previously viewed bytes and the revised matrix-factorization image was viewed again. Full article acceptance recorded separately.

Source locations checked:

Related topics

No matches. Try a synonym or acronym.

0 results shown

Wrap the whole query in double quotes for a phrase match.