Akshay 🚀 Profile picture
Jul 28 11 tweets 4 min read Read on X
Ditch "os.path" and master Python's pathlib module today:
Pathlib is a Python module that turns file system paths into easy-to-manage objects, making your code cleaner and more intuitive.

Today, I'll explain everything you need to know about pathlib!

Let's go! 🚀 Image
1️⃣ Importing

Pathlib comes as a builtin module in python, here's how you import it: Image
2️⃣ Creating Paths

Instead of dealing with file path strings, `pathlib` allows you to create path objects easily. Here's how you can define a path to your home directory: Image
3️⃣ Navigating with Paths

`pathlib` makes navigating through directories a breeze. Use the `/` operator to join paths intuitively: Image
4️⃣ Checking Path Existence

Before you perform any file operations, you can check if the path exists: Image
5️⃣ Reading & Writing Files

`pathlib` simplifies file operations. Here's how to write and then read from a file: Image
6️⃣ Listing Directory Contents

List all files in a directory with `iterdir`, and filter them easily with comprehensions: Image
8️⃣ Path Properties & working with parts of path

`pathlib` makes it easy to access path properties & different parts of a path, such as the parent directory, name of the file, or its suffix & more... Image
9️⃣ Getting File Size

You can call .stat() method on a Path object & it retrieves:

• File size
• Permissions
• Modification time
• Owner and group IDs

Here's how we can get file size using this: Image
If you're interested in:

- Python 🐍
- ML/AI Engineering ⚙️

Find me → @akshay_pachaar ✔️

Enjoyed this tutorial❓
Check out my book on Python: bit.ly/InstantPython
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

Jul 30
Self-attention in transformers clearly explained:
Before we start a quick primer on tokenization!

Raw text → Tokenization → Embedding → Model

Embedding is a meaningful representation of each token (roughly a word) using a bunch of numbers.

This embedding is what we provide as an input to our language models.

Check this👇 Image
The core idea of Language modelling is to understand the structure and patterns within language.

By modeling the relationships between words (tokens) in a sentence, we can capture the context and meaning of the text. Image
Read 9 tweets
Jul 26
Backpropagation in PyTorch, clearly explained:
Backpropagation is the key to optimizing our neural network by adjusting it's weights.

And it's done by calculating gradients of the loss function w.r.t. these weights!

Today, we learn how to do this using PyTorch...👇 Image
In PyTorch, a model is treated as a computational graph.

This graph is directed, with nodes representing variables or operations, and edges symbolizing the dependencies between them.

Now, both the forward and backward pass occur over this graph.

The image explains it further👇 Image
Read 6 tweets
Jul 24
Let's build a RAG app using MetaAI's Llama-3.1 (100% local):
Before we begin, take a look at what we're about to create!

Here's what you'll learn:

- @Llama_Index for orchestration
- @qdrant_engine to self-host a vector DB
- @Ollama for locally serving Llama-3.1
- @LightningAI for development & hosting

Let's go! 🚀
The architecture diagram presented below illustrates some of the key components & how they interact with each other!

It will be followed by detailed descriptions & code for each component: Image
Read 11 tweets
Jul 23
SQL Joins clearly explained:
Let's setup 2 DataFrames to perform merge operations & name them:

• left
• right

A, B, C are the common keys ✅

Check this 👇 Image
1️⃣ INNER Join:

Only returns the rows which share a common key on both left & right.

Image below should explain 👇 Image
Read 11 tweets
Jul 23
Illustrated Guide to Tensor Parallelism (supercharge your LLM training):
What is Tensor Parallelism?

Tensor Parallelism is form of model parallelism. It splits individual tensors across GPUs for efficient computation and memory use.

Perfect for training LLMs!

Let's simplify it today! 🚀 Image
There are two strategies:

1️⃣ Column-wise Parallelism

The weight matrix is split along the columns.

Each GPU gets the same input and performs matrix multiplication with its portion of the weights.

Outputs are concatenated. Image
Read 11 tweets
Jul 18
Let's implement & train this neural network step-by-step, from scratch using PyTorch!

1/n Image
First of all let's define our model in PyTorch:

2/n Image
Neural networks are universal function approximators. With data (input-output pairs), you can fit a function to them.

We'll train our network to act as an XOR Gate.

The code below defines our XOR dataset!

(I've shared a thread on PyTorch datasets at the end)

3/n Image
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!

:(