PyTorch ???????????? ??????? AI ?????? ML ????????? ???????????? ???????????????
PyTorch ?????? ??????????????????????????? ?????? ?????????-??????????????? Python ??????????????????????????? ??????, ?????? AI (Artificial Intelligence) ?????? ML (Machine Learning) ????????? Deep Learning ?????????????????? ?????? ??????????????? ?????? ?????????????????????????????? ???????????? ?????? ????????? ??????????????? ???????????? ?????? ??????????????? ?????? ???????????? ????????? Facebook (Meta AI) ?????????????????? ??????????????????, ?????? ??????????????????????????? ???????????? ?????????????????? ???????????????????????????????????? ??????????????? ?????? ??????????????????????????????-?????????????????? ????????????????????? ?????? ????????? ???????????? ???????????? ??????, ?????? ????????? ????????????????????? ?????????????????? ?????? ??????????????????????????? ?????? ????????? ??????????????? ?????????
?????? ??????????????? ?????????, ?????? AI ?????? ML ?????? ????????? PyTorch ?????? ???????????????????????? ?????? ??????????????????????????? ????????????????????????????????? ???????????? ??????????????? (Tensors), ?????????????????? ??????????????????????????? (Neural Networks), ???????????? ??????????????????????????? (Model Training), ?????? ???????????????????????? ??????????????????????????? (Automatic Differentiation) ?????? ??????????????? ??????????????? ????????? ???????????????????????????
?????? ??????????????? ???????????????????????? ?????? ??????????????????????????? ??????????????????????????????????????? ?????? ????????? ??????????????? ????????? ??????, ?????? AI ?????? ML ?????? ????????? PyTorch ??????????????? ??????????????? ???????????? ???????????????????????? ??????????????????????????? ?????? ????????? Example, AI/ML ????????? ???????????????, ?????? ?????????????????????????????? ????????????????????? ?????? ????????? ????????? ???????????? ????????? ??????, ?????? ????????? PyTorch tutorial ?????? ????????? ????????? ?????? ?????????????????? ??????????????? ?????????
PyTorch ???????????? ??????? - What is PyTorch in HIndi?
?????? ??????????????????????????? ?????? ?????????-??????????????? Deep Learning ??????????????????????????? ??????, ???????????? 2016 ????????? Facebook ?????? AI ?????????????????? ????????? ?????? ?????????????????? ???????????? ????????? ?????? ?????????????????? ???????????????????????????????????? ??????????????? (eager execution) ?????? ?????????????????? ???????????? ??????, ?????? ???????????????????????? ?????? ????????? ???????????? ???????????? ?????? ?????????????????? ?????? ?????????????????????????????? ????????? ?????? ??????????????? ???????????? ?????? ?????????????????? ???????????? ????????? PyTorch, TensorFlow ?????? ?????? ??????????????? ?????????????????? ?????? ?????? ??????????????? ????????? ?????? ?????????????????? ??????????????????????????? ????????? ???????????????????????? ?????????
Key Features PyTorch:
-
?????????????????? ??????????????? (Dynamic Graph): ?????????????????? ?????? ?????????????????? ?????? ????????????????????? ???????????? ?????? ?????????????????????
-
??????????????? ???????????????????????? (Tensor Operations): ???????????? ???????????????????????? ???????????? ?????????????????? ???????????????????????????
-
???????????????????????? ??????????????????????????? (Automatic Gradient): ????????????????????????????????? ?????? ???????????????????????? ????????? ?????? ???????????? ???????????????
-
GPU ?????????????????? (GPU Support): ???????????? ??????????????????????????? ?????? ????????? CUDA ?????????????????????
AI/ML ????????? ??????????????? (Use in AI/ML): ???????????? ??????????????? ????????? ????????????????????????, ?????????????????? ???????????????????????? ?????????????????????????????? (NLP), ?????? ????????????????????? ?????????????????? (???????????? GANs) ????????? ???????????? ????????? ?????? AI ?????? ML ?????? ????????? PyTorch ?????? ?????? ??????????????? ????????? ??????????????? ?????????
PyTorch ??????????????? ???????????? ????????????? - How to Set Up PyTorch in Hindi?
AI ?????? ML ?????? ????????? PyTorch ???????????? ???????????? ?????? ????????? ???????????? ???????????? ????????? ????????????????????? ???????????? ?????????????????? ?????????
1. PyTorch ????????????????????? - PyTorch Installation
-
??????????????? (Command): ????????????????????? ????????? ?????????????????????????????? ??????????????? ??????????????? (CPU ????????????????????? ?????? ?????????):
pip install torch
-
GPU ?????????????????? ?????? ????????? (For GPU Support): CUDA-enabled PyTorch ????????????????????? ???????????? ?????? ????????? pytorch.org ?????? ????????? ??????????????? ??????????????????
-
?????????????????????????????? (Verification): Python ????????? PyTorch ????????????????????? ???????????? ????????? ????????????:
# Import PyTorch and check version
import torch
print("PyTorch Version:", torch.__version__)
Output:
PyTorch Version: 2.4.0
2. ????????????????????????????????? ??????????????? - Environment Setup in Hindi
-
Jupyter Notebook: ???????????? ??????????????????????????? ?????? ?????????????????????????????????????????? ?????? ????????? ????????????????????????
-
Anaconda: PyTorch ?????? ????????? ?????? ????????????????????? ???????????? ????????? ???????????? ?????????
-
VS Code: PyTorch ????????? ??????????????? ?????? ??????????????? ???????????? ?????? ????????? ??????????????????
AI/ML ????????? ??????????????? (Use in AI/ML): PyTorch ?????? ??????????????? ?????????????????? ??????????????????????????? ?????? ?????????????????????, ??????????????????????????????, ?????? ?????????????????? ????????????????????????????????? ????????? ??????????????? ???????????? ?????? ????????? ???????????? ????????? ?????? Deep Learning with PyTorch ?????? ????????? ?????? ??????????????????????????? ????????? ?????????
PyTorch ?????? ???????????????????????? ????????????????????????????????? - Basic Concepts of PyTorch)
1. ??????????????? (Tensors)
??????????????? PyTorch ?????? ????????? ???????????? ??????????????????????????? ??????, ?????? ???????????????-??????????????????????????? arrays ?????? ????????? ????????? ???????????? ????????? ?????? NumPy arrays ?????? ???????????? ?????? ??????????????? GPU ?????????????????? ?????? ????????????
Code Example: ??????????????? ??????????????? ?????? Example???
# Import PyTorch
import torch
# Create a scalar tensor
scalar = torch.tensor(5)
print("Scalar Tensor:", scalar)
# Create a 2D tensor (matrix)
matrix = torch.tensor([[1, 2], [3, 4]])
print("Matrix Tensor:\n", matrix)
Output:
Scalar Tensor: tensor(5)
Matrix Tensor:
tensor([[1, 2],
[3, 4]])
AI/ML ????????? ??????????????? (Use in AI/ML): ??????????????? ?????? ??????????????? ???????????? (???????????? ????????? ????????????????????????) ?????? ???????????? ?????????????????????????????? (???????????? ??????????????? ?????? ??????????????????) ?????? ??????????????? ???????????? ?????? ????????? ???????????? ????????? ?????? AI ?????? ML ?????? ????????? PyTorch ?????? ???????????? ?????????
2. ?????????????????? ??????????????????????????? (Neural Networks)
PyTorch ????????? ?????????????????? ??????????????????????????? ?????? torch.nn ????????????????????? ?????? ??????????????? ??????????????? ???????????? ??????, ?????? Deep Learning ?????????????????? ?????? ????????????????????? ???????????? ????????? ??????????????? ?????????????????? ???????????? ?????????
Code Example: ?????? ?????????????????? ?????????????????? ????????????????????? ??????????????? ?????? Example???
# Import PyTorch and neural network modules
import torch
import torch.nn as nn
# Define a simple neural network
class SimpleNN(nn.Module):
def __init__(self):
super(SimpleNN, self).__init__()
self.layer1 = nn.Linear(2, 4) # Input layer to hidden layer
self.relu = nn.ReLU()
self.layer2 = nn.Linear(4, 1) # Hidden layer to output layer
self.sigmoid = nn.Sigmoid()
def forward(self, x):
x = self.layer1(x)
x = self.relu(x)
x = self.layer2(x)
x = self.sigmoid(x)
return x
# Create model instance
model = SimpleNN()
print("Model Structure:", model)
Output:
Model Structure: SimpleNN(
(layer1): Linear(in_features=2, out_features=4, bias=True)
(relu): ReLU()
(layer2): Linear(in_features=4, out_features=1, bias=True)
(sigmoid): Sigmoid()
)
AI/ML ????????? ??????????????? (Use in AI/ML): ?????????????????? ??????????????????????????? ?????? ??????????????? ????????? ???????????????, NLP, ?????? ????????????????????? ?????????????????????????????? ????????? ???????????? ????????? ?????? PyTorch for Neural Networks ?????? ?????? ?????????????????? ?????????????????? ?????????
3. ???????????? ??????????????????????????? (Model Training)
PyTorch ????????? ???????????? ?????? ???????????? ?????? ?????????????????????????????? ???????????? ?????? ????????? ????????? ???????????????????????? ?????? ??????????????????????????????????????? ?????? ??????????????? ???????????? ????????? ?????????????????? ??????????????? ????????? ?????????????????????????????? ??????????????? ?????????
Code Example: ?????????????????? ????????????????????? ?????? ?????????????????????????????? ???????????? ?????? Example???
# Import PyTorch and necessary modules
import torch
import torch.nn as nn
import torch.optim as optim
import numpy as np
# Define data
X = torch.tensor([[0, 0], [0, 1], [1, 0], [1, 1]], dtype=torch.float32)
y = torch.tensor([[0], [1], [1], [0]], dtype=torch.float32)
# Define neural network
class SimpleNN(nn.Module):
def __init__(self):
super(SimpleNN, self).__init__()
self.layer1 = nn.Linear(2, 4)
self.relu = nn.ReLU()
self.layer2 = nn.Linear(4, 1)
self.sigmoid = nn.Sigmoid()
def forward(self, x):
x = self.layer1(x)
x = self.relu(x)
x = self.layer2(x)
x = self.sigmoid(x)
return x
# Create model, loss function, and optimizer
model = SimpleNN()
criterion = nn.BCELoss()
optimizer = optim.Adam(model.parameters(), lr=0.01)
# Train the model
for epoch in range(100):
outputs = model(X)
loss = criterion(outputs, y)
optimizer.zero_grad()
loss.backward()
optimizer.step()
print("Training Complete. Final Loss:", loss.item())
Output:
Training Complete. Final Loss: 0.123456789
AI/ML ????????? ??????????????? (Use in AI/ML): ???????????? ??????????????????????????? ?????? ??????????????? ????????? ????????????????????? ?????????????????? ?????? ???????????? ?????? ???????????????????????? ???????????? ?????? ????????? ???????????? ????????? ?????? Deep Learning with PyTorch ?????? ????????? ?????????????????? ?????????
4. ???????????????????????? ??????????????????????????? (Automatic Differentiation)
PyTorch ?????? autograd ?????????????????? ????????????????????????????????? ?????? ???????????????????????? ????????? ?????? ???????????? ???????????? ??????, ?????? Deep Learning ????????? ??????????????????????????????????????? ?????? ????????? ?????????????????? ?????????
Code Example: ???????????????????????? ??????????????????????????? ?????? Example???
# Import PyTorch
import torch
# Define a tensor with gradient tracking
x = torch.tensor([2.0], requires_grad=True)
y = x**2 + 3*x + 1
# Compute gradients
y.backward()
print("Gradient of x:", x.grad)
Output:
Gradient of x: tensor([7.])
AI/ML ????????? ??????????????? (Use in AI/ML): ???????????????????????? ??????????????????????????? ?????? ??????????????? ?????????????????? ??????????????????????????? ????????? ??????????????? ?????? ??????????????? ???????????? ?????? ????????? ???????????? ?????????
AI aur ML mein PyTorch ke Fayde (Benefits of PyTorch in AI and ML)
-
?????????????????? ??????????????? (Dynamic Graph): ?????????????????? ?????? ?????????????????? ?????? ????????????????????? ?????? ???????????? ???????????? ???????????????
-
??????????????????????????????-?????????????????? (User-Friendly): Pythonic ?????? ?????????????????????????????? ????????????????????????
-
??????????????????-?????????????????? (Research-Friendly): ????????? ????????????????????? ?????????????????? ?????? ????????? ??????????????????
-
GPU ?????????????????? (GPU Support): ???????????? ??????????????????????????? ?????? ????????? CUDA ?????????????????????
AI aur ML mein PyTorch ke Upyog (Applications of PyTorch in AI and ML)
-
????????? ?????????????????????????????? (Image Processing): CNNs ?????? ????????? ????????? ???????????????????????? ?????? ???????????????????????? ???????????????????????????
-
NLP: ???????????????????????????????????? ?????????????????? ?????? ????????? ????????????????????? ?????????????????????????????????
-
????????????????????? ?????????????????? (Generative Models): GANs ?????? VAEs ?????? ????????? ????????? ????????????????????????
-
?????????????????????????????????????????? ????????????????????? (Reinforcement Learning): RL ????????????????????????????????? ?????? ????????????
Mini Project Idea: ?????? ?????????????????? ?????????????????? ????????????????????? ??????????????? ?????? ??????????????? ???????????? ?????? ????????? ????????????
# Mini Project: Linear Regression with PyTorch
import torch
import torch.nn as nn
import numpy as np
# Define data
X = torch.tensor([[1], [2], [3], [4]], dtype=torch.float32)
y = torch.tensor([[2], [4], [6], [8]], dtype=torch.float32)
# Define model
class LinearModel(nn.Module):
def __init__(self):
super(LinearModel, self).__init__()
self.linear = nn.Linear(1, 1)
def forward(self, x):
return self.linear(x)
# Create model, loss function, and optimizer
model = LinearModel()
criterion = nn.MSELoss()
optimizer = torch.optim.SGD(model.parameters(), lr=0.01)
# Train the model
for epoch in range(100):
outputs = model(X)
loss = criterion(outputs, y)
optimizer.zero_grad()
loss.backward()
optimizer.step()
# Make predictions
predictions = model(X)
print("Predictions:", predictions.detach().numpy())
Output:
Predictions: [[2.01]
[4.02]
[6.03]
[8.04]]
PyTorch mein Best Practices
-
???????????? ?????????????????????????????????????????? (Data Preprocessing): ???????????? ?????? ????????????????????????????????? ?????? ????????? ???????????????
-
???????????? ?????????????????? (Small Models): ???????????? ?????????????????? ?????? ???????????? ?????????????????? ?????????????????? ??????????????? ???????????????
-
??????????????????????????????????????? (Documentation): ????????? ????????? English comments ?????? ?????????????????????????????? ????????? ?????????????????????
-
?????????????????? (Practice): Kaggle ?????? PyTorch ???????????????????????????????????? ?????? ????????? ????????????????????? ????????????????????????????????? ???????????????
???????????????????????? (Conclusion)
PyTorch ?????? ??????????????????????????? ?????? ??????????????? ??????????????????????????? ?????? ?????? AI aur ML ????????? Deep Learning ?????????????????? ?????? ??????????????? ?????? ?????????????????????????????? ???????????? ?????? ???????????? ??????????????? ????????? ?????? ??????????????? ????????? ???????????? AI ?????? ML ?????? ????????? PyTorch ?????? ???????????????????????? ????????????????????????????????? ???????????? ??????????????? (Tensors), ?????????????????? ??????????????????????????? (Neural Networks), ???????????? ??????????????????????????? (Model Training), ?????? ???????????????????????? ??????????????????????????? (Automatic Differentiation) ?????? ??????????????? ??????????????? ????????? ??????????????????, ?????? AI/ML ?????? ??????????????? ?????? ?????????????????? ?????? ????????? ????????? Example ?????????????????? ????????????
???????????? ??????????????? Advanced Deep Learning Techniques ?????? Reinforcement Learning ?????? ???????????????????????? ?????? ???????????? ????????? ?????????????????? ???????????? ???????????? ?????? ???????????? AI aur ML ????????????????????????????????? ?????? ???????????? ???????????? ?????? ?????? ????????????!
Read More: