liveBook · Manning

Latent space

As explained in AI-Powered Search

A latent factor is a learned, lower-dimensional attribute inferred from data to represent an underlying pattern associated with users or items.

A latent space represents users or items with features inferred from data rather than recorded as explicit attributes. In personalized search, these features help identify shared interests, recommend products, and boost results for a particular user. section 9.0 section 9.3.1

One way to learn this space is matrix factorization. Start with a user–item matrix whose entries reflect interactions such as purchases or ratings. Factor it into a user matrix and an item matrix, both using the same smaller set of latent features. Multiplying a user’s feature values by an item’s corresponding values and summing them predicts that user’s preference—even for an item with no recorded interaction. This is especially useful when the original matrix is too sparse for direct comparisons between users. section 4.2.3 section 9.3.1

Finding a pattern without product descriptions

Suppose several shoppers buy stainless-steel microwaves, refrigerators, and dishwashers, while others buy black versions of those appliances. Their interaction patterns can reveal a latent feature that separates the products by color, even if the model receives only product IDs. The learned feature need not come with a readable label. section 9.3.1 section 9.4.1

Figure 9.7 Matrix factorization. The user-item matrix R is decomposed into two matrices, a user matrix U and an item matrix I. The product of these two matrices (U . I) should be as close as possible to the original user-item matrix R.
figure

The diagram shows how a user–item matrix is represented by smaller user and item matrices whose product approximates the observed preferences. section 9.3.1

Latent spaces can also come from document content. A language model maps each product’s text to an embedding: each dimension is a latent feature, and its value indicates how strongly that feature appears. Product embeddings and user interactions can then form an evolving profile for personalizing search results. Unlike illustrative dimensions labeled “color” or “cost,” real embedding dimensions are generally unlabeled and more complex. section 9.4.1

Listing 9.12 Generating product embeddings
from sentence_transformers import SentenceTransformer  #1
transformer = SentenceTransformer("all-mpnet-base-v2")  #1
...  #2

def get_embeddings(texts, model, cache_name, ignore_cache=False):
  ...  #2
    embeddings = model.encode(texts)  #3
  ... #2
  return embeddings

product_embeddings = get_embeddings(product_names,
 transformer, cache_name="all_product_embeddings")

The Python listing generates product embeddings with SentenceTransformer and its encode method, making the content-based route concrete. section 9.4.1

Latent features extend limited signals into predicted preferences; they do not eliminate the need for signals. Collaborative filtering can miss a new item that has never attracted an interaction—the cold-start problem. Content-derived embeddings offer a different way to represent items using their text. section 4.2.3 section 9.4.1

How AI-Powered Search covers it

How deep it goes
Works through user–item matrix factorization and preference prediction, then introduces content embeddings while deferring language-model training mechanics.
Examples
Uses movie purchase histories, appliance-color purchase patterns, a user–item matrix, and Python-generated product embeddings.
What it assumes
Defines latent features from observed interactions and explains matrix factorization without requiring access to item descriptions.
What you can do after
Evaluate/understand how inferred features predict missing preferences and support personalized recommendations or search boosts.
How it connects
Connects collaborative filtering and matrix factorization with embeddings, user profiles, and personalized search.

Also explained in

Compare how 18 books explain latent space →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of AI-Powered Search. The section links point to the parts of the book it draws on.