From d26e9ff87c90de3023e34c416f6c2ae011c8d0be Mon Sep 17 00:00:00 2001 From: Siddharth Parekh Date: Wed, 28 Jan 2026 15:10:54 -0500 Subject: [PATCH] Replaced ASSIGN with HW for consistency with Homework website. --- README.md | 6 +++--- minitorch/autodiff.py | 8 ++++---- project/run_sentiment.py | 28 ++++++++++++++-------------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index d51a767..cb5b87a 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ python migrate_kernel.py --hw1-dir --hw2-dir Implement automatic differentiation. We have provided the derivative operations for internal Python operators in `minitorch.Function.backward` call. Your task is to write the two core functions needed for automatic differentiation: `topological_sort` and `backpropagate`. This will allow us to traverse the computation graph and compute the gradients along the way. -Complete the following functions in `minitorch/autodiff.py`. The places where you need to fill in your code are highlighted with `BEGIN ASSIGN2_1` and `END ASSIGN2_1` +Complete the following functions in `minitorch/autodiff.py`. The places where you need to fill in your code are highlighted with `BEGIN HW2_1` and `END HW2_1` **Note**: Be sure to checkout the functions in `class Variable(Protocol)`! @@ -134,7 +134,7 @@ python -m pytest -l -v -k "autodiff" ## Problem 2: Neural Network Architecture (30 points) -In this section, you will implement the neural network architecture. Complete the following functions in `run_sentiment.py` under the project folder. The places where you need to fill in your code are highlighted with `BEGIN ASSIGN2_2` and `END ASSIGN2_2`. +In this section, you will implement the neural network architecture. Complete the following functions in `run_sentiment.py` under the project folder. The places where you need to fill in your code are highlighted with `BEGIN HW2_2` and `END HW2_2`. ### 1. Implement Linear layer @@ -197,7 +197,7 @@ python -m pytest -l -v -k "network" ## Problem 3: Training and Evaluation (30 points) -In this section, you will implement codes for training and perform training on a simple MLP for the sentence sentiment classification task. The places where you need to fill in your code are highlighted with `BEGIN ASSIGN2_3` and `END ASSIGN2_3`. +In this section, you will implement codes for training and perform training on a simple MLP for the sentence sentiment classification task. The places where you need to fill in your code are highlighted with `BEGIN HW2_3` and `END HW2_3`. ### 1. Implement cross entropy loss function diff --git a/minitorch/autodiff.py b/minitorch/autodiff.py index fdf0efa..ced12ba 100644 --- a/minitorch/autodiff.py +++ b/minitorch/autodiff.py @@ -105,11 +105,11 @@ def topological_sort(variable: Variable) -> Iterable[Variable]: 2. When the children nodes of the current node are visited, add the current node at the front of the result order list. """ - # BEGIN ASSIGN2_1 + # BEGIN HW2_1 # TODO raise NotImplementedError("Task Autodiff Not Implemented Yet") - # END ASSIGN2_1 + # END HW2_1 def backpropagate(variable: Variable, deriv: Any) -> None: @@ -128,11 +128,11 @@ def backpropagate(variable: Variable, deriv: Any) -> None: 2. If the node is a leaf, the derivative should be accumulated 3. Otherwise, the derivative should be propagated via chain rule """ - # BEGIN ASSIGN2_1 + # BEGIN HW2_1 # TODO raise NotImplementedError("Task Autodiff Not Implemented Yet") - # END ASSIGN2_1 + # END HW2_1 @dataclass diff --git a/project/run_sentiment.py b/project/run_sentiment.py index 38a53ca..4a25ee3 100644 --- a/project/run_sentiment.py +++ b/project/run_sentiment.py @@ -32,7 +32,7 @@ def binary_cross_entropy_loss(out, y): y: true labels [0, 1] (batch_size,) """ - # BEGIN ASSIGN2_3 + # BEGIN HW2_3 # TODO # 1. Create ones tensor with same shape as y # 2. Compute log softmax of out and (ones - out) @@ -41,13 +41,13 @@ def binary_cross_entropy_loss(out, y): raise NotImplementedError("cross_entropy_loss not implemented") - # END ASSIGN2_3 + # END HW2_3 class Linear(minitorch.Module): def __init__(self, in_size, out_size): super().__init__() - # BEGIN ASSIGN2_2 + # BEGIN HW2_2 # TODO # 1. Initialize self.weights to be a random parameter of (in_size, out_size). # 2. Initialize self.bias to be a random parameter of (out_size) @@ -56,13 +56,13 @@ def __init__(self, in_size, out_size): raise NotImplementedError("Linear not implemented") - # END ASSIGN2_2 + # END HW2_2 def forward(self, x): batch, in_size = x.shape - # BEGIN ASSIGN2_2 + # BEGIN HW2_2 # TODO # 1. Reshape the input x to be of size (batch, in_size) # 2. Reshape self.weights to be of size (in_size, self.out_size) @@ -72,7 +72,7 @@ def forward(self, x): raise NotImplementedError("Linear forward not implemented") - # END ASSIGN2_2 + # END HW2_2 @@ -99,14 +99,14 @@ def __init__( self.embedding_dim = embedding_dim self.dropout_prob = dropout_prob - # BEGIN ASSIGN2_2 + # BEGIN HW2_2 # TODO # 1. Construct two linear layers: the first one is embedding_dim * hidden_dim # the second one is hidden_dim * 1 raise NotImplementedError("Network not implemented") - # END ASSIGN2_2 + # END HW2_2 @@ -115,7 +115,7 @@ def forward(self, embeddings): embeddings tensor: [batch x sentence length x embedding dim] """ - # BEGIN ASSIGN2_2 + # BEGIN HW2_2 # TODO # 1. Average the embeddings on the sentence length dimension to obtain a tensor of (batch, embedding_dim) # 2. Apply the first linear layer @@ -126,7 +126,7 @@ def forward(self, embeddings): raise NotImplementedError("Network forward not implemented") - # END ASSIGN2_2 + # END HW2_2 # Evaluation helper methods @@ -209,7 +209,7 @@ def train( ): out=None - # BEGIN ASSIGN2_3 + # BEGIN HW2_3 # TODO # 1. Create x and y using minitorch.tensor function # 2. Get the model output (as out) @@ -219,7 +219,7 @@ def train( raise NotImplementedError("SentenceSentimentTrain train not implemented") - # END ASSIGN2_3 + # END HW2_3 # Save training results @@ -233,7 +233,7 @@ def train( (X_val, y_val) = data_val model.eval() - # BEGIN ASSIGN2_3 + # BEGIN HW2_3 # TODO # 1. Create x and y using minitorch.tensor function # 2. Get the output of the model @@ -242,7 +242,7 @@ def train( raise NotImplementedError("SentenceSentimentTrain train not implemented") - # END ASSIGN2_3 + # END HW2_3 model.train()