liveBook · Manning

Language model

As explained in AI-Powered Search

A large language model is a neural language model trained on large text corpora to predict and generate language and perform related language-understanding tasks.

A searcher may want an answer, not just a ranked list of documents. A language model helps a search system interpret the query, represent document meaning, and produce a response. A language model represents a probability distribution over word sequences; a large language model (LLM) is a deep neural network trained on massive amounts of text to recognize, summarize, predict, and generate language. section 5.0 section 1.3.4

Transformer-based LLMs learn representations of words and their relationships in context. They can encode text as an embedding—a numerical vector representing meaning. Comparing query and document embeddings supports semantic search, while document embeddings can also become latent features in a user profile. Generative models can use language context to produce summaries or answers. section 1.3.4 section 9.4.1

In a search pipeline, choose the model’s job before choosing a model:

  • Encode queries and documents for dense-vector retrieval or query understanding. section 1.3.5
  • Fine-tune a Transformer-based model to extract short answers from retrieved documents. section 14.0
  • Pass retrieved results as context to a generative model to synthesize a sourced answer. section 1.3.5

Embedding products for personalization

Retrieve product names and identifiers, then encode the names with `SentenceTransformer("all-mpnet-base-v2")`. Each product receives a vector of latent features learned from text. Combine those vectors with a user’s document interactions to build an evolving profile and personalize results. The vector dimensions are not reliable, human-readable labels. 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 shows the model load and `model.encode(texts)` call used to generate product embeddings. section 9.4.1

Do not treat fluent output as verified fact. Model parameters compress training data rather than retain its sources, so generated answers can confuse facts or reflect prompt wording. For factual search, retrieve relevant documents, supply them as context, and let users verify the cited sources. General-purpose models may also miss domain-specific information absent from training; fine-tuning on domain data can help. section 15.2.2 section 2.6

Listing 15.3 Prompt to foundation model to summarize search results
Web search results:

[1] "A large language model, or LLM, is a deep learning algorithm that
can recognize, summarize, translate, predict and generate text and other
content based on knowledge gained from massive datasets."
URL: https://blogs.nvidia.com/blog/2023/
     01/26/what-are-large-language-models-used-for/

[2] A large language model (LLM) is a language model consisting of a
neural network with many parameters (typically billions of weights or
more), trained on large quantities of unlabeled text using
self-supervised learning. LLMs emerged around 2018 and perform well at a
wide variety of tasks. This has shifted the focus of natural language
processing research away from the previous paradigm of training
specialized supervised models for specific tasks.
URL: https://en.wikipedia.org/wiki/Large_language_model

[3] "In this guide, we'll discuss everything you need to know about
Large Language Models (LLMs), including key terms, algorithms,
fine-tuning, and more. As ChatGPT has taken the internet by storm crossing
1 million users in its first 5 days, you may be wondering what machine
learning algorithm is running under the hood. While ChatGPT uses a
specific type of reinforcement learning called "Reinforcement Learning
from Human Feedback (RLHF)", at a high level it is an example of a
Large Language Model (LLM)."
URL: https://www.mlq.ai/what-is-a-large-language-model-llm/

Instructions: Using the provided web search results, write a comprehensive
reply to the given query. Make sure to cite results using
[[number](URL)] notation after the reference. If the provided search
results refer to multiple subjects with the same name, write separate
answers for each subject.

Query: What is a large language model?

The prompt illustrates how retrieved web results and their URLs can be supplied to a model for results summarization. section 15.2.2

How AI-Powered Search covers it

How deep it goes
Defines language models and outlines Transformer representations, then develops embedding and fine-tuning workflows without requiring model training from scratch.
Examples
Works through product embeddings for personalization, short answers from an outdoors question-answering dataset, and sourced web-result summarization.
What it assumes
Builds on search and dense-vector comparisons, introduces Transformers, and defers LLM training mechanics during the embedding workflow.
What you can do after
Apply it via SentenceTransformer to embed products, or fine-tune a Transformer-based model to return short answers from documents.
How it connects
Connects language models to Transformers, embeddings, semantic search, personalized search, question answering, and retrieval augmented generation.

Also explained in

Compare how 67 books explain language model →

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.