Akshay 🚀 Profile picture
Oct 1 10 tweets 3 min read Twitter logo Read on Twitter
Broadcasting in NumPy is widely used, yet poorly understood❗️

Today, I'll clearly explain how broadcasting works!

Same rules apply to PyTorch & TensorFlow!

Let's go! 🚀 Image
Broadcasting describes how NumPy treats arrays with different shapes during arithmetic operations.

The smaller array is “broadcast” across the larger array, such that the 2 have compatible shapes.

Check this out👇 Image
In the image below, scalar "b" is being stretched into an array with the same shape as "a".

But how do we generalise these things?

continue reading ... 📖 Image
💫 General Rules:

1) Broadcasting starts with the trailing (i.e. rightmost) dimensions and works its way left .

2) Two dimensions are compatible, either when they are equal or one of them is 1.

Check out the examples 👇 Image
When ever a one dimensional array is involved in broadcasting, consider it as a row vector!

Array → [1, 2, 3] ; shape → (3,)
Treated as → [[1, 2, 3]] ; shape → (1, 3)

Remember, broadcasting occurs from trailing dimension!

Check this out👇
Image
Image
Let's check a scenario when broadcasting doesn't occur!

- a(4x3)
- b(4) will be treated as b(1x4)

Now, broadcasting starts from trailing dimension but (4x3) & (1x4) are not compatible!

Check this out👇 Image
Let's take one more example to make out understanding concrete!

Remember, 1D array treated as a row vector while broadcasting!

Check this out👇 Image
Here's how an array of shape (4x1) & (3,) broadcasts together!

Check this out👇 Image
Why use broadcasting❓

Broadcasting provides a means of vectorising array operations so that looping occurs in C instead of Python.

It does this without making needless copies of data and usually leads to efficient algorithm implementations.
That's a wrap!

If you Enjoyed reading this & are interested in

- Python 🐍
- ML/MLOps 🛠
- CV/NLP 🗣
- LLMs 🧠
- AI Engineering ⚙️

Find me → @akshay_pachaar ✔️
Everyday, I share tutorials on the above topics!

Cheers! 🥂

• • •

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

Oct 2
I started my career in Data Science back in 2016 ⏳

Here's a roadmap for those starting out today:
First of all, learn concepts from the first principles!

@brilliantorg reached out & shared their courses with me!

I was truly amazed by the highly engaging & world class learning material they provided!

Here's a good Example 👇
Master Python 🐍

The language Machine Learning community speaks!

@brilliantorg offers easy to understand, byte-sized & interactive lessons on Python!

Check this👇
Read 8 tweets
Sep 30
AI Engineering is going to be a high leverage skill!

Here's a list of top GitHub repos on LLMs & AI Engineering!

Topics covered:

- LLMs
- LLMOps
- AI Agents
- Fine-tuning LLMs
- Prompt Engineering
- Retrieval augmented Generation! (RAGs)

Read more!👇 Image
1️⃣ Lit-GPT

Hackable implementation of SOTA open source LLMs!

@LightningAI's Lit-GPT is:

• Simple: Single-file implementation without boilerplate
• Correct: Numerically equivalent to the original model
• Open-source: No strings attached

Check this👇
github.com/Lightning-AI/l…
2️⃣ Prompt Engineering Guide

A guide that contains all the latest papers, learning guides, lectures, references, and tools related to prompt engineering for LLMs.

Happy Prompting!

Check this out👇
github.com/dair-ai/Prompt…
Read 10 tweets
Sep 22
PyTorch 101: Tensors clearly explained!

Tensors are the fundamental building blocks for performing mathematical operations in deep learning models.

Today, I will provide a comprehensive explanation with illustrative code examples.

Let's go! 🚀 Image
Tensors are multi-dimensional arrays that form the backbone of numerical computing!

In PyTorch, creating tensors is a breeze!

You can initialize tensors from lists, zeros, ones, or even random values!

Check this out👇 Image
Every tensor has attributes like `dtype`, `shape`, and `device` which tells us about the nature of the tensor.

Tensors can live on CPU or GPU, and PyTorch makes it seamless to perform operations between them!

Check this out👇 Image
Read 6 tweets
Sep 21
I started my career in Data Science back in 2016 ⏳

Here's a list of Python libraries for ML that I highly recommend mastering!

Find links to official docs & some good tutorials...👇 Image
1️⃣ NumPy:

The most popular Python library for scientific computing.

Appears simple but takes practice to master.

Docs: 👇


Video Tutorial: 👇
numpy.org/doc/stable/use…
2️⃣ Pandas:

Go to Python library for data manipulation and analysis.

Docs: 👇


Video Tutorial: 👇
pandas.pydata.org/pandas-docs/ve…
youtube.com/playlist?list=…
Read 14 tweets
Sep 20
Everyone should learn how to fine-tune LLMs.

However, LLMs barely fit in GPU memory❗️

This is where fine-tuning & more importantly parameter efficient fine-tuning (PEFT) become essential.

Let's understand them today: Image
GPT-4 is not a silver bullet solution.

We often need to teach an LLM or fine-tune it to perform specific tasks based on our custom knowledge base.

Read more:


Here's an illustration of different fine-tuning strategies! 👇 lightning.ai/pages/communit…
Image
We know LLMs today barely fit in GPU memory!

And say we want to update all the layers (Fine tuining II) as it gives best performance.

This is were we need to think of some Parameter efficient technique!

One such way is to use Transformer block with adapters!

Check this out👇 Image
Read 8 tweets
Sep 17
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 ... 👇
Read 9 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 on Twitter!

:(