DML: Build & Serve a Production-Ready Classifier in 1 Hour Using LLMs
Stop Manually Creating Your ML AWS Infrastructure - use Terraform! Build & Serve a Production-Ready Classifier in 1 Hour Using LLMs.
Hello there, I am Paul Iusztin ๐๐ผ
Within this newsletter, I will help you decode complex topics about ML & MLOps one week at a time ๐ฅ
This weekโs ML & MLOps topics:
Stop Manually Creating Your ML AWS Infrastructure. Use Terraform!
Build & Serve a Production-Ready Classifier in 1 Hour Using LLMs.
Before going into our subject of the day, I have some news to share with you ๐
If you want to ๐พ๐๐ถ๐ฐ๐ธ๐น๐ ๐น๐ฒ๐ฎ๐ฟ๐ป in a ๐๐๐ฟ๐๐ฐ๐๐๐ฟ๐ฒ๐ฑ ๐๐ฎ๐ how to ๐ฏ๐๐ถ๐น๐ฑ ๐ฒ๐ป๐ฑ-๐๐ผ-๐ฒ๐ป๐ฑ ๐ ๐ ๐๐๐๐๐ฒ๐บ๐ ๐๐๐ถ๐ป๐ด ๐๐๐ ๐, emphasizing ๐ฟ๐ฒ๐ฎ๐น-๐๐ผ๐ฟ๐น๐ฑ ๐ฒ๐ ๐ฎ๐บ๐ฝ๐น๐ฒ๐?
I want to let you know that โ
I am invited on ๐ฆ๐ฒ๐ฝ๐๐ฒ๐บ๐ฏ๐ฒ๐ฟ ๐ฎ๐ด๐๐ต to a ๐๐ฒ๐ฏ๐ถ๐ป๐ฎ๐ฟ to present an overview of the ๐๐ฎ๐ป๐ฑ๐-๐ผ๐ป ๐๐๐ ๐ course I am creating.
I will show you a ๐ต๐ฎ๐ป๐ฑ๐-๐ผ๐ป ๐ฒ๐ ๐ฎ๐บ๐ฝ๐น๐ฒ of how to ๐ฏ๐๐ถ๐น๐ฑ ๐ฎ ๐ณ๐ถ๐ป๐ฎ๐ป๐ฐ๐ถ๐ฎ๐น ๐ฏ๐ผ๐ ๐๐๐ถ๐ป๐ด ๐๐๐ ๐. Here is what I will cover โ
creating your Q&A dataset in a semi-automated way (OpenAI GPT)
fine-tuning an LLM on your new dataset using QLoRA (HuggingFace, Peft, Comet ML, Beam)
build a streaming pipeline to ingest news in real time into a vector DB (Bytewax, Qdrant, AWS)
build a financial bot based on the fine-tuned model and real-time financial news (LangChain, Comet ML, Beam)
build a simple UI to interact with the financial bot
โNo Notebooks or fragmented examples.
โ I want to show you how to build a real product.
โ More precisely, I will focus on the engineering and system design, showing you how the components described above work together.
.
If this is something you want to learn, be sure to register using the link below โ
โณ๐ Engineering an End-to-End ML System for a Financial Assistant Using LLMs (September 28th).
See you there ๐
Now back to business ๐ฅ
#1. Stop Manually Creating Your ML AWS Infrastructure. Use Terraform!
I was uselessly spending 1000$ dollars every month on cloud machines until I started using this tool ๐
Terraform!
.
๐
๐ข๐ซ๐ฌ๐ญ, ๐ฅ๐๐ญ'๐ฌ ๐ฎ๐ง๐๐๐ซ๐ฌ๐ญ๐๐ง๐ ๐ฐ๐ก๐ฒ ๐ฐ๐ ๐ง๐๐๐ ๐๐๐ซ๐ซ๐๐๐จ๐ซ๐ฆ.
When you want to deploy a software application, there are two main steps:
1. Provisioning infrastructure
2. Deploying applications
A regular workflow would be that before deploying your applications or building your CI/CD pipelines, you manually go and spin up your, let's say, AWS machines.
Initially, this workflow should be just fine, but there are two scenarios when it could get problematic.
#1. Your infrastructure gets too big and complicated. Thus, it is cumbersome and might yield bugs in manually replicating it.
#2. In the world of AI, there are many cases when you want to spin up a GPU machine to train your models, and afterward, you don't need it anymore. Thus, if you forget to close it, you will end up uselessly paying a lot of $$$.
With Terraform, you can solve both of these issues.
.
So...
๐๐ก๐๐ญ ๐ข๐ฌ ๐๐๐ซ๐ซ๐๐๐จ๐ซ๐ฆ?
It sits on the provisioning infrastructure layer as a: "infrastructure as code" tool that:
- is declarative (you focus on the WHAT, not on the HOW)
- automates and manages your infrastructure
- is open source
Yeah... yeah... that sounds fancy. But ๐ฐ๐ก๐๐ญ ๐๐๐ง ๐ ๐๐จ ๐ฐ๐ข๐ญ๐ก ๐ข๐ญ?
Let's take AWS as an example, where you have to:
- create a VPC
- create AWS users and permissions
- spin up EC2 machines
- install programs (e.g., Docker)
- create a K8s cluster
Using Terraform...
You can do all that just by providing a configuration file that reflects the state of your infrastructure.
Basically, it helps you create all the infrastructure you need programmatically. Isn't that awesome?
If you want to quickly understand Terraform enough to start using it in your own projects:
โณ check out my 7-minute read article: ๐ Stop Manually Creating Your AWS Infrastructure. Use Terraform!
#2. Build & Serve a Production-Ready Classifier in 1 Hour Using LLMs
๐๐๐๐ด ๐ข๐ณ๐ฆ ๐ข ๐ญ๐ฐ๐ต ๐ฎ๐ฐ๐ณ๐ฆ ๐ต๐ฉ๐ข๐ฏ ๐ค๐ฉ๐ข๐ต๐ฃ๐ฐ๐ต๐ด. ๐๐ฉ๐ฆ๐ด๐ฆ ๐ฎ๐ฐ๐ฅ๐ฆ๐ญ๐ด ๐ข๐ณ๐ฆ ๐ณ๐ฆ๐ท๐ฐ๐ญ๐ถ๐ต๐ช๐ฐ๐ฏ๐ช๐ป๐ช๐ฏ๐จ ๐ฉ๐ฐ๐ธ ๐๐ ๐ด๐บ๐ด๐ต๐ฆ๐ฎ๐ด ๐ข๐ณ๐ฆ ๐ฃ๐ถ๐ช๐ญ๐ต.
.
Using the standard approach when building an end-to-end ML application, you had to:
- get labeled data: 1 month
- train the model: 2 months
- serve de model: 3 months
These 3 steps might take ~6 months to implement.
So far, it worked great.
But here is the catch โ
.
๐ ๐ฐ๐ถ ๐ค๐ข๐ฏ ๐ณ๐ฆ๐ข๐ค๐ฉ ๐ข๐ญ๐ฎ๐ฐ๐ด๐ต ๐ต๐ฉ๐ฆ ๐ด๐ข๐ฎ๐ฆ ๐ณ๐ฆ๐ด๐ถ๐ญ๐ต ๐ช๐ฏ ๐ข ๐ง๐ฆ๐ธ ๐ฉ๐ฐ๐ถ๐ณ๐ด ๐ฐ๐ณ ๐ฅ๐ข๐บ๐ด ๐ถ๐ด๐ช๐ฏ๐จ ๐ข ๐ฑ๐ณ๐ฐ๐ฎ๐ฑ๐ต-๐ฃ๐ข๐ด๐ฆ๐ฅ ๐ญ๐ฆ๐ข๐ณ๐ฏ๐ช๐ฏ๐จ ๐ข๐ฑ๐ฑ๐ณ๐ฐ๐ข๐ค๐ฉ.
Let's take a classification task as an example โ
๐ฆ๐๐ฒ๐ฝ ๐ญ: You write a system prompt explaining the model and what types of inputs and outputs it will get.
"
You will be provided with customer service queries.
Classify each query into the following categories:
- Billing
- Account Management
- General Inquiry
"
๐ฆ๐๐ฒ๐ฝ ๐ฎ: You can give the model an example to make sure it understands the task (known as one-shot learning):
"
User: I want to know the price of the pro subscription plan.
Assistant: Billing
"
๐ฆ๐๐ฒ๐ฝ ๐ฏ: Attach the user prompt and create the input prompt, which now consists of the following:
- system
- example
- user
...prompts
๐ฆ๐๐ฒ๐ฝ ๐ฐ: Call the LLM's API... and boom, you built a classifier in under one hour.
Cool, right? ๐ฅ
Using this approach, the only time-consuming step is to tweak the prompt until it reaches the desired result.
To conclude...
In today's LLMs world, to build a classifier, you have to write:
- a system prompt
- an example
- attach the user prompt
- pass the input prompt to the LLM API
Thatโs it for today ๐พ
See you next Thursday at 9:00 a.m. CET.
Have a fantastic weekend!
Paul
Whenever youโre ready, here is how I can help you:
The Full Stack 7-Steps MLOps Framework: a 7-lesson FREE course that will walk you step-by-step through how to design, implement, train, deploy, and monitor an ML batch system using MLOps good practices. It contains the source code + 2.5 hours of reading & video materials on Medium.
Machine Learning & MLOps Blog: in-depth topics about designing and productionizing ML systems using MLOps.
Machine Learning & MLOps Hub: a place where all my work is aggregated in one place (courses, articles, webinars, podcasts, etc.).