{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "CIS521_midterm_2_notes.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/"
        },
        "outputId": "f3ce416b-5643-4240-91ff-3322cf01bbe8"
      },
      "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": null,
      "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/"
        },
        "outputId": "1d4a7438-7dfc-4030-c9c3-11f0bbac36f8"
      },
      "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": null,
      "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 = True"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "GZZXyrV-xuAp"
      },
      "source": [
        "# Module 8 - Markov Decision Process"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Y2NfE1CKxzS-"
      },
      "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 = \"\"\" Chapter 16.1 summary. \"\"\"  + sample_equation\n",
        "chapter16_2 =  \"\"\" Your summary here \"\"\"\n",
        "chapter16_3 =  \"\"\" Your summary here \"\"\"\n",
        "\n",
        "\n",
        "# Russell and Norvig, AIMA Chapter 17, “Making Complex Decision” (17.1-17.2)\n",
        "chapter17_1 = \"\"\" Your summary here \"\"\"\n",
        "chapter17_2 =  \"\"\" Your summary here \"\"\"\n",
        "\n",
        "# Lecture notes \n",
        "module8_lecture_notes = \"\"\" In Markov Decision Processes out big change is we \\\n",
        "begins when we start to treat the transition models as stochastic. Now are \\\n",
        "transition models are written as:  \n",
        "$$T(s, a, s')$$  \n",
        "which is a function of the \\\n",
        "state <em>s</em>, the action <em>a</em>, and the probability of arriving in \\\n",
        "the state <em>s'</em>. It can also be written as a probability:  \n",
        "$$p(s' | s, a)$$  \n",
        "The Markov part refers to the fact that the probability of arriving in the new \\\n",
        "state <em>s'</em> depends only on the current state <em>s</em> and the action \\\n",
        "<em>a</em> that is taken, not the prior history of actions.  \\\n",
        "We also introduce a reward function in which some value is extracted (positive or\\\n",
        "negative) when transitioning from <em>s</em> to <em>s'</em> by taking action \\\n",
        "<em>a</em>. The utility (sum of rewards) then is a value dependent on the \\\n",
        "sequence of all actions and transitions up to the current state <em>s</em>.  \\\n",
        "The solution requires that a set of states, a set of actions, a transition \\\n",
        "function, a reward function, and an initial state all be defined. There may \\\n",
        "optionally be a terminal state(s) defined.  \n",
        "The solution to the MDP becomes a policy in which we define an action <em>a</em>\\\n",
        " to take based on the current state <em>s</em> $$\\pi(s) = a$$  \n",
        " Policies require <em>exapected</em> utility of the possible paths. \\\n",
        "This is because of the stochastic nature of the tranisition model.  \\\n",
        "We must be careful. If there is no time limit, then an optimal policy is \\\n",
        "one in which we are stationary! Policies that depend on time are called \\\n",
        "<em>nonstationary</em>.  \\\n",
        "The introduction of a reward discount, <em>$\\gamma$</em> is to prevent our agent \\\n",
        "from bouncing around two states infinitely to maximally extract a reward.  \\\n",
        "There are a couple of equations worth knowing to describe the value of a state \\\n",
        "based on optimially acting. $$V^{*}(s) = max_{a}Q^{*}(s,a)$$  \n",
        "and starting out having taken action <em>a</em> from state <em>s</em> and acting \\\n",
        "optimially moving forward. \\\n",
        "$$Q^{*}(s,a) = \\sum\\limits_{s'}^{} T(s,a,s')[R(s,a,s')+\\gamma V^{*}(s')]$$  \\\n",
        "We can substitute the <em>Q<sup>*</sup></em> into the original and get the Bellman \\\n",
        "Equations.  \n",
        "The Bellman equations can be used for policy iteration at a cost of O(S<sup>2</sup>\\\n",
        "A). Policy iteration improves this by 1) evaluting some fixed policy until \\\n",
        "convergence then 2) updating the policy using one-step look-ahead 3) repeat \\\n",
        "until convergence. The end result is an optimal policy.\"\"\"\n",
        "\n",
        "\n",
        "# Definitions of concepts from Module 8.\n",
        "# You can define any term in the textbook or lecture, \n",
        "# but you most use your own words for the definitions.\n",
        "# Each definition should be at most 25 words long.\n",
        "\n",
        "module8_definitions = {\n",
        "\"utility function\" : \"Your definition here\",\n",
        "\"expected utility\" : \"your definition here\",\n",
        "\"etc.\": \"your definition here\",\n",
        "}\n",
        "\n"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "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": 1027
        },
        "outputId": "82769350-046a-4f24-e45a-22b28c33c064"
      },
      "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": null,
      "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 Chapter 16.1 summary.  $P(\\textnormal{RESULT}(a)=s') = \\sum_s P(s)P(s'|s,a)$ \n\n## AIMA Chapter 16.2 The Basis of Utility Theory\n Your summary here \n\n## AIMA Chapter 16.3 Utility Functions\n Your summary here \n\n## AIMA Chapter 17.1 Sequential Decision Problems\n Your summary here \n\n## AIMA Chapter 17.2 Algorithms for MDPs\n Your summary here \n\n## Module 8 Lecture Notes\n In Markov Decision Processes out big change is we begins when we start to treat the transition models as stochastic. Now are transition models are written as:  \n$$T(s, a, s')$$  \nwhich is a function of the state <em>s</em>, the action <em>a</em>, and the probability of arriving in the state <em>s'</em>. It can also be written as a probability:  \n$$p(s' | s, a)$$  \nThe Markov part refers to the fact that the probability of arriving in the new state <em>s'</em> depends only on the current state <em>s</em> and the action <em>a</em> that is taken, not the prior history of actions.  We also introduce a reward function in which some value is extracted (positive ornegative) when transitioning from <em>s</em> to <em>s'</em> by taking action <em>a</em>. The utility (sum of rewards) then is a value dependent on the sequence of all actions and transitions up to the current state <em>s</em>.  The solution requires that a set of states, a set of actions, a transition function, a reward function, and an initial state all be defined. There may optionally be a terminal state(s) defined.  \nThe solution to the MDP becomes a policy in which we define an action <em>a</em> to take based on the current state <em>s</em> $$\\pi(s) = a$$  \n Policies require <em>exapected</em> utility of the possible paths. This is because of the stochastic nature of the tranisition model.  We must be careful. If there is no time limit, then an optimal policy is one in which we are stationary! Policies that depend on time are called <em>nonstationary</em>.  The introduction of a reward discount, <em>$\\gamma$</em> is to prevent our agent from bouncing around two states infinitely to maximally extract a reward.  There are a couple of equations worth knowing to describe the value of a state based on optimially acting. $$V^{*}(s) = max_{a}Q^{*}(s,a)$$  \nand starting out having taken action <em>a</em> from state <em>s</em> and acting optimially moving forward. $$Q^{*}(s,a) = \\sum\\limits_{s'}^{} T(s,a,s')[R(s,a,s')+\\gamma V^{*}(s')]$$  We can substitute the <em>Q<sup>*</sup></em> into the original and get the Bellman Equations.  \nThe Bellman equations can be used for policy iteration at a cost of O(S<sup>2</sup>A). Policy iteration improves this by 1) evaluting some fixed policy until convergence then 2) updating the policy using one-step look-ahead 3) repeat until convergence. The end result is an optimal policy.\n\n## Module 8 Definitions\n* **Utility function** - Your definition here\n* **Expected utility** - your definition here\n* **Etc.** - your definition here\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    },
    {
      "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 =  \"\"\" Your summary here \"\"\"\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 = \"\"\" When working with Markov decision processes we were \\\n",
        "able to use offline planning. That is we computed the policy based on the \\\n",
        "details of the MDP we were given. Reinforcement learning changes that in that \\\n",
        "we must play the game to arrive at the policy. We act so as to maximize the \\\n",
        "the expected rewards of the game. The reason we play to arrive at the policy \\\n",
        "in reinforcement learning is that we don't know the transition model or \\\n",
        "reward. We must learn them.  \\\n",
        "Direct evaluation, a method in which we compute values for all states under the \\\n",
        "the policy using an averaged set of observations, is the most straightforward \\\n",
        "and intuitive way of approaching reinforcment learning. It is also horribly \\\n",
        "slow. A sample-based policy evaluation treats a sample of outcomes as the \\\n",
        "transition model and reward in the Bellman equations.  \\\n",
        "$$V_{k+1}^{\\pi} \\leftarrow \\sum_{s'}^{}T(s,\\pi (s),s')[R(s,\\pi (s),s') + \\gamma V_{k}^{\\pi} (s')]$$  \\\n",
        "Temporal difference learning takes this a step forward by using a moving average \\\n",
        "of samples. We further refine the method using Exponential Moving Average \\\n",
        "in which we discount older actions using some parameter \\\\alpha.  \\\n",
        "$$\\overline{x}_{n} = \\\\frac{x_n + (1-\\\\alpha) x_{n-1} + (1-\\\\alpha)^{2}x_{n-2} + ...}{1+(1-\\\\alpha)+(1-\\\\alpha)^{2}+...}$$  \\\n",
        "This method however does not allow us to change the policy. We are therefor \\\n",
        "better off learning the Q values, not the values. We must substitute the \\\n",
        "Q value for the value term in the above to do so.  \\\n",
        "Exploration functions introduce the idea of refining our explore/exploit \\\n",
        "process by no longer randomally selecting actions with some probability \\\n",
        "\\episilon . Instead we update the Q as $$ Q(s,a) \\leftarrow _{ \\\\alpha } R(s,a,s') + \\gamma max_{a'}f(Q(s',a'),N(s',a'))$$  \\\n",
        "Approximate Q learning attempts to generalize by learning based off of a set \\\n",
        "of features and weights. We then have a Q function that is evaluted \\\n",
        "based on the set of features describing the state.\"\"\"\n",
        "\n",
        "# Each definition should be at most 25 words long.\n",
        "module9_definitions = {\n",
        "\"Exploration\" : \"The act of trying unknown actions to gather information\",\n",
        "\"Exploitation\": \"Using the information gained to act optimally\",\n",
        "\"Regret\": \"The cost of a mistake\",\n",
        "\"Sampling\": \"Repeated trying of an action to minimize the impact of chance\",\n",
        "\"Model-based Learning\": \"Method in which we use an approximate model, then solve for models assuming the learned model was correct\",\n",
        "\"Passive Reinforcement Learning\": \"Using a fixed policy and learning the state values from experience\",\n",
        "\"Direct Evaluation\": \"Computing the values for each state under the policy using an averaged set of observations\",\n",
        "\"\\episilon -greedy\": \"using a random action to explore in which \\episilon is the probability in which we act randomly\",\n",
        "}"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ydOK__lwWgdp",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 945
        },
        "outputId": "04e978da-2918-461e-f8e8-7285a4817a58"
      },
      "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": null,
      "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 Your summary here \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 When working with Markov decision processes we were able to use offline planning. That is we computed the policy based on the details of the MDP we were given. Reinforcement learning changes that in that we must play the game to arrive at the policy. We act so as to maximize the the expected rewards of the game. The reason we play to arrive at the policy in reinforcement learning is that we don't know the transition model or reward. We must learn them.  Direct evaluation, a method in which we compute values for all states under the the policy using an averaged set of observations, is the most straightforward and intuitive way of approaching reinforcment learning. It is also horribly slow. A sample-based policy evaluation treats a sample of outcomes as the transition model and reward in the Bellman equations.  $$V_{k+1}^{\\pi} \\leftarrow \\sum_{s'}^{}T(s,\\pi (s),s')[R(s,\\pi (s),s') + \\gamma V_{k}^{\\pi} (s')]$$  Temporal difference learning takes this a step forward by using a moving average of samples. We further refine the method using Exponential Moving Average in which we discount older actions using some parameter \\alpha.  $$\\overline{x}_{n} = \\frac{x_n + (1-\\alpha) x_{n-1} + (1-\\alpha)^{2}x_{n-2} + ...}{1+(1-\\alpha)+(1-\\alpha)^{2}+...}$$  This method however does not allow us to change the policy. We are therefor better off learning the Q values, not the values. We must substitute the Q value for the value term in the above to do so.  Exploration functions introduce the idea of refining our explore/exploit process by no longer randomally selecting actions with some probability \\episilon . Instead we update the Q as $$ Q(s,a) \\leftarrow _{ \\alpha } R(s,a,s') + \\gamma max_{a'}f(Q(s',a'),N(s',a'))$$  Approximate Q learning attempts to generalize by learning based off of a set of features and weights. We then have a Q function that is evaluted based on the set of features describing the state.\n\n## Module 9 Definitions\n* **Exploration** - The act of trying unknown actions to gather information\n* **Exploitation** - Using the information gained to act optimally\n* **Regret** - The cost of a mistake\n* **Sampling** - Repeated trying of an action to minimize the impact of chance\n* **Model-based learning** - Method in which we use an approximate model, then solve for models assuming the learned model was correct\n* **Passive reinforcement learning** - Using a fixed policy and learning the state values from experience\n* **Direct evaluation** - Computing the values for each state under the policy using an averaged set of observations\n* **\\episilon -greedy** - using a random action to explore in which \\episilon is the probability in which we act randomly\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 = \"\"\" Conditional probability:  \\\n",
        "$$ P(a|b) = \\\\frac{P(a,b)}{P(b)} $$  \\\n",
        "Product Rule:  \\\n",
        "$$ P(y)P(x|y) = P(x,y) $$  \\\n",
        "Chain Rule:  \\\n",
        "$$ P(x_1,x_2,x_3) = P(x_1)P(x_2|x_1)P(x_3|x_1,x_2) $$  \\\n",
        "Bayes Rule:  \\\n",
        "$$ P(x|y) = \\\\frac{P(y|x)}{P(y)}P(x)$$  \\\n",
        "As we start applying the above to language models, things get hairy. \\\n",
        "The odds of us having an exact sequence of words appear multiple times is \\\n",
        "rare. We therefor focus on key words. The concept of the n-gram is how many \\\n",
        "key words we look at. A bigram would look at one prior word (the second being \\\n",
        "the word itself). A trigram, two prior words, and so on. We can still run into \\\n",
        "issues with unseen words (will be handled in later modules).\n",
        "\"\"\"\n",
        "\n",
        "\n",
        "# Each definition should be at most 25 words long.\n",
        "module10_definitions = {\n",
        "\"term\" : \"your definition here\",\n",
        "}"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "lvtN3p7ET3Tx",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1278
        },
        "cellView": "form",
        "outputId": "2ba43c99-eed7-438a-e4e9-e84f571c57aa"
      },
      "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": null,
      "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 Conditional probability:  $$ P(a|b) = \\frac{P(a,b)}{P(b)} $$  Product Rule:  $$ P(y)P(x|y) = P(x,y) $$  Chain Rule:  $$ P(x_1,x_2,x_3) = P(x_1)P(x_2|x_1)P(x_3|x_1,x_2) $$  Bayes Rule:  $$ P(x|y) = \\frac{P(y|x)}{P(y)}P(x)$$  As we start applying the above to language models, things get hairy. The odds of us having an exact sequence of words appear multiple times is rare. We therefor focus on key words. The concept of the n-gram is how many key words we look at. A bigram would look at one prior word (the second being the word itself). A trigram, two prior words, and so on. We can still run into issues with unseen words (will be handled in later modules).\n\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 = \"\"\" Independence:  \\\n",
        "$$ X \\perp \\!\\!\\! \\perp Y$$  \\\n",
        "Conditional Independence:  \\\n",
        "$$ X \\perp \\!\\!\\! \\perp Y|Z $$  \n",
        "Active Triples:  \\\n",
        "Casual Chain A &rarr; B &rarr; C with B unobserved  \n",
        "Common Cause A &larr; B &rarr; C with B unobserved  \n",
        "Common Effect A &rarr; B &larr; C where B or one of descendents observed  \n",
        "Inactive Triples:  \n",
        "Casual Chain with B observed  \n",
        "Common Effect with B observed  \n",
        "Common Effect where B or descendent is unobserved  \n",
        "\n",
        "A single inactive segment blocks the entire path from being active. \n",
        "\"\"\"\n",
        "\n",
        "# Definitions\n",
        "module11_definitions = {\n",
        "\"concept\" : \"definition\",    \n",
        "}\n"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "vqtEs0gHs9sO",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 633
        },
        "cellView": "form",
        "outputId": "be9b2545-b906-4bdf-bd07-bad794c48d18"
      },
      "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": null,
      "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 Independence:  $$ X \\perp \\!\\!\\! \\perp Y$$  Conditional Independence:  $$ X \\perp \\!\\!\\! \\perp Y|Z $$  \nActive Triples:  Casual Chain A &rarr; B &rarr; C with B unobserved  \nCommon Cause A &larr; B &rarr; C with B unobserved  \nCommon Effect A &rarr; B &larr; C where B or one of descendents observed  \nInactive Triples:  \nCasual Chain with B observed  \nCommon Effect with B observed  \nCommon Effect where B or descendent is unobserved  \n\nA single inactive segment blocks the entire path from being active. \n\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": [
        "# Lecture notes \n",
        "module12_lecture_notes = \"\"\" We use Laplace smoothing to avoid overfitting \\\n",
        "our machine learning models. This can create issues for the case P(X|Y) \\\n",
        "whenver |X| is very large or |Y| is very small.  \n",
        "Typically we adjust parameters on the training set and adjust \\\n",
        "hyperparameters on the hold out set. We then test the model on the test set. \\\n",
        "The hyperparameters are the smoothing techniques.\"\"\"\n",
        "\n",
        "# Definitions\n",
        "module12_definitions = {\n",
        "\"concept\" : \"definition\",    \n",
        "}\n",
        "\n"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "KUc_LgzDvWf-",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1331
        },
        "cellView": "form",
        "outputId": "ebcf1b59-91aa-45da-8c15-b71158a67ccc"
      },
      "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": null,
      "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 We use Laplace smoothing to avoid overfitting our machine learning models. This can create issues for the case P(X|Y) whenver |X| is very large or |Y| is very small.  \nTypically we adjust parameters on the training set and adjust hyperparameters on the hold out set. We then test the model on the test set. The hyperparameters are the smoothing techniques.\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 = \"\"\" \n",
        "Sigmoid Function:  \n",
        "$$ \\\\frac{1}{1+e^{-z}} $$  \n",
        "Probability using \\sigma (z):  \n",
        "$$ P(y=1) = \\sigma (wx+b) = \\\\frac{1}{1+e^{-(wx+b)}} $$  \n",
        "We set our decision boundary (above which yes, below which no) as some value \\\n",
        "between 0 and 1. Traditionally, 0.5. Doesn't have to be though.  \n",
        "Keep in mind that the features are an entire vector!  \n",
        "$$ z = \\sum_{i}^{}w_i x_i + b $$  \n",
        "The loss function becomes a quantification of how different our prediction \\\n",
        "(y-hat) is from the correction output y. One example is the mean squared error.\n",
        "$$ L_{MSE}(\\hat{y},y) = \\\\frac{1}{2}(\\hat{y} - y)^{2} $$  \n",
        "Loss functions help us to choose parameters (w and b) that maximize the log \\\n",
        "probabilities of the true labels in the data. This gives us a loss function \\\n",
        "that is the negative log likelihood loss (<em>cross entropy loss</em>).  \n",
        "$$ L_{CE}(\\hat{y},y) = -log p(y|x) = -[ylog\\hat{y} + (1-y)log(1-\\hat{y})] $$  \n",
        "$$ L_{CE}(\\hat{y},y) = -[ylog\\sigma (wx+b) + (1-y)log(1-\\sigma (wx+b))] $$  \n",
        "Gradient Descent Update:\n",
        "$$ w^{t+1} = w^{t} - \\eta \\\\frac{d}{dw}f(x;w) $$  \n",
        "Choose our learning rate carefully. We don't want to take too long to converge \\\n",
        "(small learning rate) but we also don't want to jump over local/global \\\n",
        "minima in the process (potentially ping-ponging back and forth) \\\n",
        "from choosing too large of a learning rate.  \n",
        "The average loss is what we seek to minimize (as cost function):  \n",
        "$$ Cost(w,b) = \\\\frac{1}{m} \\sum_{i=1}^{m} L_{CE}(\\hat{y}^{(i)},y^{i}) $$  \n",
        "We introduce some randomness to avoid local minima. This is the stochastic \\\n",
        "part of stoachastic gradient descent. This chooses some random example to start \\\n",
        "with. We can also use batch training which computes a gradient over the entirety \\\n",
        "of a dataset. More often, we strike a balance with mini-batch training \\\n",
        "and use some small batch rather than the whole data set.  \n",
        "Regularization is a way in which we smooth out high weights that would come \\\n",
        "about from a feature only occuring once in a class. It acts as a penalty \\\n",
        "that helps to avoid overfitting problems.  \n",
        "When we venture into multinomial regression (more than two classifications) \\\n",
        "we take advantage of the softmax function. This will return a normalized vector \\\n",
        "representing the classifications (ensuring total probability is 1).  \n",
        "Example of neural network withs ingle hidden layer, input x, output y, and \\\n",
        "weight matrices W and U with bias vector b:  \n",
        "$$ h = \\sigma(Wx+b) $$\n",
        "$$ z = Uh $$\n",
        "$$ y = softmax(z) $$  \n",
        "We can see where gradient descent would get to be a bit confusing. No worries \\\n",
        "! It's actually simple. We just backward differentiate to get all our partials \\\n",
        ". We just need to be certain we see all the dependecies created by the feed-forward \\\n",
        "orientation of the network.\n",
        "\"\"\"\n",
        "\n",
        "# Definitions\n",
        "module13_definitions = {\n",
        "\"concept\" : \"definition\",    \n",
        "}\n"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "kKWbCsbfxL3R",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1822
        },
        "cellView": "form",
        "outputId": "25bf969d-01f2-421a-c005-d873ecad8b8e"
      },
      "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": null,
      "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 \nSigmoid Function:  \n$$ \\frac{1}{1+e^{-z}} $$  \nProbability using \\sigma (z):  \n$$ P(y=1) = \\sigma (wx+b) = \\frac{1}{1+e^{-(wx+b)}} $$  \nWe set our decision boundary (above which yes, below which no) as some value between 0 and 1. Traditionally, 0.5. Doesn't have to be though.  \nKeep in mind that the features are an entire vector!  \n$$ z = \\sum_{i}^{}w_i x_i + b $$  \nThe loss function becomes a quantification of how different our prediction (y-hat) is from the correction output y. One example is the mean squared error.\n$$ L_{MSE}(\\hat{y},y) = \\frac{1}{2}(\\hat{y} - y)^{2} $$  \nLoss functions help us to choose parameters (w and b) that maximize the log probabilities of the true labels in the data. This gives us a loss function that is the negative log likelihood loss (<em>cross entropy loss</em>).  \n$$ L_{CE}(\\hat{y},y) = -log p(y|x) = -[ylog\\hat{y} + (1-y)log(1-\\hat{y})] $$  \n$$ L_{CE}(\\hat{y},y) = -[ylog\\sigma (wx+b) + (1-y)log(1-\\sigma (wx+b))] $$  \nGradient Descent Update:\n$$ w^{t+1} = w^{t} - \\eta \\frac{d}{dw}f(x;w) $$  \nChoose our learning rate carefully. We don't want to take too long to converge (small learning rate) but we also don't want to jump over local/global minima in the process (potentially ping-ponging back and forth) from choosing too large of a learning rate.  \nThe average loss is what we seek to minimize (as cost function):  \n$$ Cost(w,b) = \\frac{1}{m} \\sum_{i=1}^{m} L_{CE}(\\hat{y}^{(i)},y^{i}) $$  \nWe introduce some randomness to avoid local minima. This is the stochastic part of stoachastic gradient descent. This chooses some random example to start with. We can also use batch training which computes a gradient over the entirety of a dataset. More often, we strike a balance with mini-batch training and use some small batch rather than the whole data set.  \nRegularization is a way in which we smooth out high weights that would come about from a feature only occuring once in a class. It acts as a penalty that helps to avoid overfitting problems.  \nWhen we venture into multinomial regression (more than two classifications) we take advantage of the softmax function. This will return a normalized vector representing the classifications (ensuring total probability is 1).  \nExample of neural network withs ingle hidden layer, input x, output y, and weight matrices W and U with bias vector b:  \n$$ h = \\sigma(Wx+b) $$\n$$ z = Uh $$\n$$ y = softmax(z) $$  \nWe can see where gradient descent would get to be a bit confusing. No worries ! It's actually simple. We just backward differentiate to get all our partials . We just need to be certain we see all the dependecies created by the feed-forward orientation of the network.\n\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": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "lXNcHuKjyNXa",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1688
        },
        "outputId": "c16cef1c-d367-461b-b1ae-e91466c2ec2c"
      },
      "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": null,
      "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 \nSigmoid Function:  \n$$ \\frac{1}{1+e^{-z}} $$  \nProbability using \\sigma (z):  \n$$ P(y=1) = \\sigma (wx+b) = \\frac{1}{1+e^{-(wx+b)}} $$  \nWe set our decision boundary (above which yes, below which no) as some value between 0 and 1. Traditionally, 0.5. Doesn't have to be though.  \nKeep in mind that the features are an entire vector!  \n$$ z = \\sum_{i}^{}w_i x_i + b $$  \nThe loss function becomes a quantification of how different our prediction (y-hat) is from the correction output y. One example is the mean squared error.\n$$ L_{MSE}(\\hat{y},y) = \\frac{1}{2}(\\hat{y} - y)^{2} $$  \nLoss functions help us to choose parameters (w and b) that maximize the log probabilities of the true labels in the data. This gives us a loss function that is the negative log likelihood loss (<em>cross entropy loss</em>).  \n$$ L_{CE}(\\hat{y},y) = -log p(y|x) = -[ylog\\hat{y} + (1-y)log(1-\\hat{y})] $$  \n$$ L_{CE}(\\hat{y},y) = -[ylog\\sigma (wx+b) + (1-y)log(1-\\sigma (wx+b))] $$  \nGradient Descent Update:\n$$ w^{t+1} = w^{t} - \\eta \\frac{d}{dw}f(x;w) $$  \nChoose our learning rate carefully. We don't want to take too long to converge (small learning rate) but we also don't want to jump over local/global minima in the process (potentially ping-ponging back and forth) from choosing too large of a learning rate.  \nThe average loss is what we seek to minimize (as cost function):  \n$$ Cost(w,b) = \\frac{1}{m} \\sum_{i=1}^{m} L_{CE}(\\hat{y}^{(i)},y^{i}) $$  \nWe introduce some randomness to avoid local minima. This is the stochastic part of stoachastic gradient descent. This chooses some random example to start with. We can also use batch training which computes a gradient over the entirety of a dataset. More often, we strike a balance with mini-batch training and use some small batch rather than the whole data set.  \nRegularization is a way in which we smooth out high weights that would come about from a feature only occuring once in a class. It acts as a penalty that helps to avoid overfitting problems.  \nWhen we venture into multinomial regression (more than two classifications) we take advantage of the softmax function. This will return a normalized vector representing the classifications (ensuring total probability is 1).  \nExample of neural network withs ingle hidden layer, input x, output y, and weight matrices W and U with bias vector b:  \n$$ h = \\sigma(Wx+b) $$\n$$ z = Uh $$\n$$ y = softmax(z) $$  \nWe can see where gradient descent would get to be a bit confusing. No worries ! It's actually simple. We just backward differentiate to get all our partials . We just need to be certain we see all the dependecies created by the feed-forward orientation of the network.\n\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": 8586
        },
        "id": "T3cm1WV542_a",
        "outputId": "1d584ee1-fa12-45fe-81b4-1ffd62de3b74"
      },
      "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": null,
      "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 Chapter 16.1 summary.  $P(\\textnormal{RESULT}(a)=s') = \\sum_s P(s)P(s'|s,a)$ \n\n## AIMA Chapter 16.2 The Basis of Utility Theory\n Your summary here \n\n## AIMA Chapter 16.3 Utility Functions\n Your summary here \n\n## AIMA Chapter 17.1 Sequential Decision Problems\n Your summary here \n\n## AIMA Chapter 17.2 Algorithms for MDPs\n Your summary here \n\n## Module 8 Lecture Notes\n In Markov Decision Processes out big change is we begins when we start to treat the transition models as stochastic. Now are transition models are written as:  \n$$T(s, a, s')$$  \nwhich is a function of the state <em>s</em>, the action <em>a</em>, and the probability of arriving in the state <em>s'</em>. It can also be written as a probability:  \n$$p(s' | s, a)$$  \nThe Markov part refers to the fact that the probability of arriving in the new state <em>s'</em> depends only on the current state <em>s</em> and the action <em>a</em> that is taken, not the prior history of actions.  We also introduce a reward function in which some value is extracted (positive ornegative) when transitioning from <em>s</em> to <em>s'</em> by taking action <em>a</em>. The utility (sum of rewards) then is a value dependent on the sequence of all actions and transitions up to the current state <em>s</em>.  The solution requires that a set of states, a set of actions, a transition function, a reward function, and an initial state all be defined. There may optionally be a terminal state(s) defined.  \nThe solution to the MDP becomes a policy in which we define an action <em>a</em> to take based on the current state <em>s</em> $$\\pi(s) = a$$  \n Policies require <em>exapected</em> utility of the possible paths. This is because of the stochastic nature of the tranisition model.  We must be careful. If there is no time limit, then an optimal policy is one in which we are stationary! Policies that depend on time are called <em>nonstationary</em>.  The introduction of a reward discount, <em>$\\gamma$</em> is to prevent our agent from bouncing around two states infinitely to maximally extract a reward.  There are a couple of equations worth knowing to describe the value of a state based on optimially acting. $$V^{*}(s) = max_{a}Q^{*}(s,a)$$  \nand starting out having taken action <em>a</em> from state <em>s</em> and acting optimially moving forward. $$Q^{*}(s,a) = \\sum\\limits_{s'}^{} T(s,a,s')[R(s,a,s')+\\gamma V^{*}(s')]$$  We can substitute the <em>Q<sup>*</sup></em> into the original and get the Bellman Equations.  \nThe Bellman equations can be used for policy iteration at a cost of O(S<sup>2</sup>A). Policy iteration improves this by 1) evaluting some fixed policy until convergence then 2) updating the policy using one-step look-ahead 3) repeat until convergence. The end result is an optimal policy.\n\n## Module 8 Definitions\n* **Utility function** - Your definition here\n* **Expected utility** - your definition here\n* **Etc.** - your definition here\n\n\n# Module 9: Reinforcement Learning\n## AIMA Chapter 17.3 Bandit Problems\n Your summary here \n\n## AIMA Chapter 22.1 Learning from Rewards\n Your summary here \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 When working with Markov decision processes we were able to use offline planning. That is we computed the policy based on the details of the MDP we were given. Reinforcement learning changes that in that we must play the game to arrive at the policy. We act so as to maximize the the expected rewards of the game. The reason we play to arrive at the policy in reinforcement learning is that we don't know the transition model or reward. We must learn them.  Direct evaluation, a method in which we compute values for all states under the the policy using an averaged set of observations, is the most straightforward and intuitive way of approaching reinforcment learning. It is also horribly slow. A sample-based policy evaluation treats a sample of outcomes as the transition model and reward in the Bellman equations.  $$V_{k+1}^{\\pi} \\leftarrow \\sum_{s'}^{}T(s,\\pi (s),s')[R(s,\\pi (s),s') + \\gamma V_{k}^{\\pi} (s')]$$  Temporal difference learning takes this a step forward by using a moving average of samples. We further refine the method using Exponential Moving Average in which we discount older actions using some parameter \\alpha.  $$\\overline{x}_{n} = \\frac{x_n + (1-\\alpha) x_{n-1} + (1-\\alpha)^{2}x_{n-2} + ...}{1+(1-\\alpha)+(1-\\alpha)^{2}+...}$$  This method however does not allow us to change the policy. We are therefor better off learning the Q values, not the values. We must substitute the Q value for the value term in the above to do so.  Exploration functions introduce the idea of refining our explore/exploit process by no longer randomally selecting actions with some probability \\episilon . Instead we update the Q as $$ Q(s,a) \\leftarrow _{ \\alpha } R(s,a,s') + \\gamma max_{a'}f(Q(s',a'),N(s',a'))$$  Approximate Q learning attempts to generalize by learning based off of a set of features and weights. We then have a Q function that is evaluted based on the set of features describing the state.\n\n## Module 9 Definitions\n* **Exploration** - The act of trying unknown actions to gather information\n* **Exploitation** - Using the information gained to act optimally\n* **Regret** - The cost of a mistake\n* **Sampling** - Repeated trying of an action to minimize the impact of chance\n* **Model-based learning** - Method in which we use an approximate model, then solve for models assuming the learned model was correct\n* **Passive reinforcement learning** - Using a fixed policy and learning the state values from experience\n* **Direct evaluation** - Computing the values for each state under the policy using an averaged set of observations\n* **\\episilon -greedy** - using a random action to explore in which \\episilon is the probability in which we act randomly\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 Conditional probability:  $$ P(a|b) = \\frac{P(a,b)}{P(b)} $$  Product Rule:  $$ P(y)P(x|y) = P(x,y) $$  Chain Rule:  $$ P(x_1,x_2,x_3) = P(x_1)P(x_2|x_1)P(x_3|x_1,x_2) $$  Bayes Rule:  $$ P(x|y) = \\frac{P(y|x)}{P(y)}P(x)$$  As we start applying the above to language models, things get hairy. The odds of us having an exact sequence of words appear multiple times is rare. We therefor focus on key words. The concept of the n-gram is how many key words we look at. A bigram would look at one prior word (the second being the word itself). A trigram, two prior words, and so on. We can still run into issues with unseen words (will be handled in later modules).\n\n\n## Module 10 Definitions\n* **Term** - your definition here\n\n\n# Module 11: Probabilistic Reasoning and Bayes’ Nets\n## AIMA Chapter 13.1 Representing Knowledge in an Uncertain Domain\n 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 Independence:  $$ X \\perp \\!\\!\\! \\perp Y$$  Conditional Independence:  $$ X \\perp \\!\\!\\! \\perp Y|Z $$  \nActive Triples:  Casual Chain A &rarr; B &rarr; C with B unobserved  \nCommon Cause A &larr; B &rarr; C with B unobserved  \nCommon Effect A &rarr; B &larr; C where B or one of descendents observed  \nInactive Triples:  \nCasual Chain with B observed  \nCommon Effect with B observed  \nCommon Effect where B or descendent is unobserved  \n\nA single inactive segment blocks the entire path from being active. \n\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 We use Laplace smoothing to avoid overfitting our machine learning models. This can create issues for the case P(X|Y) whenver |X| is very large or |Y| is very small.  \nTypically we adjust parameters on the training set and adjust hyperparameters on the hold out set. We then test the model on the test set. The hyperparameters are the smoothing techniques.\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 \nSigmoid Function:  \n$$ \\frac{1}{1+e^{-z}} $$  \nProbability using \\sigma (z):  \n$$ P(y=1) = \\sigma (wx+b) = \\frac{1}{1+e^{-(wx+b)}} $$  \nWe set our decision boundary (above which yes, below which no) as some value between 0 and 1. Traditionally, 0.5. Doesn't have to be though.  \nKeep in mind that the features are an entire vector!  \n$$ z = \\sum_{i}^{}w_i x_i + b $$  \nThe loss function becomes a quantification of how different our prediction (y-hat) is from the correction output y. One example is the mean squared error.\n$$ L_{MSE}(\\hat{y},y) = \\frac{1}{2}(\\hat{y} - y)^{2} $$  \nLoss functions help us to choose parameters (w and b) that maximize the log probabilities of the true labels in the data. This gives us a loss function that is the negative log likelihood loss (<em>cross entropy loss</em>).  \n$$ L_{CE}(\\hat{y},y) = -log p(y|x) = -[ylog\\hat{y} + (1-y)log(1-\\hat{y})] $$  \n$$ L_{CE}(\\hat{y},y) = -[ylog\\sigma (wx+b) + (1-y)log(1-\\sigma (wx+b))] $$  \nGradient Descent Update:\n$$ w^{t+1} = w^{t} - \\eta \\frac{d}{dw}f(x;w) $$  \nChoose our learning rate carefully. We don't want to take too long to converge (small learning rate) but we also don't want to jump over local/global minima in the process (potentially ping-ponging back and forth) from choosing too large of a learning rate.  \nThe average loss is what we seek to minimize (as cost function):  \n$$ Cost(w,b) = \\frac{1}{m} \\sum_{i=1}^{m} L_{CE}(\\hat{y}^{(i)},y^{i}) $$  \nWe introduce some randomness to avoid local minima. This is the stochastic part of stoachastic gradient descent. This chooses some random example to start with. We can also use batch training which computes a gradient over the entirety of a dataset. More often, we strike a balance with mini-batch training and use some small batch rather than the whole data set.  \nRegularization is a way in which we smooth out high weights that would come about from a feature only occuring once in a class. It acts as a penalty that helps to avoid overfitting problems.  \nWhen we venture into multinomial regression (more than two classifications) we take advantage of the softmax function. This will return a normalized vector representing the classifications (ensuring total probability is 1).  \nExample of neural network withs ingle hidden layer, input x, output y, and weight matrices W and U with bias vector b:  \n$$ h = \\sigma(Wx+b) $$\n$$ z = Uh $$\n$$ y = softmax(z) $$  \nWe can see where gradient descent would get to be a bit confusing. No worries ! It's actually simple. We just backward differentiate to get all our partials . We just need to be certain we see all the dependecies created by the feed-forward orientation of the network.\n\n\n## Module 13 Definitions\n* **Concept** - definition\n\n\n# Module 14: Natural Language Processing\n## SLP Chapter 9.1 Language Models Revisited\n Your summary here \n\n## SLP Chapter 9.2 Recurrent Neural Networks\n Your summary here \n\n## SLP Chapter 9.3 RNNs as Language Models\n Your summary here \n\n## SLP Chapter 6.1 Lexical Semantics\n Your summary here \n\n## SLP Chapter 6.2 Vector Semantics\n Your summary here \n\n## SLP Chapter 6.3 Words and Vectors\n Your summary here \n\n## SLP Chapter 6.4 Cosine for measuring similarity\n Your summary here \n\n## SLP Chapter 6.8 Word2vec\n Your summary here \n\n## SLP Chapter 6.10 Semantic properties of embeddings\n Your summary here \n\n## SLP Chapter 6.11 Bias and Embeddings\n Your summary here \n\n## SLP Chapter 6.12 Evaluating Vector Models\n Your summary here \n\n## Module 13 Lecture Notes\n \nSigmoid Function:  \n$$ \\frac{1}{1+e^{-z}} $$  \nProbability using \\sigma (z):  \n$$ P(y=1) = \\sigma (wx+b) = \\frac{1}{1+e^{-(wx+b)}} $$  \nWe set our decision boundary (above which yes, below which no) as some value between 0 and 1. Traditionally, 0.5. Doesn't have to be though.  \nKeep in mind that the features are an entire vector!  \n$$ z = \\sum_{i}^{}w_i x_i + b $$  \nThe loss function becomes a quantification of how different our prediction (y-hat) is from the correction output y. One example is the mean squared error.\n$$ L_{MSE}(\\hat{y},y) = \\frac{1}{2}(\\hat{y} - y)^{2} $$  \nLoss functions help us to choose parameters (w and b) that maximize the log probabilities of the true labels in the data. This gives us a loss function that is the negative log likelihood loss (<em>cross entropy loss</em>).  \n$$ L_{CE}(\\hat{y},y) = -log p(y|x) = -[ylog\\hat{y} + (1-y)log(1-\\hat{y})] $$  \n$$ L_{CE}(\\hat{y},y) = -[ylog\\sigma (wx+b) + (1-y)log(1-\\sigma (wx+b))] $$  \nGradient Descent Update:\n$$ w^{t+1} = w^{t} - \\eta \\frac{d}{dw}f(x;w) $$  \nChoose our learning rate carefully. We don't want to take too long to converge (small learning rate) but we also don't want to jump over local/global minima in the process (potentially ping-ponging back and forth) from choosing too large of a learning rate.  \nThe average loss is what we seek to minimize (as cost function):  \n$$ Cost(w,b) = \\frac{1}{m} \\sum_{i=1}^{m} L_{CE}(\\hat{y}^{(i)},y^{i}) $$  \nWe introduce some randomness to avoid local minima. This is the stochastic part of stoachastic gradient descent. This chooses some random example to start with. We can also use batch training which computes a gradient over the entirety of a dataset. More often, we strike a balance with mini-batch training and use some small batch rather than the whole data set.  \nRegularization is a way in which we smooth out high weights that would come about from a feature only occuring once in a class. It acts as a penalty that helps to avoid overfitting problems.  \nWhen we venture into multinomial regression (more than two classifications) we take advantage of the softmax function. This will return a normalized vector representing the classifications (ensuring total probability is 1).  \nExample of neural network withs ingle hidden layer, input x, output y, and weight matrices W and U with bias vector b:  \n$$ h = \\sigma(Wx+b) $$\n$$ z = Uh $$\n$$ y = softmax(z) $$  \nWe can see where gradient descent would get to be a bit confusing. No worries ! It's actually simple. We just backward differentiate to get all our partials . We just need to be certain we see all the dependecies created by the feed-forward orientation of the network.\n\n\n## Module 14 Definitions\n* **Concept** - definition\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    }
  ]
}