write a long article, at least with 5 sections, about the book called "Building LLM powered applications" written by Valentina Alto. The title must be "the Art of LLM Control: Tame Their Errors, and Forge Ahead with Valentina Alto's Blueprint". write it like the book is able to teach the secrets to control with creativity and safety your LLM. Use the provided text from the book as your reference.
Your writing style must be as follow: Begin with a strong hook, perhaps a relevant anecdote or surprising fact.Clearly state your opinion on the topic and why you feel passionately about it. Use vivid examples and relatable scenarios to illustrate your points. Ask the reader rhetorical questions to get them thinking critically. Emphasize important points with exclamations. Conclude by reiterating your main points and leaving the reader with something to ponder. Remember: Maintain a conversational tone and avoid overly technical language.But do not be too friendly, the reader is not your buddy! Aim to inform, entertain, and inspire the reader. Show, don't tell: Use descriptive language to paint a picture with words. The article must be 2500 words long.
[ start of text]
"unlike humans, LLMs cannot recover from errors on their own"
With this book, we embark upon an exploration of large language models (LLMs) and the transformative paradigm they represent within the realm of artificial intelligence (AI). This comprehensive
guide helps you delve into the fundamental concepts, from solid theoretical foundations of these cutting-edge technologies to practical applications that LLMs offer, ultimately converging on the ethical and responsible considerations while using generative AI solutions. This book aims to provide you with a firm understanding of how the emerging LLMs in the market can impact individuals, large enterprises, and society. It focuses on how to build powerful applications powered by LLMs, leveraging new AI orchestrators such as LangChain and uncovering new trends in modern application development. By the end of this book, you will be able to navigate the rapidly evolving ecosystem of generative AI solutions more easily; plus, you will have the tools to get the most out of LLMs in both your daily tasks and your businesses. Let’s get started!
The book is designed to mainly appeal to a technical audience with some basic Python code foundations.
However, the theoretical chapters and the hands-on exercises are based on generative AI foundations
and industry-led use cases, which might be of interest to non-technical audiences as well.
Overall, the book caters to individuals interested in gaining a comprehensive understanding of the
transformative power of LLMs and define, enabling them to navigate the rapidly evolving AI land-
scape with confidence and foresight. All kinds of readers are welcome, but readers who can benefit
the most from this book include:
• Software developers and engineers: This book provides practical guidance for developers
looking to build applications leveraging LLMs. It covers integrating LLMs into app backends,
APIs, architectures, and so on.
• Data scientists: For data scientists interested in deploying LLMs for real-world usage, this book
shows how to take models from research to production. It covers model serving, monitoring,
and optimization.
• AI/ML engineers: Engineers focused on AI/ML applications can leverage this book to under-
stand how to architect and deploy LLMs as part of intelligent systems and agents.
• Technical founders/CTOs: Startup founders and CTOs can use this book to evaluate if and how
LLMs could be used within their apps and products. It provides a technical overview alongside
business considerations.
• Students: Graduate students and advanced undergraduates studying AI, ML, natural language
processing (NLP), or computer science can learn how LLMs are applied in practice from this
book.
• LLM researchers: Researchers working on novel LLM architectures, training techniques, and
so on will gain insight into real-world model usage and the associated challenges.
What this book covers
Chapter 1, Introduction to Large Language Models, provides an introduction to and deep dive into LLMs, a powerful set of deep learning neural networks in the domain of generative AI. It introduces the concept of LLMs, their differentiators from classical machine learning models, and the relevant jargon. It also discusses the architecture of the most popular LLMs, moving on to explore how LLMs are trained and consumed and compare base LLMs with fine-tuned LLMs. By the end of this chapter, you will have the foundations of what LLMs are and their positioning in the landscape of AI, creating the basis for the subsequent chapters.
Chapter 2, LLMs for AI-Powered Applications, explores how LLMs are revolutionizing the world of software development, leading to a new era of AI-powered applications. By the end of this chapter, you will have a clearer picture of how LLMs can be embedded in different application scenarios, with the help of new AI orchestrator frameworks that are currently available in the AI development market.
Chapter 3, Choosing an LLM for Your Application, highlights how different LLMs may have different
architectures, sizes, training data, capabilities, and limitations. Choosing the right LLM for your application is not a trivial decision as it can significantly impact the performance, quality, and cost of your solution. In this chapter, we will navigate the process of choosing the right LLM for your application. We will discuss the most promising LLMs in the market, the main criteria and tools to use when comparing LLMs, and the various trade-offs between size and performance. By the end of this chapter, you should have a clear understanding of how to choose the right LLM for your application and how to use it effectively and responsibly.
Chapter 4, Prompt Engineering, explains how prompt engineering is a crucial activity while designing LLM-powered applications since prompts have a massive impact on the performance of LLMs. In fact, there are several techniques that can be implemented to not only to refine your LLM’s responses but also reduce risks associated with hallucination and biases. In this chapter, we will cover the emerging techniques in the field of prompt engineering, from basic approaches up to advanced frameworks. By the end of this chapter, you will have the foundations to build functional and solid prompts for your LLM-powered applications, which will also be relevant in the upcoming chapters.
Chapter 5, Embedding LLMs within Your Applications, discusses a new set of components introduced
into the landscape of software development with the advent of developing applications with LLMs.
To make it easier to orchestrate LLMs and their related components in an application flow, several AI frameworks have emerged, of which LangChain is one of the most widely used. In this chapter, we
will take a deep dive into LangChain and how to use it, and learn how to call open-source LLM APIs
into code via Hugging Face Hub and manage prompt engineering. By the end of this chapter, you will
have the technical foundations to start developing your LLM-powered applications using LangChain
and open-source Hugging Face models.
Chapter 6, Building Conversational Applications, allows us to embark on the hands-on section of this book with your first concrete implementation of LLM-powered applications. Throughout this chapter, we will cover a step-by-step implementation of a conversational application, using LangChain and its components. We will configure the schema of a simple chatbot, adding a memory component, non-parametric knowledge, and tools to make the chatbot “agentic.” By the end of this chapter, you will be able to set up your own conversational application project with just a few lines of code.
Chapter 7, Search and Recommendation Engines with LLMs, explores how LLMs can enhance recom-
mendation systems, using both embeddings and generative models. We will discuss the definition
and evolution of recommendation systems, learn how generative AI is impacting this field of research, and understand how to build recommendation systems with LangChain. By the end of this chapter, you will be able to create your own recommendation application and leverage state-of-the-art LLMs using LangChain as the framework.
Chapter 8, Using LLMs with Structured Data, covers a great capability of LLMs: the ability to handle structured, tabular data. We will see how, with plug-ins and an agentic approach, we can use LLMs as a natural language interface between us and our structured data, reducing the gap between the business user and the structured information. To demonstrate this, we will build a database copilot with LangChain. By the end of this chapter, you will be able to build your own natural language interface for your data estate, combining unstructured with structured sources.
Chapter 9, Working with Code, covers another great capability of LLMs: working with programming
languages. In the previous chapter, we’ve already seen a glimpse of this capability, when we asked
our LLM to generate SQL queries against a SQL Database. In this chapter, we are going to examine in which other ways LLMs can be used with code, from “simple” code understanding and generation to
the building of applications that behave as if they were an algorithm. By the end of this chapter, you will be able to build LLM-powered applications for your coding projects, as well as build LLM-powered applications with natural language interfaces to work with code.
Chapter 10, Building Multimodal Applications with LLMs, goes beyond LLMs, introducing the concept
of multi-modality while building agents. We will see the logic behind the combination of foundation models in different AI domains – language, images, audio – into one single agent that can adapt to a variety of tasks. You will learn how to build a multi-modal agent with single-modal LLMs using LangChain. By the end of this chapter, you will be able to build your own multi-modal agent, providing it with the tools and LLMs needed to perform various AI tasks.
Chapter 11, Fine-Tuning Large Language Models, covers the technical details of fine-tuning LLMs, from the theory behind it to hands-on implementation with Python and Hugging Face. We will delve into how you can prepare your data to fine-tune a base model on your data, as well as discuss hosting strategies for your fine-tuned model. By the end of this chapter, you will be able to fine-tune an LLM on your own data so that you can build domain-specific applications powered by that LLM.
Chapter 12, Responsible AI, introduces the fundamentals of the discipline behind the mitigation of the potential harms of LLMs – and AI models in general – that is, responsible AI. This is important because LLMs open the doors to a new set of risks and biases to be taken into account while developing LLM-powered applications.
We will then move on to the risks associated with LLMs and how to prevent or, at the very least, mitigate them using proper techniques. By the end of this chapter, you will have a deeper understanding of how to prevent LLMs from making your application potentially harmful.
Chapter 13, Emerging Trends and Innovations, explores the latest advancements and future trends in
the field of generative AI.
In this book, we will see the theory and practice of how to build LLM-powered applications, addressing a variety of scenarios and showing new components and frameworks that are entering the domain of software development in this new era of AI. The book will start with Part 1, where we will introduce the theory behind LLMs, the most promising LLMs in the market right now, and the emerging frameworks for LLMs-powered applications. Afterward, we will move to a hands-on part where we will implement many applications using various LLMs, addressing different scenarios and real-world problems. Finally, we will conclude the book with a third part, covering the emerging trends in the field of LLMs, alongside the risk of AI tools and how to mitigate them with responsible AI practices.
in chapter 3 we see Choosing an LLM for Your Application
In the last chapter, we saw how pivotal it is to properly orchestrate large language models (LLMs) and their components within applications. In fact, we saw that not all LLMs are created equal. The next key decision is which LLMs to actually use. Different LLMs may have different architectures, sizes, training data, capabilities, and limitations. Choosing the right LLM for your application is not a trivial decision, as it can have a significant impact on the performance, quality, and cost of your solution. In this chapter, we will guide you through the process of choosing the right LLM for your application. We will cover the following topics:
• An overview of the most promising LLMs in the market
• The main criteria and tools to use when comparing LLMs
• Trade-offs between size and performance
By the end of this chapter, you should have a clear understanding of how to choose the right LLM for your application and how to use it effectively and responsibly. here together with proprietary models like gemini, cohere, ChatGPT are presented also a bi variety of open-source models from hugging face hub, like Llama2, Falcon and Mistral.
Now, the question is: which one should I use within my applications? The truth is that there is not a straightforward answer to this question.
Considerations. There are many factors to consider when choosing an LLM for your application. Those factors also need to be declined in two scenarios: proprietary and open-source LLMs. The following are some factors and trade-offs you might want to consider while choosing your LLMs:
• Size and performance: We saw that more complex models (that means, with a high number
of parameters) tend to have better performance, especially in terms of parametric knowledge
and generalization capabilities. Nevertheless, the larger the model, the more computation and
memory it requires to process the input and generate the output, which can result in higher
latency and, as we will see, higher costs.
• Cost and hosting strategy: When incorporating LLMs within our applications, there are two
types of costs we have to keep in mind: Cost for model consumption: This refers to the fee we pay to consume the model. Proprietary models like GPT-4 or Claude 2 require a fee, which is typically proportional to the number of tokens processed. On the other hand, open-source models like LlaMA
or Falcon LLM are free to use. Cost for model hosting: This refers to your hosting strategy. Typically, proprietary models are hosted in a private or public hyperscaler, so that they can be consumed via a REST API and you don’t have to worry about the underlying infrastructure (for
example, GPT-4 is hosted in a super-computer built in the Microsoft Azure cloud). With
open-source models, we typically need to provide our own infrastructure, since those
models can be downloaded locally. Of course, the larger the model, the more powerful
the computational power needed.
In chapter 4, we are going to cover the emerging techniques in the field of prompt engineering,
starting from basic approaches up to advanced frameworks. By the end of this chapter, you will have the foundations to build functional and solid prompts for your LLM-powered applications, which will also be relevant in the upcoming chapters.
We will go through the following topics:
• Introduction to prompt engineering
• Basic principles of prompt engineering
• Advanced techniques of prompt engineering
Split complex tasks into subtasks: As discussed earlier, prompt engineering is a technique that involves designing effective inputs for LLMs to perform various tasks. Sometimes, the tasks are too complex or ambiguous for a single prompt to handle, and it is better to split them into simpler subtasks that can be solved by different prompts.
Ask for justification: LLMs are built in such a way that they predict the next token based on the previous ones without looking back at their generations. This might lead the model to output wrong content to the user, yet in a very convincing way. If the LLM-powered application does not provide a specific reference to that response, it might be hard to validate the ground truth behind it. Henceforth, specifying in the prompt to support the LLM’s answer with some reflections and justification could prompt the model to recover from its actions. Furthermore, asking for justification might be useful also in case of answers that are right but we simply don’t know the LLM’s reasoning behind it.
Generate many outputs, then use the model to pick the best one: As we saw in the previous section, LLMs are built in such a way that they predict the next token based on the previous ones without looking back at their generations. If this is the case, if one sampled token is the wrong one (in other words, if the model is unlucky), the LLM will keep generating wrong tokens and, henceforth, wrong content. Now, the bad news is that, unlike humans, LLMs cannot recover from errors on their own. This means that, if we ask them, they acknowledge the error, but we need to explicitly prompt them to think about that. One way to overcome this limitation is to broaden the space of probabilities of picking the right token. Rather than generating just one response, we can prompt the model to generate multiple responses, and then pick the one that is most suitable for the user’s query.
Repeat instructions at the end: LLMs tend not to process the metaprompt attributing the same weight or imprortance to all the sections. In fact, in his blog post Large Language Model Prompt Engineering for Complex Summarization, John Stewart (a software engineer at Microsoft) found some interesting outcomes from arranging prompt sections (https://devblogs.microsoft.com/ise/gpt-summary-prompt-engineering/). More specifically, after several experimentations, he found that repeating the main instruction at the end of the prompt can help the model overcome its inner recency bias.
Use delimiters: The last principle to be covered is related to the format we want to give to our metaprompt. This helps our LLM to better understand its intents as well as relate different sections and paragraphs to each other. To achieve this, we can use delimiters within our prompt. A delimiter can be any sequence of characters or symbols that is clearly mapping a schema rather than a concept.
[end of text]