Recommendation with Side Information

Encoding and fusing continuous, categorical, text, and image signals

Ben Dai

CUHK · Department of Statistics and Data Science

The ID-only network is narrow

The ID-only network maps user and item IDs to embeddings, concatenates them, and passes them through a hidden layer to one score.

The ID-only graph has two inputs: a user ID and an item ID. Side information adds more inputs to the same graph.

Modern recommenders have more signals

CONTINUOUSprice, age, time

Numeric signals from profiles, content, or context.

CATEGORICALstore, genre, device

Discrete labels that can become embeddings.

TEXTtitle, description

Product or item text, encoded by an LLM or a smaller model.

IMAGEphoto, poster

Product or item images, encoded by a CNN or ViT.

raw signal
→
encoder
→
vector
→
recommender

The modelling question is not “do we have IDs?” but “how do we encode and fuse all the information we have?”

The dataset: Amazon Reviews 2023

A classroom subset of the Video Games category, built from the 5-core rating-only split. One row is one rating; product metadata joins on item_id.

2,000products
39,796ratings
29,209users
300product images
RATINGS1–5 stars

Continuous target; evaluate with RMSE.

PRODUCT METADATAprice + categories + text

Price, store, category path, title, description, features.

SPLITrandom 80 / 20 rows

Each rating is assigned to train or test at random; all users and items can appear in both.

Amazon Reviews 2023 (Hou et al., 2024). Rating-derived fields such as average_rating and rating_number are excluded; they would leak the target.

How each modality enters the network

Continuous, categorical, text, and image blocks each have an encoder; their vectors are concatenated and passed to a recommender head.

Each block has a different encoder, but the head sees vectors. That is the whole “load side information into the network” pattern.

A concrete side-information table

user product price store image rating
AHNZ… Pro Evolution Soccer 2013 20.25 Konami yes 5
AH5A… Demon Slayer: Hinokami Chronicles 34.98 SEGA yes 4
AFXA… Sim Theme Park 35.00 Electronic Arts no 2
AHJW… Xbox One 1TB Console 349.99 Microsoft no 1
USER SIDEhistory

User ID and activity count from training interactions.

ITEM SIDEmetadata + text + image

Title/description, price, store/category, product photo.

LABELrating 1–5

A continuous star rating, evaluated with RMSE.

All four modalities are available before the rating. Exclude average_rating and rating_number: they leak the target.

The whole lecture in one picture

1 · REQUIREDContinuous

Already a vector. Preprocess, then fuse.

2 · REQUIREDCategorical

Encode, then learn an embedding table.

3 · OPTIONALText

LLM encoder produces a dense vector.

4 · OPTIONALImage

CNN or ViT produces a dense vector.

encode
raw feature → vector
→
fuse
early concat or two towers
→
evaluate
does it actually help?

The encoder changes with the modality. The fusion and evaluation questions do not.

Part 1 · Continuous features

Already vectors — preprocess, then fuse.

Continuous features: price and user_count

\[x_{\text{cont}}=[\text{price}_z,\text{user count}_z]\in\mathbb R^2,\qquad g_{\text{cont}}(x)=\mathrm{Linear}_{16}(\mathrm{ReLU}(\mathrm{Linear}_2(x)))\in\mathbb R\]
feature raw notebook transform unseen / missing
price 20.25 log1p → train z-score train median
user_count 12 training count → z-score 0
NOTEBOOK BLOCK2 → 16 → 1

Section 2 prepares the columns; MFNetCont adds this block to MFNet. Scalers and counts use training rows only.

price + user_count
2 raw numbers
→
log1p + z-score
training only
→
concat
xcont ∈ ℝ²
→
2 → 16 → 1
gcont(x)

X["cont"] has exactly these two columns. Other product metadata belongs to the categorical, text, or image block.

Three ways to fuse continuous features

Three fusion diagrams: early concatenation into an MLP, an additive MF feature correction, and separate user and item towers followed by a dot product.

Early concat lets one MLP learn all interactions; additive MF keeps the ID score and adds a feature correction; two towers encode each side separately before the dot product.

Part 2 · Categorical features

A category is an ID. An embedding is a learned lookup table.

A category is an ID

A user ID and a store category both use the same embedding lookup: an integer index selects a learned row.

User ID, store, category — the same nn.Embedding lookup; only the table size changes.

Continuous + categorical fusion

Continuous and categorical features are encoded into vectors, concatenated, and passed through an MLP.

The recommender only sees vectors. Swapping an encoder should not change the fusion block.

Part 3 · Fusion architectures

Same encoders, different interaction.

Three ways to use side information

FEATURES ONLY\(f(x_u,z_i)\)

Handles new IDs, but may miss individual preferences.

ADD TO MF\(p_u^\top q_i+f(x_u,z_i)\)

Keeps personalized ID factors and adds a feature contribution.

SIDE-AWARE FACTORS\(p(u,x_u)^\top q(i,z_i)\)

Builds each factor from ID and features together.

Use features-only when IDs are weak; additive MF when IDs are strong; side-aware factors when both sides have rich features.

The third approach makes the interaction depend on the features on both sides.

Feature-only vs additive MF

\[ \begin{aligned} \text{feature-only:}\quad & \widehat r_{ui}=f_\theta(x_u,z_i)\\ \text{additive MF:}\quad & \widehat r_{ui}=\mu+a_u+b_i+p_u^\top q_i+f_\theta(x_u,z_i) \end{aligned} \]

Feature-only model uses features through one MLP. Additive MF keeps the ID score and adds a feature correction.

Feature-only works for a new ID but has no individual preference. Additive MF keeps the ID score and adds a feature correction — the safest first model.

Side-aware factors

\[ \begin{aligned} p(u,x_u)&=p_u+A x_u+e_{c(u)}\\ q(i,z_i)&=q_i+B z_i+e_{g(i)}\\ \widehat r_{ui}&=p(u,x_u)^\top q(i,z_i) \end{aligned} \]

Side-aware user and item factors are each built from an ID residual, a feature map, and a category embedding, then combined by a dot product.

Features and category embeddings build each factor; the ID term is a learned residual. A new ID sets the residual to zero, but the feature path still produces a vector.

Two-tower architecture

User and item features are encoded by separate towers, then combined by a dot product or a small MLP.

Each tower learns nonlinear interactions within its side; the final layer learns the interaction across sides.

Part 4 · Train, evaluate, diagnose

The model is only as good as the split.

Four questions and the loss

1 · MODELID score + one block per modality

Start with MFNet; add only the blocks the data supports.

2 · HYPERPARAMETERS\(K\), hidden, learning rate, epochs

Choose before fitting; tune on validation.

3 · CRITERIONmean squared error

MSE on the observed 1–5 ratings.

4 · LEARNEDtables + blocks

ID/category embeddings, biases, and the additive blocks.

\[\mathrm{L}(\theta)=\frac1{|\Omega|}\sum_{(u,i)\in\Omega}(r_{ui}-\widehat r_{ui})^2\]

One MSE trains the ID tables and every side-information block. Select hyperparameters on validation.

One dict, one named input per modality

\[ X=\{\mathrm{ids}:(N,2),\ \mathrm{cont}:(N,2),\ \mathrm{cat}:(N,3),\ \mathrm{text}:(N,384),\ \mathrm{image}:(N,512)\} \]
X["ids"]
user, item
→
forward(ids, …)
named argument
→
MFNet
base score
WHY A DICTone key per modality

A new block adds a key; it does not move column positions.

SKORCHkeys become arguments

X["cont"] is passed to forward(…, cont).

MODELtake only what you need

MFNet uses ids; MFNetText also uses text.

A new modality is a new dictionary key and a new named argument — not a new column index.

A PyTorch implementation sketch

class MFNetCont(MFNet):
    def __init__(self, n_users, n_items, K=16, mu=0.0, d_cont=2):
        super().__init__(n_users, n_items, K, mu)
        self.cont = nn.Sequential(
            nn.Linear(d_cont, 16), nn.ReLU(), nn.Linear(16, 1)
        )

    def forward(self, ids, cont):
        return super().forward(ids) + self.cont(cont)

For this model, X only needs ids and cont; later models receive larger dicts.

One subclass, one new block. The dict keys select the named arguments; skorch handles the training loop and prediction.

A random row split

SPLIT80 / 20 random rows

31,836 train rows · 7,960 test rows. No user or item is deliberately removed.

WHAT IT MEASURESinterpolation

IDs are not held out; most test rows reuse users and items seen in training.

WHAT IT DOES NOTnew-item generalization

A random split does not test a genuinely new product or a new user.

SAFEfit preprocessing on training rows

Scalers and rating summaries use training rows only; ID vocabularies can use the catalogue.

LEAKYrating-derived features

Rating mean, rating count, or quantile computed from the target leaks even in a random split.

The notebook uses a random 80/20 split, so report test RMSE and describe it as in-distribution interpolation.

Baselines and ablation

Random 80/20 row split: 31,836 train rows · 7,960 test rows. Select on validation; report test once. Lower RMSE is better.

model added input validation RMSE test RMSE
MFNet IDs only 1.1644 1.1587
+ continuous price + user_count 1.1656 1.1589
+ categorical store + category path 1.1635 1.1598
+ text MiniLM title + description 1.1589 1.1535

Image subset (300 products): text only 1.1437 → + image 1.1438. Not comparable with the full table.

CLEAR GAIN+ text

0.0052 lower test RMSE than MFNet.

NO RELIABLE GAIN+ continuous / categorical

Changes are tiny and do not hold on test.

NEUTRAL+ image

+0.0001 on the image subset.

More side information is not automatically better. On this split, text is the only clear gain; the image block is neutral.

Intuition: with a random split the item ID is already seen in training, so price and category add little beyond the ID; text still adds product semantics.

Part 5 · Text side information

Optional Product text → embedding → a small additive block.

Text: what goes in

field example why
title Pro Evolution Soccer 2013 short, high signal
description long product copy use cases and context
features bullet list structured attributes
\[\text{text}_i=\text{title}_i\;\|\;\text{description}_i\;\|\;\text{features}_i\]

One string per item_id: 2,000 products, one embedding each.

USEproduct text

Title, description, and feature bullets are available before the rating.

DO NOT USEreview text

Review title/text is written together with the star rating; it leaks the target.

One string per product, built from product metadata only. Review text is not a feature.

Text: the feature-extraction pipeline

# Colab: !pip -q install transformers
import numpy as np
from transformers import pipeline

embed = pipeline("feature-extraction", model="sentence-transformers/all-MiniLM-L6-v2")
texts = (items.title.fillna("") + " " +
         items.description.fillna("") + " " +
         items.features.fillna("")).tolist()
out = embed(texts, batch_size=64,
            truncation=True, max_length=256)
# out[i][0].shape -> (n_tokens, 384)
text_vectors = np.array([np.mean(o[0], axis=0) for o in out])  # (n_items, 384)
one string
title + description + features
→
tokenizer
truncate at 256
→
MiniLM
(n_tokens, 384)
→
mean pool
(384,)

feature-extraction returns one vector per token, not one vector per product. Mean pooling turns it into a single 384-d embedding.

Text: append the vector and add a block

\[ \begin{aligned} \widehat r_{ui}&=\text{MFNet}(u,i)+g_{\text{cont}}+g_{\text{cat}}+g_{\text{text}}(e_i)\\ g_{\text{text}}(e)&=\mathrm{Linear}_{16}(\mathrm{ReLU}(\mathrm{Linear}_{32}(e)))\in\mathbb R \end{aligned} \]

New input: X["text"] = e_text, shape (N, 384). MFNetText.forward(ids, cont, cat, text).

text embedding
ei ∈ ℝ384
→
projection
384 → 32
→
text block
32 → 16 → 1
→
additive correction
+ gtext(ei)

Trainable parameters: 12,320 + 528 + 17 ≈ 12.9k; MiniLM stays frozen at ~22M.

This is MFNetText: one projection, one small block, added to the existing score. The MiniLM encoder stays frozen.

Text: frozen, fine-tuned, or fused

FROZENstart here

Precompute 2,000 × 384; train only the projection and block. Cheap and reproducible.

FINE-TUNEDonly with evidence

Update MiniLM only when the domain is specialized and frozen features clearly underperform.

FUSEDproject first

Project 384 → 32, then add or concat. L2-normalize if using cosine-style retrieval.

BATCH64

Embed in batches; cache the matrix.

LENGTH256 tokens

Truncate long descriptions.

JOINitem_id

One embedding per product; map to rating rows.

COSTone pass

No encoder call at serving time.

Freeze first, cache the 2,000 embeddings, and measure on the same random split. Fine-tune only with evidence.

Part 6 · Image side information

Optional Product photo → 512-d vector → a small additive block.

Image: what goes in

A video game product photo from the Amazon subset.

One of the 300 product photos in the subset.

SOURCEimage_path

Prefix with the local dataset folder; in Colab, prefix with the GitHub BASE URL.

SUBSET300 products

One embedding per product; the image ablation uses only rating rows for these products.

LEAKAGEavailable before the rating

The product photo is metadata, not review content. Do not use review images or rating-derived fields.

Only a subset has an image, so image results are not directly comparable with the full-table numbers.

Image: the feature-extraction pipeline

from transformers import pipeline

embed_image = pipeline(
    "image-feature-extraction",
    model="microsoft/resnet-18",
)

image_items = items[items.image_path.notna()]
paths = [f"{LOCAL or BASE}/{p}" for p in image_items.image_path]

image_vectors = np.array(
    embed_image(paths, batch_size=32, pool=True)
).reshape(len(paths), -1)
image_vectors /= np.linalg.norm(image_vectors, axis=1, keepdims=True)
image_emb = pd.DataFrame(image_vectors, index=image_items.item_id)
d_image = image_emb.shape[1]   # 512
image path / URL
300 products
→
ResNet18
frozen backbone
→
feature map
(1, 512, 1, 1)
→
flatten
(512,)

pool=True averages the 7×7 feature map; each vector is then L2-normalized.

image-feature-extraction returns a spatial tensor; flatten it to one 512-d vector per product.

Image: append the vector and add a block

\[ \begin{aligned} \widehat r_{ui}&=\text{MFNet}(u,i)+g_{\text{cont}}+g_{\text{cat}}+g_{\text{text}}(e_i)+g_{\text{image}}(v_i)\\ g_{\text{image}}(v)&=\mathrm{Linear}_{16}(\mathrm{ReLU}(\mathrm{Linear}_{32}(v)))\in\mathbb R \end{aligned} \]

New input: X["image"] = v_i, shape (N, 512). MFNetImage.forward(ids, cont, cat, text, image).

image embedding
vi ∈ ℝ512
→
projection
512 → 32
→
image block
32 → 16 → 1
→
additive correction
+ gimage(vi)

Trainable: 16,416 + 528 + 17 ≈ 17k; ResNet18 stays frozen. Evaluate on the 300-image subset.

MFNetImage inherits MFNetText and adds one projection plus one block.

Image: frozen, fine-tuned, or multimodal

FROZENstart here

Precompute 300 × 512; train only the projection and image block.

FINE-TUNEDdomain shift

Fine-tune the last block only when you have enough images and compute.

MULTIMODALearly or late

Concat for ranking; image tower for retrieval; CLIP-style alignment for zero-shot items.

INPUT300 images

Paths or URLs; batch 32.

FEATURE512-d unit vector

Flatten the pooled ResNet map; L2-normalize.

BLOCK512 → 32

then 16 → 1; small additive head.

COSTone pass

Cache embeddings; no CNN at serving time.

Image subset: text only 1.1437 → + image 1.1438. No gain; freeze first and measure.

Part 7 · Industry systems

Optional Same pattern at scale.

YouTube: two-tower retrieval

YouTube two-tower retrieval architecture: watch and search embeddings, ReLU layers, user vector, softmax training, and nearest-neighbour serving.
USER TOWERwatch + search + context

Average embeddings, then ReLU layers produce the user vector u.

ITEM TOWERvideo vectors

Softmax trains the item side; nearest-neighbour search serves candidates.

SIDE INFOhistory is a feature

Watch/search sequences and demographics enter before the final interaction.

The two-tower pattern is a retrieval architecture first; the same encoders can feed a ranking model later.

eBay: sequence plus content

eBay two-tower architecture: GRU user tower over event sequences; title, aspect, and category item tower; dot product affinity.
USER TOWERevent sequence → GRU

Clicks and purchases become a user embedding.

ITEM TOWERtext + category → MLP

Title and aspect CBOW embeddings plus a leaf-category embedding.

SCOREdot product

Affinity between the user and candidate item embedding.

Same two-tower pattern: a sequence encoder on the user side, a text/category encoder on the item side.

Alibaba: behavior sequence + feature crossing

Alibaba behavior sequence transformer architecture: user profile, item, context, cross features, and behavior sequence are embedded, passed through a Transformer, concatenated with the target item, and scored.
INPUTprofile + item + context

Other features and the user behavior sequence enter the embedding layer.

SEQUENCETransformer

Multi-head self-attention models the order of past items.

OUTPUTclick probability

Concatenate target item with sequence output; MLP + sigmoid.

Alibaba uses a sequence Transformer plus feature crossing; Wide & Deep and DeepFM are earlier early-fusion variants.

Retrieval vs ranking, and the feature store

retrieval ranking
goal millions → hundreds hundreds → top few
model two-tower, dot product richer MLP, crosses, context
latency milliseconds tens of milliseconds
features available for every candidate rich user/item/context features
FEATURE STOREoffline / online

The same feature definition must be available at training and serving time.

FRESHNESStime matters

A rating mean computed yesterday is not the same feature today.

A side-information model is also a data-engineering contract. Training-serving skew is a modelling bug.

Summary

ID-only MF
personalization
→
continuous + categorical
tabular side info
→
text + image
optional encoders
→
two-tower
learned fusion
→
random split
honest evaluation
ENCODEmodality → vector

Scale, embed, or pretrain; the recommender sees vectors.

FUSEearly or late

Additive maps for interpretability; two towers for new entities and retrieval.

EVALUATEmatch the claim

Random split: report test RMSE. Add new-entity splits only for generalization claims.

Side information is a representation strategy, a fusion choice, and an evaluation protocol — and on this dataset, only text improved test RMSE.

References

  • Covington, Adams & Sargin (2016). Deep Neural Networks for YouTube Recommendations.
  • Wang, Brovman & Madhvanath (2021). Personalized Embedding-based E-commerce Recommendations at eBay.
  • Hou et al. (2024). Bridging Language and Items for Retrieval and Recommendation (Amazon Reviews 2023).
  • Chen et al. (2019). Behavior Sequence Transformer for E-commerce Recommendation in Alibaba.
  • Cheng et al. (2016). Wide & Deep Learning for Recommender Systems; Guo et al. (2017). DeepFM.
  • PyTorch nn.Embedding; scikit-learn OneHotEncoder, StandardScaler; Hugging Face pipeline(“feature-extraction”) and pipeline(“image-feature-extraction”); Sentence Transformers all-MiniLM-L6-v2; microsoft/resnet-18; CLIP.