Module 4 extends MiniTorch with convolutional neural network operations to build an image recognition system. You'll implement a version of LeNet on MNIST for digit recognition and 1D convolution for NLP sentiment classification:
- 1D and 2D convolution for feature extraction and image processing
- Pooling operations for spatial down-sampling and dimension reduction
- Advanced NN functions including softmax, dropout, and max operations
- MNIST digit classification and SST2 sentiment analysis with CNNs
# Install dependencies
pip install -e ".[dev,extra]"
# Set up MNIST dataset
./get_mnist.sh
# Sync files from Module 3
python sync_previous_module.py ../Module-3 .
# Run Module 4 tests
pytest -m task4_1
pytest -m task4_2
pytest -m task4_3
pytest -m task4_4
# Train CNN models
python project/run_mnist_multiclass.py # MNIST digits
python project/run_sentiment.py # SST2 sentiment
# Run style checks
pre-commit run --all-filesFile: minitorch/fast_conv.py
- Implement
_tensor_conv1d()function - Support forward and backward convolution with parallel processing
File: minitorch/fast_conv.py
- Implement
_tensor_conv2d()function - Optimize for image processing with efficient memory access
File: minitorch/nn.py
- Implement
tile()tensor reshaping function - Implement
avgpool2d()for average pooling
File: minitorch/nn.py
- Implement
max(),argmax(),softmax(),logsoftmax(), anddropout() - Implement
maxpool2d()for max pooling operations - Add property tests and ensure gradient computation correctness
File: minitorch/cuda_conv.py (Create this file)
- Implement
conv1dandconv2don CUDA for efficient GPU processing - Critical for large-scale image recognition performance
- Show output on Google Colab
Files: project/run_sentiment.py and project/run_mnist_multiclass.py
- Implement Conv1D, Conv2D, and Network for both sentiment and image classification
- Train models on SST2 sentiment data and MNIST digit classification
- Use Streamlit visualization to view hidden states of your model
Training Requirements:
- Train a model on Sentiment (SST2), add training logs as
sentiment.txtshowing train loss, train accuracy and validation accuracy (should achieve >70% best validation accuracy) - Train a model on Digit classification (MNIST), add logs as
mnist.txtshowing train loss and validation accuracy - Implement Conv1D, Conv2D, and Network classes for both training files
- Installation Guide: Setup instructions with MNIST
- Testing Guide: CNN testing strategies