Akshay ๐Ÿš€ Profile picture
Dec 18, 2023 โ€ข 8 tweets โ€ข 3 min read โ€ข Read on X
Decorators are one of the most powerful feature of Python! ๐Ÿ”ฅ

However, understanding them can be a bit overwhelming!

Today, I'll clearly explain how decorators work!

Let's go! ๐Ÿš€ Image
Before we jump onto decorator, we must understand that functions in python are "first-class" objects!

It means that a function can be:

- passed around as an argument
- used in expressions
- returned as values of other functions

Just like integers or string!

Check this out๐Ÿ‘‡ Image
To get the essence of Decorators, let's imagine it's your friend's birthday, you're giving them a gift.

But before you do, you wrap it in a fancy gift paper to enhance its look, right?

Decorators do the same thing but with functions. โœจ

Let's see how ... ๐Ÿ‘‡
Decorators are a bit like wrapping paper.

They're functions that take another function, add some functionality, and return the new "decorated" function.

Check this out๐Ÿ‘‡ Image
The syntax we saw above is a bit clumsy.

However Python has a subtle way to do it! ๐Ÿ’ซ

We can use the `@` symbol along with the decorator name right before the function definition.

It does exactly the same thing as before but looks cleaner!โœจ

Check this out๐Ÿ‘‡ Image
Now if you are wondering, what happens when my function takes an argument!

Here'a an illustration of how decoration works when the function being greeted takes an argument!

Check this out๐Ÿ‘‡ Image
Decorators are powerful and flexible.

They can be used to:
- log function calls
- check function arguments
- run code before and after functions,
- and much more ...

They allow us to add functionality in a clean, consistent way.

Here's an interesting & generic use-case ๐Ÿ‘‡ Image
That's a wrap!

If you interested in:

- Python ๐Ÿ
- Maths for ML ๐Ÿงฎ
- ML/MLOps ๐Ÿ› 
- CV/NLP ๐Ÿ—ฃ
- LLMs ๐Ÿง 
- Ai Engineering โš™๏ธ

Find me โ†’ @akshay_pachaar โœ”๏ธ

I also write a technical newsletter on AI Engineering!

Join 4.5K+ readers: mlspring.beehiiv.com/subscribe
Image

โ€ข โ€ข โ€ข

Missing some Tweet in this thread? You can try to force a refresh
ใ€€

Keep Current with Akshay ๐Ÿš€

Akshay ๐Ÿš€ Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @akshay_pachaar

Aug 6
Let's compare OpenAI gpt-oss and Qwen-3 on maths & reasoning:
Before we dive in, here's a quick demo of what we're building!

Tech stack:

- @LiteLLM for orchestration
- @Cometml's Opik to build the eval pipeline (open-source)
- @OpenRouterAI to access the models

You'll also learn about G-Eval & building custom eval metrics.

Let's go! ๐Ÿš€
Here's the workflow:

- User submits query
- Both models generate reasoning tokens along with the final response
- Query, response and reasoning logic are sent for evaluation
- Detailed evaluation is conducted using Opik's G-Eval across four metrics.

Letโ€™s implement this!
Read 14 tweets
Aug 5
Tech giants use Multimodal RAG every day in production!

- Spotify uses it to answer music queries
- YouTube uses it to turn prompts into tracks
- Amazon Music uses it to create playlist from prompt

Let's learn how to build a Multimodal Agentic RAG (with code):
Today, we'll build a multimodal Agentic RAG that can query documents and audio files using the user's speech.

Tech stack:

- @AssemblyAI for transcription.
- @milvusio as the vector DB.
- @beam_cloud for deployment.
- @crewAIInc Flows for orchestration.

Let's build it!
Here's the workflow:

- User inputs data (audio + docs).
- AssemblyAI transcribes the audio files.
- Transcribed text & docs are embedded in the Milvus vector DB.
- Research Agent retrieves info from user query.
- Response Agent uses it to craft a response.

Check this๐Ÿ‘‡
Read 13 tweets
Aug 4
Sub-agents in Claude Code, clearly explained:
Claude Code subagents solved two of AIโ€™s biggest problems:

- Large Context management
- Right tool selection

Making it the best AI coding assistant!

Let's understand how to build and use Sub-agents in Claude code:
What are subagents?

Subagents are like focused teammates for your IDE

Each one:

- Has a specific purpose
- Uses a separate context window
- Can be limited to selected tools
- Follows a custom system prompt

It works independently and returns focused results.
Read 13 tweets
Aug 3
uv in Python, clearly explained (with code):
uv is incredibly fast.

- Creating virtual envs. using uv is ~80x faster than python -m venv.
- Package installation is 4โ€“12x faster without caching, and ~100x with caching

Today, let's understand how to use uv for Python package management.

Let's dive in! Image
uv is a Rust-based Python package manager built to be fast and reliable.

It replaces not just pip but also pip-tools, virtualenv, pipx, poetry, and pyenv, all with a single standalone binary.

Here's a uv cheatsheet for Python devs๐Ÿ‘‡

Let's look at the code next!
Read 10 tweets
Aug 1
Let's build a (Text2SQL + RAG), hybrid agentic workflow:
Before we dive in, here's a quick demo of what we're building!

Tech stack:

- @Llama_Index for orchestration
- @Milvusio to self-host a vectorDB
- @CleanlabAI to validate the response
- @OpenRouterAI to access the latest Qwen3

Let's go! ๐Ÿš€
Here's how our app works:

- LLM processes the query to select a tool
- Converts the query into right format (text/SQL)
- Executes the tool and fetch the output
- Generates a response with enriched context
- Validates the response using Cleanlab's Codex

Now, let's see the code!
Read 14 tweets
Jul 31
"Attention is all you need" implemented from scratch using PyTorch:
This is the paper that revolutionized AI!

Today, we'll implement:

- The complete Transformer architecture
- Multi-Head Attention mechanism
- Encoder-Decoder structure
- Positional Encoding

Everything in clean, educational Python code!

Let's go! ๐Ÿš€ Image
Here's the full Transformer model that we'll build piece by piece!

Notice the key components:

- Encoder & Decoder stacks
- Multi-head attention layers
- Position-wise feed-forward networks
- Positional encoding

Now let's break it down! ๐Ÿ‘‡ Image
Read 17 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us!

:(