here's some context for the assignment: Assignment 7: Neural Complete Overview In…
- User
here's some context for the assignment:
Assignment 7: Neural Complete Overview In Assignment 6 you computed a language model from scratch. Now it's time to apply your deep learning knowledge to the autocomplete problem and use what you've learned about deep learning to train a neural language model for next character prediction.
Assignment Objectives Understand how a character-level RNN works and how it can model sequences. Implement a recurrent neural network in PyTorch. Learn about sequence modeling, hidden state propagation, and embedding layers. Train a model to predict the next character in a sequence using a sliding window dataset. Generate novel sequences of text based on a trained model. Experiment with model hyperparameters and observe their effect on performance. Pre-Requisites Python & PyTorch: You should be familiar with Python syntax and have basic experience with PyTorch tensors and modules (from Assignment 5). Neural Networks: You should understand how neural networks work, including layers, forward passes, and training with loss functions. Recurrent Neural Networks: You should have seen the basic RNN recurrence equations in lecture. Student Tasks Milestone 0. Understand the code Start by opening char_rnn_starter.py reading through whats provided and familiarizing yourself with the structure.
The key components are
A CharDataset class to slice training data into overlapping character sequences. A CharRNN class with an incomplete forward() method and missing parameters. A training loop that handles batching and the forward pass. A sampling loop to generate new text using your trained model 2 functions are incomplete. In the CharDataset class you will notice a concept of stride is used. When creating the training data for a character-level language model, we break long text into shorter overlapping sequences so the model can learn from many parts of the text.
This is most easily understood with an example. Lets say your training data is the sequence "abcedfgh" and you are learning a model for sequence_length=3.
With stride = 1: Input Target "abc" "bcd" "bcd" "cde" "cde" "def" "def" "efg" "efg" "fgh" With stride = 2: Input Target "abc" "bcd" "cde" "def" "efg" "fgh" So as you can see, a higher stride results in less examples. This is a training hyperparameter which you can experiment with — smaller values increase data size and overlap, while larger values reduce redundancy and speed up training.
Milestone 1. Teach an RNN the alphabet Now that you've gone through the code it's time to implement the RNN and get the model to train on the alphabet sequence. Note once you've completed this your model should get a very high accuracy (close to 100%) as this is a very simple repeated sequence.
First, we'd recommend you complete the training section up until the training loop. Then, complete the model implementation. Then complete the training loop and try to train your model.
Training setup components The code has a number of TODOs prior to the training loop, these should be pretty straightforward and are designed to help you understand the flow of the code by tieing in concepts from previous assignments.
- Assistant
- User
- Assistant
- User
let's get to completing the CharRnn class
- Assistant
- User
def init(self, input_size, hidden_size, output_size, embedding_dim=30): super().init() self.hidden_size = hidden_size self.embedding = nn.Embedding(output_size, embedding_dim) # TODO: Initialize your model parameters as needed e.g. W_e, W_h, etc.
- Assistant