{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "CIS521_midterm_2_notes_db.ipynb",
      "provenance": [],
      "collapsed_sections": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "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",
      "metadata": {
        "id": "lzaavW96tcxM",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 0
        },
        "outputId": "6862d9b3-6d5b-4916-95ab-5ee061bb60c7"
      },
      "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)))"
      ],
      "execution_count": 1,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "The example summary is 116 words long, so you could write an additional 384 words.\n"
          ]
        }
      ]
    },
    {
      "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",
      "metadata": {
        "id": "8DvZ57A-djo1",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 0
        },
        "outputId": "21b085db-9f26-4a6f-eb0a-8dd285af1371"
      },
      "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))"
      ],
      "execution_count": 2,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "The length in words is 500\n",
            "The length in characters is 3030\n"
          ]
        }
      ]
    },
    {
      "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",
      "metadata": {
        "id": "2RECnJArJew4"
      },
      "source": [
        "name = \"\"\n",
        "permission = True\n",
        "anonymous = False"
      ],
      "execution_count": 3,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "GZZXyrV-xuAp"
      },
      "source": [
        "# Module 8 - Markov Decision Process"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Y2NfE1CKxzS-",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 0
        },
        "outputId": "e1662e66-e209-43b7-acd4-828386ae797b"
      },
      "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",
        "\n",
        "chapter16_1 = \"\"\"\n",
        "Decision theory deals with choosing among actions based on the desirability of their \\\n",
        "immediate outcomes (\"immediate\" implying that the environment is assumed to be episodic). \\\n",
        "We therefore consider an agent that must make a decision about what action to take next. \\\n",
        "A **Utility Function** $U(s)$ captures an agent's preferences by assigning a single numeric \\\n",
        "value to express the desirability of a given state $s$. However, \\ \n",
        "there is uncertainty about the current state, so the agent assigns a probability \\\n",
        "$P(s)$ to each possible current state $s$. There is also uncertainty about the outcome \\\n",
        "of a given action, so the transition model is described by $P(s'|s,a)$ the probability \\\n",
        "that taking an action $a$ from state $s$ will result in state $s'$. The overall \\\n",
        "probability of getting to state $s'$ by taking action $a$ from the current state \\\n",
        "(whatever that may be) is therefore: $P(Result(a)=s')= \\sum_s P(s)P(s'|s,a)$ \\\n",
        "The **Expected Utility** of an action, $EU(a)$, is then the average utility of each outcome \\\n",
        "weighted by the probability of that outcome: $EU(a) = \\sum_{s'} P(Result(a)=s')U(s')$ \\\n",
        "\n",
        "\n",
        "The principle of **maximum expected utility (MEU)** states that a rational agent should \\\n",
        "choose the action that maximizes the agent's expected utility: $action = argmax_a EU(a)$ \\\n",
        "This principle formalized the general notion of rational behavior, but it does not \\\n",
        "operationalize it. Actually estimating and calculating the various quantities needed \\\n",
        "($P(s)$, $P(s'|s,a)$, $U(s)$, etc.) may be difficult or subject to uncertainty themselves. \\\n",
        "The MEU principle is related to the performance measures discussed in Ch. 2 - if a \\\n",
        "utility function reflects the performance measure, then maximizing the utility results \\\n",
        "in getting the highest (average) performance score. However while the performance measure \\\n",
        "gives a score for a history retrospectively, a utility function applies to the next state \\\n",
        "so is done on a step-by-step basis to guide actions.\n",
        "\n",
        "\"\"\"\n",
        "chapter16_2 =  \"\"\"\n",
        "We identify constraints that must govern a rational agent's preferences; the MEU \\\n",
        "principle is a consequence of these constraints.\n",
        "<h3>Notation</h3>\n",
        "<ul><li>$A\\succ B$: the agent prefers $A$ over $B$</li>\n",
        "<li>$A\\sim B$: the agent is indifferent between $A$ and $B$</li>\n",
        "<li>$A\\succsim B$: the agent prefers $A$ over $B$ OR is indifferent between them</li>\n",
        "<li>$L=[p_1,S_1;p_2,S_2;...;p_n,S_n]$: A lottery $L$ with the possible outcomes \\\n",
        "$S_1,S_2,...,S_n$ with associated probablilites of $p_1,p_2,...,p_n$. Each $S_i$ \\\n",
        "is either an atomic state or another lottery</li></ul>\n",
        "\n",
        "<h3>Constraints; aka Axioms of Utility Theory</h3>\n",
        "<ul><li><b>Orderability</b>: Given any two lotteries, a rational agent must either prefer \\\n",
        "one to the other or be indifferent between them; \n",
        "\n",
        "exactly one of \\\n",
        "$(A\\succ B)$, $(A\\prec B)$, or $(A\\sim B)$ holds</li>\n",
        "<li><b>Transitivity</b>: If an agent prefers $A$ to $B$ \\\n",
        "and $B$ to $C$, then it must prefer $A$ to $C$\n",
        "\n",
        "$(A\\succ B)\\wedge (B\\succ C)\\Rightarrow (A\\succ C) $</li>\n",
        "<li><b>Continuity</b>: If some lottery $B$ is between $A$ and $C$ in preference \\\n",
        "then there exists some probability, $p$, for which a rational agent will be indifferent \\\n",
        "between $B$ and the lottery that yields $A$ with probability $p$ and $C$ with probability $(1-p)$\n",
        "\n",
        "$A\\succ B\\succ C\\Rightarrow \\exists p\\;\\;s.t.\\;\\;B\\sim [p,A;(1-p),C]$</li>\n",
        "<li><b>Substitutability</b>: If an agent is indifferent between two lotteries $A$ and $B$ \\\n",
        "then it is also indifferent between two, more complex lotteries that are the same except \\\n",
        "$A$ is substituted for $B$\n",
        "\n",
        "$A\\sim B\\Rightarrow [p,A;(1-p),C]\\sim [p,B;(1-p),C]$</li>\n",
        "<li><b>Monotonicity</b>: If two lotteries have the same two possible outcomes, $A$ and $B$, \\\n",
        "and an agent prefers $A$ to $B$, then the agent must prefer the lottery that has a higher \\\n",
        "probability of yeilding $A$ (and vice versa)\n",
        "\n",
        "$A\\succ B\\Rightarrow (p>q\\Leftrightarrow [p,A;(1-p),B]\\succ [q,A;(1-q),B])$</li>\n",
        "<li><b>Decomposability</b>: Compound lotteries can be reduced to simpler ones using the laws \\\n",
        "of probability\n",
        "\n",
        "$[p,A;(1-p),[q,B;(1-q),C]]\\sim [p,A;(1-p)q,B;(1-p)(1-q),C]$</li></ul>\n",
        "\"\"\"\n",
        "chapter16_3 =  \"\"\"\n",
        "<h3>Discussion</h3>\n",
        "From the axioms listed above we can derive the following:\n",
        "<ul><li><b>Existence of Utility Function</b>: if an agent's preferences obey the \\\n",
        "axioms of utility, then there exists a function $U$ such that $U(A)>U(B)$ <b><i>iff</i></b> \\\n",
        "the agent prefers $A$ to $B$, and $U(A)=U(B)$ <b><i>iff</i></b> the agent is indifferent between \\\n",
        "$A$ and $B$.\n",
        "\n",
        "$U(A)>U(B)\\Leftrightarrow A\\succ B$ and $U(A)=U(B)\\Leftrightarrow A\\sim B$</li>\n",
        "<li><b>Expected Utility of a Lottery</b>: the utility of a lottery is the sum over all outcomes \\\n",
        "of each outcome's probability times its utility\n",
        "\n",
        "$U([p_1,S_1;p_2,S_2;...;p_n,S_n])=\\sum_i p_iU(S_i)$</li></ul>\n",
        "These findings establish that a utility function exists for any rational agent, \\\n",
        "but not that the utility function is unique; e.g an agent's behavior does not change \\\n",
        "if its utility function $U(S)$ is transformed to $U'(S)=aU(s)+b$, where $a>0$; i.e. behavior is\n",
        "invariant under positive linear transformation. Furthermore, \\\n",
        "even though it exists, an agent may not be explicitly maximizing its utility function. \\\n",
        "It may be generating rational behavior via some other mechanism (e.g. table lookup). However \\\n",
        "an observer could learn the agent's utility function by watching its behavior. In a deterministic \\\n",
        "environment, only the ordinal utility is needed; i.e. the total order/ranking of states.\n",
        "\"\"\"\n",
        "\n",
        "\n",
        "# Russell and Norvig, AIMA Chapter 17, “Making Complex Decision” (17.1-17.2)\n",
        "chapter17_1 = \"\"\"\n",
        "a **Markov Decision Process** or **MDP** is a sequential decision \\\n",
        "problem for a fully observable, stochasitic environment with a Markovian transition model and \\\n",
        "additive rewards. It consists of:\n",
        "<ul>\n",
        "<li>A set of states, and initial state $s_0$</li>\n",
        "<li>A set of actions $Actions(s)$ in each state</li>\n",
        "<li>A transition model $P(s'|s,a)$ - also written as $T(s,a,s')$. We \\\n",
        "assume it is <b>Markovian</b> i.e the probability of reaching $s'$ from \\\n",
        "$s$ only depends on $s$ and not the history of earlier states.</li>\n",
        "<li>A reward function $R(s,a,s')$ - For a sequential decision problem, the agent's utility \\\n",
        "depends on a sequence of states and actions, an \\\n",
        "environment history, rather than a single state. We define a reward function which \\\n",
        "assigns a reward (+ or -) for each transition $s$ to $s'$ via $a$, and the utility \\\n",
        "of an environment history is the sum of (discounted) rewards received.</li>\n",
        "</ul>\n",
        "Because the outcome of each action is uncertain, the solution is not a fixed action sequence, \\\n",
        "but rather a <b>policy</b>, denoted by $\\pi$, that specifies what action to take in any given state, $\\pi (s)$. \\\n",
        "A policy is evaluated by its expected utility of the possible environment histories \\\n",
        "it may generate. An <b>optimal policy</b>, $\\pi^*$, is one that yields the highest expected utility. \\\n",
        "A policy that depends on time left is called nonstationary (finite horizon; fixed time), \\\n",
        "whereas a policy that acts only on the current \\\n",
        "state is stationary (infinite horizon; no time limit).\n",
        "\n",
        "\n",
        "Additive discounted rewards: $U_h(s_0,a_0,s_1,a_1,...) = R(s_0,a_0,s_1) + \\gamma R(s_1,a_1,s_2) + \\gamma^2 R(s_2,a_2,s_3)+...  = \\sum_{t=0}^{\\infty} \\gamma^t R(s_t,a_t,s_{t+1})$ \\\n",
        "\n",
        "<ol>\n",
        "<li>For inf. sequence w/ discounted rewards, the utility is finite: \\\n",
        "$\\gamma < 1$ and rewards are bounded by $\\mp R_{max}$ and \n",
        "$$U_h(...)\\leq\\sum\\gamma^t R_{max}=(R_{max})/(1-\\gamma)$$</li>\n",
        "<li>If the environment contains terminal states and if the agent is guaranteed \\\n",
        "to reach one eventually, then the sequence will not be infinite and we can use $\\gamma = 1$. \\\n",
        "A <b>proper policy</b> is one that is guaranteed to reach a terminal state.</li>\n",
        "<li>Infinite sequences can be compared by the average reward per step</li>\n",
        "</ol>\n",
        "\n",
        "\n",
        "The expected utility of executing $\\pi$ starting in s:\n",
        "$$U^{\\pi}(s)=E[\\sum_{t=0}^{\\infty}\\gamma^t R(S_t,\\pi(S_t),S_{t+1})]$$\n",
        "One (or more) optimal policies will have higher expected utilities. With discounted utilities and infinite horizons, the optimal policy is independent \\\n",
        "of the starting state so we can just write $\\pi^*$:\n",
        "$$\\pi^*=argmax_{\\pi}U^{\\pi}(s)$$\n",
        "The <b>Bellman Equation</b>:\n",
        "$$U(s)=max_{a\\in A(s)}\\sum_{s'}P(s'|s,a)[R(s,a,s')+\\gamma U(s')] $$\n",
        "Therfore:\n",
        "$$\\pi^*=argmax_{a\\in A(s)}\\sum_{s'}P(s'|s,a)[R(s,a,s')+\\gamma U(s')]$$\n",
        "Action-Utility or Q-Function\n",
        "$$U(s)=max_aQ(s,a)$$ \n",
        "From which $\\pi^*$ can be derived\n",
        "$$\\pi^*=argmax_aQ(s,a)$$\n",
        "Bellman Equation for Q-Functions:\n",
        "$$Q(s,a)=\\sum_{s'}P(s'|s,a)[R(s,a,s')+\\gamma U(s')]=\\sum_{s'}P(s'|s,a)[R(s,a,s')+\\gamma Q(s',a')]$$\n",
        "\"\"\"\n",
        "chapter17_2 =  \"\"\"\n",
        "There are four different algorithms for solving MDPs. The first 3 generate exact solutions \\\n",
        "offline. The fourth is a family of online approximate algorithms.\n",
        "\n",
        "<h4>1) Value Iteration</h4>\n",
        "The basis for this approach is the Bellman Equation. Given $n$ states, there are $n$ \\\n",
        "Bellman equations, one for each state, and each contains $n$ unknowns. However the \"max\"\n",
        "operator is not a linear operator so the equations are nonlinear and we cannot simply use \\\n",
        "linear algebra to solve the system of equations. We instead use an iterative approach. \\\n",
        "Start with arbitrary initial values for the utilities; calculate the RHS of the equation \\\n",
        "and use that to update the LHS, thus updating the utility of each state from the utilities \\\n",
        "of its neighbors; and repeat this until we reach equilibrium i.e. convergence.\n",
        "\n",
        "\n",
        "The Bellman Update for state $s$ and iteration $i$:\n",
        "$$U_{i+1}(s)\\leftarrow max_{a\\in A(s)}\\sum_{s'}P(s'|s,a)[R(s,a,s')+\\gamma U_i(s')]$$\n",
        "\n",
        "<h4>2) Policy Iteration</h4>\n",
        "Alternate between the following two steps until convergence:\n",
        "<ol>\n",
        "<li>Policy Evaluation: given a policy $\\pi_i$, calculate $U_i = U^{\\pi_i}$, \\\n",
        "the utility of each state if $\\pi_i$ were to be used. We can use the following \\\n",
        "$$U_i(s)= \\sum_{s'}P(s'|s,\\pi_i (s))[R(s,\\pi_i (s),s')+\\gamma U_i(s')]$$\n",
        "This is now linear since \"max\" has been removed and the system of equations now \\\n",
        "can be solved using linear algebra in $O(n^3)$. For large state spaces it may be \\\n",
        "more efficient to perform a <b>modified policy iteration</b> by using a simplified Bellman update\\\n",
        "$$U_{i+1}(s)\\leftarrow \\sum_{s'}P(s'|s,\\pi_i (s))[R(s,\\pi_i (s),s')+\\gamma U_i(s')]$$</li>\n",
        "<li>Policy Improvement: calculate a new policy $\\pi_{i+1}$ using one-step look-ahead \\\n",
        "based on $U_i$</li>\n",
        "</ol>\n",
        "\n",
        "<h4>3) Linear Programming</h4>\n",
        "\n",
        "<h4>4) Online Algorithms</h4>\n",
        "\"\"\"\n",
        "\n",
        "# Lecture notes \n",
        "module8_lecture_notes = \"\"\" Your summary here \"\"\"\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",
        "\"Markovian Decision Process (MDP)\": \"a sequential decision process in a fully observable,\\\n",
        "stochastic environment with a Markovian transition model and additive rewards\",\n",
        "\"Bellman Equation\": \"the utility of a state is the expected reward for the \\\n",
        "next transition plus the discounted utility of the next state, assuming optimal action\",\n",
        "\"Action-Utility-Function/Q-Function\" : \"the expected utility of taking a given action in a given state\" \n",
        "}\n",
        "\n",
        "print(\"The length in words is\", len(chapter17_1.split(' ')))\n",
        "print(\"The length in characters is\", len(chapter17_1))"
      ],
      "execution_count": 4,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "The length in words is 379\n",
            "The length in characters is 2976\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",
      "metadata": {
        "id": "gYYeNcdM_maE",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 2845
        },
        "cellView": "form",
        "outputId": "31aea03d-a9a5-4cab-e064-926e26250e1d"
      },
      "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))"
      ],
      "execution_count": 5,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 8: Markov Decision Processes\n## AIMA Chapter 16.1 Combining Beliefs and Desires under Uncertainty\n\nDecision theory deals with choosing among actions based on the desirability of their immediate outcomes (\"immediate\" implying that the environment is assumed to be episodic). We therefore consider an agent that must make a decision about what action to take next. A **Utility Function** $U(s)$ captures an agent's preferences by assigning a single numeric value to express the desirability of a given state $s$. However, \\ \nthere is uncertainty about the current state, so the agent assigns a probability $P(s)$ to each possible current state $s$. There is also uncertainty about the outcome of a given action, so the transition model is described by $P(s'|s,a)$ the probability that taking an action $a$ from state $s$ will result in state $s'$. The overall probability of getting to state $s'$ by taking action $a$ from the current state (whatever that may be) is therefore: $P(Result(a)=s')= \\sum_s P(s)P(s'|s,a)$ The **Expected Utility** of an action, $EU(a)$, is then the average utility of each outcome weighted by the probability of that outcome: $EU(a) = \\sum_{s'} P(Result(a)=s')U(s')$ \n\nThe principle of **maximum expected utility (MEU)** states that a rational agent should choose the action that maximizes the agent's expected utility: $action = argmax_a EU(a)$ This principle formalized the general notion of rational behavior, but it does not operationalize it. Actually estimating and calculating the various quantities needed ($P(s)$, $P(s'|s,a)$, $U(s)$, etc.) may be difficult or subject to uncertainty themselves. The MEU principle is related to the performance measures discussed in Ch. 2 - if a utility function reflects the performance measure, then maximizing the utility results in getting the highest (average) performance score. However while the performance measure gives a score for a history retrospectively, a utility function applies to the next state so is done on a step-by-step basis to guide actions.\n\n\n\n## AIMA Chapter 16.2 The Basis of Utility Theory\n\nWe identify constraints that must govern a rational agent's preferences; the MEU principle is a consequence of these constraints.\n<h3>Notation</h3>\n<ul><li>$A\\succ B$: the agent prefers $A$ over $B$</li>\n<li>$A\\sim B$: the agent is indifferent between $A$ and $B$</li>\n<li>$A\\succsim B$: the agent prefers $A$ over $B$ OR is indifferent between them</li>\n<li>$L=[p_1,S_1;p_2,S_2;...;p_n,S_n]$: A lottery $L$ with the possible outcomes $S_1,S_2,...,S_n$ with associated probablilites of $p_1,p_2,...,p_n$. Each $S_i$ is either an atomic state or another lottery</li></ul>\n\n<h3>Constraints; aka Axioms of Utility Theory</h3>\n<ul><li><b>Orderability</b>: Given any two lotteries, a rational agent must either prefer one to the other or be indifferent between them; \n\nexactly one of $(A\\succ B)$, $(A\\prec B)$, or $(A\\sim B)$ holds</li>\n<li><b>Transitivity</b>: If an agent prefers $A$ to $B$ and $B$ to $C$, then it must prefer $A$ to $C$\n\n$(A\\succ B)\\wedge (B\\succ C)\\Rightarrow (A\\succ C) $</li>\n<li><b>Continuity</b>: If some lottery $B$ is between $A$ and $C$ in preference then there exists some probability, $p$, for which a rational agent will be indifferent between $B$ and the lottery that yields $A$ with probability $p$ and $C$ with probability $(1-p)$\n\n$A\\succ B\\succ C\\Rightarrow \\exists p\\;\\;s.t.\\;\\;B\\sim [p,A;(1-p),C]$</li>\n<li><b>Substitutability</b>: If an agent is indifferent between two lotteries $A$ and $B$ then it is also indifferent between two, more complex lotteries that are the same except $A$ is substituted for $B$\n\n$A\\sim B\\Rightarrow [p,A;(1-p),C]\\sim [p,B;(1-p),C]$</li>\n<li><b>Monotonicity</b>: If two lotteries have the same two possible outcomes, $A$ and $B$, and an agent prefers $A$ to $B$, then the agent must prefer the lottery that has a higher probability of yeilding $A$ (and vice versa)\n\n$A\\succ B\\Rightarrow (p>q\\Leftrightarrow [p,A;(1-p),B]\\succ [q,A;(1-q),B])$</li>\n<li><b>Decomposability</b>: Compound lotteries can be reduced to simpler ones using the laws of probability\n\n$[p,A;(1-p),[q,B;(1-q),C]]\\sim [p,A;(1-p)q,B;(1-p)(1-q),C]$</li></ul>\n\n\n## AIMA Chapter 16.3 Utility Functions\n\n<h3>Discussion</h3>\nFrom the axioms listed above we can derive the following:\n<ul><li><b>Existence of Utility Function</b>: if an agent's preferences obey the axioms of utility, then there exists a function $U$ such that $U(A)>U(B)$ <b><i>iff</i></b> the agent prefers $A$ to $B$, and $U(A)=U(B)$ <b><i>iff</i></b> the agent is indifferent between $A$ and $B$.\n\n$U(A)>U(B)\\Leftrightarrow A\\succ B$ and $U(A)=U(B)\\Leftrightarrow A\\sim B$</li>\n<li><b>Expected Utility of a Lottery</b>: the utility of a lottery is the sum over all outcomes of each outcome's probability times its utility\n\n$U([p_1,S_1;p_2,S_2;...;p_n,S_n])=\\sum_i p_iU(S_i)$</li></ul>\nThese findings establish that a utility function exists for any rational agent, but not that the utility function is unique; e.g an agent's behavior does not change if its utility function $U(S)$ is transformed to $U'(S)=aU(s)+b$, where $a>0$; i.e. behavior is\ninvariant under positive linear transformation. Furthermore, even though it exists, an agent may not be explicitly maximizing its utility function. It may be generating rational behavior via some other mechanism (e.g. table lookup). However an observer could learn the agent's utility function by watching its behavior. In a deterministic environment, only the ordinal utility is needed; i.e. the total order/ranking of states.\n\n\n## AIMA Chapter 17.1 Sequential Decision Problems\n\na **Markov Decision Process** or **MDP** is a sequential decision problem for a fully observable, stochasitic environment with a Markovian transition model and additive rewards. It consists of:\n<ul>\n<li>A set of states, and initial state $s_0$</li>\n<li>A set of actions $Actions(s)$ in each state</li>\n<li>A transition model $P(s'|s,a)$ - also written as $T(s,a,s')$. We assume it is <b>Markovian</b> i.e the probability of reaching $s'$ from $s$ only depends on $s$ and not the history of earlier states.</li>\n<li>A reward function $R(s,a,s')$ - For a sequential decision problem, the agent's utility depends on a sequence of states and actions, an environment history, rather than a single state. We define a reward function which assigns a reward (+ or -) for each transition $s$ to $s'$ via $a$, and the utility of an environment history is the sum of (discounted) rewards received.</li>\n</ul>\nBecause the outcome of each action is uncertain, the solution is not a fixed action sequence, but rather a <b>policy</b>, denoted by $\\pi$, that specifies what action to take in any given state, $\\pi (s)$. A policy is evaluated by its expected utility of the possible environment histories it may generate. An <b>optimal policy</b>, $\\pi^*$, is one that yields the highest expected utility. A policy that depends on time left is called nonstationary (finite horizon; fixed time), whereas a policy that acts only on the current state is stationary (infinite horizon; no time limit).\n\n\nAdditive discounted rewards: $U_h(s_0,a_0,s_1,a_1,...) = R(s_0,a_0,s_1) + \\gamma R(s_1,a_1,s_2) + \\gamma^2 R(s_2,a_2,s_3)+...  = \\sum_{t=0}^{\\infty} \\gamma^t R(s_t,a_t,s_{t+1})$ \n<ol>\n<li>For inf. sequence w/ discounted rewards, the utility is finite: $\\gamma < 1$ and rewards are bounded by $\\mp R_{max}$ and \n$$U_h(...)\\leq\\sum\\gamma^t R_{max}=(R_{max})/(1-\\gamma)$$</li>\n<li>If the environment contains terminal states and if the agent is guaranteed to reach one eventually, then the sequence will not be infinite and we can use $\\gamma = 1$. A <b>proper policy</b> is one that is guaranteed to reach a terminal state.</li>\n<li>Infinite sequences can be compared by the average reward per step</li>\n</ol>\n\n\nThe expected utility of executing $\\pi$ starting in s:\n$$U^{\\pi}(s)=E[\\sum_{t=0}^{\\infty}\\gamma^t R(S_t,\\pi(S_t),S_{t+1})]$$\nOne (or more) optimal policies will have higher expected utilities. With discounted utilities and infinite horizons, the optimal policy is independent of the starting state so we can just write $\\pi^*$:\n$$\\pi^*=argmax_{\\pi}U^{\\pi}(s)$$\nThe <b>Bellman Equation</b>:\n$$U(s)=max_{a\\in A(s)}\\sum_{s'}P(s'|s,a)[R(s,a,s')+\\gamma U(s')] $$\nTherfore:\n$$\\pi^*=argmax_{a\\in A(s)}\\sum_{s'}P(s'|s,a)[R(s,a,s')+\\gamma U(s')]$$\nAction-Utility or Q-Function\n$$U(s)=max_aQ(s,a)$$ \nFrom which $\\pi^*$ can be derived\n$$\\pi^*=argmax_aQ(s,a)$$\nBellman Equation for Q-Functions:\n$$Q(s,a)=\\sum_{s'}P(s'|s,a)[R(s,a,s')+\\gamma U(s')]=\\sum_{s'}P(s'|s,a)[R(s,a,s')+\\gamma Q(s',a')]$$\n\n\n## AIMA Chapter 17.2 Algorithms for MDPs\n\nThere are four different algorithms for solving MDPs. The first 3 generate exact solutions offline. The fourth is a family of online approximate algorithms.\n\n<h4>1) Value Iteration</h4>\nThe basis for this approach is the Bellman Equation. Given $n$ states, there are $n$ Bellman equations, one for each state, and each contains $n$ unknowns. However the \"max\"\noperator is not a linear operator so the equations are nonlinear and we cannot simply use linear algebra to solve the system of equations. We instead use an iterative approach. Start with arbitrary initial values for the utilities; calculate the RHS of the equation and use that to update the LHS, thus updating the utility of each state from the utilities of its neighbors; and repeat this until we reach equilibrium i.e. convergence.\n\n\nThe Bellman Update for state $s$ and iteration $i$:\n$$U_{i+1}(s)\\leftarrow max_{a\\in A(s)}\\sum_{s'}P(s'|s,a)[R(s,a,s')+\\gamma U_i(s')]$$\n\n<h4>2) Policy Iteration</h4>\nAlternate between the following two steps until convergence:\n<ol>\n<li>Policy Evaluation: given a policy $\\pi_i$, calculate $U_i = U^{\\pi_i}$, the utility of each state if $\\pi_i$ were to be used. We can use the following $$U_i(s)= \\sum_{s'}P(s'|s,\\pi_i (s))[R(s,\\pi_i (s),s')+\\gamma U_i(s')]$$\nThis is now linear since \"max\" has been removed and the system of equations now can be solved using linear algebra in $O(n^3)$. For large state spaces it may be more efficient to perform a <b>modified policy iteration</b> by using a simplified Bellman update$$U_{i+1}(s)\\leftarrow \\sum_{s'}P(s'|s,\\pi_i (s))[R(s,\\pi_i (s),s')+\\gamma U_i(s')]$$</li>\n<li>Policy Improvement: calculate a new policy $\\pi_{i+1}$ using one-step look-ahead based on $U_i$</li>\n</ol>\n\n<h4>3) Linear Programming</h4>\n\n<h4>4) Online Algorithms</h4>\n\n\n## Module 8 Lecture Notes\n Your summary here \n\n## Module 8 Definitions\n* **Utility function** - Your definition here\n* **Expected utility** - your definition here\n* **Markovian decision process (mdp)** - a sequential decision process in a fully observable,stochastic environment with a Markovian transition model and additive rewards\n* **Bellman equation** - the utility of a state is the expected reward for the next transition plus the discounted utility of the next state, assuming optimal action\n* **Action-utility-function/q-function** - the expected utility of taking a given action in a given state\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "9xRbdqDox2zD"
      },
      "source": [
        "#Module 9 - Reinforcement Learning"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "DpBvu7EMx7sy"
      },
      "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 =  \"\"\"\n",
        "In Reinforcment learning, the agent interacts with the world and periodically recieves \\\n",
        "**rewards** (or **reinforcements**) based on how well it is doing. E.g. a chess playing agent \\\n",
        "might recieve rewards of 1, 0, and 1/2 for win, loss, and draw respectively. Or we might provide less \\\n",
        "**sparse** rewards based on pieces it has captured or board position features. \\\n",
        "Reinforcment learning differs from MDPs in that now the agent isn't just \"given\" the MDP \\\n",
        "to solve; it must act in order to learn the transition model and reward function which \\\n",
        "may initially be unknown. We identify two broad categories of approaches to reinforcement learning:\\\n",
        "<ul>\n",
        "<li><b>Model-Based</b>: the agent uses a transition model of the environment to help interpret \\\n",
        "the reward signals and make decisions. The transition model may initially be known, as in a chess \\\n",
        "playing agent that knows the rules and how peices move (but not which moves to make). Or the \\\n",
        "transition model may be unknown, in which case the agent must learn it from observing the effects of \\\n",
        "its actions. The agent often also uses a utility function, based on the sum of rewards from each state.</li>\n",
        "<li><b>Model-Free</b>: the agent neither knows nor learns a transition model, but rather learns a more \\\n",
        "directly the best actions to take. There are two types of such learning:\n",
        "<ul>\n",
        "<li><b>Action-Utility Learning</b>: most common of which is <b>Q-Learning</b> where the agent \\\n",
        "learns a Q-Function, $Q(s,a)$, which gives the sum of rewards from state $s$ onwards taking \\\n",
        "action $a$. The agent chooses the action with the highest Q-value.</li>\n",
        "<li><b>Policy Search</b>: the agent learns a policy $\\pi(s)$ that maps directly from states to actions. This is a <b>reflex agent</b>.</li>\n",
        "</ul>\n",
        "</li>\n",
        "</ul>\n",
        "\"\"\"\n",
        "chapter22_2 =  \"\"\" Your summary here \"\"\"\n",
        "chapter22_3 =  \"\"\" Your summary here \"\"\"\n",
        "chapter22_4 =  \"\"\" Your summary here \"\"\"\n",
        "chapter22_5 =  \"\"\" Your summary here \"\"\"\n",
        "\n",
        "\n",
        "# Lecture notes \n",
        "module9_lecture_notes = \"\"\"\n",
        "Before, with MDPs we knew the transition policy and reward functions, and could plan the policy \\\n",
        "before actually doing anything. In reinforcment learning, we actually \"learn\" as we perform actions \\\n",
        "then observe the results (and associated rewards) of those actions. There is still an underlying MDP \\\n",
        "but we can't solve it just with computation, we also need \"discover\" the MDP. \\\n",
        "\n",
        "\n",
        "Important Concpets:\n",
        "Exploration vs Exploitation - need to determine the tradeoff between these two\n",
        "\n",
        "MDPs - can be done offline solution calculation\n",
        "Reinforcement Learning - online learning\n",
        "<h3>Model-Based Learning</h3>\n",
        "perform actions to try and empiraclly determine T and R. then plug these \\\n",
        "into and MDP model and solve as if these values were correct. \\\n",
        "step1) act for a whilte to learn empirical MDP model: count outcomes s' for each s,a pair; \\\n",
        "normalize to get T(s,a,s'); discover R(s,a,s') when we experience (s,a,s'). \\\n",
        "step2) solve MDP as before. \n",
        "\n",
        "<h3>Model-Free Learning</h3>\n",
        "don't actually construct an explicit probability model for T; i.e. don't keep track of transtion or reward function. \\\n",
        "Instead, we take an action and compare the actual result with what we thought would happen; when it deviates from our \\\n",
        "expectation (bettwer or worse), we adjust our values up or down. we track just the values of \\\n",
        "interest themselves (the values of being in certain states).\n",
        "\n",
        "\n",
        "Passive vs active learning???? (how does this relate to model-based vs model-free??)\n",
        "\"\"\"\n",
        "\n",
        "# Each definition should be at most 25 words long.\n",
        "module9_definitions = {\n",
        "\"Exploration\" : \"trying unknown actions to get information\",\n",
        "\"Exploitation\" : \"using what you already know; determining the best action based on what you know\",\n",
        "\"Regret\" : \"we will end up making mistakes, taking actions that are bad, in the interest of learning\",\n",
        "\"Sampling\" : \"becasue environment is non-deterministic/stochastic, must try things repeatedly to doscover probabilities\",\n",
        "\"Difficulty\": \"learning can be harder than solving a known MDP\"\n",
        "}"
      ],
      "execution_count": 6,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ydOK__lwWgdp",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1133
        },
        "cellView": "form",
        "outputId": "a176f62c-88e8-4ffd-c05c-ceae5c05fe8b"
      },
      "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))"
      ],
      "execution_count": 7,
      "outputs": [
        {
          "output_type": "display_data",
          "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\nIn Reinforcment learning, the agent interacts with the world and periodically recieves **rewards** (or **reinforcements**) based on how well it is doing. E.g. a chess playing agent might recieve rewards of 1, 0, and 1/2 for win, loss, and draw respectively. Or we might provide less **sparse** rewards based on pieces it has captured or board position features. Reinforcment learning differs from MDPs in that now the agent isn't just \"given\" the MDP to solve; it must act in order to learn the transition model and reward function which may initially be unknown. We identify two broad categories of approaches to reinforcement learning:<ul>\n<li><b>Model-Based</b>: the agent uses a transition model of the environment to help interpret the reward signals and make decisions. The transition model may initially be known, as in a chess playing agent that knows the rules and how peices move (but not which moves to make). Or the transition model may be unknown, in which case the agent must learn it from observing the effects of its actions. The agent often also uses a utility function, based on the sum of rewards from each state.</li>\n<li><b>Model-Free</b>: the agent neither knows nor learns a transition model, but rather learns a more directly the best actions to take. There are two types of such learning:\n<ul>\n<li><b>Action-Utility Learning</b>: most common of which is <b>Q-Learning</b> where the agent learns a Q-Function, $Q(s,a)$, which gives the sum of rewards from state $s$ onwards taking action $a$. The agent chooses the action with the highest Q-value.</li>\n<li><b>Policy Search</b>: the agent learns a policy $\\pi(s)$ that maps directly from states to actions. This is a <b>reflex agent</b>.</li>\n</ul>\n</li>\n</ul>\n\n\n## AIMA Chapter 22.2 Passive Reinforcement Learning\n Your summary here \n\n## AIMA Chapter 22.3 Active Reinforcement Learning\n Your summary here \n\n## AIMA Chapter 22.4 Generalization in Reinforcement Learning\n Your summary here \n\n## Module 9 Lecture Notes\n\nBefore, with MDPs we knew the transition policy and reward functions, and could plan the policy before actually doing anything. In reinforcment learning, we actually \"learn\" as we perform actions then observe the results (and associated rewards) of those actions. There is still an underlying MDP but we can't solve it just with computation, we also need \"discover\" the MDP. \n\nImportant Concpets:\nExploration vs Exploitation - need to determine the tradeoff between these two\n\nMDPs - can be done offline solution calculation\nReinforcement Learning - online learning\n<h3>Model-Based Learning</h3>\nperform actions to try and empiraclly determine T and R. then plug these into and MDP model and solve as if these values were correct. step1) act for a whilte to learn empirical MDP model: count outcomes s' for each s,a pair; normalize to get T(s,a,s'); discover R(s,a,s') when we experience (s,a,s'). step2) solve MDP as before. \n\n<h3>Model-Free Learning</h3>\ndon't actually construct an explicit probability model for T; i.e. don't keep track of transtion or reward function. Instead, we take an action and compare the actual result with what we thought would happen; when it deviates from our expectation (bettwer or worse), we adjust our values up or down. we track just the values of interest themselves (the values of being in certain states).\n\n\nPassive vs active learning???? (how does this relate to model-based vs model-free??)\n\n\n## Module 9 Definitions\n* **Exploration** - trying unknown actions to get information\n* **Exploitation** - using what you already know; determining the best action based on what you know\n* **Regret** - we will end up making mistakes, taking actions that are bad, in the interest of learning\n* **Sampling** - becasue environment is non-deterministic/stochastic, must try things repeatedly to doscover probabilities\n* **Difficulty** - learning can be harder than solving a known MDP\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "46MQLR-Gx8dZ"
      },
      "source": [
        "#Module 10 - Probabilities and Language Models"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "BN0b1eVYx-nd"
      },
      "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 = \"\"\" Your summary here \"\"\"\n",
        "chapter12_3 = \"\"\" Your summary here \"\"\"\n",
        "chapter12_4 = \"\"\" Your summary here \"\"\"\n",
        "chapter12_5 = \"\"\" Your summary here \"\"\"\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 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "\n",
        "# Each definition should be at most 25 words long.\n",
        "module10_definitions = {\n",
        "\"term\" : \"your definition here\",\n",
        "}"
      ],
      "execution_count": 8,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "lvtN3p7ET3Tx",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1077
        },
        "cellView": "form",
        "outputId": "5d673ede-00d2-4895-fc95-a0bf2f412614"
      },
      "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))"
      ],
      "execution_count": 9,
      "outputs": [
        {
          "output_type": "display_data",
          "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 Your summary here \n\n## AIMA Chapter 12.3 Inference Using Full Joint Distributions\n Your summary here \n\n## AIMA Chapter 12.4 Independence\n Your summary here \n\n## AIMA Chapter 12.5 Bayes’ Rule and Its Use\n Your summary here \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 Your summary here \n\n## Module 10 Definitions\n* **Term** - your definition here\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "WHREsHSSyA-h"
      },
      "source": [
        "#Module 11 - Probabilistic Reasoning and Bayes’ Nets"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "tuFC8w7CyCns"
      },
      "source": [
        "# Russell and Norvig, Russell and Norvig, AIMA Chapter 13 “Probabilistic Reasoning” (13.1, 13.2, 13.3)\n",
        "chapter13_1 = \"\"\" Your summary here \"\"\"\n",
        "chapter13_2 = \"\"\" Your summary here \"\"\"\n",
        "chapter13_3 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "\n",
        "# Lecture notes \n",
        "module11_lecture_notes = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "# Definitions\n",
        "module11_definitions = {\n",
        "\"concept\" : \"definition\",    \n",
        "}\n"
      ],
      "execution_count": 10,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "vqtEs0gHs9sO",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 410
        },
        "cellView": "form",
        "outputId": "0a692a86-e51c-41bf-e9df-d0d41ef302f2"
      },
      "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))"
      ],
      "execution_count": 11,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 11: Probabilistic Reasoning and Bayes’ Nets\n## AIMA Chapter 13.1 Representing Knowledge in an Uncertain Domain\n Your summary here \n\n## AIMA Chapter 13.2 The Semantics of Bayesian Networks\n Your summary here \n\n## AIMA 13.3 Exact Inference in Bayesian Networks\n Your summary here \n\n## Module 11 Lecture Notes\n Your summary here \n\n## Module 11 Definitions\n* **Concept** - definition\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "F3FPMzG9yUls"
      },
      "source": [
        "#Module 12 - Naive Bayes and Perceptrons"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "iEIOpL7vyWcc"
      },
      "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 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "# Definitions\n",
        "module12_definitions = {\n",
        "\"concept\" : \"definition\",    \n",
        "}\n",
        "\n"
      ],
      "execution_count": 12,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "KUc_LgzDvWf-",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1278
        },
        "cellView": "form",
        "outputId": "19621bd0-5769-4d70-f343-6036bd0192f1"
      },
      "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))"
      ],
      "execution_count": 13,
      "outputs": [
        {
          "output_type": "display_data",
          "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 Your summary here \n\n## Module 12 Definitions\n* **Concept** - definition\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "qVSQhTVSyYYO"
      },
      "source": [
        "# Module 13 - Neural Networks"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Wm4mfW82yaRH"
      },
      "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 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "# Definitions\n",
        "module13_definitions = {\n",
        "\"concept\" : \"definition\",    \n",
        "}\n"
      ],
      "execution_count": 14,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "kKWbCsbfxL3R",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1077
        },
        "cellView": "form",
        "outputId": "4aa49a5e-2b8b-4250-ca8a-7ae49e2ba23c"
      },
      "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))"
      ],
      "execution_count": 15,
      "outputs": [
        {
          "output_type": "display_data",
          "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 Your summary here \n\n## Module 13 Definitions\n* **Concept** - definition\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "RYESi2kMybL8"
      },
      "source": [
        "# Module 14 - Natural Language Processing"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "qIRJ4YYCzNHL"
      },
      "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 = \"\"\" Your summary here \"\"\"\n",
        "\n",
        "# Definitions\n",
        "module14_definitions = {\n",
        "\"concept\" : \"definition\",    \n",
        "}\n",
        "\n"
      ],
      "execution_count": 16,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "lXNcHuKjyNXa",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 944
        },
        "outputId": "937e9346-e80e-4910-cf24-12353760658d"
      },
      "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))"
      ],
      "execution_count": 17,
      "outputs": [
        {
          "output_type": "display_data",
          "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 Your summary here \n\n## Module 14 Definitions\n* **Concept** - definition\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    },
    {
      "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",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 8634
        },
        "id": "T3cm1WV542_a",
        "outputId": "e76e26ac-cbbf-4ba8-b5ad-2040426c58e8"
      },
      "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))"
      ],
      "execution_count": 18,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/markdown": "# Module 8: Markov Decision Processes\n## AIMA Chapter 16.1 Combining Beliefs and Desires under Uncertainty\n\nDecision theory deals with choosing among actions based on the desirability of their immediate outcomes (\"immediate\" implying that the environment is assumed to be episodic). We therefore consider an agent that must make a decision about what action to take next. A **Utility Function** $U(s)$ captures an agent's preferences by assigning a single numeric value to express the desirability of a given state $s$. However, \\ \nthere is uncertainty about the current state, so the agent assigns a probability $P(s)$ to each possible current state $s$. There is also uncertainty about the outcome of a given action, so the transition model is described by $P(s'|s,a)$ the probability that taking an action $a$ from state $s$ will result in state $s'$. The overall probability of getting to state $s'$ by taking action $a$ from the current state (whatever that may be) is therefore: $P(Result(a)=s')= \\sum_s P(s)P(s'|s,a)$ The **Expected Utility** of an action, $EU(a)$, is then the average utility of each outcome weighted by the probability of that outcome: $EU(a) = \\sum_{s'} P(Result(a)=s')U(s')$ \n\nThe principle of **maximum expected utility (MEU)** states that a rational agent should choose the action that maximizes the agent's expected utility: $action = argmax_a EU(a)$ This principle formalized the general notion of rational behavior, but it does not operationalize it. Actually estimating and calculating the various quantities needed ($P(s)$, $P(s'|s,a)$, $U(s)$, etc.) may be difficult or subject to uncertainty themselves. The MEU principle is related to the performance measures discussed in Ch. 2 - if a utility function reflects the performance measure, then maximizing the utility results in getting the highest (average) performance score. However while the performance measure gives a score for a history retrospectively, a utility function applies to the next state so is done on a step-by-step basis to guide actions.\n\n\n\n## AIMA Chapter 16.2 The Basis of Utility Theory\n\nWe identify constraints that must govern a rational agent's preferences; the MEU principle is a consequence of these constraints.\n<h3>Notation</h3>\n<ul><li>$A\\succ B$: the agent prefers $A$ over $B$</li>\n<li>$A\\sim B$: the agent is indifferent between $A$ and $B$</li>\n<li>$A\\succsim B$: the agent prefers $A$ over $B$ OR is indifferent between them</li>\n<li>$L=[p_1,S_1;p_2,S_2;...;p_n,S_n]$: A lottery $L$ with the possible outcomes $S_1,S_2,...,S_n$ with associated probablilites of $p_1,p_2,...,p_n$. Each $S_i$ is either an atomic state or another lottery</li></ul>\n\n<h3>Constraints; aka Axioms of Utility Theory</h3>\n<ul><li><b>Orderability</b>: Given any two lotteries, a rational agent must either prefer one to the other or be indifferent between them; \n\nexactly one of $(A\\succ B)$, $(A\\prec B)$, or $(A\\sim B)$ holds</li>\n<li><b>Transitivity</b>: If an agent prefers $A$ to $B$ and $B$ to $C$, then it must prefer $A$ to $C$\n\n$(A\\succ B)\\wedge (B\\succ C)\\Rightarrow (A\\succ C) $</li>\n<li><b>Continuity</b>: If some lottery $B$ is between $A$ and $C$ in preference then there exists some probability, $p$, for which a rational agent will be indifferent between $B$ and the lottery that yields $A$ with probability $p$ and $C$ with probability $(1-p)$\n\n$A\\succ B\\succ C\\Rightarrow \\exists p\\;\\;s.t.\\;\\;B\\sim [p,A;(1-p),C]$</li>\n<li><b>Substitutability</b>: If an agent is indifferent between two lotteries $A$ and $B$ then it is also indifferent between two, more complex lotteries that are the same except $A$ is substituted for $B$\n\n$A\\sim B\\Rightarrow [p,A;(1-p),C]\\sim [p,B;(1-p),C]$</li>\n<li><b>Monotonicity</b>: If two lotteries have the same two possible outcomes, $A$ and $B$, and an agent prefers $A$ to $B$, then the agent must prefer the lottery that has a higher probability of yeilding $A$ (and vice versa)\n\n$A\\succ B\\Rightarrow (p>q\\Leftrightarrow [p,A;(1-p),B]\\succ [q,A;(1-q),B])$</li>\n<li><b>Decomposability</b>: Compound lotteries can be reduced to simpler ones using the laws of probability\n\n$[p,A;(1-p),[q,B;(1-q),C]]\\sim [p,A;(1-p)q,B;(1-p)(1-q),C]$</li></ul>\n\n\n## AIMA Chapter 16.3 Utility Functions\n\n<h3>Discussion</h3>\nFrom the axioms listed above we can derive the following:\n<ul><li><b>Existence of Utility Function</b>: if an agent's preferences obey the axioms of utility, then there exists a function $U$ such that $U(A)>U(B)$ <b><i>iff</i></b> the agent prefers $A$ to $B$, and $U(A)=U(B)$ <b><i>iff</i></b> the agent is indifferent between $A$ and $B$.\n\n$U(A)>U(B)\\Leftrightarrow A\\succ B$ and $U(A)=U(B)\\Leftrightarrow A\\sim B$</li>\n<li><b>Expected Utility of a Lottery</b>: the utility of a lottery is the sum over all outcomes of each outcome's probability times its utility\n\n$U([p_1,S_1;p_2,S_2;...;p_n,S_n])=\\sum_i p_iU(S_i)$</li></ul>\nThese findings establish that a utility function exists for any rational agent, but not that the utility function is unique; e.g an agent's behavior does not change if its utility function $U(S)$ is transformed to $U'(S)=aU(s)+b$, where $a>0$; i.e. behavior is\ninvariant under positive linear transformation. Furthermore, even though it exists, an agent may not be explicitly maximizing its utility function. It may be generating rational behavior via some other mechanism (e.g. table lookup). However an observer could learn the agent's utility function by watching its behavior. In a deterministic environment, only the ordinal utility is needed; i.e. the total order/ranking of states.\n\n\n## AIMA Chapter 17.1 Sequential Decision Problems\n\na **Markov Decision Process** or **MDP** is a sequential decision problem for a fully observable, stochasitic environment with a Markovian transition model and additive rewards. It consists of:\n<ul>\n<li>A set of states, and initial state $s_0$</li>\n<li>A set of actions $Actions(s)$ in each state</li>\n<li>A transition model $P(s'|s,a)$ - also written as $T(s,a,s')$. We assume it is <b>Markovian</b> i.e the probability of reaching $s'$ from $s$ only depends on $s$ and not the history of earlier states.</li>\n<li>A reward function $R(s,a,s')$ - For a sequential decision problem, the agent's utility depends on a sequence of states and actions, an environment history, rather than a single state. We define a reward function which assigns a reward (+ or -) for each transition $s$ to $s'$ via $a$, and the utility of an environment history is the sum of (discounted) rewards received.</li>\n</ul>\nBecause the outcome of each action is uncertain, the solution is not a fixed action sequence, but rather a <b>policy</b>, denoted by $\\pi$, that specifies what action to take in any given state, $\\pi (s)$. A policy is evaluated by its expected utility of the possible environment histories it may generate. An <b>optimal policy</b>, $\\pi^*$, is one that yields the highest expected utility. A policy that depends on time left is called nonstationary (finite horizon; fixed time), whereas a policy that acts only on the current state is stationary (infinite horizon; no time limit).\n\n\nAdditive discounted rewards: $U_h(s_0,a_0,s_1,a_1,...) = R(s_0,a_0,s_1) + \\gamma R(s_1,a_1,s_2) + \\gamma^2 R(s_2,a_2,s_3)+...  = \\sum_{t=0}^{\\infty} \\gamma^t R(s_t,a_t,s_{t+1})$ \n<ol>\n<li>For inf. sequence w/ discounted rewards, the utility is finite: $\\gamma < 1$ and rewards are bounded by $\\mp R_{max}$ and \n$$U_h(...)\\leq\\sum\\gamma^t R_{max}=(R_{max})/(1-\\gamma)$$</li>\n<li>If the environment contains terminal states and if the agent is guaranteed to reach one eventually, then the sequence will not be infinite and we can use $\\gamma = 1$. A <b>proper policy</b> is one that is guaranteed to reach a terminal state.</li>\n<li>Infinite sequences can be compared by the average reward per step</li>\n</ol>\n\n\nThe expected utility of executing $\\pi$ starting in s:\n$$U^{\\pi}(s)=E[\\sum_{t=0}^{\\infty}\\gamma^t R(S_t,\\pi(S_t),S_{t+1})]$$\nOne (or more) optimal policies will have higher expected utilities. With discounted utilities and infinite horizons, the optimal policy is independent of the starting state so we can just write $\\pi^*$:\n$$\\pi^*=argmax_{\\pi}U^{\\pi}(s)$$\nThe <b>Bellman Equation</b>:\n$$U(s)=max_{a\\in A(s)}\\sum_{s'}P(s'|s,a)[R(s,a,s')+\\gamma U(s')] $$\nTherfore:\n$$\\pi^*=argmax_{a\\in A(s)}\\sum_{s'}P(s'|s,a)[R(s,a,s')+\\gamma U(s')]$$\nAction-Utility or Q-Function\n$$U(s)=max_aQ(s,a)$$ \nFrom which $\\pi^*$ can be derived\n$$\\pi^*=argmax_aQ(s,a)$$\nBellman Equation for Q-Functions:\n$$Q(s,a)=\\sum_{s'}P(s'|s,a)[R(s,a,s')+\\gamma U(s')]=\\sum_{s'}P(s'|s,a)[R(s,a,s')+\\gamma Q(s',a')]$$\n\n\n## AIMA Chapter 17.2 Algorithms for MDPs\n\nThere are four different algorithms for solving MDPs. The first 3 generate exact solutions offline. The fourth is a family of online approximate algorithms.\n\n<h4>1) Value Iteration</h4>\nThe basis for this approach is the Bellman Equation. Given $n$ states, there are $n$ Bellman equations, one for each state, and each contains $n$ unknowns. However the \"max\"\noperator is not a linear operator so the equations are nonlinear and we cannot simply use linear algebra to solve the system of equations. We instead use an iterative approach. Start with arbitrary initial values for the utilities; calculate the RHS of the equation and use that to update the LHS, thus updating the utility of each state from the utilities of its neighbors; and repeat this until we reach equilibrium i.e. convergence.\n\n\nThe Bellman Update for state $s$ and iteration $i$:\n$$U_{i+1}(s)\\leftarrow max_{a\\in A(s)}\\sum_{s'}P(s'|s,a)[R(s,a,s')+\\gamma U_i(s')]$$\n\n<h4>2) Policy Iteration</h4>\nAlternate between the following two steps until convergence:\n<ol>\n<li>Policy Evaluation: given a policy $\\pi_i$, calculate $U_i = U^{\\pi_i}$, the utility of each state if $\\pi_i$ were to be used. We can use the following $$U_i(s)= \\sum_{s'}P(s'|s,\\pi_i (s))[R(s,\\pi_i (s),s')+\\gamma U_i(s')]$$\nThis is now linear since \"max\" has been removed and the system of equations now can be solved using linear algebra in $O(n^3)$. For large state spaces it may be more efficient to perform a <b>modified policy iteration</b> by using a simplified Bellman update$$U_{i+1}(s)\\leftarrow \\sum_{s'}P(s'|s,\\pi_i (s))[R(s,\\pi_i (s),s')+\\gamma U_i(s')]$$</li>\n<li>Policy Improvement: calculate a new policy $\\pi_{i+1}$ using one-step look-ahead based on $U_i$</li>\n</ol>\n\n<h4>3) Linear Programming</h4>\n\n<h4>4) Online Algorithms</h4>\n\n\n## Module 8 Lecture Notes\n Your summary here \n\n## Module 8 Definitions\n* **Utility function** - Your definition here\n* **Expected utility** - your definition here\n* **Markovian decision process (mdp)** - a sequential decision process in a fully observable,stochastic environment with a Markovian transition model and additive rewards\n* **Bellman equation** - the utility of a state is the expected reward for the next transition plus the discounted utility of the next state, assuming optimal action\n* **Action-utility-function/q-function** - the expected utility of taking a given action in a given state\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\nIn Reinforcment learning, the agent interacts with the world and periodically recieves **rewards** (or **reinforcements**) based on how well it is doing. E.g. a chess playing agent might recieve rewards of 1, 0, and 1/2 for win, loss, and draw respectively. Or we might provide less **sparse** rewards based on pieces it has captured or board position features. Reinforcment learning differs from MDPs in that now the agent isn't just \"given\" the MDP to solve; it must act in order to learn the transition model and reward function which may initially be unknown. We identify two broad categories of approaches to reinforcement learning:<ul>\n<li><b>Model-Based</b>: the agent uses a transition model of the environment to help interpret the reward signals and make decisions. The transition model may initially be known, as in a chess playing agent that knows the rules and how peices move (but not which moves to make). Or the transition model may be unknown, in which case the agent must learn it from observing the effects of its actions. The agent often also uses a utility function, based on the sum of rewards from each state.</li>\n<li><b>Model-Free</b>: the agent neither knows nor learns a transition model, but rather learns a more directly the best actions to take. There are two types of such learning:\n<ul>\n<li><b>Action-Utility Learning</b>: most common of which is <b>Q-Learning</b> where the agent learns a Q-Function, $Q(s,a)$, which gives the sum of rewards from state $s$ onwards taking action $a$. The agent chooses the action with the highest Q-value.</li>\n<li><b>Policy Search</b>: the agent learns a policy $\\pi(s)$ that maps directly from states to actions. This is a <b>reflex agent</b>.</li>\n</ul>\n</li>\n</ul>\n\n\n## AIMA Chapter 22.2 Passive Reinforcement Learning\n Your summary here \n\n## AIMA Chapter 22.3 Active Reinforcement Learning\n Your summary here \n\n## AIMA Chapter 22.4 Generalization in Reinforcement Learning\n Your summary here \n\n## Module 9 Lecture Notes\n\nBefore, with MDPs we knew the transition policy and reward functions, and could plan the policy before actually doing anything. In reinforcment learning, we actually \"learn\" as we perform actions then observe the results (and associated rewards) of those actions. There is still an underlying MDP but we can't solve it just with computation, we also need \"discover\" the MDP. \n\nImportant Concpets:\nExploration vs Exploitation - need to determine the tradeoff between these two\n\nMDPs - can be done offline solution calculation\nReinforcement Learning - online learning\n<h3>Model-Based Learning</h3>\nperform actions to try and empiraclly determine T and R. then plug these into and MDP model and solve as if these values were correct. step1) act for a whilte to learn empirical MDP model: count outcomes s' for each s,a pair; normalize to get T(s,a,s'); discover R(s,a,s') when we experience (s,a,s'). step2) solve MDP as before. \n\n<h3>Model-Free Learning</h3>\ndon't actually construct an explicit probability model for T; i.e. don't keep track of transtion or reward function. Instead, we take an action and compare the actual result with what we thought would happen; when it deviates from our expectation (bettwer or worse), we adjust our values up or down. we track just the values of interest themselves (the values of being in certain states).\n\n\nPassive vs active learning???? (how does this relate to model-based vs model-free??)\n\n\n## Module 9 Definitions\n* **Exploration** - trying unknown actions to get information\n* **Exploitation** - using what you already know; determining the best action based on what you know\n* **Regret** - we will end up making mistakes, taking actions that are bad, in the interest of learning\n* **Sampling** - becasue environment is non-deterministic/stochastic, must try things repeatedly to doscover probabilities\n* **Difficulty** - learning can be harder than solving a known MDP\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 Your summary here \n\n## AIMA Chapter 12.3 Inference Using Full Joint Distributions\n Your summary here \n\n## AIMA Chapter 12.4 Independence\n Your summary here \n\n## AIMA Chapter 12.5 Bayes’ Rule and Its Use\n Your summary here \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 Your summary here \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 Your summary here \n\n## AIMA Chapter 13.2 The Semantics of Bayesian Networks\n Your summary here \n\n## AIMA 13.3 Exact Inference in Bayesian Networks\n Your summary here \n\n## Module 11 Lecture Notes\n Your summary here \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 Your summary here \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 Your summary here \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 Your summary here \n\n## Module 14 Definitions\n* **Concept** - definition\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    }
  ]
}