liveBook · Manning

Language model

As explained in Domain-Specific Small Language Models

A very large neural language model trained on broad text corpora to predict or generate language, used here for code generation and assistance.

A language model generates content from text prompts. Large language models (LLMs) can produce prose, code, mathematical expressions, and structured data. Transformer-based models use self-attention to process text sequences; decoder-only GPT models are used for generation. section 1.7

A generalist LLM is a useful starting point when a task does not require specialized knowledge. For a narrow domain, a pretrained model can be adapted with domain-specific data through transfer learning. That choice depends on data quality, accuracy needs, computing resources, privacy, and regulatory requirements. section 1.6 section 1.7

Table 1.2 Pros and cons of generalist and domain-specific LLMs

Generalist LLMs

Domain-specific LLMs

Pros

  • Offer a wide range of knowledge and capabilities
  • Can handle diverse tasks and topics
  • Have the flexibility to learn and adapt to new domains (assuming you have the computational power to do it)
  • Can generate content on a wide array of subjects
  • Provide specialized expertise in a specific domain
  • Well-suited for focused applications and specific industries
  • Higher accuracy and performance in specific areas of expertise
  • Better understanding and context within a specific domain

Cons

  • Lack in-depth expertise in specific domains
  • Require additional fine-tuning and customization for specific tasks
  • Potential risk of making errors or producing inaccurate content
  • Require more computing power and resources
  • Limited applicability and effectiveness in non-specialized areas
  • Less flexibility to handle tasks outside the chosen domain
  • Could require more data and resources for training, fine-tuning, or RAG

Compare generalist breadth with domain-specific accuracy and context, alongside each approach’s limitations. section 1.6

Deployment requires more than selecting a capable model. Parameter count and numerical precision affect GPU memory needs; serving multiple requests adds cost and performance constraints. Benchmark inference rather than assuming that a smaller representation will be faster on every setup. section 4.2 section 11.2.1

Choosing a model to serve

GPT-Neo 2.7B provides a reference for estimating inference resources. A separate GPT-2 small workflow benchmarks PyTorch, ONNX, optimized ONNX, and FP16 variants before choosing a candidate for FastAPI serving. In its reported CPU measurements, the FP16 variant is slower than the other variants. section 4.1 section 11.2.1

How Domain-Specific Small Language Models covers it

How deep it goes
Explains model tradeoffs, memory estimation, and latency benchmarking, but does not develop model training from scratch here.
Examples
Uses GPT-Neo for resource estimates and GPT-2 variants for a serving-oriented latency comparison.
What you can do after
Evaluate/understand model choices by comparing specialization needs, memory demands, and measured inference latency.
How it connects
Connects to transformers, self-attention, transfer learning, fine-tuning, quantization, and inference benchmarking.

Also explained in

Compare how 69 books explain language model →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Domain-Specific Small Language Models. The section links point to the parts of the book it draws on.