Akshay πŸš€'s Avatar

Akshay πŸš€

@akshay-pachaar

Simplifying LLMs, MLOps, Python & Machine Learning for you! β€’ Co-founder DailyDoseofDS β€’ BITS Pilani β€’ 3 Patents β€’ ex-AI Engineer @ LightningAI

393
Followers
126
Following
93
Posts
22.11.2024
Joined
Posts Following

Latest posts by Akshay πŸš€ @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 βœ”οΈ

25.12.2024 12:30 πŸ‘ 3 πŸ” 0 πŸ’¬ 1 πŸ“Œ 0
Post image

F-strings also support formatting for different data types, such as dates and times:

25.12.2024 12:30 πŸ‘ 3 πŸ” 0 πŸ’¬ 1 πŸ“Œ 0
Post image

If you need to use braces literally in an f-string, you can escape them with double braces:

25.12.2024 12:30 πŸ‘ 2 πŸ” 0 πŸ’¬ 1 πŸ“Œ 0
Post image

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:

25.12.2024 12:30 πŸ‘ 2 πŸ” 0 πŸ’¬ 1 πŸ“Œ 0
Post image

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:

25.12.2024 12:30 πŸ‘ 1 πŸ” 0 πŸ’¬ 1 πŸ“Œ 0
Post image

Need to format numbers or strings❓

F-strings support format specifiers:

25.12.2024 12:30 πŸ‘ 1 πŸ” 0 πŸ’¬ 1 πŸ“Œ 0
Post image

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πŸ‘‡

25.12.2024 12:30 πŸ‘ 1 πŸ” 0 πŸ’¬ 1 πŸ“Œ 0
Post image

Simply put, f-strings are strings prefixed with 'f' that allow you to embed expressions inside string literals.

Here's an example:

25.12.2024 12:30 πŸ‘ 2 πŸ” 0 πŸ’¬ 1 πŸ“Œ 0
Post image

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! πŸš€

25.12.2024 12:30 πŸ‘ 3 πŸ” 0 πŸ’¬ 1 πŸ“Œ 0

f-strings in Python clearly explained:

25.12.2024 12:30 πŸ‘ 7 πŸ” 1 πŸ’¬ 1 πŸ“Œ 0

If you interested in:

- Python 🐍
- ML/AI Engineering βš™οΈ

Find me β†’Β @akshay_pachaarΒ βœ”οΈ
My Newsletter on AI Engineering β†’Β @DailyDoseOfDS_Β βœ”οΈ

Cheers! πŸ₯‚

12.12.2024 12:30 πŸ‘ 0 πŸ” 0 πŸ’¬ 0 πŸ“Œ 0

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...

12.12.2024 12:30 πŸ‘ 1 πŸ” 0 πŸ’¬ 1 πŸ“Œ 0
Post image

7️⃣ Evaluate finetuned T-5 small RAG program

**Notice the score, it beats a vanilla Mistral RAG πŸ”₯

12.12.2024 12:30 πŸ‘ 0 πŸ” 0 πŸ’¬ 1 πŸ“Œ 0
Post image

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πŸ‘‡

12.12.2024 12:30 πŸ‘ 0 πŸ” 0 πŸ’¬ 1 πŸ“Œ 0
Post image

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πŸ‘‡

12.12.2024 12:30 πŸ‘ 0 πŸ” 0 πŸ’¬ 1 πŸ“Œ 0
Post image

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πŸ‘‡

12.12.2024 12:30 πŸ‘ 0 πŸ” 0 πŸ’¬ 1 πŸ“Œ 0
Post image

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πŸ‘‡

12.12.2024 12:30 πŸ‘ 0 πŸ” 0 πŸ’¬ 1 πŸ“Œ 0
Post image

2️⃣ Load dataset

Next we load theΒ HotPotQA dataset for training & validation. HotPotQA dataset in available in `dspy.datasets`

Check this outπŸ‘‡

12.12.2024 12:30 πŸ‘ 0 πŸ” 0 πŸ’¬ 1 πŸ“Œ 0
Post image

1️⃣ Set Up

We start by setting up the LM (Mistral-7B served using @Ollama & retriever model, RM which is ColBERTv2)

Check this outπŸ‘‡

12.12.2024 12:30 πŸ‘ 0 πŸ” 0 πŸ’¬ 1 πŸ“Œ 0
Post image

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! πŸš€

12.12.2024 12:30 πŸ‘ 0 πŸ” 0 πŸ’¬ 1 πŸ“Œ 0

Let's learn how to finetune your RAG pipeline using DSPy, step-by-step:

12.12.2024 12:30 πŸ‘ 2 πŸ” 1 πŸ’¬ 1 πŸ“Œ 0

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

10.12.2024 12:32 πŸ‘ 0 πŸ” 0 πŸ’¬ 0 πŸ“Œ 0
Post image

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 πŸ‘‡

10.12.2024 12:32 πŸ‘ 0 πŸ” 0 πŸ’¬ 1 πŸ“Œ 0

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! πŸ₯‚

10.12.2024 12:31 πŸ‘ 0 πŸ” 0 πŸ’¬ 1 πŸ“Œ 0
Post image

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 πŸ‘‡

10.12.2024 12:31 πŸ‘ 0 πŸ” 0 πŸ’¬ 1 πŸ“Œ 0
Post image

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 πŸ‘‡

10.12.2024 12:31 πŸ‘ 0 πŸ” 0 πŸ’¬ 1 πŸ“Œ 0
Post image

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πŸ‘‡

10.12.2024 12:31 πŸ‘ 0 πŸ” 0 πŸ’¬ 1 πŸ“Œ 0
Post image

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πŸ‘‡

10.12.2024 12:31 πŸ‘ 0 πŸ” 0 πŸ’¬ 1 πŸ“Œ 0

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!

...πŸ‘‡

10.12.2024 12:31 πŸ‘ 0 πŸ” 0 πŸ’¬ 1 πŸ“Œ 0

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

...πŸ‘‡

10.12.2024 12:31 πŸ‘ 0 πŸ” 0 πŸ’¬ 1 πŸ“Œ 0