Akshay 🚀 Profile picture
Jul 28, 2024 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 25
How LLMs train LLMs, clearly explained (with visuals):
LLMs learn not only from raw text but also from other models.

Google’s Gemma 2 and 3, for example, were distilled from the larger Gemini model.

Today we cover, the three most common knowledge‑distillation methods.

Let's dive in! 🚀
1️⃣ Soft-label Distillation

Generate token-level softmax probabilities over the entire corpus using:

- A frozen, pre-trained Teacher LLM
- An untrained Student LLM

Train the Student LLM to match the Teacher's probabilities.

Check this out👇
Read 10 tweets
Jul 23
I just built the ultimate MCP server for Multimodal AI.

It lets you do RAG over audio, video, images and text!

100% open-source, here's the full breakdown...👇
Before we dive in, here's a quick demo of what we're building!

Tech stack:

- @pixeltablehq to build the multi-modal AI infrastructure
- @crewAIInc to orchestrate the agentic workflow

Quickly check the thread, then return here for a detailed overview. 🚀
First of all, what is Pixeltable?

Pixeltable is a go-to Python library for Multimodal AI—streamlining entire pipeline from data storage to model execution.

Handles images, videos, text & audio effortlessly.

Our MCP servers are built on top of Pixeltable.
Read 15 tweets
Jul 21
Transformer vs. Mixture of Experts in LLMs, clearly explained (with visuals):
Mixture of Experts (MoE) is a popular architecture that uses different "experts" to improve Transformer models.

The visual below explains how they differ from Transformers.

Let's dive in to learn more about MoE!
Transformer and MoE differ in the decoder block:

- Transformer uses a feed-forward network.
- MoE uses experts, which are feed-forward networks but smaller compared to that in Transformer.

During inference, a subset of experts are selected. This makes inference faster in MoE.
Read 10 tweets
Jul 20
MCP security is completely broken!

Let's understand tool poisoning attacks and how to defend against them:
MCP allows AI agents to connect with external tools and data sources through a plugin-like architecture.

It's rapidly taking over the AI agent landscape with millions of requests processed daily.

But there's a serious problem... 👇
1️⃣ What is a Tool Poisoning Attack (TPA)?

When Malicious instructions are hidden within MCP tool descriptions that are:

❌ Invisible to users
✅ Visible to AI models

These instructions trick AI models into unauthorized actions, unnoticed by users.
Read 13 tweets
Jul 17
10 GitHub repos that will set you up for a career in AI engineering (100% free):
1️⃣ ML for Beginners by Microsoft

A 12-week project-based curriculum that teaches classical ML using real-world datasets using Scikit-learn.

Includes quizzes, R/Python lessons, and hands-on projects. Some of the lessons are available as short-form videos.

Check this👇 Image
2️⃣ AI for Beginners by Microsoft

This repo covers neural networks, NLP, CV, transformers, ethics & more. There are hands-on labs in PyTorch & TensorFlow using jupyter notebooks.

Beginner-friendly, project-based, and full of real-world applications.

Check this 👇 Image
Read 13 tweets
Jul 16
Let's build a multi-agent content creation system (100% local):
Before we dive in, here's a quick demo of what we're building!

Tech stack:

- @motiadev as the unified backend framework
- @firecrawl_dev to scrape web content
- @ollama to locally serve Deepseek-R1 LLM

The only AI framework you'll ever need to learn! 🚀
Here's the workflow:

- User submits URL to scrape
- Firecrawl scrapes content and converts it to markdown
- Twitter and LinkedIn agents run in parallel to generate content
- Generated content gets scheduled via Typefully

Now, let's dive into code!
Read 14 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!

:(