अब जब आपने Deep Learning के theory और models (जैसे CNN, RNN, BERT) अच्छे से समझ लिए हैं —
तो अगला practical step है:
⚙️ TensorFlow और Keras के साथ Deep Learning models बनाना सीखना।
🔷 1. TensorFlow क्या है?
TensorFlow एक open-source deep learning framework है जिसे Google ने बनाया है।
यह numerical computation और large-scale machine learning models के लिए design किया गया है।
🧠 TensorFlow का नाम “Tensor” (data structure) + “Flow” (computation graph) से आया है।
✅ Key Features:
Feature | Detail |
---|---|
📊 Automatic Differentiation | Gradient calculation |
🧮 GPU/TPU Support | तेज़ computation |
🧠 High-level + Low-level APIs | Flexibility |
🔧 Deployment | Android, Web, Edge devices |
🤝 Ecosystem | TF Hub, TF Lite, TF.js, TF-Serving |
🔷 2. Keras क्या है?
Keras एक high-level deep learning API है, जो TensorFlow के ऊपर चलता है।
यह models को लिखना, train करना और debug करना बहुत आसान बना देता है।
🎯 “Keras = Simplicity + Productivity + Modularity”
✅ Keras क्यों चुनें?
Benefit | Reason |
---|---|
🚀 Easy to Learn | Pythonic syntax |
🧩 Modular | Layers, Optimizers, Loss अलग-अलग |
🧠 Powerful | Advanced models possible |
🔧 Fast prototyping | जल्दी result देखने के लिए |
🔌 TF Backend | TensorFlow की ताकत use करता है |
🔷 3. Tensor, Model, and Layer Basics
🔹 Tensor:
Multidimensional array (जैसे NumPy array, लेकिन GPU-compatible)
import tensorflow as tf
x = tf.constant([[1, 2], [3, 4]])
print(x.shape) # (2, 2)
🔹 Layer:
Neural network का एक building block (Dense, Conv2D, LSTM)
from tensorflow.keras.layers import Dense
dense = Dense(units=64, activation='relu')
🔹 Model:
Input से Output तक का पूरा network architecture
from tensorflow.keras.models import Sequential
model = Sequential([
Dense(128, activation='relu'),
Dense(10, activation='softmax')
])
🔷 4. Keras में Model बनाना (Step-by-Step)
✅ Step 1: Import
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
✅ Step 2: Model Define
model = Sequential([
Dense(64, activation='relu', input_shape=(100,)),
Dense(10, activation='softmax')
])
✅ Step 3: Compile
model.compile(
optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy']
)
✅ Step 4: Train
model.fit(x_train, y_train, epochs=10, batch_size=32)
✅ Step 5: Evaluate
model.evaluate(x_test, y_test)
🧪 Example: Simple Binary Classifier
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
model = Sequential([
Dense(16, activation='relu', input_shape=(2,)),
Dense(1, activation='sigmoid')
])
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
model.fit(X_train, y_train, epochs=20)
🔧 Useful Layers in Keras
Layer | Use |
---|---|
Dense | Fully connected layer |
Conv2D | Image convolution layer |
LSTM / GRU | Sequence modeling |
Dropout | Regularization |
Flatten | Input flattening |
Embedding | Word embedding for NLP |
🧠 Visualization: Model Summary
model.summary()
📝 Practice Questions:
- TensorFlow और Keras में क्या अंतर है?
- Sequential model क्या होता है?
- Model को compile करने में किन चीज़ों की ज़रूरत होती है?
- Dense layer क्या है?
- एक simple 3-layer model का कोड लिखिए।
🧠 Summary Table
Concept | Description |
---|---|
TensorFlow | Google का ML framework |
Keras | Easy high-level API |
Tensor | Multidimensional data |
Layer | Model का हिस्सा (Dense, Conv) |
Model | Complete NN architecture |