Machine Learning
40.5K subscribers
3.63K photos
29 videos
47 files
661 links
Real Machine Learning — simple, practical, and built on experience.
Learn step by step with clear explanations and working code.

Admin: @HusseinSheikho || @Hussein_Sheikho
Download Telegram
🤖 Calculating the Self-Attention mechanism in pure PyTorch.

The Attention Mechanism allows transformer neural networks to determine the connection between words in a text and dynamically focus on the most important context. We will step by step implement the basic algorithm Scaled Dot-Product Attention, using classic matrices of queries (Query), keys (Key) and values (Value). This will help us to visually see how the attention weights are mathematically calculated and how the model matches the tokens with each other. 🧠

To start, we will install the PyTorch library for performing tensor calculations. 🛠️

pip install torch

The library has been successfully loaded and is ready for mathematical modeling of transformer layers.

We will generate random vectors Query, Key and Value to simulate the passage of tokens through linear projections. 🎲

import torch
import torch.nn.functional as F

q = torch.randn(1, 3, 4) # (batch, seq_len, dim)
k = torch.randn(1, 3, 4)
v = torch.randn(1, 3, 4)

The tensors have been initialized and represent three hidden states for a sequence of three words. 📝

We will calculate the token similarity matrix through the scalar product and then scale it by the square root of the vector dimensions. 🔢

scores = torch.bmm(q, k.transpose(1, 2)) / (q.shape[-1] ** 0.5)
attention_weights = F.softmax(scores, dim=-1)
output = torch.bmm(attention_weights, v)

The scalar product has been translated into probability weights, based on which the final contextual vector has been formed. 🔄

A control run of the output dimension calculation:

python3 -c "import torch; q, k = torch.randn(1, 3, 4), torch.randn(1, 3, 4); print('Attention OK') if torch.bmm(q, k.transpose(1, 2)).shape == (1, 3, 3) else print('Error')"

Expected output: Attention OK

The Self-Attention formula lies at the heart of all modern LLMs, allowing them to process long contexts in parallel, unlike old recurrent networks (RNNs). Understanding this base is critically important for working with transformers, optimizing architectures and configuring KV-cache mechanisms. 🚀🧠

#PyTorch #Transformer #DeepLearning #AI #MachineLearning #LLM

Join Best TG Channels https://t.iss.one/addlist/0f6vfFbEMdAwODBk

⭐️ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A

🚀 Level up your AI & Data Science skills with HelloEncyclo — a growing all-in-one platform featuring hands-on courses in LLMs, Deep Learning, MLOps, Data Engineering, and more.
13 courses live + 40+ coming soon
🎯 One access, lifetime updates
🔑 Use code: PRESALE-BOOK-WAVE-2GFG
👉 https://helloencyclo.com/?ref=HUSSEINSHEIKHO
Please open Telegram to view this post
VIEW IN TELEGRAM
5
Classical machine learning equations and diagrams cheat sheet 📊

https://github.com/soulmachine/machine-learning-cheat-sheet

#MachineLearning #ML #DataScience #CheatSheet #AI #DeepLearning

Join Best TG Channels https://t.iss.one/addlist/0f6vfFbEMdAwODBk

⭐️ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A

🚀 Level up your AI & Data Science skills with HelloEncyclo — a growing all-in-one platform featuring hands-on courses in LLMs, Deep Learning, MLOps, Data Engineering, and more.
13 courses live + 40+ coming soon
🎯 One access, lifetime updates
🔑 Use code: PRESALE-BOOK-WAVE-2GFG
👉 https://helloencyclo.com/?ref=HUSSEINSHEIKHO
3
This media is not supported in your browser
VIEW IN TELEGRAM
Multi-agent RL is beautiful precisely at the moment when it starts to converge. 🤖

#MultiAgent #RL #ReinforcementLearning #AI #MachineLearning #DeepLearning

Join Best TG Channels https://t.iss.one/addlist/0f6vfFbEMdAwODBk

⭐️ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A

🚀 Level up your AI & Data Science skills with HelloEncyclo — a growing all-in-one platform featuring hands-on courses in LLMs, Deep Learning, MLOps, Data Engineering, and more.
13 courses live + 40+ coming soon
🎯 One access, lifetime updates
🔑 Use code: PRESALE-BOOK-WAVE-2GFG
👉 https://helloencyclo.com/?ref=HUSSEINSHEIKHO
1🤩1
500 AI/ML/Computer Vision/NLP projects with code 🚀

This is a large collection of 500 ready-made projects in the field of machine learning, deep learning, computer vision, and NLP 🧠

All examples come with code, so you can not just read them, but immediately analyze and run them ⚙️

➡️ Link to GitHub:
https://github.com/ashishpatel26/500-AI-Machine-learning-Deep-learning-Computer-vision-NLP-Projects-with-code

#AI #MachineLearning #DeepLearning #ComputerVision #NLP #DataScience

Join Best TG Channels https://t.iss.one/addlist/0f6vfFbEMdAwODBk

⭐️ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A
4
A Chinese developer has released an open-source replacement for NumPy that performs calculations on GPUs. It's called CuPy 🚀. In many cases, it's enough to replace a single line:

import cupy as cp

The same code can run on CUDA up to 100 times faster ⚡️.

What it can do:
→ Compatible with existing NumPy and SciPy code 🛠️.
→ No need to rewrite the program or learn new syntax 📝.
→ Supports not only CUDA but also AMD ROCm 💻.

The project is completely open-source 📂:
🔗 https://github.com/cupy/cupy

#Python #GPU #NumPy #CuPy #AI #DeepLearning

Join Best TG Channels https://t.iss.one/addlist/0f6vfFbEMdAwODBk

⭐️ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A
5
Reinforcement Learning Methods and Tutorials 🧠📚

In these tutorials for reinforcement learning, it covers from the basic RL algorithms to advanced algorithms developed recent years.

Learning Resources: https://github.com/MorvanZhou/Reinforcement-learning-with-tensorflow 🚀

Here's a collection of simple materials on methods and practical guides, covering both basic reinforcement learning algorithms and modern, recently developed, and updated advanced algorithms. 📖

#ReinforcementLearning #MachineLearning #AI #DeepLearning #TechTutorials #DataScience

Join Best TG Channels https://t.iss.one/addlist/0f6vfFbEMdAwODBk

⭐️ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A
5
Diving deep into Deep Learning, Reinforcement Learning, Machine Learning, Computer Vision, and NLP. 🤖🧠

Lectures: 🎓📚
https://github.com/kmario23/deep-learning-drizzle

#DeepLearning #MachineLearning #AI #ReinforcementLearning #ComputerVision #NLP

Join Best TG Channels https://t.iss.one/addlist/0f6vfFbEMdAwODBk

⭐️ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A
6
This repository contains a collection of the best resources on PyTorch: https://github.com/ritchieng/the-incredible-pytorch

Join Best TG Channels https://t.iss.one/addlist/0f6vfFbEMdAwODBk

⭐️ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A

#PyTorch #AI #MachineLearning #DeepLearning #Coding #Resources
6
🔖 A large collection of lectures on Machine Learning and Deep Learning 🧠

We found a repository that brings together high-quality materials on several areas of artificial intelligence. 🤖

Excellent material for both learning and reviewing key topics. 📚

⛓️ Link to GitHub
https://github.com/kmario23/deep-learning-drizzle

#MachineLearning #DeepLearning #AI #Tech #Coding #Learning

Join Best TG Channels https://t.iss.one/addlist/0f6vfFbEMdAwODBk

⭐️ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A
5
This media is not supported in your browser
VIEW IN TELEGRAM
sequence of four inputs, carrying every hidden state forward yourself. 🔄

1. Given

Four inputs X1 to X4, recurrent weights and biases for hidden layers a, b, c, and an output layer y. 📊

2. Initialize

Let us set the hidden states a0, b0, c0 to zeros. Nothing has been read yet. 🛑

3. First hidden layer (a)

We build the transformation matrix by laying the input weights, the state weights and the biases side by side. We stack X1, the previous state a0, and an extra 1 underneath. Multiply the two, and a1 = [0, 1]. 🧮

4. Second hidden layer (b)

Let us do it again, one layer up. Now a1 is the input, and b0 is the previous state. Multiply: b1 = [1, -1]. ⬆️

5. Third hidden layer (c)

Once more. b1 is the input, c0 is the previous state, and c1 = [1, 1]. 🔁

6. Output layer (y)

Let us read the answer off the top of the stack. Weights and biases against [c1; 1], and Y1 = [3, 0, 3]. 📝

7. Carry the states forward

We copy a1, b1, c1 across. This is the whole trick of a recurrent network: the states are the only thing the next input gets to see. 🚀

8. Process X2

Repeat steps 3 to 6 for the second input: three hidden layers, then the output. Y2 = [5, 0, 4]. 🔢

9. Carry the states forward

Let us copy a2, b2, c2 across, exactly as before. 🔄

10. Process X3

Same four moves, third input. Y3 = [13, -1, 9]. 🧩

11. Carry the states forward

We copy a3, b3, c3 across, one last time. ⏭️

12. Process X4

Repeat once more. Y4 = [15, 7, 2].

You have just run a Deep RNN over a whole sequence by hand. ✍️

The outputs:
Y1: [3, 0, 3]
Y2: [5, 0, 4]
Y3: [13, -1, 9]
Y4: [15, 7, 2]

The takeaway: the hidden states are the memory, and they are the only memory there is. Everything the network learns from X1 has to fit in those little two-cell columns and get handed forward, one step at a time. 🧠

#RNN #DeepLearning #AI #MachineLearning #NeuralNetworks #Tech

Join Best TG Channels https://t.iss.one/addlist/0f6vfFbEMdAwODBk
⭐️ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A
5👍1💩1