Building Language Applications with Hugging Face
Lewis Tunstall, Leandro von Werra, and Thomas Wolf, Aurélien Géron

#NLP
🧠 ترنسفورمرها از وقتی که ۲۰۱۷ معرفی شدن، بهطرز وحشتناکی سرعت گرفتن و الان تو بیشتر تسکهای NLP دست بالا رو دارن. از نوشتن خبرهای واقعینما گرفته تا بهتر کردن نتایج جستجوی گوگل، یا ساختن Chatbotهایی که جوک بیمزه میگن 😄.
این کتاب – که تازه هم تمام رنگی شده – یک راهنمای دستبهکد برای یاد گرفتن معماری ترنسفورمر و پیادهسازیش با کتابخانه Hugging Face Transformers در پایتونه. سه نفر از آدمهای کلیدی پشت Hugging Face – لوئیس تانستال، لئاندرو ون ورّا، و توماس ولف – قدمبهقدم نشونت میدن چطور مدلها رو بسازی، دیباگ کنی و برای تسکهای واقعی بهینهسازی کنی.
Since their introduction in 2017, transformers have quickly become the dominant architecture for achieving state-of-the-art results on a variety of natural language processing tasks. If you're a data scientist or coder, this practical book -now revised in full color- shows you how to train and scale these large models using Hugging Face Transformers, a Python-based deep learning library.
Transformers have been used to write realistic news stories, improve Google Search queries, and even create chatbots that tell corny jokes. In this guide, authors Lewis Tunstall, Leandro von Werra, and Thomas Wolf, among the creators of Hugging Face Transformers, use a hands-on approach to teach you how transformers work and how to integrate them in your applications. You'll quickly learn a variety of tasks they can help you solve.
Table of Contents
1. Hello Transformers
2. Text Classification
3. Transformer Anatomy
4. Multilingual Named Entity Recognition
5. Text Generation
6. Summarization
7. Question Answering
8. Making Transformers Efficient in Production
9. Dealing with Few to No Labels
10. Training Transformers from Scratch
11. Future Directions
Who Is This Book For?
This book is written for data scientists and machine learning engineers who may have heard about the recent breakthroughs involving transformers, but are lacking an in-depth guide to help them adapt these models to their own use cases. The book is not meant to be an introduction to machine learning, and we assume you are comfortable programming in Python and has a basic understanding of deep learning frameworks like PyTorch and TensorFlow. We also assume you have some practical experience with training models on GPUs. Although the book focuses on the PyTorch API of Transformers, Chapter 2 shows you how to translate all the examples to TensorFlow.
What You Will Learn
The goal of this book is to enable you to build your own language applications. To that end, it focuses on practical use cases, and delves into theory only where necessary. The style of the book is hands-on, and we highly recommend you experiment by running the code examples yourself.
The book covers all the major applications of transformers in NLP by having each chapter (with a few exceptions) dedicated to one task, combined with a realistic use case and dataset. Each chapter also introduces some additional concepts. Here’s a high-level overview of the tasks and topics we’ll cover:
- Chapter 1, Hello Transformers, introduces transformers and puts them into context. It also provides an introduction to the Hugging Face ecosystem.
- Chapter 2, Text Classification, focuses on the task of sentiment analysis (a common text classification problem) and introduces the Trainer API.
- Chapter 3, Transformer Anatomy, dives into the Transformer architecture in more depth, to prepare you for the chapters that follow.
- Chapter 4, Multilingual Named Entity Recognition, focuses on the task of identifying entities in texts in multiple languages (a token classification problem).
- Chapter 5, Text Generation, explores the ability of transformer models to generate text, and introduces decoding strategies and metrics.
- Chapter 6, Summarization, digs into the complex sequence-to-sequence task of text summarization and explores the metrics used for this task.
- Chapter 7, Question Answering, focuses on building a review-based question answering system and introduces retrieval with Haystack.
- Chapter 8, Making Transformers Efficient in Production, focuses on model performance. We’ll look at the task of intent detection (a type of sequence classification problem) and explore techniques such a knowledge distillation, quantization, and pruning.
- Chapter 9, Dealing with Few to No Labels, looks at ways to improve model performance in the absence of large amounts of labeled data. We’ll build a GitHub issues tagger and explore techniques such as zero-shot classification and data augmentation.
- Chapter 10, Training Transformers from Scratch, shows you how to build and train a model for autocompleting Python source code from scratch. We’ll look at dataset streaming and large-scale training, and build our own tokenizer.
- Chapter 11, Future Directions, explores the challenges transformers face and some of the exciting new directions that research in this area is going into.
Lewis Tunstall is a data scientist at Swisscom, focused on building machine learning powered applications in the domains of natural language processing and time series. A former theoretical physicist, he has over 10 years experience translating complex subject matter to lay audiences and has taught machine learning to university students at both the graduate and undergraduate levels.
Leandro von Werra is a data scientist at Swiss Mobiliar where he leads the company's natural language processing efforts to streamline and simplify processes for customers and employees. He has experience working across the whole machine learning stack, and is the creator of a popular Python library that combines Transformers with reinforcement learning. He also teaches data science and visualisation at the Bern University of Applied Sciences.
Thomas Wolf is Chief Science Officer and co-founder of HuggingFace. His team is on a mission to catalyze and democratize NLP research. Prior to HuggingFace, Thomas gained a Ph.D. in physics, and later a law degree. He worked as a physics researcher and a European Patent Attorney.









