Build a Large Language Model (From Scratch)

Оглавление⌄
contentsprefaceacknowledgmentsabout this bookWho should read this bookHow this book is organized: A roadmapAbout the codeliveBook discussion forumOther online resourcesabout the authorabout the cover illustration1 Understanding large language models1.1 What is an LLM?1.2 Applications of LLMs1.3 Stages of building and using LLMs1.4 Introducing the transformer architecture1.5 Utilizing large datasets1.6 A closer look at the GPT architecture1.7 Building a large language modelSummary2 Working with text data2.1 Understanding word embeddings2.2 Tokenizing text2.3 Converting tokens into token IDs2.4 Adding special context tokens2.5 Byte pair encoding2.6 Data sampling with a sliding window2.7 Creating token embeddings2.8 Encoding word positionsSummary3 Coding attention mechanisms3.1 The problem with modeling long sequences3.2 Capturing data dependencies with attention mechanisms3.3 Attending to different parts of the input with self-attention3.3.1 A simple self-attention mechanism without trainable weights3.3.2 Computing attention weights for all input tokens3.4 Implementing self-attention with trainable weights3.4.1 Computing the attention weights step by step3.4.2 Implementing a compact self-attention Python class3.5 Hiding future words with causal attention3.5.1 Applying a causal attention mask3.5.2 Masking additional attention weights with dropout3.5.3 Implementing a compact causal attention class3.6 Extending single-head attention to multi-head attention3.6.1 Stacking multiple single-head attention layers3.6.2 Implementing multi-head attention with weight splitsSummary4 Implementing a GPT model from scratch to generate text4.1 Coding an LLM architecture4.2 Normalizing activations with layer normalization4.3 Implementing a feed forward network with GELU activations4.4 Adding shortcut connections4.5 Connecting attention and linear layers in a transformer block4.6 Coding the GPT model4.7 Generating textSummary5 Pretraining on unlabeled data5.1 Evaluating generative text models5.1.1 Using GPT to generate text5.1.2 Calculating the text generation loss5.1.3 Calculating the training and validation set losses5.2 Training an LLM5.3 Decoding strategies to control randomness5.3.1 Temperature scaling5.3.2 Top-k sampling5.3.3 Modifying the text generation function5.4 Loading and saving model weights in PyTorch5.5 Loading pretrained weights from OpenAISummary6 Fine-tuning for classification6.1 Different categories of fine-tuning6.2 Preparing the dataset6.3 Creating data loaders6.4 Initializing a model with pretrained weights6.5 Adding a classification head6.6 Calculating the classification loss and accuracy6.7 Fine-tuning the model on supervised data6.8 Using the LLM as a spam classifierSummary7 Fine-tuning to follow instructions7.1 Introduction to instruction fine-tuning7.2 Preparing a dataset for supervised instruction fine-tuning7.3 Organizing data into training batches7.4 Creating data loaders for an instruction dataset7.5 Loading a pretrained LLM7.6 Fine-tuning the LLM on instruction data7.7 Extracting and saving responses7.8 Evaluating the fine-tuned LLM7.9 Conclusions7.9.1 What’s next?7.9.2 Staying up to date in a fast-moving field7.9.3 Final wordsSummaryappendix A—Introduction to PyTorchA.1 What is PyTorch?A.1.1 The three core components of PyTorchA.1.2 Defining deep learningA.1.3 Installing PyTorchA.2 Understanding tensorsA.2.1 Scalars, vectors, matrices, and tensorsA.2.2 Tensor data typesA.2.3 Common PyTorch tensor operationsA.3 Seeing models as computation graphsA.4 Automatic differentiation made easyA.5 Implementing multilayer neural networksA.6 Setting up efficient data loadersA.7 A typical training loopA.8 Saving and loading modelsA.9 Optimizing training performance with GPUsA.9.1 PyTorch computations on GPU devicesA.9.2 Single-GPU trainingA.9.3 Training with multiple GPUsSummaryappendix B—References and further readingChapter....1Chapter....2Chapter....3Chapter....4Chapter....5Chapter....6Chapter....7Appendix Aappendix C—Exercise solutionsChapter....2Chapter....3Chapter....4Chapter....5Chapter....6Chapter....7Appendix Aappendix D—Adding bells and whistles to the training loopD.1 Learning rate warmupD.2 Cosine decayD.3 Gradient clippingD.4 The modified training functionappendix E—Parameter-efficient fine-tuning with LoRAE.1 Introduction to LoRAE.2 Preparing the datasetE.3 Initializing the modelE.4 Parameter-efficient fine-tuning with LoRAindex
Описание
В этом материале разберём тему: your.
Learn how to create, train, and tweak large language models (LLMs) by building one from the ground up!
Each stage is explained with clear text, diagrams, and examples. In Build a Large Language Model (from Scratch) bestselling author Sebastian Raschka guides you step by step through creating your own LLM. You’ll go from the initial design and creation, to pretraining on a general corpus, and on to fine-tuning for specific tasks.
As you work through each key stage of LLM creation, you’ll develop an in-depth understanding of how LLMs work, their limitations, and their customization methods. Build a Large Language Model (from Scratch) teaches you how to:Plan and code all the parts of an LLMPrepare a dataset suitable for LLM trainingFine-tune LLMs for text classification and with your own dataUse human feedback to ensure your LLM follows instructionsLoad pretrained weights into an LLMBuild a Large Language Model (from Scratch) takes you inside the AI black box to tinker with the internal systems that power generative AI. Your LLM can be developed on an ordinary laptop, and used as your own personal assistant.
Feynman reportedly said, “I don’t understand anything I can’t build.” Based on this same powerful principle, bestselling author Sebastian Raschka guides you step by step as you build a GPT-style LLM that you can run on your laptop. About the technologyPhysicist Richard P. This is an engaging book that covers each stage of the process, from planning and coding to training and fine-tuning.
Without relying on any existing LLM libraries, you’ll code a base model, evolve it into a text classifier, and ultimately create a chatbot that can follow your conversational instructions. About the bookBuild a Large Language Model (From Scratch) is a practical and eminently-satisfying hands-on journey into the foundations of generative AI. And you’ll really understand it because you built it yourself!
What's insidePlan and code an LLM comparable to GPT-2Load pretrained weightsConstruct a complete training pipelineFine-tune your LLM for text classificationDevelop LLMs that follow human instructionsAbout the readerReaders need intermediate Python skills and some knowledge of machine learning. The LLM you create will run on any modern laptop and can optionally utilize GPUs.
Файл доступен для загрузки ниже.
Поделиться
Частые вопросы
Можно ли скачать «Build a Large Language Model (From Scratch)» бесплатно?
Да, «Build a Large Language Model (From Scratch)» доступна для бесплатного скачивания на нашем сайте в формате PDF. Ссылка на файл находится на этой странице.
В каком формате и какого размера файл?
Книга предоставляется в формате PDF, размер файла 4,6 МБ.
Кто автор и когда вышла книга?
автор — Raschka Sebastian, издательство Manning Publications Co., год выпуска 2025, 370 страниц.
О чём книга «Build a Large Language Model (From Scratch)»?
Learn how to create, train, and tweak large language models (LLMs) by building one from the ground up!In Build a Large Language Model (from Scratch) bestselling author Sebastian Raschka guides you step by step through creating your own LLM.