liveBook · Manning

Transformer architecture

As explained in AI-Powered Search

A transformer is a neural-network architecture that models relationships among sequence elements using attention and can encode and decode representations.

A transformer is a deep neural-network architecture used to represent meaning in context. In search, its encoder can turn queries and documents into dense numerical vectors called embeddings. Comparing those vectors makes it possible to retrieve related content even when the words differ. section 13.3.1 section 13.4

The meaning of a word depends on its surroundings. A transformer uses attention to interpret each token in relation to other tokens in the input and relationships learned during training. It can encode that contextual meaning as vectors; a decoder can turn vector representations back into text. Search need not use both parts: an encoder alone can supply embeddings for retrieval. section 2.5.2 section 13.3.1

Context changes the query

“What is the difference between a capital and capitol?” calls for a different interpretation of capital than “What is the difference between a capital and lowercase word?” A context-sensitive model can distinguish the questions rather than treating capital as a fixed synonym or meaning. section 1.3.4 section 2.5.2

A transformer-based autocomplete or semantic-search pipeline can follow these steps:

  • Pass corpus text through a transformer encoder and index the resulting embeddings. section 13.4
  • Encode an incoming query with the transformer, then retrieve the k-nearest indexed vectors using a similarity measure. section 13.4
  • Use the retrieved content to recommend related autocomplete terms or rank matching documents. section 13.4
Figure 13.5 A conceptual architecture for end-to-end search using Transformer-encoded vectors
figure

The end-to-end architecture diagram connects the content source, transformer-generated vectors, nearest-neighbor index, and query-time search. section 13.4

Training a transformer from scratch demands substantial computing power, time, and potentially large amounts of GPU memory. Pretrained models offer a practical starting point. Contextual embeddings also do not replace every search signal: when a query remains unclear, keyword search and domain understanding can provide useful fallbacks. section 13.3.2 section 2.5.2

How AI-Powered Search covers it

How deep it goes
Explains attention, encoding, decoding, and a query-to-index retrieval pipeline without specifying model training internals.
Examples
Uses contrasting capital queries, English–Armenian greetings, and a transformer-encoded autocomplete pipeline.
What it assumes
Assumes some Python knowledge for practical model use while explaining embeddings and the encoder–decoder distinction.
What you can do after
Apply it via a pretrained transformer to encode content and queries for nearest-neighbor search.
How it connects
Connects attention and embeddings to dense vector search, nearest-neighbor retrieval, autocomplete, and question answering.

Also explained in

Compare how 28 books explain transformer architecture →

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.