Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rossheat/scorch
The scorch deep learning library
https://github.com/rossheat/scorch
Last synced: about 1 month ago
JSON representation
The scorch deep learning library
- Host: GitHub
- URL: https://github.com/rossheat/scorch
- Owner: rossheat
- License: mit
- Created: 2023-11-14T21:37:42.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-11-17T20:38:18.000Z (about 1 year ago)
- Last Synced: 2023-11-17T21:36:42.800Z (about 1 year ago)
- Language: Python
- Size: 9.77 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
I made this library to gain a better understanding of how backpropagation is used to train a neural network.
## Features
- **Backpropagation:** Scorch supports the backpropagation algorithm, enabling models to learn from their training data.
- **Neural Network Foundation Blocks:** Define a neural network with core components like Linear, ReLU, and Flatten.
- **Loss Functions:** Implement loss functions such as CrossEntropyLoss and MSELoss.
- **Optimizers:** Use gradient descent optimization with the provided SGD optimizer.
- **Data Handling:** Load and batch datasets effectively for model training with Dataset and DataLoader.
### ExamplesScorch Neural Network definition mimics PyTorch, as shown in the side-by-side comparison:
#### PyTorch
```python
import torch
import torch.nn as nnclass PyTorchNetwork(nn.Module):
def __init__(self):
super().__init__()
self.flatten = nn.Flatten()
self.linear_relu_stack = nn.Sequential(
nn.Linear(28*28, 512),
nn.ReLU(),
nn.Linear(512, 512),
nn.ReLU(),
nn.Linear(512, 10)
)def forward(self, x):
x = self.flatten(x)
return self.linear_relu_stack(x)model = PyTorchNetwork()
loss_fn = nn.CrossEntropyLoss()
optimizer = torch.optim.SGD(model.parameters(), lr=1e-3)
```#### Scorch
```python
import scorch
import scorch.nn as nnclass ScorchNetwork(nn.Module):
def __init__(self):
super().__init__()
self.flatten = nn.Flatten()
self.stack = nn.Sequential(
nn.Linear(28*28, 512),
nn.ReLU(),
nn.Linear(512, 512),
nn.ReLU(),
nn.Linear(512, 10)
)
def forward(self, x):
x = self.flatten(x)
return self.stack(x)model = ScorchNetwork()
loss_fn = nn.CrossEntropyLoss()
optimizer = scorch.optim.SGD(model.parameters(), lr=1e-3)
```Please find training examples in the `examples` directory.
## Installation
Clone the repository and install:
```bash
git clone https://github.com/rossheat/scorch.git
cd scorch
python setup.py install
python examples/diabetes.py
```## License
Scorch is MIT licensed, as found in the LICENSE file.
## Acknowledgments
Scorch is inspired by PyTorch and is intended strictly for educational purposes, honoring the original work of the creators and contributors of PyTorch.