Reader small image

You're reading from  Mastering NLP from Foundations to LLMs

Product typeBook
Published inApr 2024
PublisherPackt
ISBN-139781804619186
Edition1st Edition
Right arrow
Authors (2):
Lior Gazit
Lior Gazit
author image
Lior Gazit

Lior Gazit is a highly skilled Machine Learning professional with a proven track record of success in building and leading teams drive business growth. He is an expert in Natural Language Processing and has successfully developed innovative Machine Learning pipelines and products. He holds a Master degree and has published in peer-reviewed journals and conferences. As a Senior Director of the Machine Learning group in the Financial sector, and a Principal Machine Learning Advisor at an emerging startup, Lior is a respected leader in the industry, with a wealth of knowledge and experience to share. With much passion and inspiration, Lior is dedicated to using Machine Learning to drive positive change and growth in his organizations.
Read more about Lior Gazit

Meysam Ghaffari
Meysam Ghaffari
author image
Meysam Ghaffari

Meysam Ghaffari is a Senior Data Scientist with a strong background in Natural Language Processing and Deep Learning. Currently working at MSKCC, where he specialize in developing and improving Machine Learning and NLP models for healthcare problems. He has over 9 years of experience in Machine Learning and over 4 years of experience in NLP and Deep Learning. He received his Ph.D. in Computer Science from Florida State University, His MS in Computer Science - Artificial Intelligence from Isfahan University of Technology and his B.S. in Computer Science at Iran University of Science and Technology. He also worked as a post doctoral research associate at University of Wisconsin-Madison before joining MSKCC.
Read more about Meysam Ghaffari

View More author details
Right arrow

Exploring the Frontiers: Advanced Applications and Innovations Driven by LLMs

In the rapidly evolving landscape of natural language processing (NLP), large language models (LLMs) have marked a revolutionary step forward, reshaping how we interact with information, automate processes, and derive insights from vast data pools. This chapter represents the culmination of our journey through the emergence and development of NLP methods. It is here that the theoretical foundations laid in previous chapters converge with practical, cutting-edge applications, illuminating the remarkable capabilities of LLMs when harnessed with the right tools and techniques.

We delve into the most recent and thrilling advancements in LLM applications, presented through detailed Python code examples designed for hands-on learning. This approach not only illustrates the power of LLMs but also equips you with the skills to implement these technologies in real-world scenarios. The subjects covered in this chapter...

Technical requirements

For this chapter, the following will be necessary:

  • Programming knowledge: Familiarity with Python programming is a must since the open source models, OpenAI’s API, and LangChain are all illustrated using Python code.
  • Access to OpenAI’s API: An API key from OpenAI will be required to explore closed source models. This can be obtained by creating an account with OpenAI and agreeing to their terms of service.
  • Open source models: Access to the specific open source models mentioned in this chapter will be necessary. These can be accessed and downloaded from their respective repositories or via package managers such as pip or conda.
  • Local development environment: A local development environment setup with Python installed is required. An integrated development environment (IDE) such as PyCharm, Jupyter Notebook, or a simple text editor can be used. Note that we recommend a free Google Colab notebook, as it encapsulates all these requirements...

Enhancing LLM performance with RAG and LangChain – a dive into advanced functionalities

The retrieval-augmented generation (RAG) framework has become instrumental in tailoring large language models (LLMs) for specific domains or tasks, bridging the gap between the simplicity of prompt engineering and the complexity of model fine-tuning.

Prompt engineering stands as the initial, most accessible technique for customizing LLMs. It leverages the model’s capacity to interpret and respond to queries based on the input prompt. For example, to inquire if Nvidia surpassed earnings expectations in its latest announcement, directly providing the earnings call content within the prompt can compensate for the LLM’s lack of immediate, up-to-date context. This approach, while straightforward, hinges on the model’s ability to digest and analyze the provided information within a single or a series of carefully crafted prompts.

When the scope of inquiry exceeds what...

Advanced methods with chains

In this section, we will continue our exploration of ways one can utilize LLM pipelines. We will focus on chains.

Refer to the following notebook: Ch9_Advanced_Methods_with_Chains.ipynb. This notebook presents an evolution of a chain pipeline, as every iteration exemplifies another feature that LangChain allows us to employ.

For the sake of using minimal computational resources, memory, and time, we use OpenAI’s API. You can choose to use a free LLM instead and may do so in a similar way to how we set up the notebook from the previous example in this chapter.

The notebook starts with the basic configurations, as always, so we can skip to reviewing the notebook’s content.

Asking the LLM a general knowledge question

In this example, we want to use the LLM to tell us an answer to a simple question that would require common knowledge that a trained LLM is expected to have:

"Who are the members of Metallica. List them as...

Retrieving information from various web sources automatically

In this example, we will review how simple it is to leverage LLMs to access the web and extract information. We may wish to research a particular topic, and so we would like to consolidate all the information from a few web pages, several YouTube videos that present that topic, and so on. Such an endeavor can take a while, as the content may be massive. For instance, several YouTube videos can sometimes take hours to review. Often, one doesn’t know how useful the video is until one has watched a significant portion of it.

Another use case is when looking to track various trends in real time. This may include tracking news sources, YouTube videos, and so on. Here, speed is crucial. Unlike the previous example where speed was important to save us personal time, here, speed is necessary for getting our algorithm to be relevant for identifying real-time emerging trends.

In this section, we put together a very simple...

Prompt compression and API cost reduction

This part is dedicated to a recent development in resource optimization for when employing API-based LLMs, such as OpenAI’s services. When considering the many trade-offs between employing a remote LLM as a service and hosting an LLM locally, one key metric is cost. In particular, based on the application and usage, the API costs can accumulate to a significant amount. API costs are mainly driven by the number of tokens that are being sent to and from the LLM service.

In order to illustrate the significance of this payment model on a business plan, consider business units for which the product or service relies on API calls to OpenAI’s GPT, where OpenAI serves as a third-party vendor. As a particular example, imagine a social network that lets its users have LLM assistance to comment on posts. In that use case, a user is interested in commenting on a post, and instead of having to write a complete comment, a feature lets the...

Multiple agents – forming a team of LLMs that collaborate

This section deals with one of the most exciting recent methods in the world of LLMs, employing multiple LLMs simultaneously. In the context of this section, we seek to define multiple agents, each backed by an LLM and given a different designated role to play. Instead of the user working directly with the LLM, as we see in ChatGPT, here, the user sets up multiple LLMs and sets their role by defining a different system prompt for each of them.

Potential advantages of multiple LLM agents working simultaneously

Much like with people working together, here too, we see the advantages of employing several LLMs simultaneously.

Some advantages are the following:

  • Enhancing validation and reducing hallucinations: It has been shown that when providing feedback to an LLM and asking it to reason or to check its response, the reliability of its response improves. When designating roles for the various LLM agents on...

Summary

Throughout this pivotal chapter, we have embarked on an in-depth exploration of the most recent and groundbreaking applications of LLMs, presented through comprehensive Python code examples. We began by unlocking advanced functionalities by using the RAG framework and LangChain, enhancing LLM performance for domain-specific tasks. The journey continued with advanced methods in chains for sophisticated formatting and processing, followed by the automation of information retrieval from diverse web sources. We also tackled the optimization of prompt engineering through prompt compression techniques, significantly reducing API costs. Finally, we ventured into the collaborative potential of LLMs by forming a team of models that work in concert to solve complex problems.

By mastering these topics, you have now acquired a robust set of skills, enabling you to harness the power of LLMs for a variety of applications. These newfound abilities not only prepare you to tackle current...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Mastering NLP from Foundations to LLMs
Published in: Apr 2024Publisher: PacktISBN-13: 9781804619186
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (2)

author image
Lior Gazit

Lior Gazit is a highly skilled Machine Learning professional with a proven track record of success in building and leading teams drive business growth. He is an expert in Natural Language Processing and has successfully developed innovative Machine Learning pipelines and products. He holds a Master degree and has published in peer-reviewed journals and conferences. As a Senior Director of the Machine Learning group in the Financial sector, and a Principal Machine Learning Advisor at an emerging startup, Lior is a respected leader in the industry, with a wealth of knowledge and experience to share. With much passion and inspiration, Lior is dedicated to using Machine Learning to drive positive change and growth in his organizations.
Read more about Lior Gazit

author image
Meysam Ghaffari

Meysam Ghaffari is a Senior Data Scientist with a strong background in Natural Language Processing and Deep Learning. Currently working at MSKCC, where he specialize in developing and improving Machine Learning and NLP models for healthcare problems. He has over 9 years of experience in Machine Learning and over 4 years of experience in NLP and Deep Learning. He received his Ph.D. in Computer Science from Florida State University, His MS in Computer Science - Artificial Intelligence from Isfahan University of Technology and his B.S. in Computer Science at Iran University of Science and Technology. He also worked as a post doctoral research associate at University of Wisconsin-Madison before joining MSKCC.
Read more about Meysam Ghaffari