pykeres 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pykeres-1.0.0/PKG-INFO +128 -0
- pykeres-1.0.0/README.md +116 -0
- pykeres-1.0.0/pyproject.toml +29 -0
- pykeres-1.0.0/setup.cfg +4 -0
- pykeres-1.0.0/setup.py +15 -0
- pykeres-1.0.0/src/keres/__init__.py +100 -0
- pykeres-1.0.0/src/keres/cli.py +64 -0
- pykeres-1.0.0/src/keres/data/__init__.py +1 -0
- pykeres-1.0.0/src/keres/data/mock_practical.txt +220 -0
- pykeres-1.0.0/src/keres/data/practical_01.txt +204 -0
- pykeres-1.0.0/src/keres/data/practical_02.txt +277 -0
- pykeres-1.0.0/src/keres/data/practical_03.txt +196 -0
- pykeres-1.0.0/src/keres/data/practical_04.txt +205 -0
- pykeres-1.0.0/src/keres/data/practical_05.txt +229 -0
- pykeres-1.0.0/src/keres/data/practical_06.txt +181 -0
- pykeres-1.0.0/src/keres/data/practical_07.txt +133 -0
- pykeres-1.0.0/src/keres/data/practical_08.txt +156 -0
- pykeres-1.0.0/src/keres/data/practicals_data.json +393 -0
- pykeres-1.0.0/src/keres/guide.py +274 -0
- pykeres-1.0.0/src/pykeres.egg-info/PKG-INFO +128 -0
- pykeres-1.0.0/src/pykeres.egg-info/SOURCES.txt +22 -0
- pykeres-1.0.0/src/pykeres.egg-info/dependency_links.txt +1 -0
- pykeres-1.0.0/src/pykeres.egg-info/entry_points.txt +2 -0
- pykeres-1.0.0/src/pykeres.egg-info/top_level.txt +1 -0
pykeres-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pykeres
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: pykeres: Deep Learning Practicals Code Guide Library with Cell-by-Cell Notebook Implementations and Viva Cheat Sheets
|
|
5
|
+
Author-email: Shreyas Daptare <shreyas@example.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Operating System :: OS Independent
|
|
9
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
10
|
+
Requires-Python: >=3.8
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
|
|
13
|
+
# keres
|
|
14
|
+
|
|
15
|
+
A weirdly named, ultra-handy Python code guide library containing cell-by-cell implementations of Deep Learning Lab Practicals (Roll No. 23 - Shreyas Daptare).
|
|
16
|
+
|
|
17
|
+
Inspired by the `MLExamples` cheat-sheet pattern in `seaborne`, `keres` stores Jupyter notebooks converted into structured, cell-by-cell plaintext that can be browsed interactively, printed, extracted, or exported back into standalone Python scripts or Jupyter Notebooks.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
Install in development/editable mode:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
cd keres
|
|
27
|
+
pip install -e .
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Or direct pip install:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pip install ./keres
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## Python API Usage
|
|
39
|
+
|
|
40
|
+
### Built-in Interactive Guide & Cheat Sheet
|
|
41
|
+
```python
|
|
42
|
+
import keres
|
|
43
|
+
|
|
44
|
+
# Open built-in interactive guide
|
|
45
|
+
keres.guide() # or keres.help()
|
|
46
|
+
|
|
47
|
+
# View quick tweak recipes for exams/viva:
|
|
48
|
+
keres.tweaks(2) # Swapping FashionMNIST with Pandas local CSV, Adam to SGD, Dropout
|
|
49
|
+
keres.tweaks(7) # MobileNetV2 -> ResNet/EfficientNet, 10x smaller fine-tuning lr rule
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Direct Module Access (Quickest)
|
|
53
|
+
```python
|
|
54
|
+
import keres
|
|
55
|
+
|
|
56
|
+
# List all available practicals
|
|
57
|
+
keres.list_practicals()
|
|
58
|
+
|
|
59
|
+
# Print practicals cell-by-cell
|
|
60
|
+
keres.practical_1()
|
|
61
|
+
keres.practical_2(tweaks=True) # Full code + viva tweak recipes appended
|
|
62
|
+
keres.mock_practical()
|
|
63
|
+
|
|
64
|
+
# Inspect a single cell (1-based index)
|
|
65
|
+
keres.practical_1(cell=1) # View Cell 1 only (AND Gate Perceptron)
|
|
66
|
+
keres.practical_1(cell=2) # View Cell 2 only (OR Gate Perceptron)
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Class-based Access (`Keres`)
|
|
70
|
+
```python
|
|
71
|
+
from keres import Keres
|
|
72
|
+
|
|
73
|
+
guide = Keres()
|
|
74
|
+
|
|
75
|
+
# Programmatic retrieval
|
|
76
|
+
code_str = guide.get_practical(num=3)
|
|
77
|
+
cells = guide.get_cells(num=3)
|
|
78
|
+
for c in cells:
|
|
79
|
+
print(f"Cell {c['cell_number']}: {c['title']}")
|
|
80
|
+
|
|
81
|
+
# Exporting utilities
|
|
82
|
+
guide.export_all_texts("./my_txt_notes")
|
|
83
|
+
guide.export_script(num=1, output_path="run_practical_1.py")
|
|
84
|
+
guide.export_notebook(num=1, output_path="practical_1.ipynb")
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## CLI Usage
|
|
90
|
+
|
|
91
|
+
`keres` provides an intuitive command-line interface:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
# Display built-in guide & cheat sheet
|
|
95
|
+
keres guide # or simply run: keres
|
|
96
|
+
|
|
97
|
+
# List all practicals
|
|
98
|
+
keres list
|
|
99
|
+
|
|
100
|
+
# Display a practical cell-by-cell
|
|
101
|
+
keres show 1
|
|
102
|
+
keres show 2 --tweaks
|
|
103
|
+
|
|
104
|
+
# Display a specific cell only
|
|
105
|
+
keres show 1 --cell 2
|
|
106
|
+
|
|
107
|
+
# View only the quick tweak recipe (Pandas CSV, Optimizers, Viva notes)
|
|
108
|
+
keres tweaks 2
|
|
109
|
+
|
|
110
|
+
# Export all practicals as text files
|
|
111
|
+
keres export --out-dir ./my_txt_notes
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## Practical Index
|
|
117
|
+
|
|
118
|
+
| Practical | Title / Topic | Framework | Cells |
|
|
119
|
+
| :--- | :--- | :--- | :---: |
|
|
120
|
+
| **Mock Practical** | Neural Network Training with Different Loss Functions | PyTorch | 5 |
|
|
121
|
+
| **Practical 01** | Single-Layer Perceptron (AND & OR Gate Decision Boundaries) | NumPy / Matplotlib | 2 |
|
|
122
|
+
| **Practical 02** | Multi-Layer Perceptron (MLP) Comparison on Fashion-MNIST | PyTorch / Torchvision | 8 |
|
|
123
|
+
| **Practical 03** | Regularization Techniques (L2 Weight Decay vs Dropout) | TensorFlow / Keras | 6 |
|
|
124
|
+
| **Practical 04** | Activation Functions Analysis (Sigmoid, Tanh, ReLU, LeakyReLU) | PyTorch | 5 |
|
|
125
|
+
| **Practical 05** | Convolutional Neural Networks (CNN) vs MLP for Image Classification | PyTorch / Torchvision | 10 |
|
|
126
|
+
| **Practical 06** | Recurrent Neural Networks (LSTM) for IMDB Sentiment Classification | TensorFlow / Keras | 6 |
|
|
127
|
+
| **Practical 07** | Transfer Learning & Fine-Tuning with MobileNetV2 | TensorFlow / Keras | 6 |
|
|
128
|
+
| **Practical 08** | Hyperparameter Optimization & TensorBoard Visualization | PyTorch / TensorBoard | 5 |
|
pykeres-1.0.0/README.md
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# keres
|
|
2
|
+
|
|
3
|
+
A weirdly named, ultra-handy Python code guide library containing cell-by-cell implementations of Deep Learning Lab Practicals (Roll No. 23 - Shreyas Daptare).
|
|
4
|
+
|
|
5
|
+
Inspired by the `MLExamples` cheat-sheet pattern in `seaborne`, `keres` stores Jupyter notebooks converted into structured, cell-by-cell plaintext that can be browsed interactively, printed, extracted, or exported back into standalone Python scripts or Jupyter Notebooks.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
Install in development/editable mode:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
cd keres
|
|
15
|
+
pip install -e .
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Or direct pip install:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pip install ./keres
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Python API Usage
|
|
27
|
+
|
|
28
|
+
### Built-in Interactive Guide & Cheat Sheet
|
|
29
|
+
```python
|
|
30
|
+
import keres
|
|
31
|
+
|
|
32
|
+
# Open built-in interactive guide
|
|
33
|
+
keres.guide() # or keres.help()
|
|
34
|
+
|
|
35
|
+
# View quick tweak recipes for exams/viva:
|
|
36
|
+
keres.tweaks(2) # Swapping FashionMNIST with Pandas local CSV, Adam to SGD, Dropout
|
|
37
|
+
keres.tweaks(7) # MobileNetV2 -> ResNet/EfficientNet, 10x smaller fine-tuning lr rule
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Direct Module Access (Quickest)
|
|
41
|
+
```python
|
|
42
|
+
import keres
|
|
43
|
+
|
|
44
|
+
# List all available practicals
|
|
45
|
+
keres.list_practicals()
|
|
46
|
+
|
|
47
|
+
# Print practicals cell-by-cell
|
|
48
|
+
keres.practical_1()
|
|
49
|
+
keres.practical_2(tweaks=True) # Full code + viva tweak recipes appended
|
|
50
|
+
keres.mock_practical()
|
|
51
|
+
|
|
52
|
+
# Inspect a single cell (1-based index)
|
|
53
|
+
keres.practical_1(cell=1) # View Cell 1 only (AND Gate Perceptron)
|
|
54
|
+
keres.practical_1(cell=2) # View Cell 2 only (OR Gate Perceptron)
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Class-based Access (`Keres`)
|
|
58
|
+
```python
|
|
59
|
+
from keres import Keres
|
|
60
|
+
|
|
61
|
+
guide = Keres()
|
|
62
|
+
|
|
63
|
+
# Programmatic retrieval
|
|
64
|
+
code_str = guide.get_practical(num=3)
|
|
65
|
+
cells = guide.get_cells(num=3)
|
|
66
|
+
for c in cells:
|
|
67
|
+
print(f"Cell {c['cell_number']}: {c['title']}")
|
|
68
|
+
|
|
69
|
+
# Exporting utilities
|
|
70
|
+
guide.export_all_texts("./my_txt_notes")
|
|
71
|
+
guide.export_script(num=1, output_path="run_practical_1.py")
|
|
72
|
+
guide.export_notebook(num=1, output_path="practical_1.ipynb")
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## CLI Usage
|
|
78
|
+
|
|
79
|
+
`keres` provides an intuitive command-line interface:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
# Display built-in guide & cheat sheet
|
|
83
|
+
keres guide # or simply run: keres
|
|
84
|
+
|
|
85
|
+
# List all practicals
|
|
86
|
+
keres list
|
|
87
|
+
|
|
88
|
+
# Display a practical cell-by-cell
|
|
89
|
+
keres show 1
|
|
90
|
+
keres show 2 --tweaks
|
|
91
|
+
|
|
92
|
+
# Display a specific cell only
|
|
93
|
+
keres show 1 --cell 2
|
|
94
|
+
|
|
95
|
+
# View only the quick tweak recipe (Pandas CSV, Optimizers, Viva notes)
|
|
96
|
+
keres tweaks 2
|
|
97
|
+
|
|
98
|
+
# Export all practicals as text files
|
|
99
|
+
keres export --out-dir ./my_txt_notes
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## Practical Index
|
|
105
|
+
|
|
106
|
+
| Practical | Title / Topic | Framework | Cells |
|
|
107
|
+
| :--- | :--- | :--- | :---: |
|
|
108
|
+
| **Mock Practical** | Neural Network Training with Different Loss Functions | PyTorch | 5 |
|
|
109
|
+
| **Practical 01** | Single-Layer Perceptron (AND & OR Gate Decision Boundaries) | NumPy / Matplotlib | 2 |
|
|
110
|
+
| **Practical 02** | Multi-Layer Perceptron (MLP) Comparison on Fashion-MNIST | PyTorch / Torchvision | 8 |
|
|
111
|
+
| **Practical 03** | Regularization Techniques (L2 Weight Decay vs Dropout) | TensorFlow / Keras | 6 |
|
|
112
|
+
| **Practical 04** | Activation Functions Analysis (Sigmoid, Tanh, ReLU, LeakyReLU) | PyTorch | 5 |
|
|
113
|
+
| **Practical 05** | Convolutional Neural Networks (CNN) vs MLP for Image Classification | PyTorch / Torchvision | 10 |
|
|
114
|
+
| **Practical 06** | Recurrent Neural Networks (LSTM) for IMDB Sentiment Classification | TensorFlow / Keras | 6 |
|
|
115
|
+
| **Practical 07** | Transfer Learning & Fine-Tuning with MobileNetV2 | TensorFlow / Keras | 6 |
|
|
116
|
+
| **Practical 08** | Hyperparameter Optimization & TensorBoard Visualization | PyTorch / TensorBoard | 5 |
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "pykeres"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
authors = [
|
|
9
|
+
{ name="Shreyas Daptare", email="shreyas@example.com" },
|
|
10
|
+
]
|
|
11
|
+
description = "pykeres: Deep Learning Practicals Code Guide Library with Cell-by-Cell Notebook Implementations and Viva Cheat Sheets"
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
requires-python = ">=3.8"
|
|
14
|
+
license = { text = "MIT" }
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
[project.scripts]
|
|
22
|
+
keres = "keres.cli:main"
|
|
23
|
+
|
|
24
|
+
[tool.setuptools.packages.find]
|
|
25
|
+
where = ["src"]
|
|
26
|
+
include = ["keres*"]
|
|
27
|
+
|
|
28
|
+
[tool.setuptools.package-data]
|
|
29
|
+
keres = ["data/*"]
|
pykeres-1.0.0/setup.cfg
ADDED
pykeres-1.0.0/setup.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
setup(
|
|
4
|
+
name="pykeres",
|
|
5
|
+
version="1.0.0",
|
|
6
|
+
package_dir={"": "src"},
|
|
7
|
+
packages=find_packages(where="src"),
|
|
8
|
+
package_data={"keres": ["data/*"]},
|
|
9
|
+
include_package_data=True,
|
|
10
|
+
entry_points={
|
|
11
|
+
"console_scripts": [
|
|
12
|
+
"keres=keres.cli:main",
|
|
13
|
+
],
|
|
14
|
+
},
|
|
15
|
+
)
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"""
|
|
2
|
+
keres: A cell-by-cell Deep Learning Practicals Code Guide Library.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from .guide import Keres, DLPracticals
|
|
6
|
+
|
|
7
|
+
# Default instance for convenient top-level access
|
|
8
|
+
_default_instance = Keres()
|
|
9
|
+
|
|
10
|
+
def list_practicals():
|
|
11
|
+
"""List all available practicals."""
|
|
12
|
+
_default_instance.list_practicals()
|
|
13
|
+
|
|
14
|
+
def mock_practical(cell=None, tweaks=False):
|
|
15
|
+
"""View Mock Practical cell-by-cell or with tweak recipes."""
|
|
16
|
+
_default_instance.mock_practical(cell=cell, tweaks=tweaks)
|
|
17
|
+
|
|
18
|
+
def practical_1(cell=None, tweaks=False):
|
|
19
|
+
"""View Practical 01 (Perceptron AND/OR) cell-by-cell or with tweak recipes."""
|
|
20
|
+
_default_instance.practical_1(cell=cell, tweaks=tweaks)
|
|
21
|
+
|
|
22
|
+
def practical_2(cell=None, tweaks=False):
|
|
23
|
+
"""View Practical 02 (MLP on Fashion-MNIST) cell-by-cell or with tweak recipes."""
|
|
24
|
+
_default_instance.practical_2(cell=cell, tweaks=tweaks)
|
|
25
|
+
|
|
26
|
+
def practical_3(cell=None, tweaks=False):
|
|
27
|
+
"""View Practical 03 (L2 vs Dropout Regularization) cell-by-cell or with tweak recipes."""
|
|
28
|
+
_default_instance.practical_3(cell=cell, tweaks=tweaks)
|
|
29
|
+
|
|
30
|
+
def practical_4(cell=None, tweaks=False):
|
|
31
|
+
"""View Practical 04 (Activation Functions Analysis) cell-by-cell or with tweak recipes."""
|
|
32
|
+
_default_instance.practical_4(cell=cell, tweaks=tweaks)
|
|
33
|
+
|
|
34
|
+
def practical_5(cell=None, tweaks=False):
|
|
35
|
+
"""View Practical 05 (CNN vs MLP on Images) cell-by-cell or with tweak recipes."""
|
|
36
|
+
_default_instance.practical_5(cell=cell, tweaks=tweaks)
|
|
37
|
+
|
|
38
|
+
def practical_6(cell=None, tweaks=False):
|
|
39
|
+
"""View Practical 06 (LSTM for IMDB Sentiment) cell-by-cell or with tweak recipes."""
|
|
40
|
+
_default_instance.practical_6(cell=cell, tweaks=tweaks)
|
|
41
|
+
|
|
42
|
+
def practical_7(cell=None, tweaks=False):
|
|
43
|
+
"""View Practical 07 (Transfer Learning with MobileNetV2) cell-by-cell or with tweak recipes."""
|
|
44
|
+
_default_instance.practical_7(cell=cell, tweaks=tweaks)
|
|
45
|
+
|
|
46
|
+
def practical_8(cell=None, tweaks=False):
|
|
47
|
+
"""View Practical 08 (Hyperparameter Tuning & TensorBoard) cell-by-cell or with tweak recipes."""
|
|
48
|
+
_default_instance.practical_8(cell=cell, tweaks=tweaks)
|
|
49
|
+
|
|
50
|
+
def get_practical(num, cell=None, tweaks=False):
|
|
51
|
+
"""Retrieve practical text, specific cell code, or code with tweak recipes."""
|
|
52
|
+
return _default_instance.get_practical(num, cell=cell, tweaks=tweaks)
|
|
53
|
+
|
|
54
|
+
def tweaks(num):
|
|
55
|
+
"""View quick tweak recipes (dataset switching, optimizers, viva notes) for a practical."""
|
|
56
|
+
_default_instance.tweaks(num)
|
|
57
|
+
|
|
58
|
+
def get_tweaks(num):
|
|
59
|
+
"""Retrieve quick tweak recipe string for a practical."""
|
|
60
|
+
return _default_instance.get_tweaks(num)
|
|
61
|
+
|
|
62
|
+
def guide():
|
|
63
|
+
"""Display the built-in quickstart guide and cheat sheet."""
|
|
64
|
+
_default_instance.guide()
|
|
65
|
+
|
|
66
|
+
help = guide
|
|
67
|
+
quickstart = guide
|
|
68
|
+
|
|
69
|
+
def export_all_texts(output_dir):
|
|
70
|
+
"""Export all practicals as plaintext files (.txt) to output_dir."""
|
|
71
|
+
_default_instance.export_all_texts(output_dir)
|
|
72
|
+
|
|
73
|
+
def get_cells(num):
|
|
74
|
+
"""Retrieve list of cell dicts for a practical."""
|
|
75
|
+
return _default_instance.get_cells(num)
|
|
76
|
+
|
|
77
|
+
__all__ = [
|
|
78
|
+
"Keres",
|
|
79
|
+
"DLPracticals",
|
|
80
|
+
"list_practicals",
|
|
81
|
+
"guide",
|
|
82
|
+
"help",
|
|
83
|
+
"quickstart",
|
|
84
|
+
"mock_practical",
|
|
85
|
+
"practical_1",
|
|
86
|
+
"practical_2",
|
|
87
|
+
"practical_3",
|
|
88
|
+
"practical_4",
|
|
89
|
+
"practical_5",
|
|
90
|
+
"practical_6",
|
|
91
|
+
"practical_7",
|
|
92
|
+
"practical_8",
|
|
93
|
+
"get_practical",
|
|
94
|
+
"get_cells",
|
|
95
|
+
"tweaks",
|
|
96
|
+
"get_tweaks",
|
|
97
|
+
"export_all_texts",
|
|
98
|
+
]
|
|
99
|
+
|
|
100
|
+
__version__ = "1.0.0"
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Command-line interface for keres.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import sys
|
|
7
|
+
from keres.guide import Keres
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def main():
|
|
11
|
+
parser = argparse.ArgumentParser(
|
|
12
|
+
prog="keres",
|
|
13
|
+
description="keres: Deep Learning Practicals Code Guide CLI (Roll No. 23 - Shreyas Daptare)"
|
|
14
|
+
)
|
|
15
|
+
subparsers = parser.add_subparsers(dest="command", help="Command to run")
|
|
16
|
+
|
|
17
|
+
# guide / help
|
|
18
|
+
subparsers.add_parser("guide", help="Show built-in quickstart guide and cheat sheet")
|
|
19
|
+
subparsers.add_parser("help", help="Show built-in quickstart guide and cheat sheet")
|
|
20
|
+
|
|
21
|
+
# list
|
|
22
|
+
subparsers.add_parser("list", help="List all available practicals")
|
|
23
|
+
|
|
24
|
+
# show
|
|
25
|
+
show_parser = subparsers.add_parser("show", help="Display practical code cell-by-cell")
|
|
26
|
+
show_parser.add_argument("number", help="Practical number (0 for Mock, 1..8 for Practicals 1..8)")
|
|
27
|
+
show_parser.add_argument("--cell", type=int, default=None, help="Specific cell number (1-based)")
|
|
28
|
+
show_parser.add_argument("--tweaks", "-t", action="store_true", help="Include quick tweak recipes at the end")
|
|
29
|
+
|
|
30
|
+
# tweaks
|
|
31
|
+
tweaks_parser = subparsers.add_parser("tweaks", help="Display quick tweak recipes (dataset, optimizer, viva)")
|
|
32
|
+
tweaks_parser.add_argument("number", help="Practical number (0 for Mock, 1..8 for Practicals 1..8)")
|
|
33
|
+
|
|
34
|
+
# export
|
|
35
|
+
export_parser = subparsers.add_parser("export", help="Export practicals to a directory")
|
|
36
|
+
export_parser.add_argument("--out", "--out-dir", "-o", dest="out", default="./keres_practicals_txt", help="Output directory")
|
|
37
|
+
|
|
38
|
+
args = parser.parse_args()
|
|
39
|
+
guide = Keres()
|
|
40
|
+
|
|
41
|
+
if args.command in ("guide", "help") or args.command is None:
|
|
42
|
+
guide.guide()
|
|
43
|
+
elif args.command == "list":
|
|
44
|
+
guide.list_practicals()
|
|
45
|
+
elif args.command == "show":
|
|
46
|
+
try:
|
|
47
|
+
guide._display_or_return(args.number, cell=args.cell, tweaks=args.tweaks)
|
|
48
|
+
except Exception as e:
|
|
49
|
+
print(f"Error: {e}", file=sys.stderr)
|
|
50
|
+
sys.exit(1)
|
|
51
|
+
elif args.command == "tweaks":
|
|
52
|
+
try:
|
|
53
|
+
guide.tweaks(args.number)
|
|
54
|
+
except Exception as e:
|
|
55
|
+
print(f"Error: {e}", file=sys.stderr)
|
|
56
|
+
sys.exit(1)
|
|
57
|
+
elif args.command == "export":
|
|
58
|
+
guide.export_all_texts(args.out)
|
|
59
|
+
else:
|
|
60
|
+
parser.print_help()
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
if __name__ == "__main__":
|
|
64
|
+
main()
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# keres data package
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
================================================================================
|
|
2
|
+
# Mock Practical: Neural Network Training with Different Loss Functions
|
|
3
|
+
# Library: keres | Framework: PyTorch | Total Cells: 5
|
|
4
|
+
================================================================================
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
# --------------------------------------------------------------------------------
|
|
8
|
+
# [CELL 1 / 5] : Imports & Environment Setup
|
|
9
|
+
# --------------------------------------------------------------------------------
|
|
10
|
+
import random
|
|
11
|
+
import numpy as np
|
|
12
|
+
import matplotlib.pyplot as plt
|
|
13
|
+
import torch
|
|
14
|
+
import torch.nn as nn
|
|
15
|
+
from torch.utils.data import TensorDataset, DataLoader
|
|
16
|
+
from sklearn.datasets import load_digits
|
|
17
|
+
from sklearn.model_selection import train_test_split
|
|
18
|
+
from sklearn.preprocessing import StandardScaler
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
# --------------------------------------------------------------------------------
|
|
22
|
+
# [CELL 2 / 5] : Random Seed & Reproducibility Setup
|
|
23
|
+
# --------------------------------------------------------------------------------
|
|
24
|
+
SEED = 42
|
|
25
|
+
torch.manual_seed(SEED)
|
|
26
|
+
np.random.seed(SEED)
|
|
27
|
+
random.seed(SEED)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
# --------------------------------------------------------------------------------
|
|
31
|
+
# [CELL 3 / 5] : Synthetic Dataset Generation (Binary Classification)
|
|
32
|
+
# --------------------------------------------------------------------------------
|
|
33
|
+
# Dataset
|
|
34
|
+
digits = load_digits()
|
|
35
|
+
X = digits.data.astype(np.float32)
|
|
36
|
+
y = digits.target
|
|
37
|
+
|
|
38
|
+
X_train, X_val, y_train, y_val = train_test_split(
|
|
39
|
+
X, y, test_size=0.20, stratify=y, random_state=SEED
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
scaler = StandardScaler()
|
|
43
|
+
X_train = scaler.fit_transform(X_train).astype(np.float32)
|
|
44
|
+
X_val = scaler.transform(X_val).astype(np.float32)
|
|
45
|
+
|
|
46
|
+
train_loader = DataLoader(
|
|
47
|
+
TensorDataset(torch.tensor(X_train), torch.tensor(y_train)),
|
|
48
|
+
batch_size=64, shuffle=True
|
|
49
|
+
)
|
|
50
|
+
val_loader = DataLoader(
|
|
51
|
+
TensorDataset(torch.tensor(X_val), torch.tensor(y_val)),
|
|
52
|
+
batch_size=256
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
# --------------------------------------------------------------------------------
|
|
57
|
+
# [CELL 4 / 5] : MLP Architecture, Training Loop & Loss Function Experiments
|
|
58
|
+
# --------------------------------------------------------------------------------
|
|
59
|
+
# Same MLP architecture for all experiments
|
|
60
|
+
class MLP(nn.Module):
|
|
61
|
+
def __init__(self, activation):
|
|
62
|
+
super().__init__()
|
|
63
|
+
self.net = nn.Sequential(
|
|
64
|
+
nn.Linear(64, 128), activation(),
|
|
65
|
+
nn.Linear(128, 128), activation(),
|
|
66
|
+
nn.Linear(128, 64), activation(),
|
|
67
|
+
nn.Linear(64, 10)
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
def forward(self, x):
|
|
71
|
+
return self.net(x)
|
|
72
|
+
|
|
73
|
+
activations = {
|
|
74
|
+
"Sigmoid": nn.Sigmoid,
|
|
75
|
+
"Tanh": nn.Tanh,
|
|
76
|
+
"ReLU": nn.ReLU
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
criterion = nn.CrossEntropyLoss()
|
|
80
|
+
results = {}
|
|
81
|
+
|
|
82
|
+
for name, activation in activations.items():
|
|
83
|
+
torch.manual_seed(SEED)
|
|
84
|
+
model = MLP(activation)
|
|
85
|
+
optimizer = torch.optim.Adam(model.parameters(), lr=0.01)
|
|
86
|
+
|
|
87
|
+
losses, accuracies, gradients = [], [], []
|
|
88
|
+
|
|
89
|
+
print(f"\nTraining with {name}")
|
|
90
|
+
|
|
91
|
+
for epoch in range(5):
|
|
92
|
+
model.train()
|
|
93
|
+
total_loss = 0
|
|
94
|
+
batch_gradients = []
|
|
95
|
+
|
|
96
|
+
for xb, yb in train_loader:
|
|
97
|
+
optimizer.zero_grad()
|
|
98
|
+
|
|
99
|
+
output = model(xb)
|
|
100
|
+
loss = criterion(output, yb)
|
|
101
|
+
loss.backward()
|
|
102
|
+
|
|
103
|
+
# Global L2 gradient norm
|
|
104
|
+
sq_norm = sum(
|
|
105
|
+
p.grad.detach().pow(2).sum().item()
|
|
106
|
+
for p in model.parameters()
|
|
107
|
+
if p.grad is not None
|
|
108
|
+
)
|
|
109
|
+
batch_gradients.append(np.sqrt(sq_norm))
|
|
110
|
+
|
|
111
|
+
optimizer.step()
|
|
112
|
+
total_loss += loss.item() * len(yb)
|
|
113
|
+
|
|
114
|
+
epoch_loss = total_loss / len(X_train)
|
|
115
|
+
|
|
116
|
+
model.eval()
|
|
117
|
+
correct = total = 0
|
|
118
|
+
with torch.no_grad():
|
|
119
|
+
for xb, yb in val_loader:
|
|
120
|
+
pred = model(xb).argmax(dim=1)
|
|
121
|
+
correct += (pred == yb).sum().item()
|
|
122
|
+
total += len(yb)
|
|
123
|
+
|
|
124
|
+
accuracy = 100 * correct / total
|
|
125
|
+
gradient = np.mean(batch_gradients)
|
|
126
|
+
|
|
127
|
+
losses.append(epoch_loss)
|
|
128
|
+
accuracies.append(accuracy)
|
|
129
|
+
gradients.append(gradient)
|
|
130
|
+
|
|
131
|
+
print(
|
|
132
|
+
f"Epoch {epoch+1}: "
|
|
133
|
+
f"Loss={epoch_loss:.4f}, "
|
|
134
|
+
f"Val Acc={accuracy:.2f}%"
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
results[name] = {
|
|
138
|
+
"loss": losses,
|
|
139
|
+
"accuracy": accuracies,
|
|
140
|
+
"gradient": gradients
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
# --------------------------------------------------------------------------------
|
|
145
|
+
# [CELL 5 / 5] : Comparative Loss & Accuracy Curve Visualization
|
|
146
|
+
# --------------------------------------------------------------------------------
|
|
147
|
+
# Plot results
|
|
148
|
+
epochs = np.arange(1, 6)
|
|
149
|
+
fig, axes = plt.subplots(1, 3, figsize=(13, 4.5))
|
|
150
|
+
|
|
151
|
+
for name in activations:
|
|
152
|
+
axes[0].plot(epochs, results[name]["loss"], marker="o", label=name)
|
|
153
|
+
axes[1].plot(epochs, results[name]["accuracy"], marker="o", label=name)
|
|
154
|
+
axes[2].plot(epochs, results[name]["gradient"], marker="o", label=name)
|
|
155
|
+
|
|
156
|
+
axes[0].set_title("Training Loss")
|
|
157
|
+
axes[0].set_xlabel("Epoch")
|
|
158
|
+
axes[0].set_ylabel("Loss")
|
|
159
|
+
|
|
160
|
+
axes[1].set_title("Validation Accuracy")
|
|
161
|
+
axes[1].set_xlabel("Epoch")
|
|
162
|
+
axes[1].set_ylabel("Accuracy (%)")
|
|
163
|
+
|
|
164
|
+
axes[2].set_title("Gradient Norms (Flow)")
|
|
165
|
+
axes[2].set_xlabel("Epoch")
|
|
166
|
+
axes[2].set_ylabel("Average Gradient Norm")
|
|
167
|
+
|
|
168
|
+
for ax in axes:
|
|
169
|
+
ax.set_xticks(epochs)
|
|
170
|
+
ax.grid(alpha=0.2)
|
|
171
|
+
ax.legend()
|
|
172
|
+
|
|
173
|
+
plt.tight_layout()
|
|
174
|
+
plt.savefig("activation_functions_output.png", dpi=180)
|
|
175
|
+
plt.show()
|
|
176
|
+
|
|
177
|
+
================================================================================
|
|
178
|
+
💡 QUICK TWEAK RECIPES FOR MOCK PRACTICAL (Multi-Loss MLP in PyTorch):
|
|
179
|
+
================================================================================
|
|
180
|
+
1. SWITCH TO LOCAL CSV VIA PANDAS:
|
|
181
|
+
import pandas as pd
|
|
182
|
+
from sklearn.model_selection import train_test_split
|
|
183
|
+
from sklearn.preprocessing import StandardScaler
|
|
184
|
+
df = pd.read_csv('your_dataset.csv')
|
|
185
|
+
X_raw = df.drop('target', axis=1).values
|
|
186
|
+
y_raw = df['target'].values
|
|
187
|
+
X_tr, X_te, y_tr, y_te = train_test_split(X_raw, y_raw, test_size=0.2, random_state=42)
|
|
188
|
+
scaler = StandardScaler()
|
|
189
|
+
X_train = torch.tensor(scaler.fit_transform(X_tr), dtype=torch.float32)
|
|
190
|
+
X_test = torch.tensor(scaler.transform(X_te), dtype=torch.float32)
|
|
191
|
+
y_train = torch.tensor(y_tr, dtype=torch.long)
|
|
192
|
+
y_test = torch.tensor(y_te, dtype=torch.long)
|
|
193
|
+
|
|
194
|
+
2. SWITCH OPTIMIZERS:
|
|
195
|
+
# Adam (Default):
|
|
196
|
+
optimizer = torch.optim.Adam(model.parameters(), lr=0.01)
|
|
197
|
+
# SGD with Momentum:
|
|
198
|
+
optimizer = torch.optim.SGD(model.parameters(), lr=0.01, momentum=0.9)
|
|
199
|
+
# RMSprop:
|
|
200
|
+
optimizer = torch.optim.RMSprop(model.parameters(), lr=0.005)
|
|
201
|
+
# AdamW (Adam + decoupled Weight Decay):
|
|
202
|
+
optimizer = torch.optim.AdamW(model.parameters(), lr=0.01, weight_decay=1e-4)
|
|
203
|
+
|
|
204
|
+
3. SWITCH LOSS FUNCTIONS:
|
|
205
|
+
# Multi-class Classification:
|
|
206
|
+
criterion = nn.CrossEntropyLoss()
|
|
207
|
+
# Regression / Continuous:
|
|
208
|
+
criterion = nn.MSELoss() # or nn.L1Loss()
|
|
209
|
+
# Robust Regression (less sensitive to outliers):
|
|
210
|
+
criterion = nn.SmoothL1Loss(beta=1.0)
|
|
211
|
+
# Binary Classification:
|
|
212
|
+
criterion = nn.BCEWithLogitsLoss()
|
|
213
|
+
|
|
214
|
+
4. ADD DROPOUT & BATCH NORMALIZATION:
|
|
215
|
+
# Inside SimpleMLP __init__:
|
|
216
|
+
self.fc1 = nn.Linear(input_dim, 64)
|
|
217
|
+
self.bn1 = nn.BatchNorm1d(64)
|
|
218
|
+
self.dropout = nn.Dropout(0.3)
|
|
219
|
+
self.fc2 = nn.Linear(64, num_classes)
|
|
220
|
+
================================================================================
|