That's a wrap, let me know in the comments if I missed any Ninja trick! π₯
If you interested in:
- Python π
- ML/AI Engineering βοΈ
Find me β @akshay_pachaar βοΈ
That's a wrap, let me know in the comments if I missed any Ninja trick! π₯
If you interested in:
- Python π
- ML/AI Engineering βοΈ
Find me β @akshay_pachaar βοΈ
F-strings also support formatting for different data types, such as dates and times:
If you need to use braces literally in an f-string, you can escape them with double braces:
F-strings also support the `=` specifier, which can be handy for debugging or logging purposes.
It allows you to include the variable name and its value in the formatted string:
F-strings support multiline strings using triple quotes!
It's one of my favourite features, I use it for creating prompt templates.
Here's an example:
Need to format numbers or stringsβ
F-strings support format specifiers:
You can also perform operations & call functions inside the braces.
This makes f-strings incredibly versatile for constructing dynamic strings with computed values.
Check this outπ
Simply put, f-strings are strings prefixed with 'f' that allow you to embed expressions inside string literals.
Here's an example:
f-strings were introduced in Python 3.6 and have since become a favorite among developers for their simplicity and readability.
Today, we'll start with the basics and dive into all the ninja tricks of using f-strings.
Let's go! π
f-strings in Python clearly explained:
If you interested in:
- Python π
- ML/AI Engineering βοΈ
Find me βΒ @akshay_pachaarΒ βοΈ
My Newsletter on AI Engineering βΒ @DailyDoseOfDS_Β βοΈ
Cheers! π₯
You can find all the code & details in the @LightningAIβ‘οΈ studio shared below:
lightning.ai/lightning-a...
You should also check DSPy's official repo: github.com/stanfordnlp...
7οΈβ£ Evaluate finetuned T-5 small RAG program
**Notice the score, it beats a vanilla Mistral RAG π₯
6οΈβ£ Define a T-5 small RAG & Finetune it
The code below will perform finetuning & provide a checkpoint for the best model weights saved during the process.
Check this outπ
5οΈβ£ Evaluate RAG powered by Mistral
Let's first evaluate our RAG program that uses Mistral-7B as LLM
** Notice the score, this is what we want to beat!
Check this outπ
4οΈβ£ Define the RAG program
Let's define a basic DSPy program which is a RAG pipeline for answer generation.
It's like defining a model that we want to finetune & evaluate.
Check this outπ
3οΈβ£ Set eval metric
DSPy provides out of the box support for many evaluation metrics & you can define a custom metric as well.
Our program is expected to produce short factoid answers & hence, exact match with the ground truth is a good eval metric here.
Check this outπ
2οΈβ£ Load dataset
Next we load theΒ HotPotQA dataset for training & validation. HotPotQA dataset in available in `dspy.datasets`
Check this outπ
1οΈβ£ Set Up
We start by setting up the LM (Mistral-7B served using @Ollama & retriever model, RM which is ColBERTv2)
Check this outπ
DSPy is a framework for algorithmically optimizing LM prompts and weights.
DSPy : RAG :: PyTorch : DNNs
I'll make sure today's tutorial can be followed with minimal background knowledge!
Let's go! π
Let's learn how to finetune your RAG pipeline using DSPy, step-by-step:
That's a wrap, if you're interested in:
- Python π
- ML AI Engineering βοΈ
1. Find me β @akshay_pachaar βοΈ
2. Sign up for our newsletter for in-depth lessons and get a FREE eBook with 150+ core DS/ML lessons: join.dailydoseofds.com
6οΈβ£ Polymorphism π
This allows us to use a single interface for different data types or classes.
We can achieve this through method overriding, where a subclass provides a different implementation for a method defined in its parent class.
Let's understand with an example π
At this point if Abstraction and Encapsulation confuse you! π
Abstraction conceals the implementation details, but doesn't hide the data itself.
On the other hand, Encapsulation hides the data and restricts unwanted use from external sources.
Cheers! π₯
5οΈβ£ Abstraction π
This concept focuses on exposing only essential information to the outside world while hiding implementation details.
We use abstract classes and methods to define a common interface.
Here's an example π
4οΈβ£ Encapsulation π
Encapsulation helps to bundle data and methods inside a class, restricting direct access to certain attributes and methods.
We use private attributes/methods (with a `_` or `__` prefix) to achieve this.
Here's an example π
3οΈβ£ Inheritance π§¬
Let's say we want to create an Electric car & don't want to define all the properties and methods of the basic Car class.
Inheritance helps us to inherit all the properties/methods of parent class & add new ones or override existing.
Check this outπ
2οΈβ£ Class ποΈ
A class is like a blueprint for creating objects.
It defines a set of properties & functions (methods) that will be common to all objects created from the class.
So, we start with a simple example & follow along!
Let's define a class Car & create it's Objectπ
For example, a Car is an object that has properties such as color & model, and behaviours such as accelerating, braking & turning.
But, how do we create these objectsβπ€
This is where we need to understand Classes!
...π
1οΈβ£ Object π
Just look around, everything you see can be treated as an object.
For instance a Car, Dog, your Laptop are all objects.
An Object can be defined using 2 things:
- Properties: that describe an object
- Behaviour: the functions that an object can perform
...π