Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

W1D1 Post-Course Feedback (Superset) #422

Merged
merged 2 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions tutorials/W1D1_Generalization/W1D1_Tutorial1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@
"execution": {}
},
"source": [
"We build a simple interface in `gradio` to try out the model interactively. Go ahead and try some example text to see how it works. You can use images from the internet, or scan your own handwriting. Just make sure that the text fits on one line."
"We build a simple interface in `gradio` to try out the model interactively. Go ahead and try some example text to see how it works. You can use images from the internet, or scan your own handwriting. Just make sure that the text fits on one line. Observe the result of the recognized text."
]
},
{
Expand Down Expand Up @@ -1034,7 +1034,7 @@
" ############################################################\n",
" # Fill in this code to calculate character error rate and word error rate.\n",
" # Hint: have a look at the torchmetrics documentation for the proper\n",
" # metrics.\n",
" # metrics (type the proper metric name in the search bar).\n",
" #\n",
" # https://lightning.ai/docs/torchmetrics/stable/\n",
" raise NotImplementedError(\"Student has to fill in these lines\")\n",
Expand Down Expand Up @@ -1675,7 +1675,7 @@
"execution": {}
},
"source": [
"### Code exercise 3.1: Understanding the inputs and outputs of the decoder\n",
"### Code exercise 3.1: Understanding the inputs and outputs of the encoder\n",
"\n",
"Let's make sure we understand how the encoder operates by giving it a sample input and checking that its output matches the expected shape."
]
Expand All @@ -1689,9 +1689,9 @@
},
"outputs": [],
"source": [
"def inspect_decoder(model):\n",
"def inspect_encoder(model):\n",
" \"\"\"\n",
" Inspect decoder to verify that it processes inputs in the expected way.\n",
" Inspect encoder to verify that it processes inputs in the expected way.\n",
"\n",
" Args:\n",
" model: the TrOCR model\n",
Expand Down Expand Up @@ -1730,9 +1730,9 @@
"source": [
"# to_remove solution\n",
"\n",
"def inspect_decoder(model):\n",
"def inspect_encoder(model):\n",
" \"\"\"\n",
" Inspect decoder to verify that it processes inputs in the expected way.\n",
" Inspect encoder to verify that it processes inputs in the expected way.\n",
"\n",
" Args:\n",
" model: the TrOCR model\n",
Expand Down Expand Up @@ -1763,7 +1763,7 @@
},
"outputs": [],
"source": [
"inspect_decoder(model)"
"inspect_encoder(model)"
]
},
{
Expand Down
10 changes: 6 additions & 4 deletions tutorials/W1D1_Generalization/W1D1_Tutorial2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,8 @@
"\n",
"$$z = \\mathbf{W}\\mathbf{r} + c$$\n",
"\n",
"In this notation, we can interpret $\\mathbf{r}$ as the firing rates of the neurons. Take a look at the equation above: the hidden state, $\\mathbf{x}$ (representation of stimuli in the brain), is evolving over time and is driven by current stimuli input $\\mathbf{u}$ and firing rates of neurons in the previous time step, $\\mathbf{r}$. EMG activity, $z$, is a direct linear projection from firing rates. \n",
"\n",
"Let's code up this unregularized neural network."
]
},
Expand Down Expand Up @@ -1250,7 +1252,7 @@
" #################################################\n",
" inputs = inputs.to(device)\n",
" batch_size = inputs.size(0)\n",
" h = ...\n",
" h = ... #note that `UnregularizedRNN` has a specific method for that\n",
"\n",
" loss = 0\n",
" outputs = []\n",
Expand Down Expand Up @@ -1281,7 +1283,7 @@
"def generate_trajectory(model, inputs, device):\n",
" inputs = inputs.to(device)\n",
" batch_size = inputs.size(0)\n",
" h = model.init_hidden(batch_size).to(device)\n",
" h = model.init_hidden(batch_size).to(device) #note that `UnregularizedRNN` has a specific method for that\n",
"\n",
" loss = 0\n",
" outputs = []\n",
Expand Down Expand Up @@ -1658,7 +1660,7 @@
" # Project the firing rate linearly to form the output\n",
" output = self.output_linear(firing_rate)\n",
"\n",
" # Regularization terms\n",
" # Regularization terms (used for R1 calculation)\n",
" firing_rate_reg = firing_rate.pow(2).sum()\n",
"\n",
" return output, hidden, firing_rate_reg\n",
Expand Down Expand Up @@ -1800,7 +1802,7 @@
"source": [
"## Activity 3.2: Comparing trained RNN with real data\n",
"\n",
"Let's see if this regularized network's activity is aligned with the brain."
"Let's see if this regularized network's activity is aligned with the brain. PSTH (peristimulus time histogram) is the type of plot that shows the firing rates of neurons over time (or their actual firings, depending on the granularity level)."
]
},
{
Expand Down
16 changes: 8 additions & 8 deletions tutorials/W1D1_Generalization/instructor/W1D1_Tutorial1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@
"execution": {}
},
"source": [
"We build a simple interface in `gradio` to try out the model interactively. Go ahead and try some example text to see how it works. You can use images from the internet, or scan your own handwriting. Just make sure that the text fits on one line."
"We build a simple interface in `gradio` to try out the model interactively. Go ahead and try some example text to see how it works. You can use images from the internet, or scan your own handwriting. Just make sure that the text fits on one line. Observe the result of the recognized text."
]
},
{
Expand Down Expand Up @@ -1034,7 +1034,7 @@
" ############################################################\n",
" # Fill in this code to calculate character error rate and word error rate.\n",
" # Hint: have a look at the torchmetrics documentation for the proper\n",
" # metrics.\n",
" # metrics (type the proper metric name in the search bar).\n",
" #\n",
" # https://lightning.ai/docs/torchmetrics/stable/\n",
" raise NotImplementedError(\"Student has to fill in these lines\")\n",
Expand Down Expand Up @@ -1681,7 +1681,7 @@
"execution": {}
},
"source": [
"### Code exercise 3.1: Understanding the inputs and outputs of the decoder\n",
"### Code exercise 3.1: Understanding the inputs and outputs of the encoder\n",
"\n",
"Let's make sure we understand how the encoder operates by giving it a sample input and checking that its output matches the expected shape."
]
Expand All @@ -1695,9 +1695,9 @@
},
"source": [
"```python\n",
"def inspect_decoder(model):\n",
"def inspect_encoder(model):\n",
" \"\"\"\n",
" Inspect decoder to verify that it processes inputs in the expected way.\n",
" Inspect encoder to verify that it processes inputs in the expected way.\n",
"\n",
" Args:\n",
" model: the TrOCR model\n",
Expand Down Expand Up @@ -1738,9 +1738,9 @@
"source": [
"# to_remove solution\n",
"\n",
"def inspect_decoder(model):\n",
"def inspect_encoder(model):\n",
" \"\"\"\n",
" Inspect decoder to verify that it processes inputs in the expected way.\n",
" Inspect encoder to verify that it processes inputs in the expected way.\n",
"\n",
" Args:\n",
" model: the TrOCR model\n",
Expand Down Expand Up @@ -1771,7 +1771,7 @@
},
"outputs": [],
"source": [
"inspect_decoder(model)"
"inspect_encoder(model)"
]
},
{
Expand Down
10 changes: 6 additions & 4 deletions tutorials/W1D1_Generalization/instructor/W1D1_Tutorial2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,8 @@
"\n",
"$$z = \\mathbf{W}\\mathbf{r} + c$$\n",
"\n",
"In this notation, we can interpret $\\mathbf{r}$ as the firing rates of the neurons. Take a look at the equation above: the hidden state, $\\mathbf{x}$ (representation of stimuli in the brain), is evolving over time and is driven by current stimuli input $\\mathbf{u}$ and firing rates of neurons in the previous time step, $\\mathbf{r}$. EMG activity, $z$, is a direct linear projection from firing rates. \n",
"\n",
"Let's code up this unregularized neural network."
]
},
Expand Down Expand Up @@ -1252,7 +1254,7 @@
" #################################################\n",
" inputs = inputs.to(device)\n",
" batch_size = inputs.size(0)\n",
" h = ...\n",
" h = ... #note that `UnregularizedRNN` has a specific method for that\n",
"\n",
" loss = 0\n",
" outputs = []\n",
Expand Down Expand Up @@ -1285,7 +1287,7 @@
"def generate_trajectory(model, inputs, device):\n",
" inputs = inputs.to(device)\n",
" batch_size = inputs.size(0)\n",
" h = model.init_hidden(batch_size).to(device)\n",
" h = model.init_hidden(batch_size).to(device) #note that `UnregularizedRNN` has a specific method for that\n",
"\n",
" loss = 0\n",
" outputs = []\n",
Expand Down Expand Up @@ -1662,7 +1664,7 @@
" # Project the firing rate linearly to form the output\n",
" output = self.output_linear(firing_rate)\n",
"\n",
" # Regularization terms\n",
" # Regularization terms (used for R1 calculation)\n",
" firing_rate_reg = firing_rate.pow(2).sum()\n",
"\n",
" return output, hidden, firing_rate_reg\n",
Expand Down Expand Up @@ -1804,7 +1806,7 @@
"source": [
"## Activity 3.2: Comparing trained RNN with real data\n",
"\n",
"Let's see if this regularized network's activity is aligned with the brain."
"Let's see if this regularized network's activity is aligned with the brain. PSTH (peristimulus time histogram) is the type of plot that shows the firing rates of neurons over time (or their actual firings, depending on the granularity level)."
]
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

def inspect_decoder(model):
def inspect_encoder(model):
"""
Inspect decoder to verify that it processes inputs in the expected way.
Inspect encoder to verify that it processes inputs in the expected way.

Args:
model: the TrOCR model
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
def generate_trajectory(model, inputs, device):
inputs = inputs.to(device)
batch_size = inputs.size(0)
h = model.init_hidden(batch_size).to(device)
h = model.init_hidden(batch_size).to(device) #note that `UnregularizedRNN` has a specific method for that

loss = 0
outputs = []
Expand Down
14 changes: 7 additions & 7 deletions tutorials/W1D1_Generalization/student/W1D1_Tutorial1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@
"execution": {}
},
"source": [
"We build a simple interface in `gradio` to try out the model interactively. Go ahead and try some example text to see how it works. You can use images from the internet, or scan your own handwriting. Just make sure that the text fits on one line."
"We build a simple interface in `gradio` to try out the model interactively. Go ahead and try some example text to see how it works. You can use images from the internet, or scan your own handwriting. Just make sure that the text fits on one line. Observe the result of the recognized text."
]
},
{
Expand Down Expand Up @@ -1025,7 +1025,7 @@
" ############################################################\n",
" # Fill in this code to calculate character error rate and word error rate.\n",
" # Hint: have a look at the torchmetrics documentation for the proper\n",
" # metrics.\n",
" # metrics (type the proper metric name in the search bar).\n",
" #\n",
" # https://lightning.ai/docs/torchmetrics/stable/\n",
" raise NotImplementedError(\"Student has to fill in these lines\")\n",
Expand Down Expand Up @@ -1572,7 +1572,7 @@
"execution": {}
},
"source": [
"### Code exercise 3.1: Understanding the inputs and outputs of the decoder\n",
"### Code exercise 3.1: Understanding the inputs and outputs of the encoder\n",
"\n",
"Let's make sure we understand how the encoder operates by giving it a sample input and checking that its output matches the expected shape."
]
Expand All @@ -1586,9 +1586,9 @@
},
"outputs": [],
"source": [
"def inspect_decoder(model):\n",
"def inspect_encoder(model):\n",
" \"\"\"\n",
" Inspect decoder to verify that it processes inputs in the expected way.\n",
" Inspect encoder to verify that it processes inputs in the expected way.\n",
"\n",
" Args:\n",
" model: the TrOCR model\n",
Expand Down Expand Up @@ -1624,7 +1624,7 @@
"execution": {}
},
"source": [
"[*Click for solution*](https://github.com/neuromatch/NeuroAI_Course/tree/main/tutorials/W1D1_Generalization/solutions/W1D1_Tutorial1_Solution_fe1c0573.py)\n",
"[*Click for solution*](https://github.com/neuromatch/NeuroAI_Course/tree/main/tutorials/W1D1_Generalization/solutions/W1D1_Tutorial1_Solution_22613224.py)\n",
"\n"
]
},
Expand All @@ -1637,7 +1637,7 @@
},
"outputs": [],
"source": [
"inspect_decoder(model)"
"inspect_encoder(model)"
]
},
{
Expand Down
10 changes: 6 additions & 4 deletions tutorials/W1D1_Generalization/student/W1D1_Tutorial2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,8 @@
"\n",
"$$z = \\mathbf{W}\\mathbf{r} + c$$\n",
"\n",
"In this notation, we can interpret $\\mathbf{r}$ as the firing rates of the neurons. Take a look at the equation above: the hidden state, $\\mathbf{x}$ (representation of stimuli in the brain), is evolving over time and is driven by current stimuli input $\\mathbf{u}$ and firing rates of neurons in the previous time step, $\\mathbf{r}$. EMG activity, $z$, is a direct linear projection from firing rates. \n",
"\n",
"Let's code up this unregularized neural network."
]
},
Expand Down Expand Up @@ -1211,7 +1213,7 @@
" #################################################\n",
" inputs = inputs.to(device)\n",
" batch_size = inputs.size(0)\n",
" h = ...\n",
" h = ... #note that `UnregularizedRNN` has a specific method for that\n",
"\n",
" loss = 0\n",
" outputs = []\n",
Expand All @@ -1237,7 +1239,7 @@
"execution": {}
},
"source": [
"[*Click for solution*](https://github.com/neuromatch/NeuroAI_Course/tree/main/tutorials/W1D1_Generalization/solutions/W1D1_Tutorial2_Solution_dc6b3d2e.py)\n",
"[*Click for solution*](https://github.com/neuromatch/NeuroAI_Course/tree/main/tutorials/W1D1_Generalization/solutions/W1D1_Tutorial2_Solution_c14a4735.py)\n",
"\n"
]
},
Expand Down Expand Up @@ -1600,7 +1602,7 @@
" # Project the firing rate linearly to form the output\n",
" output = self.output_linear(firing_rate)\n",
"\n",
" # Regularization terms\n",
" # Regularization terms (used for R1 calculation)\n",
" firing_rate_reg = firing_rate.pow(2).sum()\n",
"\n",
" return output, hidden, firing_rate_reg\n",
Expand Down Expand Up @@ -1742,7 +1744,7 @@
"source": [
"## Activity 3.2: Comparing trained RNN with real data\n",
"\n",
"Let's see if this regularized network's activity is aligned with the brain."
"Let's see if this regularized network's activity is aligned with the brain. PSTH (peristimulus time histogram) is the type of plot that shows the firing rates of neurons over time (or their actual firings, depending on the granularity level)."
]
},
{
Expand Down