{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "brNDGX-kvzds"
   },
   "source": [
    "# Template for Notes for CIS 521 Midterm 2\n",
    "\n",
    "The midterm exam for CIS 521 will be **open notes**. No other matierals are allowed for the exam - you may not use the textbook, the internet, a Python envionement, or communicate with anyone during the exam. \n",
    "\n",
    "This python notebook is where you should save all of your notes.  It provides a structured template that allows you to add summaries for each of the textbook sections that are part of the required reading, plus room for lecture notes and definitions.\n",
    "\n",
    "Your summaries must be written in your own words.  Do not copy and paste from the textbook.  Do not share your notes with classmates, or copy any of your classmates' notes.  "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "aPtM8g7R0Pds"
   },
   "source": [
    "# Instructions\n",
    "\n",
    "1. Make a copy of this Google Colab file. From the colab menu, pick **File > Save a copy in Drive**.  That will save a copy of this notebook in your Google drive.\n",
    "2. Go through each section of the notebook, and fill in all the summaries for each chapter and its corresponding sections.  Be sure to save your work frequently!\n",
    "3. Read the notes below about how you can format your summaries.\n",
    "4. In addition to these notes, you are allowed 1 page (both sides) for figures or handwritten notes.\n",
    "5. Submit your version of this notebook to Gradescope before you start the exam.\n",
    "6. If you are taking the exam in person, then you must print a copy of your notes for yourself.   Here's how to print: \n",
    "* Run the last cell of this notebook\n",
    "* Click the \"Mirror cell in tab\" button (this is located in the upper right corner of the cell, immediately to the right of the trash can).  This will open the cell.  \n",
    "* In Chrome, you can then print your notes using the **File > Print** option from the browser's menu.  \n",
    "* In the print options, change the layout from Landscape to Portrait. \n",
    "* Clicking the Save, will save a PDF that you can then print.\n",
    "\n",
    "## Formatting Notes\n",
    "\n",
    "1. The max length for each section's summary is 500 words / 3000 characters.\n",
    "2. You can also write a 2000 word summary of the lectures for each module.\n",
    "3. You may also write definitions of concepts for each module.  The definitions should be written in your own words (not copy and pasted), and they should be no more than 20 words long for each concept. \n",
    "2. You can use Markdown formatting for your summaries. \n",
    "3. You can use Latex formatting for equations. Put two dollar signs before and after your equation like this: \n",
    "$$ \\epsilon = \\frac{1}{mc^2} $$\n",
    "4. When you write python code or psuedocode algorithms, you should surround it with triple backticks like this:\n",
    "```\n",
    "def function():\n",
    "      print('hello world')\n",
    "```\n",
    "5. Write \\ whenever you want to keep writing on the next line without a newline being inserted."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "cw5IpDLCZa4W"
   },
   "source": [
    "## Example summary\n",
    "\n",
    "This is a sample summary of [Section 2.1.1](https://web.stanford.edu/~jurafsky/slp3/2.pdf ) of Jurfasky and Martin's Speech and Language Processing's book\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "lzaavW96tcxM",
    "outputId": "722b96e3-bc0a-4851-dbe8-b0a3d289f621"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The example summary is 116 words long, so you could write an additional 384 words.\n"
     ]
    }
   ],
   "source": [
    "chapter_2_1_example = \"\"\"\n",
    "Regular expressions are an algebraic notation for characterizing \\\n",
    "a set of strings that are useful for searching for a pattern or through a corpus.\\\n",
    "Only the first matching result will be shown. The search string is case sensitive, \\\n",
    "but it can consist of a single character or a sequence of characters. \\\n",
    "While square braces specify a disjunction of characters, the dash can more easily look \\\n",
    "for characters over a range. The caret specifies the non-existence of a character. \\\n",
    "Additionally, the (?) is used to for flexibility on a single character, meaning \\\n",
    "\"the preceding character or nothing\". More importantly, the Kleene star means zero or \\\n",
    "more occurrences of the immediately previous character or regular expression in square braces.\\\n",
    "...\n",
    "\"\"\"\n",
    "\n",
    "length = len(chapter_2_1_example.split(\" \"))\n",
    "print(\"The example summary is {len} words long, so you could write an additional \\\n",
    "{remaining} words.\".format(len=length, remaining=(500-length)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "s3Uk9gQTevcj"
   },
   "source": [
    "## Example summary length\n",
    "\n",
    "The maximum summary length for each section is 500 words / 3000 characters.  Hopefully you'll find that to be quite generous. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "8DvZ57A-djo1",
    "outputId": "f82dcb8b-7075-458b-a544-0bade9193c03"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The length in words is 500\n",
      "The length in characters is 3030\n"
     ]
    }
   ],
   "source": [
    "# This is an example of a 500 word placeholder\n",
    "placeholder = \"\"\"ultrices vitae auctor eu augue ut lectus arcu bibendum at varius \\\n",
    " vel pharetra vel turpis nunc eget lorem dolor sed viverra ipsum nunc aliquet \\\n",
    " bibendum enim facilisis gravida neque convallis a cras semper auctor neque vitae \\\n",
    " tempus quam pellentesque nec nam aliquam sem et tortor consequat id porta nibh \\\n",
    " venenatis cras sed felis eget velit aliquet sagittis id consectetur purus ut \\\n",
    " faucibus pulvinar elementum integer enim neque volutpat ac tincidunt vitae semper \\ \n",
    " quis lectus nulla at volutpat diam ut venenatis tellus in metus vulputate eu \\\n",
    " scelerisque felis imperdiet proin fermentum leo vel orci porta non pulvinar neque \\ \n",
    " laoreet suspendisse interdum consectetur libero id faucibus nisl tincidunt eget \\\n",
    " nullam non nisi est sit amet facilisis magna etiam tempor orci eu lobortis \\\n",
    " elementum nibh tellus molestie nunc non blandit massa enim nec dui nunc mattis \\\n",
    " enim ut tellus elementum sagittis vitae et leo duis ut diam quam nulla porttitor \\\n",
    " massa id neque aliquam vestibulum morbi blandit cursus risus at ultrices mi tempus \\\n",
    " imperdiet nulla malesuada pellentesque elit eget gravida cum sociis natoque \\\n",
    " penatibus et magnis dis parturient montes nascetur ridiculus mus mauris vitae \\\n",
    " ultricies leo integer malesuada nunc vel risus commodo viverra maecenas accumsan \\\n",
    " lacus vel facilisis volutpat est velit egestas dui id ornare arcu odio ut sem nulla \\\n",
    " pharetra diam sit amet nisl suscipit adipiscing bibendum est ultricies integer \\\n",
    " quis auctor elit sed vulputate mi sit amet mauris commodo quis imperdiet massa \\\n",
    " tincidunt nunc pulvinar sapien et ligula ullamcorper malesuada proin libero nunc \\\n",
    " consequat interdum varius sit amet mattis vulputate enim nulla aliquet porttitor \\\n",
    " lacus luctus accumsan tortor posuere ac ut consequat semper viverra nam libero \\\n",
    " justo laoreet sit amet cursus sit amet dictum sit amet justo donec enim diam \\\n",
    " vulputate ut pharetra sit amet aliquam id diam maecenas ultricies mi eget mauris \\\n",
    " pharetra et ultrices neque ornare aenean euismod elementum nisi quis eleifend quam \\\n",
    " adipiscing vitae proin sagittis nisl rhoncus mattis rhoncus urna neque viverra justo \\\n",
    " nec ultrices dui sapien eget mi proin sed libero enim sed faucibus turpis in \\\n",
    " eu mi bibendum neque egestas congue quisque egestas diam in arcu cursus euismod \\\n",
    " quis viverra nibh cras pulvinar mattis nunc sed blandit libero volutpat sed cras \\\n",
    " ornare arcu dui vivamus arcu felis bibendum ut tristique et egestas quis ipsum \\\n",
    " suspendisse ultrices gravida dictum fusce ut placerat orci nulla pellentesque \\\n",
    " dignissim enim sit amet venenatis urna cursus eget nunc scelerisque viverra mauris \\\n",
    " in aliquam sem fringilla ut morbi tincidunt augue interdum velit euismod in \\\n",
    " pellentesque massa placerat duis ultricies lacus sed turpis tincidunt id aliquet \\\n",
    " risus feugiat in ante metus dictum at tempor commodo ullamcorper a lacus vestibulum \\\n",
    " sed arcu non odio euismod lacinia at quis risus sed vulputate odio ut enim blandit \\\n",
    " volutpat maecenas volutpat blandit aliquam etiam erat velit scelerisque in \\\n",
    " dictum non consectetur a erat nam at lectus urna\"\"\"\n",
    "\n",
    "print(\"The length in words is\", len(placeholder.split(' ')))\n",
    "print(\"The length in characters is\", len(placeholder))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "5yG3-YncJfTB"
   },
   "source": [
    "# Permissions to use your summaries\n",
    "\n",
    "We'd like to use your summaries to help develop better educational resources like [remember.school](https://remember.school) or a question-answering system about the textbook.  \n",
    "\n",
    "1. Please enter your name.  \n",
    "\n",
    "2. If you grant permission for us to use your summaries under a [Creative Commons License](https://creativecommons.org/licenses/by/4.0/), please set ```permission = True```.  If you do not grant permission, please set it to false. Your answer won't affect your grade.\n",
    "\n",
    "3. If you grant us permission, and you'd like to remain anonymous, set ```anonymous = True```.  We'll remove your name before sharing your summaries with anyone. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "id": "2RECnJArJew4"
   },
   "outputs": [],
   "source": [
    "name = \"\"\n",
    "permission = True\n",
    "anonymous = False"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "GZZXyrV-xuAp"
   },
   "source": [
    "# Module 8 - Markov Decision Process"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "id": "Y2NfE1CKxzS-"
   },
   "outputs": [],
   "source": [
    "# Russell and Norvig, AIMA Chapter 16, “Making Simple Decisions” (16.1-16.3)\n",
    "\n",
    "sample_equation = r\"\"\" $P(\\textnormal{RESULT}(a)=s') = \\sum_s P(s)P(s'|s,a)$ \"\"\"\n",
    "equation_1 = r\"\"\" $EU(a) = \\sum_s' P(\\textnormal{RESULT}(a)=s')U(s')$ \"\"\"\n",
    "\n",
    "chapter16_1 = sample_equation + equation_1 +\"\"\" \n",
    "\n",
    "The agent’s preferences are captured by a utility function,U(s) , which assigns a single number to express the desirability of a state. \n",
    "The expected utility of an action given the evidence, EU(a), \n",
    "is just the average utility value of the outcomes, weighted by the probability that the outcome occurs: $EU(a) = $\"\"\"  \n",
    "chapter16_2 =  \"\"\" We can think of the set of outcomes for each action as a lottery—think of each action as a ticket.\\n\n",
    "EXISTENCE OF UTILITY FUNCTION: U(A)>U(B) -> A>B \\n\n",
    " an agent’s behavior would not change if its utility function U(S) were transformed according to U'(S)=aU(S)+b where a and b are constants and a > 0. This is called a value function or ordinal utility function. \\n\n",
    "  \"\"\"\n",
    "chapter16_3 =  \"\"\" Utility functions map from lotteries to real numbers.They must obey the axioms of orderability, transitivity, continuity, substitutability, monotonicity, and decomposability. \\n\n",
    "we must first work out what the human’s utility function is. This process, often called preference elicitation. \\n\n",
    "We will assume, kindly perhaps, that the estimates are unbiased—that is, the expected value of the error is zero \\n\n",
    "certainty effect: people are strongly attracted to gains that are certain.\n",
    " \"\"\"\n",
    "\n",
    "\n",
    "# Russell and Norvig, AIMA Chapter 17, “Making Complex Decision” (17.1-17.2)\n",
    "chapter17_1 = \"\"\"the transition model describes the outcome of each action in each state. We will assume that transitions are Markovian: the probability of reaching s'\n",
    " from s depends only on s and not on the history of earlier states. \\n\n",
    " Because the decision problem is sequential, the utility function will depend on a sequence of states and actions—an environment history—rather than on a single state. \\n\n",
    " we simply stipulate that for every transition from s to s' \n",
    " via action a, the agent receives a reward R(s,a,s'). The rewards may be positive or negative. \\n\n",
    "A sequential decision problem for a fully observable, stochastic environment with a Markovian transition model and additive rewards is called a Markov decision process, or MDP\\n\n",
    "A solution of this kind is called a policy( π).An optimal policy is a policy that yields the highest expected utility. We use π* to denote an optimal policy. \\n\n",
    "A finite horizon means that there is a fixed time N after which nothing matters—the game is over. With a finite horizon, an optimal action in a given state may depend on how much time is left. A policy that depends on the time is called nonstationary. \\n\n",
    "A policy that is guaranteed to reach a terminal state is called a proper policy.With proper policies, we can use γ = 1 \\n\n",
    "Q-function: Q(s,a) is the expected utility of taking a given action in a given state. \"\"\"\n",
    "chapter17_2 =  \"\"\" The basic concept used in showing that value iteration converges is the notion of a contraction.A contraction is a function of one argument that, when applied to two different inputs in turn, produces two output values that are “closer together,” \n",
    "by at least some constant factor, than the original inputs. \\n\n",
    "Policy Iteration \\n\n",
    "It is possible to get an optimal policy even when the utility function estimate is inaccurate.  \"\"\"\n",
    "\n",
    "# Lecture notes \n",
    "module8_lecture_notes = \"\"\" Markov decision processes: \n",
    "• Set of states S \\n\n",
    "• Start state s0  \\n\n",
    "• Set of actions A  \\n\n",
    "• Transitions P(s’|s,a) (or T(s,a,s’)) \\n \n",
    "• Rewards R(s,a,s’) (and discount y) \\n\n",
    "What if the game lasts forever?  Solutions: (1) Finite horizon: (similar to depth-limited search)\n",
    "▪ Terminate episodes after a fixed T steps (e.g. life)\n",
    "▪ Gives nonstationary policies (pi depends on time left) \\n\n",
    "(2) Discounting: use 0 < y < 1 \\n\n",
    "(3) Absorbing state: guarantee that for every policy, a terminal state will\n",
    "eventually be reached \\n\n",
    "MDP quantities so far: • Policy = Choice of action for each state • Utility = sum of (discounted) rewards \\n\n",
    "The value (utility) of a state s:\n",
    "V^*(s) = expected utility starting in s and acting optimally \\n\n",
    "▪ The value (utility) of a q-state (s,a): Q*(s,a) = expected utility starting out having taken action a from state s and\n",
    "(thereafter) acting optimally \\n\n",
    "▪ The optimal policy:\n",
    "pi*(s) = optimal action from state s \\n\n",
    "\n",
    "Policy Iteration (converge faster) \\n\n",
    "Step 1: Policy evaluation: calculate utilities for some fixed policy (not\n",
    "optimal utilities!) until convergence \\n\n",
    "• Step 2: Policy improvement: update policy using one-step lookahead with resulting converged (but not optimal!) utilities as future\n",
    "values \\n\n",
    "• Repeat steps until policy converges \\n\n",
    "\n",
    "In value iteration: \\n\n",
    "• Every iteration updates both the values and (implicitly) the policy \\n\n",
    "• We don’t track the policy, but taking the max over actions implicitly recomputes\n",
    "it \\n\n",
    "In policy iteration: \\n\n",
    "• We do several passes that update utilities with fixed policy (each pass is fast\n",
    "because we consider only one action, not all of them) \\n\n",
    "• After the policy is evaluated, a new policy is chosen (slow like a value iteration\n",
    "pass) \\n\n",
    "• The new policy will be better \\n\n",
    "\n",
    "\"\"\"\n",
    "\n",
    "\n",
    "# Definitions of concepts from Module 8.\n",
    "# You can define any term in the textbook or lecture, \n",
    "# but you most use your own words for the definitions.\n",
    "# Each definition should be at most 25 words long.\n",
    "\n",
    "module8_definitions = {\n",
    "\"utility function\" : \"Your definition here\",\n",
    "\"expected utility\" : \"your definition here\",\n",
    "\"etc.\": \"your definition here\",\n",
    "}\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "elCCgY64spuq"
   },
   "source": [
    "## Preview of your notes for Module 8\n",
    "\n",
    "Here's a preview of your how your notes will be displayed.  At the end of this Python notebook, we'll aggregate your notes for all modules together into a single display.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 1000
    },
    "id": "gYYeNcdM_maE",
    "outputId": "f0cecb54-847f-4acc-da89-b0e4eaa1325c"
   },
   "outputs": [
    {
     "data": {
      "text/markdown": [
       "# Module 8: Markov Decision Processes\n",
       "## AIMA Chapter 16.1 Combining Beliefs and Desires under Uncertainty\n",
       " $P(\\textnormal{RESULT}(a)=s') = \\sum_s P(s)P(s'|s,a)$  $EU(a) = \\sum_s' P(\\textnormal{RESULT}(a)=s')U(s')$  \n",
       "\n",
       "The agent’s preferences are captured by a utility function,U(s) , which assigns a single number to express the desirability of a state. \n",
       "The expected utility of an action given the evidence, EU(a), \n",
       "is just the average utility value of the outcomes, weighted by the probability that the outcome occurs: $EU(a) = $\n",
       "\n",
       "## AIMA Chapter 16.2 The Basis of Utility Theory\n",
       " We can think of the set of outcomes for each action as a lottery—think of each action as a ticket.\n",
       "\n",
       "EXISTENCE OF UTILITY FUNCTION: U(A)>U(B) -> A>B \n",
       "\n",
       " an agent’s behavior would not change if its utility function U(S) were transformed according to U'(S)=aU(S)+b where a and b are constants and a > 0. This is called a value function or ordinal utility function. \n",
       "\n",
       "  \n",
       "\n",
       "## AIMA Chapter 16.3 Utility Functions\n",
       " Utility functions map from lotteries to real numbers.They must obey the axioms of orderability, transitivity, continuity, substitutability, monotonicity, and decomposability. \n",
       "\n",
       "we must first work out what the human’s utility function is. This process, often called preference elicitation. \n",
       "\n",
       "We will assume, kindly perhaps, that the estimates are unbiased—that is, the expected value of the error is zero \n",
       "\n",
       "certainty effect: people are strongly attracted to gains that are certain.\n",
       " \n",
       "\n",
       "## AIMA Chapter 17.1 Sequential Decision Problems\n",
       "the transition model describes the outcome of each action in each state. We will assume that transitions are Markovian: the probability of reaching s'\n",
       " from s depends only on s and not on the history of earlier states. \n",
       "\n",
       " Because the decision problem is sequential, the utility function will depend on a sequence of states and actions—an environment history—rather than on a single state. \n",
       "\n",
       " we simply stipulate that for every transition from s to s' \n",
       " via action a, the agent receives a reward R(s,a,s'). The rewards may be positive or negative. \n",
       "\n",
       "A sequential decision problem for a fully observable, stochastic environment with a Markovian transition model and additive rewards is called a Markov decision process, or MDP\n",
       "\n",
       "A solution of this kind is called a policy( π).An optimal policy is a policy that yields the highest expected utility. We use π* to denote an optimal policy. \n",
       "\n",
       "A finite horizon means that there is a fixed time N after which nothing matters—the game is over. With a finite horizon, an optimal action in a given state may depend on how much time is left. A policy that depends on the time is called nonstationary. \n",
       "\n",
       "A policy that is guaranteed to reach a terminal state is called a proper policy.With proper policies, we can use γ = 1 \n",
       "\n",
       "Q-function: Q(s,a) is the expected utility of taking a given action in a given state. \n",
       "\n",
       "## AIMA Chapter 17.2 Algorithms for MDPs\n",
       " The basic concept used in showing that value iteration converges is the notion of a contraction.A contraction is a function of one argument that, when applied to two different inputs in turn, produces two output values that are “closer together,” \n",
       "by at least some constant factor, than the original inputs. \n",
       "\n",
       "Policy Iteration \n",
       "\n",
       "It is possible to get an optimal policy even when the utility function estimate is inaccurate.  \n",
       "\n",
       "## Module 8 Lecture Notes\n",
       " Markov decision processes: \n",
       "• Set of states S \n",
       "\n",
       "• Start state s0  \n",
       "\n",
       "• Set of actions A  \n",
       "\n",
       "• Transitions P(s’|s,a) (or T(s,a,s’)) \n",
       " \n",
       "• Rewards R(s,a,s’) (and discount y) \n",
       "\n",
       "What if the game lasts forever?  Solutions: (1) Finite horizon: (similar to depth-limited search)\n",
       "▪ Terminate episodes after a fixed T steps (e.g. life)\n",
       "▪ Gives nonstationary policies (pi depends on time left) \n",
       "\n",
       "(2) Discounting: use 0 < y < 1 \n",
       "\n",
       "(3) Absorbing state: guarantee that for every policy, a terminal state will\n",
       "eventually be reached \n",
       "\n",
       "MDP quantities so far: • Policy = Choice of action for each state • Utility = sum of (discounted) rewards \n",
       "\n",
       "The value (utility) of a state s:\n",
       "V^*(s) = expected utility starting in s and acting optimally \n",
       "\n",
       "▪ The value (utility) of a q-state (s,a): Q*(s,a) = expected utility starting out having taken action a from state s and\n",
       "(thereafter) acting optimally \n",
       "\n",
       "▪ The optimal policy:\n",
       "pi*(s) = optimal action from state s \n",
       "\n",
       "\n",
       "Policy Iteration (converge faster) \n",
       "\n",
       "Step 1: Policy evaluation: calculate utilities for some fixed policy (not\n",
       "optimal utilities!) until convergence \n",
       "\n",
       "• Step 2: Policy improvement: update policy using one-step lookahead with resulting converged (but not optimal!) utilities as future\n",
       "values \n",
       "\n",
       "• Repeat steps until policy converges \n",
       "\n",
       "\n",
       "In value iteration: \n",
       "\n",
       "• Every iteration updates both the values and (implicitly) the policy \n",
       "\n",
       "• We don’t track the policy, but taking the max over actions implicitly recomputes\n",
       "it \n",
       "\n",
       "In policy iteration: \n",
       "\n",
       "• We do several passes that update utilities with fixed policy (each pass is fast\n",
       "because we consider only one action, not all of them) \n",
       "\n",
       "• After the policy is evaluated, a new policy is chosen (slow like a value iteration\n",
       "pass) \n",
       "\n",
       "• The new policy will be better \n",
       "\n",
       "\n",
       "\n",
       "\n",
       "## Module 8 Definitions\n",
       "* **Utility function** - Your definition here\n",
       "* **Expected utility** - your definition here\n",
       "* **Etc.** - your definition here\n"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#@title Preview of your summary\n",
    "#@markdown You don't need to modify anything in this cell. Just press play.\n",
    "from IPython.display import display, Markdown, Latex\n",
    "\n",
    "module8_sections = [\n",
    "  (\"AIMA Chapter 16.1 Combining Beliefs and Desires under Uncertainty\", chapter16_1),\n",
    "  (\"AIMA Chapter 16.2 The Basis of Utility Theory\", chapter16_2),\n",
    "  (\"AIMA Chapter 16.3 Utility Functions\", chapter16_3),\n",
    "  (\"AIMA Chapter 17.1 Sequential Decision Problems\", chapter17_1),\n",
    "  (\"AIMA Chapter 17.2 Algorithms for MDPs\", chapter17_2),\n",
    "  (\"Module 8 Lecture Notes\", module8_lecture_notes),\n",
    "]\n",
    "\n",
    "\n",
    "def length_check(sections):\n",
    "  warnings = \"\"\n",
    "  for section, summary in sections:\n",
    "    max_word_length = 500\n",
    "    max_character_length = 3000\n",
    "    if \"lecture\" in section.lower():\n",
    "      # It's OK to do longer summaries of the lectures\n",
    "      max_word_length = 2000\n",
    "      max_character_length = 12000  \n",
    "    if (len(summary) > max_character_length or len(summary.split(' ')) > max_word_length):\n",
    "      warnings += \"WARNING: Your summary of '{section}' is too long!\\n\".format(section=section)\n",
    "  return warnings\n",
    "\n",
    "def length_check_definitions(definitions):\n",
    "  warnings = \"\"\n",
    "  for concept, definition in definitions.items():\n",
    "    if(len(definition.split(' ')) > 25):\n",
    "      warnings += \"WARNING: Your definition of '{concept}' is too long!\\n\".format(concept=concept)\n",
    "  return warnings\n",
    "\n",
    "\n",
    "def format_module(module_num, title, sections, definitions, show_placeholder=False):\n",
    "  markdown = \"\"\n",
    "\n",
    "  # Check summary lengths\n",
    "  warnings = length_check(sections)\n",
    "  if warnings != \"\":\n",
    "    markdown += \"## \" + warnings\n",
    "\n",
    "  # Check definition lengths\n",
    "  warnings = length_check_definitions(definitions)\n",
    "  if warnings != \"\":\n",
    "    markdown += \"## \" + warnings\n",
    "\n",
    "  markdown += \"# Module {num}: {title}\\n\".format(num=module_num, title=title)\n",
    "\n",
    "\n",
    "  for section, summary in sections:\n",
    "    if show_placeholder and summary == \" Your summary here \":\n",
    "      summary = placeholder\n",
    "    markdown += \"## {section}\\n{summary}\\n\\n\".format(section=section, summary=summary)\n",
    "  \n",
    "  markdown += \"## Module {num} Definitions\\n\".format(num=module_num)\n",
    "  for concept, definition in definitions.items():\n",
    "    markdown += \"* **{concept}** - {definition}\\n\".format(concept=concept.capitalize(), definition=definition)\n",
    "  return markdown\n",
    "\n",
    "\n",
    "module8_markdown = format_module(8, \"Markov Decision Processes\", module8_sections, module8_definitions)\n",
    "display(Markdown(module8_markdown))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "9xRbdqDox2zD"
   },
   "source": [
    "#Module 9 - Reinforcement Learning"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "id": "DpBvu7EMx7sy"
   },
   "outputs": [],
   "source": [
    "# Russell and Norvig, AIMA Section 17.3 “Bandit Problems”\n",
    "chapter17_3 =  \"\"\" Your summary here \"\"\"\n",
    "\n",
    "# Russell and Norvig, AIMA Chapter 22 “Reinforcement Learning” (Sections 22.1-22.5)\n",
    "chapter22_1 =  \"\"\" Reinforcement learning (RL), in which an agent interacts with the world and periodically receives rewards. It may not know the transition model or the reward function, and it has to act in order to learn more.\\n\n",
    "MODEL-BASED REINFORCEMENT LEARNING: the agent uses a transition model of the environment to help interpret the reward signals and to make decisions about how to act. The model may be initially unknown, in which case the agent learns the model from observing the effects of its actions, or it may already be known \\n\n",
    "MODEL-FREE REINFORCEMENT LEARNING: In these approaches the agent neither knows nor learns a transition model for the environment.Instead, it learns a more direct representation of how to behave. Two cases: ACTION-UTILITY LEARNING: learns a Q-function denoting the sum of rewards from state s onward if action a is \n",
    "taken and POLICY SEARCH:  learns a policy π(s) that maps directly from states to actions. \\n\n",
    "passive reinforcement learning, where the agent’s policy is fixed and the task is to learn the utilities of states.Active reinforcement learning, where the agent must also figure out what to do.\"\"\"\n",
    "chapter22_2 =  \"\"\"  an agent already has a fixed policy π(s) that determines its actions. The agent is trying to learn the utility function U^π(s)—the expected total discounted reward if policy π is executed beginning in state s\"\"\"\n",
    "chapter22_3 =  \"\"\"  Temporal-difference Q-learning: The Q-learning method avoids the need for a model by learning an action-utility function Q(s,a) instead of a utility function U(s). Q-learning is an off-policy learning algorithm,  \"\"\"\n",
    "chapter22_4 =  \"\"\" Your summary here \"\"\"\n",
    "chapter22_5 =  \"\"\" Your summary here \"\"\"\n",
    "\n",
    "\n",
    "# Lecture notes \n",
    "module9_lecture_notes = \"\"\" Exploration: you have to try unknown actions to get information \\n\n",
    "Exploitation: eventually, you have to use what you know \\n\n",
    "Regret: even if you learn intelligently, you make mistakes \\n\n",
    "Sampling: because of chance, you have to try things repeatedly \\n\n",
    "Difficulty: learning can be much harder than solving a known MDP \\n\n",
    "\n",
    "Receive feedback in the form of rewards.\n",
    "Agent’s utility is defined by the reward function.\n",
    "Must (learn to) act so as to maximize expected rewards.\n",
    "All learning is based on observed samples of outcomes! \\n\n",
    "\n",
    "Still assume a Markov decision process (MDP) but we don’t know T or R and we must actually try actions and states out to learn \\n\n",
    "\n",
    " Direct Evaluation\\n\n",
    " Goal: Compute values for each state under π \\n\n",
    " Idea: Average together observed sample values \\n\n",
    "\n",
    "Regret is a measure of your total\n",
    "mistake cost: the difference between\n",
    "your (expected) rewards, including\n",
    "youthful suboptimality, and optimal\n",
    "(expected) rewards\n",
    "Minimizing regret goes beyond\n",
    "learning to be optimal – it requires\n",
    "optimally learning to be optimal\n",
    "Example: random exploration and\n",
    "exploration functions both end up\n",
    "optimal, but random exploration has\n",
    "higher regret\n",
    " \"\"\"\n",
    "\n",
    "# Each definition should be at most 25 words long.\n",
    "module9_definitions = {\n",
    "\"term\" : \"your definition here\",\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "cellView": "form",
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 1000
    },
    "id": "ydOK__lwWgdp",
    "outputId": "bbb2a688-de34-45c9-84c2-7a973e94f991"
   },
   "outputs": [
    {
     "data": {
      "text/markdown": [
       "# Module 9: Reinforcement Learning\n",
       "## AIMA Chapter 17.3 Bandit Problems\n",
       " Your summary here \n",
       "\n",
       "## AIMA Chapter 22.1 Learning from Rewards\n",
       " Reinforcement learning (RL), in which an agent interacts with the world and periodically receives rewards. It may not know the transition model or the reward function, and it has to act in order to learn more.\n",
       "\n",
       "MODEL-BASED REINFORCEMENT LEARNING: the agent uses a transition model of the environment to help interpret the reward signals and to make decisions about how to act. The model may be initially unknown, in which case the agent learns the model from observing the effects of its actions, or it may already be known \n",
       "\n",
       "MODEL-FREE REINFORCEMENT LEARNING: In these approaches the agent neither knows nor learns a transition model for the environment.Instead, it learns a more direct representation of how to behave. Two cases: ACTION-UTILITY LEARNING: learns a Q-function denoting the sum of rewards from state s onward if action a is \n",
       "taken and POLICY SEARCH:  learns a policy π(s) that maps directly from states to actions. \n",
       "\n",
       "passive reinforcement learning, where the agent’s policy is fixed and the task is to learn the utilities of states.Active reinforcement learning, where the agent must also figure out what to do.\n",
       "\n",
       "## AIMA Chapter 22.2 Passive Reinforcement Learning\n",
       "  an agent already has a fixed policy π(s) that determines its actions. The agent is trying to learn the utility function U^π(s)—the expected total discounted reward if policy π is executed beginning in state s\n",
       "\n",
       "## AIMA Chapter 22.3 Active Reinforcement Learning\n",
       "  Temporal-difference Q-learning: The Q-learning method avoids the need for a model by learning an action-utility function Q(s,a) instead of a utility function U(s). Q-learning is an off-policy learning algorithm,  \n",
       "\n",
       "## AIMA Chapter 22.4 Generalization in Reinforcement Learning\n",
       " Your summary here \n",
       "\n",
       "## Module 9 Lecture Notes\n",
       " Exploration: you have to try unknown actions to get information \n",
       "\n",
       "Exploitation: eventually, you have to use what you know \n",
       "\n",
       "Regret: even if you learn intelligently, you make mistakes \n",
       "\n",
       "Sampling: because of chance, you have to try things repeatedly \n",
       "\n",
       "Difficulty: learning can be much harder than solving a known MDP \n",
       "\n",
       "\n",
       "Receive feedback in the form of rewards.\n",
       "Agent’s utility is defined by the reward function.\n",
       "Must (learn to) act so as to maximize expected rewards.\n",
       "All learning is based on observed samples of outcomes! \n",
       "\n",
       "\n",
       "Still assume a Markov decision process (MDP) but we don’t know T or R and we must actually try actions and states out to learn \n",
       "\n",
       "\n",
       " Direct Evaluation\n",
       "\n",
       " Goal: Compute values for each state under π \n",
       "\n",
       " Idea: Average together observed sample values \n",
       "\n",
       "\n",
       "Regret is a measure of your total\n",
       "mistake cost: the difference between\n",
       "your (expected) rewards, including\n",
       "youthful suboptimality, and optimal\n",
       "(expected) rewards\n",
       "Minimizing regret goes beyond\n",
       "learning to be optimal – it requires\n",
       "optimally learning to be optimal\n",
       "Example: random exploration and\n",
       "exploration functions both end up\n",
       "optimal, but random exploration has\n",
       "higher regret\n",
       " \n",
       "\n",
       "## Module 9 Definitions\n",
       "* **Term** - your definition here\n"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#@title Preview of your summary\n",
    "#@markdown You don't need to modify anything in this cell. Just press play.\n",
    "\n",
    "module9_sections = [\n",
    "  (\"AIMA Chapter 17.3 Bandit Problems\", chapter17_3),\n",
    "  (\"AIMA Chapter 22.1 Learning from Rewards\", chapter22_1),\n",
    "  (\"AIMA Chapter 22.2 Passive Reinforcement Learning\", chapter22_2),\n",
    "  (\"AIMA Chapter 22.3 Active Reinforcement Learning\", chapter22_3),\n",
    "  (\"AIMA Chapter 22.4 Generalization in Reinforcement Learning\", chapter22_4),\n",
    "  (\"Module 9 Lecture Notes\", module9_lecture_notes),\n",
    "]\n",
    "\n",
    "module9_markdown = format_module(9, \"Reinforcement Learning\", module9_sections, module9_definitions)\n",
    "display(Markdown(module9_markdown))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "46MQLR-Gx8dZ"
   },
   "source": [
    "#Module 10 - Probabilities and Language Models"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "id": "BN0b1eVYx-nd"
   },
   "outputs": [],
   "source": [
    "# Russell and Norvig, AIMA 4th Edition, AIMA Chapter 12 “Quantifying Uncertainty” (Sections 12.1-12.7)\n",
    "chapter12_1 = \"\"\" Your summary here \"\"\"\n",
    "chapter12_2 = \"\"\" In probability theory, the set of all possible worlds is called the sample space. A fully specified probability model associates a numerical probability P(w) with each possible world.\n",
    "The basic axioms of probability theory say that every possible world has a probability between 0 and 1 and that the total probability of the set of possible worlds is 1. \\n\n",
    "An alternative range for Boolean variables is the set {0,1}, in which case the variable is said to have a Bernoulli distribution. \"\"\"\n",
    "chapter12_3 = \"\"\" The full joint probability distribution specifies the probability of each complete assignment of values to random variables. \n",
    "It is usually too large to create or use in its explicit form, but when it is available it can be used to answer queries simply by adding up entries for the possible worlds corresponding to the query propositions. \"\"\"\n",
    "chapter12_4 = \"\"\"Bayes’ rule allows unknown probabilities to be computed from known conditional probabilities, usually in the causal direction. Applying Bayes’ rule with many pieces of evidence runs into the same scaling problems as does the full joint distribution.\"\"\"\n",
    "chapter12_5 = \"\"\" Conditional independence brought about by direct causal relationships in the domain allows the full joint distribution to be factored into smaller, conditional distributions. \n",
    "The naive Bayes model assumes the conditional independence of all effect variables, given a single cause variable; its size grows linearly with the number of effects. \"\"\"\n",
    "chapter12_6 = \"\"\" Your summary here \"\"\"\n",
    "chapter12_7 = \"\"\" Your summary here \"\"\"\n",
    "\n",
    "\n",
    "# Jurafsky and Martin, Speech and Language Processing Chapter 3 “N-Gram Language Models”  (Sections 3.1-3.5,3.7)\n",
    "SLP_chapter3_1 = \"\"\" Your summary here \"\"\"\n",
    "SLP_chapter3_2 = \"\"\" Your summary here \"\"\"\n",
    "SLP_chapter3_3 = \"\"\" Your summary here \"\"\"\n",
    "SLP_chapter3_4 = \"\"\" Your summary here \"\"\"\n",
    "SLP_chapter3_5 = \"\"\" Your summary here \"\"\"\n",
    "SLP_chapter3_7 = \"\"\" Your summary here \"\"\"\n",
    "\n",
    "\n",
    "# Lecture notes \n",
    "module10_lecture_notes = \"\"\"Uncertainty: Observed variables (evidence): Agent knows certain things about the state of the world (e.g.,\n",
    "sensor readings or symptoms) \\n \n",
    "Unobserved variables (states): Agent needs to reason about other aspects (e.g. where an object\n",
    "is or what disease is present) \\n\n",
    "Model: Agent knows something about how the known variables relate to the unknown variables \\n\n",
    "In probability theory, the possible worlds are called the sample space, and they\n",
    "mutually exclusive and exhaustive. \\n\n",
    "An event is a set E of outcomes. \\n\n",
    "Probabilistic Language Modeling \\n\n",
    "Goal: compute the probability of a sentence or sequence of words \\n\n",
    "Related task: probability of an upcoming word \\n\n",
    "A model that computes either of these is called a language model or LM \\n\n",
    "Simplifying Assumption = Markov Assumption: The Markov property says that given the past state, the present and the future are independent.\n",
    " \"\"\"\n",
    "\n",
    "\n",
    "# Each definition should be at most 25 words long.\n",
    "module10_definitions = {\n",
    "\"term\" : \"your definition here\",\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "cellView": "form",
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 1000
    },
    "id": "lvtN3p7ET3Tx",
    "outputId": "101613f8-72cc-4cff-ba99-551859e56982"
   },
   "outputs": [
    {
     "data": {
      "text/markdown": [
       "# Module 10: Probabilies and Language Models\n",
       "## AIMA Chapter 12.1 Acting under Uncertainty\n",
       " Your summary here \n",
       "\n",
       "## AIMA Chapter 12.2 Basic Probability Notation\n",
       " In probability theory, the set of all possible worlds is called the sample space. A fully specified probability model associates a numerical probability P(w) with each possible world.\n",
       "The basic axioms of probability theory say that every possible world has a probability between 0 and 1 and that the total probability of the set of possible worlds is 1. \n",
       "\n",
       "An alternative range for Boolean variables is the set {0,1}, in which case the variable is said to have a Bernoulli distribution. \n",
       "\n",
       "## AIMA Chapter 12.3 Inference Using Full Joint Distributions\n",
       " The full joint probability distribution specifies the probability of each complete assignment of values to random variables. \n",
       "It is usually too large to create or use in its explicit form, but when it is available it can be used to answer queries simply by adding up entries for the possible worlds corresponding to the query propositions. \n",
       "\n",
       "## AIMA Chapter 12.4 Independence\n",
       "Bayes’ rule allows unknown probabilities to be computed from known conditional probabilities, usually in the causal direction. Applying Bayes’ rule with many pieces of evidence runs into the same scaling problems as does the full joint distribution.\n",
       "\n",
       "## AIMA Chapter 12.5 Bayes’ Rule and Its Use\n",
       " Conditional independence brought about by direct causal relationships in the domain allows the full joint distribution to be factored into smaller, conditional distributions. \n",
       "The naive Bayes model assumes the conditional independence of all effect variables, given a single cause variable; its size grows linearly with the number of effects. \n",
       "\n",
       "## AIMA Chapter 12.6 Naive Bayes Models\n",
       " Your summary here \n",
       "\n",
       "## AIMA Chapter 12.7 The Wumpus World Revisited\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 3.1 N-Grams\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 3.2 Evaluating Language Models\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 3.3 Sampling sentences from a language model\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 3.4 Generalization and Zeros\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 3.5 Smoothing\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 3.7 Huge Language Models and Stupid Backoff\n",
       " Your summary here \n",
       "\n",
       "## Module 10 Lecture Notes\n",
       "Uncertainty: Observed variables (evidence): Agent knows certain things about the state of the world (e.g.,\n",
       "sensor readings or symptoms) \n",
       " \n",
       "Unobserved variables (states): Agent needs to reason about other aspects (e.g. where an object\n",
       "is or what disease is present) \n",
       "\n",
       "Model: Agent knows something about how the known variables relate to the unknown variables \n",
       "\n",
       "In probability theory, the possible worlds are called the sample space, and they\n",
       "mutually exclusive and exhaustive. \n",
       "\n",
       "An event is a set E of outcomes. \n",
       "\n",
       "Probabilistic Language Modeling \n",
       "\n",
       "Goal: compute the probability of a sentence or sequence of words \n",
       "\n",
       "Related task: probability of an upcoming word \n",
       "\n",
       "A model that computes either of these is called a language model or LM \n",
       "\n",
       "Simplifying Assumption = Markov Assumption: The Markov property says that given the past state, the present and the future are independent.\n",
       " \n",
       "\n",
       "## Module 10 Definitions\n",
       "* **Term** - your definition here\n"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#@title Preview of your summary\n",
    "#@markdown You don't need to modify anything in this cell. Just press play.\n",
    "module10_sections = [\n",
    "  (\"AIMA Chapter 12.1 Acting under Uncertainty\", chapter12_1),\n",
    "  (\"AIMA Chapter 12.2 Basic Probability Notation\", chapter12_2),\n",
    "  (\"AIMA Chapter 12.3 Inference Using Full Joint Distributions\", chapter12_3),\n",
    "  (\"AIMA Chapter 12.4 Independence\", chapter12_4),\n",
    "  (\"AIMA Chapter 12.5 Bayes’ Rule and Its Use\", chapter12_5),\n",
    "  (\"AIMA Chapter 12.6 Naive Bayes Models\", chapter12_6),\n",
    "  (\"AIMA Chapter 12.7 The Wumpus World Revisited\", chapter12_7),\n",
    "  (\"SLP Chapter 3.1 N-Grams\", SLP_chapter3_1),\n",
    "  (\"SLP Chapter 3.2 Evaluating Language Models\", SLP_chapter3_2),\n",
    "  (\"SLP Chapter 3.3 Sampling sentences from a language model\", SLP_chapter3_3),\n",
    "  (\"SLP Chapter 3.4 Generalization and Zeros\", SLP_chapter3_4),\n",
    "  (\"SLP Chapter 3.5 Smoothing\", SLP_chapter3_5),\n",
    "  (\"SLP Chapter 3.7 Huge Language Models and Stupid Backoff\", SLP_chapter3_7),\n",
    "  (\"Module 10 Lecture Notes\", module10_lecture_notes),\n",
    "]\n",
    "\n",
    "module10_markdown = format_module(10, \"Probabilies and Language Models\", module10_sections, module10_definitions)\n",
    "display(Markdown(module10_markdown))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "WHREsHSSyA-h"
   },
   "source": [
    "#Module 11 - Probabilistic Reasoning and Bayes’ Nets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "id": "tuFC8w7CyCns"
   },
   "outputs": [],
   "source": [
    "# Russell and Norvig, Russell and Norvig, AIMA Chapter 13 “Probabilistic Reasoning” (13.1, 13.2, 13.3)\n",
    "chapter13_1 = \"\"\"Two variables are independent if: P(x,y) = P(x)P(y). \\n\n",
    "Independence is a simplifying modeling assumption. \\n\n",
    "Each node corresponds to a random variable, which may be discrete or continuous.\n",
    "Directed links or arrows connect pairs of nodes. If there is an arrow from node X to node Y, X is said to be a parent of Y. The graph has no directed cycles and hence is a directed acyclic graph, or DAG. \\n\n",
    "Each node Xi has associated probability information  that quantifies the effect of the parents on the node using a finite number of parameters\"\"\"\n",
    "chapter13_2 = \"\"\" topological order—that is, in any order consistent with the directed graph structure. locally structured (also called sparse) systems. In a locally structured system, each subcomponent interacts directly with only a bounded number of other components, \n",
    "regardless of the total number of components. Local structure is usually associated with linear rather than exponential growth in complexity. \"\"\"\n",
    "chapter13_3 = \"\"\" Your summary here \"\"\"\n",
    "\n",
    "\n",
    "# Lecture notes \n",
    "module11_lecture_notes = \"\"\"Bayes’ nets: a technique for describing complex joint\n",
    "distributions (models) using simple, local\n",
    "distributions (conditional probabilities) \\n\n",
    "More properly called graphical models. We describe how variables locally interact. Local interactions chain together to give global, indirect\n",
    "interactions\"\"\"\n",
    "\n",
    "# Definitions\n",
    "module11_definitions = {\n",
    "\"concept\" : \"definition\",    \n",
    "}\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "cellView": "form",
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 556
    },
    "id": "vqtEs0gHs9sO",
    "outputId": "e66c5bf6-522d-4c62-ad18-e0a105a528f9"
   },
   "outputs": [
    {
     "data": {
      "text/markdown": [
       "# Module 11: Probabilistic Reasoning and Bayes’ Nets\n",
       "## AIMA Chapter 13.1 Representing Knowledge in an Uncertain Domain\n",
       "Two variables are independent if: P(x,y) = P(x)P(y). \n",
       "\n",
       "Independence is a simplifying modeling assumption. \n",
       "\n",
       "Each node corresponds to a random variable, which may be discrete or continuous.\n",
       "Directed links or arrows connect pairs of nodes. If there is an arrow from node X to node Y, X is said to be a parent of Y. The graph has no directed cycles and hence is a directed acyclic graph, or DAG. \n",
       "\n",
       "Each node Xi has associated probability information  that quantifies the effect of the parents on the node using a finite number of parameters\n",
       "\n",
       "## AIMA Chapter 13.2 The Semantics of Bayesian Networks\n",
       " topological order—that is, in any order consistent with the directed graph structure. locally structured (also called sparse) systems. In a locally structured system, each subcomponent interacts directly with only a bounded number of other components, \n",
       "regardless of the total number of components. Local structure is usually associated with linear rather than exponential growth in complexity. \n",
       "\n",
       "## AIMA 13.3 Exact Inference in Bayesian Networks\n",
       " Your summary here \n",
       "\n",
       "## Module 11 Lecture Notes\n",
       "Bayes’ nets: a technique for describing complex joint\n",
       "distributions (models) using simple, local\n",
       "distributions (conditional probabilities) \n",
       "\n",
       "More properly called graphical models. We describe how variables locally interact. Local interactions chain together to give global, indirect\n",
       "interactions\n",
       "\n",
       "## Module 11 Definitions\n",
       "* **Concept** - definition\n"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#@title Preview of your summary\n",
    "#@markdown You don't need to modify anything in this cell. Just press play.\n",
    "module11_sections = [\n",
    "  (\"AIMA Chapter 13.1 Representing Knowledge in an Uncertain Domain\", chapter13_1),\n",
    "  (\"AIMA Chapter 13.2 The Semantics of Bayesian Networks\", chapter13_2),\n",
    "  (\"AIMA 13.3 Exact Inference in Bayesian Networks\", chapter13_3),\n",
    "  (\"Module 11 Lecture Notes\", module11_lecture_notes),\n",
    "]\n",
    "\n",
    "module11_markdown = format_module(11, \"Probabilistic Reasoning and Bayes’ Nets\", \n",
    "                         module11_sections, \n",
    "                         module11_definitions)\n",
    "display(Markdown(module11_markdown))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "F3FPMzG9yUls"
   },
   "source": [
    "#Module 12 - Naive Bayes and Perceptrons"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "id": "iEIOpL7vyWcc"
   },
   "outputs": [],
   "source": [
    "# Russell and Norvig, AIMA Chapter 19 “Learning from Examples” (Sections 19.1-19.6)\n",
    "\n",
    "chapter19_1 = \"\"\" Your summary here \"\"\"\n",
    "chapter19_2 = \"\"\" Your summary here \"\"\"\n",
    "chapter19_3 = \"\"\" Your summary here \"\"\"\n",
    "chapter19_4 = \"\"\" Your summary here \"\"\"\n",
    "chapter19_5 = \"\"\" Your summary here \"\"\"\n",
    "chapter19_6 = \"\"\" Your summary here \"\"\"\n",
    "\n",
    "# Speech and Language Processing Chapter 4 “Naive Bayes and Sentiment Classification”\n",
    "slp_chapter4_1 = \"\"\" Your summary here \"\"\"\n",
    "slp_chapter4_2 = \"\"\" Your summary here \"\"\"\n",
    "slp_chapter4_3 = \"\"\" Your summary here \"\"\"\n",
    "slp_chapter4_4 = \"\"\" Your summary here \"\"\"\n",
    "slp_chapter4_5 = \"\"\" Your summary here \"\"\"\n",
    "slp_chapter4_6 = \"\"\" Your summary here \"\"\"\n",
    "slp_chapter4_7 = \"\"\" Your summary here \"\"\"\n",
    "slp_chapter4_8 = \"\"\" Your summary here \"\"\"\n",
    "slp_chapter4_9 = \"\"\" Your summary here \"\"\"\n",
    "slp_chapter4_10 = \"\"\" Your summary here \"\"\"\n",
    "\n",
    "# Lecture notes \n",
    "module12_lecture_notes = \"\"\" Bag-of-words Naïve Bayes: Each position is identically distributed\n",
    "• All positions share the same conditional probs P(W|Y) \\n\n",
    "• Called “bag-of-words” because model is insensitive to word order or reordering \\n\n",
    "IMPORTANT CONCEPTS: \\n\n",
    "Features: attribute-value pairs which characterize each x \\n\n",
    "Experimentation cycle: Learn parameters (e.g. model probabilities) on training set\n",
    "• (Tune hyperparameters on held-out set)\n",
    "• Compute accuracy of test set\n",
    "• Very important: never “peek” at the test set! \\n\n",
    "Evaluation\n",
    "• Accuracy: fraction of instances predicted correctly \\n\n",
    "Overfitting and generalization\n",
    "• Want a classifier which does well on test data\n",
    "• Overfitting: fitting the training data very closely, but not generalizing well \\n\n",
    "Generalization and Overfitting: Relative frequency parameters will overfit the training data \\n\n",
    "To generalize better: we need to smooth or regularize the estimates \\n\n",
    "Laplace Smoothing: /n\n",
    "Pretend you saw every outcome once more than you actually did \\n\n",
    "The confidence of a probabilistic classifier: Represents how sure the classifier is of\n",
    "the classification • Any probabilistic model will have confidences • No guarantee confidence is correct \\n\n",
    "Summary: Bayes rule lets us do diagnostic queries with causal probabilities\n",
    "The naïve Bayes assumption takes all features to be independent given\n",
    "the class label \\n\n",
    "We can build classifiers out of a naïve Bayes model using training data\n",
    "Smoothing estimates is important in real systems \\n\n",
    "Classifier confidences are useful, when you can get them \\n\n",
    "Perceptron: \\n\n",
    "Properties of Perceptrons: Separability: true if some parameters get the training\n",
    "set perfectly correct \\n\n",
    "Convergence: if the training is separable, perceptron\n",
    "will eventually converge (binary case) \\n\n",
    "Problems with the Perceptron: \\n\n",
    "Noise: if the data isn’t separable,weights might thrash\n",
    "• Averaging weight vectors over time can help (averaged perceptron) \\n\n",
    "Mediocre generalization: finds a\n",
    "“barely” separating solution\n",
    "Overtraining: test / held-out\n",
    "accuracy usually rises, then falls \\n\n",
    "MIRA*: choose an update size that fixes the current\n",
    "mistake but, minimizes the change to w \\n\n",
    "Maximum Step Size: cap the maximum possible value of t with some\n",
    "constant C. Corresponds to an optimization that assumes nonseparable data\n",
    "• Usually converges faster than perceptron\n",
    "• Usually better, especially on noisy data\n",
    "\n",
    "Support Vector Machines \\n\n",
    "Support vector machines (SVMs) find the separator with max margin \\n\n",
    "\n",
    "Naïve Bayes\n",
    "• Builds a model training data\n",
    "• Gives prediction probabilities\n",
    "• Strong assumptions about feature independence\n",
    "• One pass through data (counting) \\n\n",
    "Perceptrons / MIRA:\n",
    "• Makes less assumptions about data\n",
    "• Mistake-driven learning\n",
    "• Multiple passes through data (prediction)\n",
    "• Often more accurate\n",
    "\n",
    "\n",
    " \"\"\"\n",
    "\n",
    "# Definitions\n",
    "module12_definitions = {\n",
    "\"concept\" : \"definition\",    \n",
    "}\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "cellView": "form",
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 1000
    },
    "id": "KUc_LgzDvWf-",
    "outputId": "1b75e2e5-fcdb-4318-e1dc-246c3d052e2f"
   },
   "outputs": [
    {
     "data": {
      "text/markdown": [
       "# Module 12: Naive Bayes and Perceptrons\n",
       "## AIMA Chapter 5.1 Game Theory\n",
       " Your summary here \n",
       "\n",
       "## AIMA Chapter 5.2 Optimal Decisions in Games\n",
       " Your summary here \n",
       "\n",
       "## AIMA Chapter 5.3 Heuristic Alpha–Beta Tree Search\n",
       " Your summary here \n",
       "\n",
       "## AIMA Chapter 5.5 Stochastic Games\n",
       " Your summary here \n",
       "\n",
       "## AIMA Chapter 16.1 Combining Beliefs and Desires under Uncertainty\n",
       " Your summary here \n",
       "\n",
       "## AIMA Chapter 16.2 The Basis of Utility Theory\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 4.1 Naive Bayes Classifiers\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 4.2 Training the Naive Bayes Classifier\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 4.3 Worked Example\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 4.4 Optimizing for Sentiment Analysis\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 4.5 Naive Bayes for other text classification tasks\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 4.6 Naive Bayes as a Language Model\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 4.7 Evaluation: Precision, Recall, F-measure\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 4.8 Test sets and Cross-validation\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 4.9 Statistical Significance Testing\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 4.10 Avoiding Harms in Classification\n",
       " Your summary here \n",
       "\n",
       "## Module 12 Lecture Notes\n",
       " Bag-of-words Naïve Bayes: Each position is identically distributed\n",
       "• All positions share the same conditional probs P(W|Y) \n",
       "\n",
       "• Called “bag-of-words” because model is insensitive to word order or reordering \n",
       "\n",
       "IMPORTANT CONCEPTS: \n",
       "\n",
       "Features: attribute-value pairs which characterize each x \n",
       "\n",
       "Experimentation cycle: Learn parameters (e.g. model probabilities) on training set\n",
       "• (Tune hyperparameters on held-out set)\n",
       "• Compute accuracy of test set\n",
       "• Very important: never “peek” at the test set! \n",
       "\n",
       "Evaluation\n",
       "• Accuracy: fraction of instances predicted correctly \n",
       "\n",
       "Overfitting and generalization\n",
       "• Want a classifier which does well on test data\n",
       "• Overfitting: fitting the training data very closely, but not generalizing well \n",
       "\n",
       "Generalization and Overfitting: Relative frequency parameters will overfit the training data \n",
       "\n",
       "To generalize better: we need to smooth or regularize the estimates \n",
       "\n",
       "Laplace Smoothing: /n\n",
       "Pretend you saw every outcome once more than you actually did \n",
       "\n",
       "The confidence of a probabilistic classifier: Represents how sure the classifier is of\n",
       "the classification • Any probabilistic model will have confidences • No guarantee confidence is correct \n",
       "\n",
       "Summary: Bayes rule lets us do diagnostic queries with causal probabilities\n",
       "The naïve Bayes assumption takes all features to be independent given\n",
       "the class label \n",
       "\n",
       "We can build classifiers out of a naïve Bayes model using training data\n",
       "Smoothing estimates is important in real systems \n",
       "\n",
       "Classifier confidences are useful, when you can get them \n",
       "\n",
       "Perceptron: \n",
       "\n",
       "Properties of Perceptrons: Separability: true if some parameters get the training\n",
       "set perfectly correct \n",
       "\n",
       "Convergence: if the training is separable, perceptron\n",
       "will eventually converge (binary case) \n",
       "\n",
       "Problems with the Perceptron: \n",
       "\n",
       "Noise: if the data isn’t separable,weights might thrash\n",
       "• Averaging weight vectors over time can help (averaged perceptron) \n",
       "\n",
       "Mediocre generalization: finds a\n",
       "“barely” separating solution\n",
       "Overtraining: test / held-out\n",
       "accuracy usually rises, then falls \n",
       "\n",
       "MIRA*: choose an update size that fixes the current\n",
       "mistake but, minimizes the change to w \n",
       "\n",
       "Maximum Step Size: cap the maximum possible value of t with some\n",
       "constant C. Corresponds to an optimization that assumes nonseparable data\n",
       "• Usually converges faster than perceptron\n",
       "• Usually better, especially on noisy data\n",
       "\n",
       "Support Vector Machines \n",
       "\n",
       "Support vector machines (SVMs) find the separator with max margin \n",
       "\n",
       "\n",
       "Naïve Bayes\n",
       "• Builds a model training data\n",
       "• Gives prediction probabilities\n",
       "• Strong assumptions about feature independence\n",
       "• One pass through data (counting) \n",
       "\n",
       "Perceptrons / MIRA:\n",
       "• Makes less assumptions about data\n",
       "• Mistake-driven learning\n",
       "• Multiple passes through data (prediction)\n",
       "• Often more accurate\n",
       "\n",
       "\n",
       " \n",
       "\n",
       "## Module 12 Definitions\n",
       "* **Concept** - definition\n"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#@title Preview of your summary\n",
    "#@markdown You don't need to modify anything in this cell. Just press play.\n",
    "module12_sections = [\n",
    "  (\"AIMA Chapter 5.1 Game Theory\", chapter19_1),\n",
    "  (\"AIMA Chapter 5.2 Optimal Decisions in Games\", chapter19_2),\n",
    "  (\"AIMA Chapter 5.3 Heuristic Alpha–Beta Tree Search\", chapter19_3),\n",
    "  (\"AIMA Chapter 5.5 Stochastic Games\", chapter19_4),\n",
    "  (\"AIMA Chapter 16.1 Combining Beliefs and Desires under Uncertainty\", chapter19_5),\n",
    "  (\"AIMA Chapter 16.2 The Basis of Utility Theory\", chapter19_6),\n",
    "  (\"SLP Chapter 4.1 Naive Bayes Classifiers\", slp_chapter4_1),\n",
    "  (\"SLP Chapter 4.2 Training the Naive Bayes Classifier\", slp_chapter4_2),\n",
    "  (\"SLP Chapter 4.3 Worked Example\", slp_chapter4_3),\n",
    "  (\"SLP Chapter 4.4 Optimizing for Sentiment Analysis\", slp_chapter4_4),\n",
    "  (\"SLP Chapter 4.5 Naive Bayes for other text classification tasks\", slp_chapter4_5),\n",
    "  (\"SLP Chapter 4.6 Naive Bayes as a Language Model\", slp_chapter4_6),\n",
    "  (\"SLP Chapter 4.7 Evaluation: Precision, Recall, F-measure\", slp_chapter4_7),\n",
    "  (\"SLP Chapter 4.8 Test sets and Cross-validation\", slp_chapter4_8),\n",
    "  (\"SLP Chapter 4.9 Statistical Significance Testing\", slp_chapter4_9),\n",
    "  (\"SLP Chapter 4.10 Avoiding Harms in Classification\", slp_chapter4_10),\n",
    "  (\"Module 12 Lecture Notes\", module12_lecture_notes),\n",
    "]\n",
    "\n",
    "module12_markdown = format_module(12, \"Naive Bayes and Perceptrons\", \n",
    "                         module12_sections, \n",
    "                         module12_definitions)\n",
    "display(Markdown(module12_markdown))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "qVSQhTVSyYYO"
   },
   "source": [
    "# Module 13 - Neural Networks"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "id": "Wm4mfW82yaRH"
   },
   "outputs": [],
   "source": [
    "# Jurafsky and Martin, Speech and Language Processing Chapter 5 “Logistic Regression” (5.1-5.6)\n",
    "\n",
    "slp_chapter5_1 = \"\"\" Your summary here \"\"\"\n",
    "slp_chapter5_2 = \"\"\" Your summary here \"\"\"\n",
    "slp_chapter5_3 = \"\"\" Your summary here \"\"\"\n",
    "slp_chapter5_4 = \"\"\" Your summary here \"\"\"\n",
    "slp_chapter5_5 = \"\"\" Your summary here \"\"\"\n",
    "slp_chapter5_6 = \"\"\" Your summary here \"\"\"\n",
    "\n",
    "# Jurafsky and Martin, Chapter 7 “Neural Networks and Neural Language Models”\n",
    "\n",
    "slp_chapter7_1 = \"\"\" Your summary here \"\"\"\n",
    "slp_chapter7_2 = \"\"\" Your summary here \"\"\"\n",
    "slp_chapter7_3 = \"\"\" Your summary here \"\"\"\n",
    "slp_chapter7_4 = \"\"\" Your summary here \"\"\"\n",
    "slp_chapter7_5 = \"\"\" Your summary here \"\"\"\n",
    "slp_chapter7_6 = \"\"\" Your summary here \"\"\"\n",
    "slp_chapter7_7 = \"\"\" Your summary here \"\"\"\n",
    "\n",
    "# Lecture notes \n",
    "module13_lecture_notes = \"\"\" Classifier components: 1.A feature representation of the input  For each input observation\n",
    "x(i), this will be a vector of features [x1,x2,...,xn]. \\n\n",
    "2. A classification function that computes the estimated class y^ via p(y|x). \\n\n",
    "3. An objective function for learning, usually involving minimizing\n",
    "error on training examples \\n\n",
    "4.An algorithm for optimizing the objective function. \\n\n",
    "\n",
    "Stochastic gradient descent chooses a single random example at a time and updates\n",
    "its weights on that example. As a result the updates can fluctuate.\n",
    "An alternate is batch training, which computes the gradient over the entire dataset.\n",
    "This gives a much better estimate of which direction to move the weights but takes a\n",
    "long time to compute.\n",
    "A commonly used compromise is mini-batch training, where we train on a small\n",
    "batch. The batch size can be 512 or 1024, often selected based on computational\n",
    "resources, so that all examples in the mini-batch can be processed in parallel. The loss\n",
    "is then accumulated. \\n\n",
    "\n",
    "The simplest kind of NN is the Feed-Forward Neural Network\n",
    "Multilayer network, all units are usually fully-connected, and no cycles.\n",
    "The outputs from each layer are passed to units in the next higher layer, and no\n",
    "outputs are passed back to lower layers.  \\n\n",
    "\n",
    "We use:\n",
    "A cross entropy loss function\n",
    "Gradient descent to perform optimization\n",
    "Error back propagation to compute the gradient of the loss function \\n\n",
    "\n",
    "\n",
    "\"\"\"\n",
    "\n",
    "# Definitions\n",
    "module13_definitions = {\n",
    "\"concept\" : \"definition\",    \n",
    "}\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "cellView": "form",
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 1000
    },
    "id": "kKWbCsbfxL3R",
    "outputId": "088a87b4-8ede-4f01-a6dc-56969c33cabb"
   },
   "outputs": [
    {
     "data": {
      "text/markdown": [
       "# Module 13: Neural Networks\n",
       "## SLP Chapter 5.1 Classification: the sigmoid\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 5.2 Learning in Logistic Regression\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 5.3 The cross-entropy loss function\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 5.4 Gradient Descent\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 5.5 Regularization\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 5.6 Multinomial logistic regression\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 7.1 Units\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 7.2 The XOR problem\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 7.3 Feedforward Neural Networks\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 7.4 Feedforward networks for NLP: Classification\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 7.5 Feedforward Neural Language Modeling\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 7.6 Training Neural Nets\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 7.7 Training the neural language model\n",
       " Your summary here \n",
       "\n",
       "## Module 13 Lecture Notes\n",
       " Classifier components: 1.A feature representation of the input  For each input observation\n",
       "x(i), this will be a vector of features [x1,x2,...,xn]. \n",
       "\n",
       "2. A classification function that computes the estimated class y^ via p(y|x). \n",
       "\n",
       "3. An objective function for learning, usually involving minimizing\n",
       "error on training examples \n",
       "\n",
       "4.An algorithm for optimizing the objective function. \n",
       "\n",
       "\n",
       "Stochastic gradient descent chooses a single random example at a time and updates\n",
       "its weights on that example. As a result the updates can fluctuate.\n",
       "An alternate is batch training, which computes the gradient over the entire dataset.\n",
       "This gives a much better estimate of which direction to move the weights but takes a\n",
       "long time to compute.\n",
       "A commonly used compromise is mini-batch training, where we train on a small\n",
       "batch. The batch size can be 512 or 1024, often selected based on computational\n",
       "resources, so that all examples in the mini-batch can be processed in parallel. The loss\n",
       "is then accumulated. \n",
       "\n",
       "\n",
       "The simplest kind of NN is the Feed-Forward Neural Network\n",
       "Multilayer network, all units are usually fully-connected, and no cycles.\n",
       "The outputs from each layer are passed to units in the next higher layer, and no\n",
       "outputs are passed back to lower layers.  \n",
       "\n",
       "\n",
       "We use:\n",
       "A cross entropy loss function\n",
       "Gradient descent to perform optimization\n",
       "Error back propagation to compute the gradient of the loss function \n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "## Module 13 Definitions\n",
       "* **Concept** - definition\n"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#@title Preview of your summary\n",
    "#@markdown You don't need to modify anything in this cell. Just press play.\n",
    "module13_sections = [\n",
    "  (\"SLP Chapter 5.1 Classification: the sigmoid\", slp_chapter5_1),\n",
    "  (\"SLP Chapter 5.2 Learning in Logistic Regression\", slp_chapter5_2),\n",
    "  (\"SLP Chapter 5.3 The cross-entropy loss function\", slp_chapter5_3),\n",
    "  (\"SLP Chapter 5.4 Gradient Descent\", slp_chapter5_4),\n",
    "  (\"SLP Chapter 5.5 Regularization\", slp_chapter5_5),\n",
    "  (\"SLP Chapter 5.6 Multinomial logistic regression\", slp_chapter5_6),\n",
    "\n",
    "  (\"SLP Chapter 7.1 Units\", slp_chapter7_1),\n",
    "  (\"SLP Chapter 7.2 The XOR problem\", slp_chapter7_2),\n",
    "  (\"SLP Chapter 7.3 Feedforward Neural Networks\", slp_chapter7_3),\n",
    "  (\"SLP Chapter 7.4 Feedforward networks for NLP: Classification\", slp_chapter7_4),\n",
    "  (\"SLP Chapter 7.5 Feedforward Neural Language Modeling\", slp_chapter7_5),\n",
    "  (\"SLP Chapter 7.6 Training Neural Nets\", slp_chapter7_6),\n",
    "  (\"SLP Chapter 7.7 Training the neural language model\", slp_chapter7_7),\n",
    "  (\"Module 13 Lecture Notes\", module13_lecture_notes),\n",
    "]\n",
    "\n",
    "module13_markdown = format_module(13, \"Neural Networks\", \n",
    "                         module13_sections, \n",
    "                         module13_definitions)\n",
    "display(Markdown(module13_markdown))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "RYESi2kMybL8"
   },
   "source": [
    "# Module 14 - Natural Language Processing"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "id": "qIRJ4YYCzNHL"
   },
   "outputs": [],
   "source": [
    "# Jurafsky and Martin, Chapter 9 “Sequence Processing with Recurrent Networks” (Sections 9.1-9.3)\n",
    "\n",
    "slp_chapter9_1 = \"\"\" Your summary here \"\"\"\n",
    "slp_chapter9_2 = \"\"\" Your summary here \"\"\"\n",
    "slp_chapter9_3 = \"\"\" Your summary here \"\"\"\n",
    "\n",
    "# Jurafsky and Martin, Chapter 6 “Vector Semantics and Embeddings” (6.1-6.4, 6.8, 6.10-6.12)\n",
    "\n",
    "slp_chapter6_1 = \"\"\" Your summary here \"\"\"\n",
    "slp_chapter6_2 = \"\"\" Your summary here \"\"\"\n",
    "slp_chapter6_3 = \"\"\" Your summary here \"\"\"\n",
    "slp_chapter6_4 = \"\"\" Your summary here \"\"\"\n",
    "slp_chapter6_8 = \"\"\" Your summary here \"\"\"\n",
    "slp_chapter6_10 = \"\"\" Your summary here \"\"\"\n",
    "slp_chapter6_11 = \"\"\" Your summary here \"\"\"\n",
    "slp_chapter6_12 = \"\"\" Your summary here \"\"\"\n",
    "\n",
    "\n",
    "\n",
    "# Lecture notes \n",
    "module14_lecture_notes = \"\"\" \n",
    "Ideally, we want a meaning representation to encode:\n",
    "1. Synonyms – words that have similar meanings\n",
    "2. Antonyms – words that have opposite meanings\n",
    "3. Connotations – words that are positive or negative\n",
    "4. Semantic Roles – buy, sell, and pay are different parts of the same underlying\n",
    "purchasing event\n",
    "5. Support for entailment \\n\n",
    "\n",
    "Intuition for algorithm:\n",
    "Two words are similar if they have similar word contexts. \\n\n",
    "\n",
    "TF-IDF\n",
    "Term frequency(How often a word occurred in a document) * inverse document frequency(1 over the number of documents that it occurred in) \\n\n",
    "\n",
    "Neural Language Models\n",
    "Neural Language models have several advantages over n-gram LMs:\n",
    "1. They don’t need smoothing\n",
    "2. They can handle much longer histories.\n",
    "3. They can generalize over contexts of similar words.\n",
    "4. Neural LMs tend to have much higher predictive accuracy than n-gram LMs.\n",
    "Disadvantage: slower to train than traditional n-gram LMs \\n\n",
    "\n",
    "1. Associate each word in the vocabulary with a vector-representation, thereby\n",
    "creating a notion of similarity between words.\n",
    "2. Express the joint probability function of a word sequence in terms of the word\n",
    "vectors for the words in that sequence.\n",
    "3. Simultaneously learn the word vectors and the parameters of the function.\n",
    "The word vectors are low-dimensional (d=30 to d=100) dense vectors, like we’ve seen\n",
    "before.\n",
    "The probability function is expressed the product of conditional probabilities of the\n",
    "next word given the previous word, using a multi-layer, feed forward neural network. \\n\n",
    "\n",
    "Word2Vec\n",
    "Predict each neighboring word in a context window of 2C of surrounding words\n",
    "So for C=2, we are given a word wt and we try to predict its 4 surrounding words\n",
    "[wt-2, wt-1, wt+1, wt+2]\n",
    "Uses \"negative sampling\" for training \\n\n",
    "\n",
    "Word2vec\n",
    "•Instead of counting how often each\n",
    "word w occurs near \"apricot\"\n",
    "•Train a classifier on a binary prediction task:\n",
    "• Is w likely to show up near \"apricot\"?\n",
    "•We don’t actually care about this task\n",
    "• But we'll take the learned classifier weights as\n",
    "the word embeddings \\n\n",
    "\n",
    "Skip-gram algorithm\n",
    "1. Treat the target word and a neighboring context\n",
    "word as positive examples.\n",
    "2. Randomly sample other words in the lexicon to get\n",
    "negative samples\n",
    "3. Use logistic regression to train a classifier to\n",
    "distinguish those two cases\n",
    "4. Use the weights as the embeddings \\n\n",
    "\n",
    "\"\"\"\n",
    "\n",
    "# Definitions\n",
    "module14_definitions = {\n",
    "\"concept\" : \"definition\",    \n",
    "}\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 1000
    },
    "id": "lXNcHuKjyNXa",
    "outputId": "ed25dc9f-435c-4681-8f90-71ad2feaa9e7"
   },
   "outputs": [
    {
     "data": {
      "text/markdown": [
       "# Module 14: Natural Language Processing\n",
       "## SLP Chapter 9.1 Language Models Revisited\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 9.2 Recurrent Neural Networks\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 9.3 RNNs as Language Models\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 6.1 Lexical Semantics\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 6.2 Vector Semantics\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 6.3 Words and Vectors\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 6.4 Cosine for measuring similarity\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 6.8 Word2vec\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 6.10 Semantic properties of embeddings\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 6.11 Bias and Embeddings\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 6.12 Evaluating Vector Models\n",
       " Your summary here \n",
       "\n",
       "## Module 13 Lecture Notes\n",
       " Classifier components: 1.A feature representation of the input  For each input observation\n",
       "x(i), this will be a vector of features [x1,x2,...,xn]. \n",
       "\n",
       "2. A classification function that computes the estimated class y^ via p(y|x). \n",
       "\n",
       "3. An objective function for learning, usually involving minimizing\n",
       "error on training examples \n",
       "\n",
       "4.An algorithm for optimizing the objective function. \n",
       "\n",
       "\n",
       "Stochastic gradient descent chooses a single random example at a time and updates\n",
       "its weights on that example. As a result the updates can fluctuate.\n",
       "An alternate is batch training, which computes the gradient over the entire dataset.\n",
       "This gives a much better estimate of which direction to move the weights but takes a\n",
       "long time to compute.\n",
       "A commonly used compromise is mini-batch training, where we train on a small\n",
       "batch. The batch size can be 512 or 1024, often selected based on computational\n",
       "resources, so that all examples in the mini-batch can be processed in parallel. The loss\n",
       "is then accumulated. \n",
       "\n",
       "\n",
       "The simplest kind of NN is the Feed-Forward Neural Network\n",
       "Multilayer network, all units are usually fully-connected, and no cycles.\n",
       "The outputs from each layer are passed to units in the next higher layer, and no\n",
       "outputs are passed back to lower layers.  \n",
       "\n",
       "\n",
       "We use:\n",
       "A cross entropy loss function\n",
       "Gradient descent to perform optimization\n",
       "Error back propagation to compute the gradient of the loss function \n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "## Module 14 Definitions\n",
       "* **Concept** - definition\n"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#@title Preview of your summary\n",
    "#@markdown You don't need to modify anything in this cell. Just press play.\n",
    "module14_sections = [\n",
    "  (\"SLP Chapter 9.1 Language Models Revisited\", slp_chapter9_1),\n",
    "  (\"SLP Chapter 9.2 Recurrent Neural Networks\", slp_chapter9_2),\n",
    "  (\"SLP Chapter 9.3 RNNs as Language Models\", slp_chapter9_3),\n",
    "\n",
    "  (\"SLP Chapter 6.1 Lexical Semantics\", slp_chapter6_1),\n",
    "  (\"SLP Chapter 6.2 Vector Semantics\", slp_chapter6_2),\n",
    "  (\"SLP Chapter 6.3 Words and Vectors\", slp_chapter6_3),\n",
    "  (\"SLP Chapter 6.4 Cosine for measuring similarity\", slp_chapter6_4),\n",
    "  (\"SLP Chapter 6.8 Word2vec\", slp_chapter6_8),\n",
    "  (\"SLP Chapter 6.10 Semantic properties of embeddings\", slp_chapter6_10),\n",
    "  (\"SLP Chapter 6.11 Bias and Embeddings\", slp_chapter6_11),\n",
    "  (\"SLP Chapter 6.12 Evaluating Vector Models\", slp_chapter6_12),\n",
    "  (\"Module 13 Lecture Notes\", module13_lecture_notes),\n",
    "]\n",
    "\n",
    "module14_markdown = format_module(14, \"Natural Language Processing\", \n",
    "                         module14_sections, \n",
    "                         module14_definitions)\n",
    "display(Markdown(module14_markdown))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "vX7lbnJd4sT5"
   },
   "source": [
    "# Your Exam Notes\n",
    "\n",
    "Here are your full set of exam notes that you can use on your midterm.  Choose **Runtime > Run all**, then your notes will be displayed.\n",
    "\n",
    "If you are taking the exam in person, then you must print a copy of your notes for yourself.   Here's how to print:\n",
    "* Run the cell below. \n",
    "* Click its \"Mirror cell in tab\" button (this is located in the upper right corner of the cell, immediately to the right of the trash can).  This will open the cell.  \n",
    "* In Chrome, you can then print your notes using the **File > Print** option from the browser's menu.  \n",
    "* In the print options, change the layout from Landscape to Portrait. \n",
    "* Clicking the Save, will save a PDF that you can then print.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 1000
    },
    "id": "T3cm1WV542_a",
    "outputId": "6743ab4e-1890-4e40-9844-ed00f9cf2612"
   },
   "outputs": [
    {
     "data": {
      "text/markdown": [
       "# Module 8: Markov Decision Processes\n",
       "## AIMA Chapter 16.1 Combining Beliefs and Desires under Uncertainty\n",
       " $P(\\textnormal{RESULT}(a)=s') = \\sum_s P(s)P(s'|s,a)$  $EU(a) = \\sum_s' P(\\textnormal{RESULT}(a)=s')U(s')$  \n",
       "\n",
       "The agent’s preferences are captured by a utility function,U(s) , which assigns a single number to express the desirability of a state. \n",
       "The expected utility of an action given the evidence, EU(a), \n",
       "is just the average utility value of the outcomes, weighted by the probability that the outcome occurs: $EU(a) = $\n",
       "\n",
       "## AIMA Chapter 16.2 The Basis of Utility Theory\n",
       " We can think of the set of outcomes for each action as a lottery—think of each action as a ticket.\n",
       "\n",
       "EXISTENCE OF UTILITY FUNCTION: U(A)>U(B) -> A>B \n",
       "\n",
       " an agent’s behavior would not change if its utility function U(S) were transformed according to U'(S)=aU(S)+b where a and b are constants and a > 0. This is called a value function or ordinal utility function. \n",
       "\n",
       "  \n",
       "\n",
       "## AIMA Chapter 16.3 Utility Functions\n",
       " Utility functions map from lotteries to real numbers.They must obey the axioms of orderability, transitivity, continuity, substitutability, monotonicity, and decomposability. \n",
       "\n",
       "we must first work out what the human’s utility function is. This process, often called preference elicitation. \n",
       "\n",
       "We will assume, kindly perhaps, that the estimates are unbiased—that is, the expected value of the error is zero \n",
       "\n",
       "certainty effect: people are strongly attracted to gains that are certain.\n",
       " \n",
       "\n",
       "## AIMA Chapter 17.1 Sequential Decision Problems\n",
       "the transition model describes the outcome of each action in each state. We will assume that transitions are Markovian: the probability of reaching s'\n",
       " from s depends only on s and not on the history of earlier states. \n",
       "\n",
       " Because the decision problem is sequential, the utility function will depend on a sequence of states and actions—an environment history—rather than on a single state. \n",
       "\n",
       " we simply stipulate that for every transition from s to s' \n",
       " via action a, the agent receives a reward R(s,a,s'). The rewards may be positive or negative. \n",
       "\n",
       "A sequential decision problem for a fully observable, stochastic environment with a Markovian transition model and additive rewards is called a Markov decision process, or MDP\n",
       "\n",
       "A solution of this kind is called a policy( π).An optimal policy is a policy that yields the highest expected utility. We use π* to denote an optimal policy. \n",
       "\n",
       "A finite horizon means that there is a fixed time N after which nothing matters—the game is over. With a finite horizon, an optimal action in a given state may depend on how much time is left. A policy that depends on the time is called nonstationary. \n",
       "\n",
       "A policy that is guaranteed to reach a terminal state is called a proper policy.With proper policies, we can use γ = 1 \n",
       "\n",
       "Q-function: Q(s,a) is the expected utility of taking a given action in a given state. \n",
       "\n",
       "## AIMA Chapter 17.2 Algorithms for MDPs\n",
       " The basic concept used in showing that value iteration converges is the notion of a contraction.A contraction is a function of one argument that, when applied to two different inputs in turn, produces two output values that are “closer together,” \n",
       "by at least some constant factor, than the original inputs. \n",
       "\n",
       "Policy Iteration \n",
       "\n",
       "It is possible to get an optimal policy even when the utility function estimate is inaccurate.  \n",
       "\n",
       "## Module 8 Lecture Notes\n",
       " Markov decision processes: \n",
       "• Set of states S \n",
       "\n",
       "• Start state s0  \n",
       "\n",
       "• Set of actions A  \n",
       "\n",
       "• Transitions P(s’|s,a) (or T(s,a,s’)) \n",
       " \n",
       "• Rewards R(s,a,s’) (and discount y) \n",
       "\n",
       "What if the game lasts forever?  Solutions: (1) Finite horizon: (similar to depth-limited search)\n",
       "▪ Terminate episodes after a fixed T steps (e.g. life)\n",
       "▪ Gives nonstationary policies (pi depends on time left) \n",
       "\n",
       "(2) Discounting: use 0 < y < 1 \n",
       "\n",
       "(3) Absorbing state: guarantee that for every policy, a terminal state will\n",
       "eventually be reached \n",
       "\n",
       "MDP quantities so far: • Policy = Choice of action for each state • Utility = sum of (discounted) rewards \n",
       "\n",
       "The value (utility) of a state s:\n",
       "V^*(s) = expected utility starting in s and acting optimally \n",
       "\n",
       "▪ The value (utility) of a q-state (s,a): Q*(s,a) = expected utility starting out having taken action a from state s and\n",
       "(thereafter) acting optimally \n",
       "\n",
       "▪ The optimal policy:\n",
       "pi*(s) = optimal action from state s \n",
       "\n",
       "\n",
       "Policy Iteration (converge faster) \n",
       "\n",
       "Step 1: Policy evaluation: calculate utilities for some fixed policy (not\n",
       "optimal utilities!) until convergence \n",
       "\n",
       "• Step 2: Policy improvement: update policy using one-step lookahead with resulting converged (but not optimal!) utilities as future\n",
       "values \n",
       "\n",
       "• Repeat steps until policy converges \n",
       "\n",
       "\n",
       "In value iteration: \n",
       "\n",
       "• Every iteration updates both the values and (implicitly) the policy \n",
       "\n",
       "• We don’t track the policy, but taking the max over actions implicitly recomputes\n",
       "it \n",
       "\n",
       "In policy iteration: \n",
       "\n",
       "• We do several passes that update utilities with fixed policy (each pass is fast\n",
       "because we consider only one action, not all of them) \n",
       "\n",
       "• After the policy is evaluated, a new policy is chosen (slow like a value iteration\n",
       "pass) \n",
       "\n",
       "• The new policy will be better \n",
       "\n",
       "\n",
       "\n",
       "\n",
       "## Module 8 Definitions\n",
       "* **Utility function** - Your definition here\n",
       "* **Expected utility** - your definition here\n",
       "* **Etc.** - your definition here\n",
       "\n",
       "\n",
       "# Module 9: Reinforcement Learning\n",
       "## AIMA Chapter 17.3 Bandit Problems\n",
       " Your summary here \n",
       "\n",
       "## AIMA Chapter 22.1 Learning from Rewards\n",
       " Reinforcement learning (RL), in which an agent interacts with the world and periodically receives rewards. It may not know the transition model or the reward function, and it has to act in order to learn more.\n",
       "\n",
       "MODEL-BASED REINFORCEMENT LEARNING: the agent uses a transition model of the environment to help interpret the reward signals and to make decisions about how to act. The model may be initially unknown, in which case the agent learns the model from observing the effects of its actions, or it may already be known \n",
       "\n",
       "MODEL-FREE REINFORCEMENT LEARNING: In these approaches the agent neither knows nor learns a transition model for the environment.Instead, it learns a more direct representation of how to behave. Two cases: ACTION-UTILITY LEARNING: learns a Q-function denoting the sum of rewards from state s onward if action a is \n",
       "taken and POLICY SEARCH:  learns a policy π(s) that maps directly from states to actions. \n",
       "\n",
       "passive reinforcement learning, where the agent’s policy is fixed and the task is to learn the utilities of states.Active reinforcement learning, where the agent must also figure out what to do.\n",
       "\n",
       "## AIMA Chapter 22.2 Passive Reinforcement Learning\n",
       "  an agent already has a fixed policy π(s) that determines its actions. The agent is trying to learn the utility function U^π(s)—the expected total discounted reward if policy π is executed beginning in state s\n",
       "\n",
       "## AIMA Chapter 22.3 Active Reinforcement Learning\n",
       "  Temporal-difference Q-learning: The Q-learning method avoids the need for a model by learning an action-utility function Q(s,a) instead of a utility function U(s). Q-learning is an off-policy learning algorithm,  \n",
       "\n",
       "## AIMA Chapter 22.4 Generalization in Reinforcement Learning\n",
       " Your summary here \n",
       "\n",
       "## Module 9 Lecture Notes\n",
       " Exploration: you have to try unknown actions to get information \n",
       "\n",
       "Exploitation: eventually, you have to use what you know \n",
       "\n",
       "Regret: even if you learn intelligently, you make mistakes \n",
       "\n",
       "Sampling: because of chance, you have to try things repeatedly \n",
       "\n",
       "Difficulty: learning can be much harder than solving a known MDP \n",
       "\n",
       "\n",
       "Receive feedback in the form of rewards.\n",
       "Agent’s utility is defined by the reward function.\n",
       "Must (learn to) act so as to maximize expected rewards.\n",
       "All learning is based on observed samples of outcomes! \n",
       "\n",
       "\n",
       "Still assume a Markov decision process (MDP) but we don’t know T or R and we must actually try actions and states out to learn \n",
       "\n",
       "\n",
       " Direct Evaluation\n",
       "\n",
       " Goal: Compute values for each state under π \n",
       "\n",
       " Idea: Average together observed sample values \n",
       "\n",
       "\n",
       "Regret is a measure of your total\n",
       "mistake cost: the difference between\n",
       "your (expected) rewards, including\n",
       "youthful suboptimality, and optimal\n",
       "(expected) rewards\n",
       "Minimizing regret goes beyond\n",
       "learning to be optimal – it requires\n",
       "optimally learning to be optimal\n",
       "Example: random exploration and\n",
       "exploration functions both end up\n",
       "optimal, but random exploration has\n",
       "higher regret\n",
       " \n",
       "\n",
       "## Module 9 Definitions\n",
       "* **Term** - your definition here\n",
       "\n",
       "\n",
       "# Module 10: Probabilies and Language Models\n",
       "## AIMA Chapter 12.1 Acting under Uncertainty\n",
       " Your summary here \n",
       "\n",
       "## AIMA Chapter 12.2 Basic Probability Notation\n",
       " In probability theory, the set of all possible worlds is called the sample space. A fully specified probability model associates a numerical probability P(w) with each possible world.\n",
       "The basic axioms of probability theory say that every possible world has a probability between 0 and 1 and that the total probability of the set of possible worlds is 1. \n",
       "\n",
       "An alternative range for Boolean variables is the set {0,1}, in which case the variable is said to have a Bernoulli distribution. \n",
       "\n",
       "## AIMA Chapter 12.3 Inference Using Full Joint Distributions\n",
       " The full joint probability distribution specifies the probability of each complete assignment of values to random variables. \n",
       "It is usually too large to create or use in its explicit form, but when it is available it can be used to answer queries simply by adding up entries for the possible worlds corresponding to the query propositions. \n",
       "\n",
       "## AIMA Chapter 12.4 Independence\n",
       "Bayes’ rule allows unknown probabilities to be computed from known conditional probabilities, usually in the causal direction. Applying Bayes’ rule with many pieces of evidence runs into the same scaling problems as does the full joint distribution.\n",
       "\n",
       "## AIMA Chapter 12.5 Bayes’ Rule and Its Use\n",
       " Conditional independence brought about by direct causal relationships in the domain allows the full joint distribution to be factored into smaller, conditional distributions. \n",
       "The naive Bayes model assumes the conditional independence of all effect variables, given a single cause variable; its size grows linearly with the number of effects. \n",
       "\n",
       "## AIMA Chapter 12.6 Naive Bayes Models\n",
       " Your summary here \n",
       "\n",
       "## AIMA Chapter 12.7 The Wumpus World Revisited\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 3.1 N-Grams\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 3.2 Evaluating Language Models\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 3.3 Sampling sentences from a language model\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 3.4 Generalization and Zeros\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 3.5 Smoothing\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 3.7 Huge Language Models and Stupid Backoff\n",
       " Your summary here \n",
       "\n",
       "## Module 10 Lecture Notes\n",
       "Uncertainty: Observed variables (evidence): Agent knows certain things about the state of the world (e.g.,\n",
       "sensor readings or symptoms) \n",
       " \n",
       "Unobserved variables (states): Agent needs to reason about other aspects (e.g. where an object\n",
       "is or what disease is present) \n",
       "\n",
       "Model: Agent knows something about how the known variables relate to the unknown variables \n",
       "\n",
       "In probability theory, the possible worlds are called the sample space, and they\n",
       "mutually exclusive and exhaustive. \n",
       "\n",
       "An event is a set E of outcomes. \n",
       "\n",
       "Probabilistic Language Modeling \n",
       "\n",
       "Goal: compute the probability of a sentence or sequence of words \n",
       "\n",
       "Related task: probability of an upcoming word \n",
       "\n",
       "A model that computes either of these is called a language model or LM \n",
       "\n",
       "Simplifying Assumption = Markov Assumption: The Markov property says that given the past state, the present and the future are independent.\n",
       " \n",
       "\n",
       "## Module 10 Definitions\n",
       "* **Term** - your definition here\n",
       "\n",
       "\n",
       "# Module 11: Probabilistic Reasoning and Bayes’ Nets\n",
       "## AIMA Chapter 13.1 Representing Knowledge in an Uncertain Domain\n",
       "Two variables are independent if: P(x,y) = P(x)P(y). \n",
       "\n",
       "Independence is a simplifying modeling assumption. \n",
       "\n",
       "Each node corresponds to a random variable, which may be discrete or continuous.\n",
       "Directed links or arrows connect pairs of nodes. If there is an arrow from node X to node Y, X is said to be a parent of Y. The graph has no directed cycles and hence is a directed acyclic graph, or DAG. \n",
       "\n",
       "Each node Xi has associated probability information  that quantifies the effect of the parents on the node using a finite number of parameters\n",
       "\n",
       "## AIMA Chapter 13.2 The Semantics of Bayesian Networks\n",
       " topological order—that is, in any order consistent with the directed graph structure. locally structured (also called sparse) systems. In a locally structured system, each subcomponent interacts directly with only a bounded number of other components, \n",
       "regardless of the total number of components. Local structure is usually associated with linear rather than exponential growth in complexity. \n",
       "\n",
       "## AIMA 13.3 Exact Inference in Bayesian Networks\n",
       " Your summary here \n",
       "\n",
       "## Module 11 Lecture Notes\n",
       "Bayes’ nets: a technique for describing complex joint\n",
       "distributions (models) using simple, local\n",
       "distributions (conditional probabilities) \n",
       "\n",
       "More properly called graphical models. We describe how variables locally interact. Local interactions chain together to give global, indirect\n",
       "interactions\n",
       "\n",
       "## Module 11 Definitions\n",
       "* **Concept** - definition\n",
       "\n",
       "\n",
       "# Module 12: Naive Bayes and Perceptrons\n",
       "## AIMA Chapter 5.1 Game Theory\n",
       " Your summary here \n",
       "\n",
       "## AIMA Chapter 5.2 Optimal Decisions in Games\n",
       " Your summary here \n",
       "\n",
       "## AIMA Chapter 5.3 Heuristic Alpha–Beta Tree Search\n",
       " Your summary here \n",
       "\n",
       "## AIMA Chapter 5.5 Stochastic Games\n",
       " Your summary here \n",
       "\n",
       "## AIMA Chapter 16.1 Combining Beliefs and Desires under Uncertainty\n",
       " Your summary here \n",
       "\n",
       "## AIMA Chapter 16.2 The Basis of Utility Theory\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 4.1 Naive Bayes Classifiers\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 4.2 Training the Naive Bayes Classifier\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 4.3 Worked Example\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 4.4 Optimizing for Sentiment Analysis\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 4.5 Naive Bayes for other text classification tasks\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 4.6 Naive Bayes as a Language Model\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 4.7 Evaluation: Precision, Recall, F-measure\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 4.8 Test sets and Cross-validation\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 4.9 Statistical Significance Testing\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 4.10 Avoiding Harms in Classification\n",
       " Your summary here \n",
       "\n",
       "## Module 12 Lecture Notes\n",
       " Bag-of-words Naïve Bayes: Each position is identically distributed\n",
       "• All positions share the same conditional probs P(W|Y) \n",
       "\n",
       "• Called “bag-of-words” because model is insensitive to word order or reordering \n",
       "\n",
       "IMPORTANT CONCEPTS: \n",
       "\n",
       "Features: attribute-value pairs which characterize each x \n",
       "\n",
       "Experimentation cycle: Learn parameters (e.g. model probabilities) on training set\n",
       "• (Tune hyperparameters on held-out set)\n",
       "• Compute accuracy of test set\n",
       "• Very important: never “peek” at the test set! \n",
       "\n",
       "Evaluation\n",
       "• Accuracy: fraction of instances predicted correctly \n",
       "\n",
       "Overfitting and generalization\n",
       "• Want a classifier which does well on test data\n",
       "• Overfitting: fitting the training data very closely, but not generalizing well \n",
       "\n",
       "Generalization and Overfitting: Relative frequency parameters will overfit the training data \n",
       "\n",
       "To generalize better: we need to smooth or regularize the estimates \n",
       "\n",
       "Laplace Smoothing: /n\n",
       "Pretend you saw every outcome once more than you actually did \n",
       "\n",
       "The confidence of a probabilistic classifier: Represents how sure the classifier is of\n",
       "the classification • Any probabilistic model will have confidences • No guarantee confidence is correct \n",
       "\n",
       "Summary: Bayes rule lets us do diagnostic queries with causal probabilities\n",
       "The naïve Bayes assumption takes all features to be independent given\n",
       "the class label \n",
       "\n",
       "We can build classifiers out of a naïve Bayes model using training data\n",
       "Smoothing estimates is important in real systems \n",
       "\n",
       "Classifier confidences are useful, when you can get them \n",
       "\n",
       "Perceptron: \n",
       "\n",
       "Properties of Perceptrons: Separability: true if some parameters get the training\n",
       "set perfectly correct \n",
       "\n",
       "Convergence: if the training is separable, perceptron\n",
       "will eventually converge (binary case) \n",
       "\n",
       "Problems with the Perceptron: \n",
       "\n",
       "Noise: if the data isn’t separable,weights might thrash\n",
       "• Averaging weight vectors over time can help (averaged perceptron) \n",
       "\n",
       "Mediocre generalization: finds a\n",
       "“barely” separating solution\n",
       "Overtraining: test / held-out\n",
       "accuracy usually rises, then falls \n",
       "\n",
       "MIRA*: choose an update size that fixes the current\n",
       "mistake but, minimizes the change to w \n",
       "\n",
       "Maximum Step Size: cap the maximum possible value of t with some\n",
       "constant C. Corresponds to an optimization that assumes nonseparable data\n",
       "• Usually converges faster than perceptron\n",
       "• Usually better, especially on noisy data\n",
       "\n",
       "Support Vector Machines \n",
       "\n",
       "Support vector machines (SVMs) find the separator with max margin \n",
       "\n",
       "\n",
       "Naïve Bayes\n",
       "• Builds a model training data\n",
       "• Gives prediction probabilities\n",
       "• Strong assumptions about feature independence\n",
       "• One pass through data (counting) \n",
       "\n",
       "Perceptrons / MIRA:\n",
       "• Makes less assumptions about data\n",
       "• Mistake-driven learning\n",
       "• Multiple passes through data (prediction)\n",
       "• Often more accurate\n",
       "\n",
       "\n",
       " \n",
       "\n",
       "## Module 12 Definitions\n",
       "* **Concept** - definition\n",
       "\n",
       "\n",
       "# Module 13: Neural Networks\n",
       "## SLP Chapter 5.1 Classification: the sigmoid\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 5.2 Learning in Logistic Regression\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 5.3 The cross-entropy loss function\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 5.4 Gradient Descent\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 5.5 Regularization\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 5.6 Multinomial logistic regression\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 7.1 Units\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 7.2 The XOR problem\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 7.3 Feedforward Neural Networks\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 7.4 Feedforward networks for NLP: Classification\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 7.5 Feedforward Neural Language Modeling\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 7.6 Training Neural Nets\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 7.7 Training the neural language model\n",
       " Your summary here \n",
       "\n",
       "## Module 13 Lecture Notes\n",
       " Classifier components: 1.A feature representation of the input  For each input observation\n",
       "x(i), this will be a vector of features [x1,x2,...,xn]. \n",
       "\n",
       "2. A classification function that computes the estimated class y^ via p(y|x). \n",
       "\n",
       "3. An objective function for learning, usually involving minimizing\n",
       "error on training examples \n",
       "\n",
       "4.An algorithm for optimizing the objective function. \n",
       "\n",
       "\n",
       "Stochastic gradient descent chooses a single random example at a time and updates\n",
       "its weights on that example. As a result the updates can fluctuate.\n",
       "An alternate is batch training, which computes the gradient over the entire dataset.\n",
       "This gives a much better estimate of which direction to move the weights but takes a\n",
       "long time to compute.\n",
       "A commonly used compromise is mini-batch training, where we train on a small\n",
       "batch. The batch size can be 512 or 1024, often selected based on computational\n",
       "resources, so that all examples in the mini-batch can be processed in parallel. The loss\n",
       "is then accumulated. \n",
       "\n",
       "\n",
       "The simplest kind of NN is the Feed-Forward Neural Network\n",
       "Multilayer network, all units are usually fully-connected, and no cycles.\n",
       "The outputs from each layer are passed to units in the next higher layer, and no\n",
       "outputs are passed back to lower layers.  \n",
       "\n",
       "\n",
       "We use:\n",
       "A cross entropy loss function\n",
       "Gradient descent to perform optimization\n",
       "Error back propagation to compute the gradient of the loss function \n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "## Module 13 Definitions\n",
       "* **Concept** - definition\n",
       "\n",
       "\n",
       "# Module 14: Natural Language Processing\n",
       "## SLP Chapter 9.1 Language Models Revisited\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 9.2 Recurrent Neural Networks\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 9.3 RNNs as Language Models\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 6.1 Lexical Semantics\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 6.2 Vector Semantics\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 6.3 Words and Vectors\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 6.4 Cosine for measuring similarity\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 6.8 Word2vec\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 6.10 Semantic properties of embeddings\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 6.11 Bias and Embeddings\n",
       " Your summary here \n",
       "\n",
       "## SLP Chapter 6.12 Evaluating Vector Models\n",
       " Your summary here \n",
       "\n",
       "## Module 13 Lecture Notes\n",
       " Classifier components: 1.A feature representation of the input  For each input observation\n",
       "x(i), this will be a vector of features [x1,x2,...,xn]. \n",
       "\n",
       "2. A classification function that computes the estimated class y^ via p(y|x). \n",
       "\n",
       "3. An objective function for learning, usually involving minimizing\n",
       "error on training examples \n",
       "\n",
       "4.An algorithm for optimizing the objective function. \n",
       "\n",
       "\n",
       "Stochastic gradient descent chooses a single random example at a time and updates\n",
       "its weights on that example. As a result the updates can fluctuate.\n",
       "An alternate is batch training, which computes the gradient over the entire dataset.\n",
       "This gives a much better estimate of which direction to move the weights but takes a\n",
       "long time to compute.\n",
       "A commonly used compromise is mini-batch training, where we train on a small\n",
       "batch. The batch size can be 512 or 1024, often selected based on computational\n",
       "resources, so that all examples in the mini-batch can be processed in parallel. The loss\n",
       "is then accumulated. \n",
       "\n",
       "\n",
       "The simplest kind of NN is the Feed-Forward Neural Network\n",
       "Multilayer network, all units are usually fully-connected, and no cycles.\n",
       "The outputs from each layer are passed to units in the next higher layer, and no\n",
       "outputs are passed back to lower layers.  \n",
       "\n",
       "\n",
       "We use:\n",
       "A cross entropy loss function\n",
       "Gradient descent to perform optimization\n",
       "Error back propagation to compute the gradient of the loss function \n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "## Module 14 Definitions\n",
       "* **Concept** - definition\n"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# This will generate the full set of notes that you can use for your exam.\n",
    "full_markdown = \"\\n\\n\".join([module8_markdown, \n",
    "                             module9_markdown, \n",
    "                             module10_markdown, \n",
    "                             module11_markdown, \n",
    "                             module12_markdown,\n",
    "                             module13_markdown,\n",
    "                             module14_markdown,]\n",
    "                       )\n",
    "display(Markdown(full_markdown))"
   ]
  }
 ],
 "metadata": {
  "colab": {
   "collapsed_sections": [],
   "name": "Copy of Template_for CIS521_midterm_2_notes.ipynb",
   "provenance": []
  },
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
