🧩 Deep Learning Frameworks: TensorFlow & PyTorch
Deep Learning models को scratch से implement करना बहुत complex और time-consuming होता है। इस समस्या को solve करने के लिए TensorFlow और PyTorch जैसे frameworks बनाए गए हैं। ये high-level APIs provide करते हैं जिससे developers और researchers आसानी से models बना, train और deploy कर सकते हैं।
💻 Example (Keras API):
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
# Model definition
model = Sequential([
Dense(64, activation='relu', input_shape=(10,)),
Dense(32, activation='relu'),
Dense(1, activation='sigmoid')
])
# Compile
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
💻 Example (PyTorch):
import torch
import torch.nn as nn
import torch.optim as optim
# Model definition
class SimpleNN(nn.Module):
def __init__(self):
super(SimpleNN, self).__init__()
self.fc1 = nn.Linear(10, 64)
self.fc2 = nn.Linear(64, 32)
self.fc3 = nn.Linear(32, 1)
def forward(self, x):
x = torch.relu(self.fc1(x))
x = torch.relu(self.fc2(x))
x = torch.sigmoid(self.fc3(x))
return x
# Initialize model
model = SimpleNN()
criterion = nn.BCELoss()
optimizer = optim.Adam(model.parameters(), lr=0.001)