liveBook · Manning

Chapter 3: End-to-end transformer fine-tuning

What you will learn in chapter 3 of Domain-Specific Small Language Models

The chapter introduces an end-to-end GPT-2 small fine-tuning example for generating Manim code and previews tuning and evaluation.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The chapter introduces an end-to-end GPT-2 small fine-tuning example for generating Manim code and previews tuning and evaluation.

3.1 Data preparation

This section introduces a GPT-2 small Manim-code task, identifies its instruction–output dataset, and prepares that dataset for fine-tuning and testing.

Key terms: GPT-2 small, Manim, domain-specific dataset, manim_python, instruction, output, train, test, preprocess_data, tokenizes

3.2 Fine-tuning

This section sets up a Hugging Face Trainer to search for hyperparameters with Optuna, fine-tune the selected model, and save it for later use.

Key terms: hyperparameters, model parameters, Optuna, Hugging Face Transformers, model_init, Trainer, training arguments, evaluation data, hp_space, search space

3.3 Testing the fine-tuned model

The section tests a fine-tuned Manim-code model on held-out prompts, examines its outputs against the requested behavior, and identifies ways to reduce the observed errors.

Key terms: test set, generate_output, instruction column, ground truth, CSV file, tokenized, maximum generation length, temperature, beam search, nucleus sampling

3.4 Domain-specific evaluation

This section builds a layered evaluation workflow for generated Manim code, from syntax checks through execution and optional visual comparison, while identifying where expert review and safety precautions remain necessary.

Key terms: statistical metrics, subject matter experts (SMEs), domain-specific evaluation, ast.parse, is_syntax_valid, syntax checking, static analysis, ManimCodeAnalyzer, NodeVisitor, Scene

3.5 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 2: Tuning for a specific domain Chapter 4: Running inference →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.