{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "Copy of Template_for 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": "52061a5f-8e74-4a4c-a732-efedfefd5984"
      },
      "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": 20,
      "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": "abaace6d-a226-4fa5-f264-4f8fb5b2f80e"
      },
      "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": 21,
      "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": 22,
      "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 = \"\"\"MDPs, Markov Decision Processes, are sequential decision problems\n",
        "for fully observable environments with stochastic transition models that have additive rewards.\n",
        "To fully define a MDP, you need a set of states, a set of actions, a transition function\n",
        "(the probability that executing action a in state s brings you to state s' for\n",
        "all potential state, action combos), a reward function (the rewards for each possible\n",
        "transition), and an initial state. A policy is a solution to a MDP (it'll tell\n",
        "you what action to take in each state). pi(s) = action to take in state s.\n",
        "pi* is the optimal policy. The same policy could lead to different results/rewards\n",
        "on different instances (because of the randomness of transitions), so optimality\n",
        "is based on the expected utilities from a policy. We'd prefer rewards sooner than\n",
        "later, so we often discount future rewards (to incentivize getting immediate rewards).\n",
        "We have a discount factor (gamma) that we multiply by the utility of rewards in the future\n",
        "to decrease them when considering them from the current time. V*(s) is the expected\n",
        "utility starting from state s and then acting optimally. Q*(s, a) is the expected \n",
        "utility starting out by taking action a in state s and then acting optimally. \n",
        "For Value Iteration, we start by initializing all V_0(s) to 0 (as with no time left,\n",
        "the expected rewards should be 0). Then we take all the V_k(s) values and do one\n",
        "level of expectimax from each state (via V_k+1(s) = max_a sum_s' T(s, a, s')[R(s, a, s') + gammaV_k(s')]).\n",
        "Then we repeat the previous step until the values converge (which will then tell\n",
        "us the optimal policy. However, the optimal polciy might converge way before the\n",
        "values do. Value Iteration takes O(S^2 * A) where S is the number of states and\n",
        "A is the number of actions. Policy Iteration: Step 1 --> policy evaluation \n",
        "(calculate the utilities for a fixed policy until convergence), \n",
        "Step 2 --> policy improvement (update the policy using one-step-look-ahead with\n",
        "the resulting converged utilities as future values), Step 3 --> repeat these steps \n",
        "until the policy converges. Computing optimal values? --> use value or policy \n",
        "iteration. Computing values for a particular policy? --> use policy evaluation.\n",
        "Want to turn your values into a policy? --> use policy extraction. \n",
        "The Principle of Maximum Expected Utility (MEU) holds that rational agents should\n",
        "choose whatever action maximizes their expected utility given what they know. \n",
        "A > B (prefer A to B). A ~ B (indifferent between A and B).\n",
        "Axiom of Transitivity: if (A > B) AND (B > C) then (A > C). \n",
        "Axiom of Orderability: (A > B) OR (A < B) OR (A ~ B).\n",
        "Axiom of Continuity: if (A > B > C) then there exists some p s.t. [p, A; 1-p, C] ~ B.\n",
        "Axiom of Substitutability: if A ~ B then [p, A; 1-p, C] ~ [p, B; 1-p, C]. \n",
        "Axiom of Monotonicity: if A > B then (p >= q iff [p, A; 1-p, B] >= [q, A; 1-q, B]). \n",
        "\"\"\"\n",
        "\n",
        "\n",
        "# Definitions of concepts from Module 8.\n",
        "# You can define any term in the textbook or lecture, \n",
        "# but you most use your own words for the definitions.\n",
        "# Each definition should be at most 25 words long.\n",
        "\n",
        "module8_definitions = {\n",
        "\"utility function\" : \"Your definition here\",\n",
        "\"expected utility\" : \"your definition here\",\n",
        "\"etc.\": \"your definition here\",\n",
        "}\n",
        "\n"
      ],
      "execution_count": 23,
      "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": 1000
        },
        "outputId": "3eee5779-6d78-4d1e-9a6b-75ef6c823078"
      },
      "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": 24,
      "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\nMDPs, Markov Decision Processes, are sequential decision problems\nfor fully observable environments with stochastic transition models that have additive rewards.\nTo fully define a MDP, you need a set of states, a set of actions, a transition function\n(the probability that executing action a in state s brings you to state s' for\nall potential state, action combos), a reward function (the rewards for each possible\ntransition), and an initial state. A policy is a solution to a MDP (it'll tell\nyou what action to take in each state). pi(s) = action to take in state s.\npi* is the optimal policy. The same policy could lead to different results/rewards\non different instances (because of the randomness of transitions), so optimality\nis based on the expected utilities from a policy. We'd prefer rewards sooner than\nlater, so we often discount future rewards (to incentivize getting immediate rewards).\nWe have a discount factor (gamma) that we multiply by the utility of rewards in the future\nto decrease them when considering them from the current time. V*(s) is the expected\nutility starting from state s and then acting optimally. Q*(s, a) is the expected \nutility starting out by taking action a in state s and then acting optimally. \nFor Value Iteration, we start by initializing all V_0(s) to 0 (as with no time left,\nthe expected rewards should be 0). Then we take all the V_k(s) values and do one\nlevel of expectimax from each state (via V_k+1(s) = max_a sum_s' T(s, a, s')[R(s, a, s') + gammaV_k(s')]).\nThen we repeat the previous step until the values converge (which will then tell\nus the optimal policy. However, the optimal polciy might converge way before the\nvalues do. Value Iteration takes O(S^2 * A) where S is the number of states and\nA is the number of actions. Policy Iteration: Step 1 --> policy evaluation \n(calculate the utilities for a fixed policy until convergence), \nStep 2 --> policy improvement (update the policy using one-step-look-ahead with\nthe resulting converged utilities as future values), Step 3 --> repeat these steps \nuntil the policy converges. Computing optimal values? --> use value or policy \niteration. Computing values for a particular policy? --> use policy evaluation.\nWant to turn your values into a policy? --> use policy extraction. \nThe Principle of Maximum Expected Utility (MEU) holds that rational agents should\nchoose whatever action maximizes their expected utility given what they know. \nA > B (prefer A to B). A ~ B (indifferent between A and B).\nAxiom of Transitivity: if (A > B) AND (B > C) then (A > C). \nAxiom of Orderability: (A > B) OR (A < B) OR (A ~ B).\nAxiom of Continuity: if (A > B > C) then there exists some p s.t. [p, A; 1-p, C] ~ B.\nAxiom of Substitutability: if A ~ B then [p, A; 1-p, C] ~ [p, B; 1-p, C]. \nAxiom of Monotonicity: if A > B then (p >= q iff [p, A; 1-p, B] >= [q, A; 1-q, B]). \n\n\n## Module 8 Definitions\n* **Utility function** - Your definition here\n* **Expected utility** - your definition here\n* **Etc.** - your definition here\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    },
    {
      "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 = \"\"\"Solving MDPs is offline planning (as you don't need to \n",
        "actually play the game, you can just figure out the best strategy through pure \n",
        "computation before starting). Online planning involves reinforcement learning (as \n",
        "you'll need to play the game to gather enough information to deduce the best strategy). \n",
        "We're still trying to ultimately solve MDPs with reinforcement learning, we just don't \n",
        "know the transition or reward functions (we have to play the game a bit to estimate those). \n",
        "Model-Based Learning --> first learn an approximated model based on experiences and then, \n",
        "pretending said model is correct, solve for values and optimal policy (play the game a bit \n",
        "and formulate a guesstimated MDP, then solve said MDP). Passive reinforcement learning \n",
        "invovles learning transition and reward functions when given a fixed policy (you're just\n",
        "along for the ride, you can't pick what to do, but you do still have to play the game). \n",
        "Direct evaluation involves taking a bunch of samples where you abide by some fixed policy \n",
        "and then average together the found state values. Temporal Difference Learning --> we'll update \n",
        "V(s) each time we transition from state s (and thus likely outcome states s' will contribute \n",
        "to updates way more often). Active reinforcement learning allows the agent to choose \n",
        "their own actions (no longer tied to a fixed policy). This introduces a tradeoff between \n",
        "exploration (trying new things) and exploitation (executing based on the current optimal \n",
        "policy). Q-Learning has the agent learn Q(s, a) values as it goes. Each time we go through \n",
        "another transition, we consider our old Q(s, a) value and our current new Q(s, a) value \n",
        "and incorporate it into our Q(s, a) running average (influenced by some learning rate). \n",
        "Q-Learning converges on an optimal policy even if you're acting suboptimally (called off-policy \n",
        "learning). Epsilon-greedy is a method of forcing exploration in which you act randomly \n",
        "with a probability of epsilon and act according to current policy with a probability \n",
        "of 1 - epsilon. Regret measures the total mistake cost (the difference between your expected \n",
        "rewards, including initial suboptimal moves, and optimal expected rewards). Minimizing \n",
        "regret requires optimally learning how to be optimal. Approximate Q-Learning generalizes previous \n",
        "experiences to current, similar situations by having q-states be weighted sums of features. \n",
        "When something bad happens, we blame the features that were on and then disprefer all \n",
        "states with this bad state's features. \"\"\"\n",
        "\n",
        "# Each definition should be at most 25 words long.\n",
        "module9_definitions = {\n",
        "\"term\" : \"your definition here\",\n",
        "}"
      ],
      "execution_count": 25,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ydOK__lwWgdp",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 978
        },
        "cellView": "form",
        "outputId": "76056656-36c6-49b7-8132-5e312cb8fffc"
      },
      "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": 26,
      "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\nSolving MDPs is offline planning (as you don't need to \nactually play the game, you can just figure out the best strategy through pure \ncomputation before starting). Online planning involves reinforcement learning (as \nyou'll need to play the game to gather enough information to deduce the best strategy). \nWe're still trying to ultimately solve MDPs with reinforcement learning, we just don't \nknow the transition or reward functions (we have to play the game a bit to estimate those). \nModel-Based Learning --> first learn an approximated model based on experiences and then, \npretending said model is correct, solve for values and optimal policy (play the game a bit \nand formulate a guesstimated MDP, then solve said MDP). Passive reinforcement learning \ninvovles learning transition and reward functions when given a fixed policy (you're just\nalong for the ride, you can't pick what to do, but you do still have to play the game). \nDirect evaluation involves taking a bunch of samples where you abide by some fixed policy \nand then average together the found state values. Temporal Difference Learning --> we'll update \nV(s) each time we transition from state s (and thus likely outcome states s' will contribute \nto updates way more often). Active reinforcement learning allows the agent to choose \ntheir own actions (no longer tied to a fixed policy). This introduces a tradeoff between \nexploration (trying new things) and exploitation (executing based on the current optimal \npolicy). Q-Learning has the agent learn Q(s, a) values as it goes. Each time we go through \nanother transition, we consider our old Q(s, a) value and our current new Q(s, a) value \nand incorporate it into our Q(s, a) running average (influenced by some learning rate). \nQ-Learning converges on an optimal policy even if you're acting suboptimally (called off-policy \nlearning). Epsilon-greedy is a method of forcing exploration in which you act randomly \nwith a probability of epsilon and act according to current policy with a probability \nof 1 - epsilon. Regret measures the total mistake cost (the difference between your expected \nrewards, including initial suboptimal moves, and optimal expected rewards). Minimizing \nregret requires optimally learning how to be optimal. Approximate Q-Learning generalizes previous \nexperiences to current, similar situations by having q-states be weighted sums of features. \nWhen something bad happens, we blame the features that were on and then disprefer all \nstates with this bad state's features. \n\n## Module 9 Definitions\n* **Term** - your definition here\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 = \"\"\"P(t) = sum_s P(t, s) (summing out s). Conditional Probability --> \n",
        "P(a | b) = P(a, b) / P(b). Product Rule --> P(y) * P(x | y) = P(x, y). Chain Rule --> \n",
        "P(x, y, z) = P(x) * P(y | x) * P(z | x, y) (can generalize to greater lengths). \n",
        "Bayes' Rule --> P(x, y) = P(x | y) * P(y) = P(y | x) * P(x) or you could write it as \n",
        "P(x | y) = P(y | x) * P(x) / P(y). Probabilistic Language Models try to predict the \n",
        "probability of a sentence (or sequence of words) or try to predict the probability \n",
        "of an upcoming word based on previous words. The Markov Assumption involves assuming that \n",
        "the probability of the next word really only depends on it and the previous word (and maybe \n",
        "just a fixed number of words before it, but the main thing is that we don't need the complete \n",
        "word history). Unigram --> don't take into consideration any previous words. Bigram --> \n",
        "1 word history. Trigram --> 2 word history. 4-gram --> 3 word history. Etc...\"\"\"\n",
        "\n",
        "\n",
        "# Each definition should be at most 25 words long.\n",
        "module10_definitions = {\n",
        "\"term\" : \"your definition here\",\n",
        "}"
      ],
      "execution_count": 27,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "lvtN3p7ET3Tx",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "cellView": "form",
        "outputId": "a551669b-bdf3-48f7-e3ad-d93035c64e16"
      },
      "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": 28,
      "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\nP(t) = sum_s P(t, s) (summing out s). Conditional Probability --> \nP(a | b) = P(a, b) / P(b). Product Rule --> P(y) * P(x | y) = P(x, y). Chain Rule --> \nP(x, y, z) = P(x) * P(y | x) * P(z | x, y) (can generalize to greater lengths). \nBayes' Rule --> P(x, y) = P(x | y) * P(y) = P(y | x) * P(x) or you could write it as \nP(x | y) = P(y | x) * P(x) / P(y). Probabilistic Language Models try to predict the \nprobability of a sentence (or sequence of words) or try to predict the probability \nof an upcoming word based on previous words. The Markov Assumption involves assuming that \nthe probability of the next word really only depends on it and the previous word (and maybe \njust a fixed number of words before it, but the main thing is that we don't need the complete \nword history). Unigram --> don't take into consideration any previous words. Bigram --> \n1 word history. Trigram --> 2 word history. 4-gram --> 3 word history. Etc...\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 = \"\"\"X and Y are independent if for all x, y P(x, y) = P(x) * P(y). \n",
        "X and Y are conditionally independent if for all x, y, z P(x, y | z) = P(x | z) * P(y | z) \n",
        "or if for all x, y, z P(x | z, y) = P(x | z). \n",
        "Conditional independence is way more common than uncoditional (absolute) independence. \n",
        "Causal Chain: P(x, y, z) = P(x) * P(y | x) * P(z | y). With causal chains, X is guaranteed \n",
        "to be independent of Z given Y (but X is not guaranteed to be independent of Z). \n",
        "Common Cause: P(x, y, z) = P(y) * P(x | y) * P(z | y). With common cause, X and Z are guaranteed \n",
        "independent given Y (but X is not guaranteed independent of Z). Common Effect: \n",
        "Two causes of one effect (a v-structure) X --> Z <-- Y. With common effect, X and Y are \n",
        "independent (but X and Y are not independent given Z). For a Bayes' Net, shade in observed \n",
        "nodes. Then, we can say that X and Y are conditionally independent given some evidence variable(s) \n",
        "if all undirected paths from X to Y are inactive. Active Paths: causal chain (A --> B --> C where B is unobserved, either direction), \n",
        "common cause (A <-- B --> C where B is unobserved), common effect (A --> B <-- C where B or one of its descendents is observed). \n",
        "If one or more paths between X and Y are active, then X and Y independence is not guaranteed, \n",
        "but if all paths are inactive, then independence is guaranteed.\"\"\"\n",
        "\n",
        "# Definitions\n",
        "module11_definitions = {\n",
        "\"concept\" : \"definition\",    \n",
        "}"
      ],
      "execution_count": 29,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "vqtEs0gHs9sO",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 697
        },
        "cellView": "form",
        "outputId": "3c2f6ff7-e23a-411d-cbad-22d571e1bab4"
      },
      "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": 30,
      "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\nX and Y are independent if for all x, y P(x, y) = P(x) * P(y). \nX and Y are conditionally independent if for all x, y, z P(x, y | z) = P(x | z) * P(y | z) \nor if for all x, y, z P(x | z, y) = P(x | z). \nConditional independence is way more common than uncoditional (absolute) independence. \nCausal Chain: P(x, y, z) = P(x) * P(y | x) * P(z | y). With causal chains, X is guaranteed \nto be independent of Z given Y (but X is not guaranteed to be independent of Z). \nCommon Cause: P(x, y, z) = P(y) * P(x | y) * P(z | y). With common cause, X and Z are guaranteed \nindependent given Y (but X is not guaranteed independent of Z). Common Effect: \nTwo causes of one effect (a v-structure) X --> Z <-- Y. With common effect, X and Y are \nindependent (but X and Y are not independent given Z). For a Bayes' Net, shade in observed \nnodes. Then, we can say that X and Y are conditionally independent given some evidence variable(s) \nif all undirected paths from X to Y are inactive. Active Paths: causal chain (A --> B --> C where B is unobserved, either direction), \ncommon cause (A <-- B --> C where B is unobserved), common effect (A --> B <-- C where B or one of its descendents is observed). \nIf one or more paths between X and Y are active, then X and Y independence is not guaranteed, \nbut if all paths are inactive, then independence is guaranteed.\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 = \"\"\"Model-Based Classification: build a Bayes Net model where \n",
        "the label and features are random variables, instantiate any observed variables, \n",
        "and then query for the distribution of the label conditioned on the features. \n",
        "Naive Bayes: assumes all features are independent effects of the label (meaning \n",
        "P(Y | F1, F2, ... , Fn) = P(Y) * P(F1 | Y) * ... * P(Fn | Y)). We also have \n",
        "P(Y, F1, ... , Fn) = P(Y) * P(F1 | Y) * P(Fn | Y). Overfitting occurs when a classifier \n",
        "fits the training data very closely but it doesn't generalize well (doesn't perform well \n",
        "on the test data). Relative frequency parameters will lead to overfitting, so we should \n",
        "smooth or regularize the estimates. Laplace Smoothing --> pretend you saw every outcome once more \n",
        "than you actually did (or maybe k times more). Laplace doesn't perform well for P(X | Y) when \n",
        "either |X| or |Y| are very large. Linear Classifiers --> We calculate the weighted sum \n",
        "of input feature values and based on whether the result was positive or not, we return +1 or -1 \n",
        "(corresponding to the two classes). If we predicted right, no changes. If we predicted \n",
        "wrong, we adjust the weight vector by adding or subtracting the feature vector (based on whether \n",
        "or not the predition was +1 or -1). Multiclass Classifiers --> We have a weight vector \n",
        "for each class. We calculate the weighted sum of the feature vector for each class and \n",
        "predict the one with the highest score. If we predict incorrectly, add the feature vector to the \n",
        "correct class weight vector and subtract the feature vector from the incorrectly predicted \n",
        "class weight vector. Perceptron Properties: separability (true if some parameters can get the \n",
        "training set perfectly correct), convergence (if the training is separable, perceptron will \n",
        "eventually converge (in the binary case)), mistake bound (the max # of mistakes (in the binary case) \n",
        "related to the margin or degree of separability (mistakes < k / delta^2)). \n",
        "You can always map a feature space to a higher-dimensional feature space where the \n",
        "training set is separable. Maybe instead of just outputting (w dot x) + bias, we apply \n",
        "a non-linear function f to z (whose output will be the activation value). We can do this \n",
        "with the sigmoid function, the tanh function, or the rectified linear unit ReLU.\"\"\"\n",
        "\n",
        "# Definitions\n",
        "module12_definitions = {\n",
        "\"concept\" : \"definition\",    \n",
        "}\n"
      ],
      "execution_count": 31,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "KUc_LgzDvWf-",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "cellView": "form",
        "outputId": "399a898a-08e5-4251-ca6d-8ddacd6cf5ca"
      },
      "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": 32,
      "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\nModel-Based Classification: build a Bayes Net model where \nthe label and features are random variables, instantiate any observed variables, \nand then query for the distribution of the label conditioned on the features. \nNaive Bayes: assumes all features are independent effects of the label (meaning \nP(Y | F1, F2, ... , Fn) = P(Y) * P(F1 | Y) * ... * P(Fn | Y)). We also have \nP(Y, F1, ... , Fn) = P(Y) * P(F1 | Y) * P(Fn | Y). Overfitting occurs when a classifier \nfits the training data very closely but it doesn't generalize well (doesn't perform well \non the test data). Relative frequency parameters will lead to overfitting, so we should \nsmooth or regularize the estimates. Laplace Smoothing --> pretend you saw every outcome once more \nthan you actually did (or maybe k times more). Laplace doesn't perform well for P(X | Y) when \neither |X| or |Y| are very large. Linear Classifiers --> We calculate the weighted sum \nof input feature values and based on whether the result was positive or not, we return +1 or -1 \n(corresponding to the two classes). If we predicted right, no changes. If we predicted \nwrong, we adjust the weight vector by adding or subtracting the feature vector (based on whether \nor not the predition was +1 or -1). Multiclass Classifiers --> We have a weight vector \nfor each class. We calculate the weighted sum of the feature vector for each class and \npredict the one with the highest score. If we predict incorrectly, add the feature vector to the \ncorrect class weight vector and subtract the feature vector from the incorrectly predicted \nclass weight vector. Perceptron Properties: separability (true if some parameters can get the \ntraining set perfectly correct), convergence (if the training is separable, perceptron will \neventually converge (in the binary case)), mistake bound (the max # of mistakes (in the binary case) \nrelated to the margin or degree of separability (mistakes < k / delta^2)). \nYou can always map a feature space to a higher-dimensional feature space where the \ntraining set is separable. Maybe instead of just outputting (w dot x) + bias, we apply \na non-linear function f to z (whose output will be the activation value). We can do this \nwith the sigmoid function, the tanh function, or the rectified linear unit ReLU.\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 = \"\"\"Machine learning classifiers need a feature representation of \n",
        "each input from the training set (a feature vector), a classification function (that \n",
        "predicts which class this input belongs to), an objective function for learning (usually \n",
        "involving minimizing error on the training examples), and an algorithm for optimizing the \n",
        "objective function. We learn the weight and bias parameters via learning, which involves two components: \n",
        "an objective function (aka loss function) that gives us the distance between the classifier's output and \n",
        "what the output should be (we use cross-entropy loss), and an algorithm for optimizing \n",
        "the objective function (we use stochastic gradient descent in order to minimize the loss function. \n",
        "We want to maximize the probability of the correct label p(y | x) --> (p(y|x) = yhat^y * (1 -yhat)^(1-y)).\n",
        "We want the loss to be small if the model's estimate is close to the truth and big if \n",
        "it's pretty wrong. Gradient Descent --> finds a function minimum via checking what direction the \n",
        "function's slope is rising most steeply and then going in the opposite direction. \n",
        "The loss function in convex (only one minimum), so gradient descent will always lead us \n",
        "to the global minimum for the loss function. The distance we jump by in gradient descent \n",
        "is the slope weighted by some learning rate (eta --> weird n). Stochastic gradient \n",
        "descent is where just one random example is chosen at a time and uses it to update its \n",
        "weights. Batch training is where the gradient is computed over the entire dataset \n",
        "(better estimate of which direction to move the weights but takes a long time). \n",
        "Mini-batch training involves training on a small batch (usually set based on \n",
        "whatever the computational resources allow). Regularization allows us to penalize \n",
        "large weights (we add a regularization term to the loss function), which is good for \n",
        "preventing features that only happen in one class but are irrelevant from getting \n",
        "too much importance. The Softmax function takes in an input vector and outputs a \n",
        "vector of values normalized into probabilities. Sigmoid neurons output based on a sigmoid activation \n",
        "function (so their outputs aren't 0 or 1, they more smoothly transition between the two instead \n",
        "of a hard swap). Feed-Forward Neural Network --> a multilayer network in which all units \n",
        "are fully-connected and don't have any cycles and each layer's outputs are passed to units \n",
        "in the next layer and no outputs are passed back to previous layers. To train neural nets, \n",
        "we need a cross entropy loss function, a gradient descent function for optimization, and \n",
        "error back propagation for computing the gradient of the loss function.\"\"\"\n",
        "\n",
        "# Definitions\n",
        "module13_definitions = {\n",
        "\"concept\" : \"definition\",    \n",
        "}\n"
      ],
      "execution_count": 33,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "kKWbCsbfxL3R",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "cellView": "form",
        "outputId": "8882919e-49a3-475a-d406-62ace095ef6c"
      },
      "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": 34,
      "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\nMachine learning classifiers need a feature representation of \neach input from the training set (a feature vector), a classification function (that \npredicts which class this input belongs to), an objective function for learning (usually \ninvolving minimizing error on the training examples), and an algorithm for optimizing the \nobjective function. We learn the weight and bias parameters via learning, which involves two components: \nan objective function (aka loss function) that gives us the distance between the classifier's output and \nwhat the output should be (we use cross-entropy loss), and an algorithm for optimizing \nthe objective function (we use stochastic gradient descent in order to minimize the loss function. \nWe want to maximize the probability of the correct label p(y | x) --> (p(y|x) = yhat^y * (1 -yhat)^(1-y)).\nWe want the loss to be small if the model's estimate is close to the truth and big if \nit's pretty wrong. Gradient Descent --> finds a function minimum via checking what direction the \nfunction's slope is rising most steeply and then going in the opposite direction. \nThe loss function in convex (only one minimum), so gradient descent will always lead us \nto the global minimum for the loss function. The distance we jump by in gradient descent \nis the slope weighted by some learning rate (eta --> weird n). Stochastic gradient \ndescent is where just one random example is chosen at a time and uses it to update its \nweights. Batch training is where the gradient is computed over the entire dataset \n(better estimate of which direction to move the weights but takes a long time). \nMini-batch training involves training on a small batch (usually set based on \nwhatever the computational resources allow). Regularization allows us to penalize \nlarge weights (we add a regularization term to the loss function), which is good for \npreventing features that only happen in one class but are irrelevant from getting \ntoo much importance. The Softmax function takes in an input vector and outputs a \nvector of values normalized into probabilities. Sigmoid neurons output based on a sigmoid activation \nfunction (so their outputs aren't 0 or 1, they more smoothly transition between the two instead \nof a hard swap). Feed-Forward Neural Network --> a multilayer network in which all units \nare fully-connected and don't have any cycles and each layer's outputs are passed to units \nin the next layer and no outputs are passed back to previous layers. To train neural nets, \nwe need a cross entropy loss function, a gradient descent function for optimization, and \nerror back propagation for computing the gradient of the loss function.\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 = \"\"\"Neural Language Models: the input is a k-gram of words w_1:k, \n",
        "the output is a probability distribution over the next word, and the k context words are \n",
        "treated as a word window in which each is associated with an embedding vector. \n",
        "The input is put into a neural network that has at least one hidden layer. \n",
        "For training, the features are the k - 1 preceeding words and the final word is the correct \n",
        "label for classification. We'll want to generalize words (so we can factor in the probabilities \n",
        "of similar words in the context when guessing the probability of the next word). \n",
        "We can do this by training feature vectors for each of the words (so similar words will have \n",
        "similar vectors). Term-Document Matrix: one column for each document and one row for \n",
        "each word in the vocabulary (the value of each cell is the # of times that word is found \n",
        "in that document). We can then check how similar two documents are by comparing their \n",
        "column vectors. Cosine distance between two row (word) vectors tells us how similar they are. \n",
        "Term-Term Matrix: One column and one row for each word in the vocabulary (the value \n",
        "of each cell is the number of times the column word appears in a context window (a bit before or a bit after) \n",
        "for the row word). TF-IDF --> term frequency * inverse document frequency (which is just \n",
        "how often a word was found in a doc * 1/# of docs that word occurred in). \n",
        "Dense vectors are better than sparse vectors (generalize better and are better at \n",
        "representing synonymy). Word embeddings often reflect societal biases (for example, \n",
        "embeddings for competence adjectives are biased towards men).\"\"\"\n",
        "\n",
        "# Definitions\n",
        "module14_definitions = {\n",
        "\"concept\" : \"definition\",    \n",
        "}\n"
      ],
      "execution_count": 35,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "lXNcHuKjyNXa",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "outputId": "97bb7fdf-e527-4126-c0a0-431afc29f85a"
      },
      "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 14 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": 36,
      "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 14 Lecture Notes\nMachine learning classifiers need a feature representation of \neach input from the training set (a feature vector), a classification function (that \npredicts which class this input belongs to), an objective function for learning (usually \ninvolving minimizing error on the training examples), and an algorithm for optimizing the \nobjective function. We learn the weight and bias parameters via learning, which involves two components: \nan objective function (aka loss function) that gives us the distance between the classifier's output and \nwhat the output should be (we use cross-entropy loss), and an algorithm for optimizing \nthe objective function (we use stochastic gradient descent in order to minimize the loss function. \nWe want to maximize the probability of the correct label p(y | x) --> (p(y|x) = yhat^y * (1 -yhat)^(1-y)).\nWe want the loss to be small if the model's estimate is close to the truth and big if \nit's pretty wrong. Gradient Descent --> finds a function minimum via checking what direction the \nfunction's slope is rising most steeply and then going in the opposite direction. \nThe loss function in convex (only one minimum), so gradient descent will always lead us \nto the global minimum for the loss function. The distance we jump by in gradient descent \nis the slope weighted by some learning rate (eta --> weird n). Stochastic gradient \ndescent is where just one random example is chosen at a time and uses it to update its \nweights. Batch training is where the gradient is computed over the entire dataset \n(better estimate of which direction to move the weights but takes a long time). \nMini-batch training involves training on a small batch (usually set based on \nwhatever the computational resources allow). Regularization allows us to penalize \nlarge weights (we add a regularization term to the loss function), which is good for \npreventing features that only happen in one class but are irrelevant from getting \ntoo much importance. The Softmax function takes in an input vector and outputs a \nvector of values normalized into probabilities. Sigmoid neurons output based on a sigmoid activation \nfunction (so their outputs aren't 0 or 1, they more smoothly transition between the two instead \nof a hard swap). Feed-Forward Neural Network --> a multilayer network in which all units \nare fully-connected and don't have any cycles and each layer's outputs are passed to units \nin the next layer and no outputs are passed back to previous layers. To train neural nets, \nwe need a cross entropy loss function, a gradient descent function for optimization, and \nerror back propagation for computing the gradient of the loss function.\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": 1000
        },
        "id": "T3cm1WV542_a",
        "outputId": "235c44c7-5c47-4d78-c199-93c221a3ca91"
      },
      "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": 37,
      "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\nMDPs, Markov Decision Processes, are sequential decision problems\nfor fully observable environments with stochastic transition models that have additive rewards.\nTo fully define a MDP, you need a set of states, a set of actions, a transition function\n(the probability that executing action a in state s brings you to state s' for\nall potential state, action combos), a reward function (the rewards for each possible\ntransition), and an initial state. A policy is a solution to a MDP (it'll tell\nyou what action to take in each state). pi(s) = action to take in state s.\npi* is the optimal policy. The same policy could lead to different results/rewards\non different instances (because of the randomness of transitions), so optimality\nis based on the expected utilities from a policy. We'd prefer rewards sooner than\nlater, so we often discount future rewards (to incentivize getting immediate rewards).\nWe have a discount factor (gamma) that we multiply by the utility of rewards in the future\nto decrease them when considering them from the current time. V*(s) is the expected\nutility starting from state s and then acting optimally. Q*(s, a) is the expected \nutility starting out by taking action a in state s and then acting optimally. \nFor Value Iteration, we start by initializing all V_0(s) to 0 (as with no time left,\nthe expected rewards should be 0). Then we take all the V_k(s) values and do one\nlevel of expectimax from each state (via V_k+1(s) = max_a sum_s' T(s, a, s')[R(s, a, s') + gammaV_k(s')]).\nThen we repeat the previous step until the values converge (which will then tell\nus the optimal policy. However, the optimal polciy might converge way before the\nvalues do. Value Iteration takes O(S^2 * A) where S is the number of states and\nA is the number of actions. Policy Iteration: Step 1 --> policy evaluation \n(calculate the utilities for a fixed policy until convergence), \nStep 2 --> policy improvement (update the policy using one-step-look-ahead with\nthe resulting converged utilities as future values), Step 3 --> repeat these steps \nuntil the policy converges. Computing optimal values? --> use value or policy \niteration. Computing values for a particular policy? --> use policy evaluation.\nWant to turn your values into a policy? --> use policy extraction. \nThe Principle of Maximum Expected Utility (MEU) holds that rational agents should\nchoose whatever action maximizes their expected utility given what they know. \nA > B (prefer A to B). A ~ B (indifferent between A and B).\nAxiom of Transitivity: if (A > B) AND (B > C) then (A > C). \nAxiom of Orderability: (A > B) OR (A < B) OR (A ~ B).\nAxiom of Continuity: if (A > B > C) then there exists some p s.t. [p, A; 1-p, C] ~ B.\nAxiom of Substitutability: if A ~ B then [p, A; 1-p, C] ~ [p, B; 1-p, C]. \nAxiom of Monotonicity: if A > B then (p >= q iff [p, A; 1-p, B] >= [q, A; 1-q, B]). \n\n\n## Module 8 Definitions\n* **Utility function** - Your definition here\n* **Expected utility** - your definition here\n* **Etc.** - your definition here\n\n\n# Module 9: Reinforcement Learning\n## AIMA Chapter 17.3 Bandit Problems\n Your summary here \n\n## AIMA Chapter 22.1 Learning from Rewards\n 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\nSolving MDPs is offline planning (as you don't need to \nactually play the game, you can just figure out the best strategy through pure \ncomputation before starting). Online planning involves reinforcement learning (as \nyou'll need to play the game to gather enough information to deduce the best strategy). \nWe're still trying to ultimately solve MDPs with reinforcement learning, we just don't \nknow the transition or reward functions (we have to play the game a bit to estimate those). \nModel-Based Learning --> first learn an approximated model based on experiences and then, \npretending said model is correct, solve for values and optimal policy (play the game a bit \nand formulate a guesstimated MDP, then solve said MDP). Passive reinforcement learning \ninvovles learning transition and reward functions when given a fixed policy (you're just\nalong for the ride, you can't pick what to do, but you do still have to play the game). \nDirect evaluation involves taking a bunch of samples where you abide by some fixed policy \nand then average together the found state values. Temporal Difference Learning --> we'll update \nV(s) each time we transition from state s (and thus likely outcome states s' will contribute \nto updates way more often). Active reinforcement learning allows the agent to choose \ntheir own actions (no longer tied to a fixed policy). This introduces a tradeoff between \nexploration (trying new things) and exploitation (executing based on the current optimal \npolicy). Q-Learning has the agent learn Q(s, a) values as it goes. Each time we go through \nanother transition, we consider our old Q(s, a) value and our current new Q(s, a) value \nand incorporate it into our Q(s, a) running average (influenced by some learning rate). \nQ-Learning converges on an optimal policy even if you're acting suboptimally (called off-policy \nlearning). Epsilon-greedy is a method of forcing exploration in which you act randomly \nwith a probability of epsilon and act according to current policy with a probability \nof 1 - epsilon. Regret measures the total mistake cost (the difference between your expected \nrewards, including initial suboptimal moves, and optimal expected rewards). Minimizing \nregret requires optimally learning how to be optimal. Approximate Q-Learning generalizes previous \nexperiences to current, similar situations by having q-states be weighted sums of features. \nWhen something bad happens, we blame the features that were on and then disprefer all \nstates with this bad state's features. \n\n## Module 9 Definitions\n* **Term** - your definition here\n\n\n# Module 10: Probabilies and Language Models\n## AIMA Chapter 12.1 Acting under Uncertainty\n Your summary here \n\n## AIMA Chapter 12.2 Basic Probability Notation\n 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\nP(t) = sum_s P(t, s) (summing out s). Conditional Probability --> \nP(a | b) = P(a, b) / P(b). Product Rule --> P(y) * P(x | y) = P(x, y). Chain Rule --> \nP(x, y, z) = P(x) * P(y | x) * P(z | x, y) (can generalize to greater lengths). \nBayes' Rule --> P(x, y) = P(x | y) * P(y) = P(y | x) * P(x) or you could write it as \nP(x | y) = P(y | x) * P(x) / P(y). Probabilistic Language Models try to predict the \nprobability of a sentence (or sequence of words) or try to predict the probability \nof an upcoming word based on previous words. The Markov Assumption involves assuming that \nthe probability of the next word really only depends on it and the previous word (and maybe \njust a fixed number of words before it, but the main thing is that we don't need the complete \nword history). Unigram --> don't take into consideration any previous words. Bigram --> \n1 word history. Trigram --> 2 word history. 4-gram --> 3 word history. Etc...\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\nX and Y are independent if for all x, y P(x, y) = P(x) * P(y). \nX and Y are conditionally independent if for all x, y, z P(x, y | z) = P(x | z) * P(y | z) \nor if for all x, y, z P(x | z, y) = P(x | z). \nConditional independence is way more common than uncoditional (absolute) independence. \nCausal Chain: P(x, y, z) = P(x) * P(y | x) * P(z | y). With causal chains, X is guaranteed \nto be independent of Z given Y (but X is not guaranteed to be independent of Z). \nCommon Cause: P(x, y, z) = P(y) * P(x | y) * P(z | y). With common cause, X and Z are guaranteed \nindependent given Y (but X is not guaranteed independent of Z). Common Effect: \nTwo causes of one effect (a v-structure) X --> Z <-- Y. With common effect, X and Y are \nindependent (but X and Y are not independent given Z). For a Bayes' Net, shade in observed \nnodes. Then, we can say that X and Y are conditionally independent given some evidence variable(s) \nif all undirected paths from X to Y are inactive. Active Paths: causal chain (A --> B --> C where B is unobserved, either direction), \ncommon cause (A <-- B --> C where B is unobserved), common effect (A --> B <-- C where B or one of its descendents is observed). \nIf one or more paths between X and Y are active, then X and Y independence is not guaranteed, \nbut if all paths are inactive, then independence is guaranteed.\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\nModel-Based Classification: build a Bayes Net model where \nthe label and features are random variables, instantiate any observed variables, \nand then query for the distribution of the label conditioned on the features. \nNaive Bayes: assumes all features are independent effects of the label (meaning \nP(Y | F1, F2, ... , Fn) = P(Y) * P(F1 | Y) * ... * P(Fn | Y)). We also have \nP(Y, F1, ... , Fn) = P(Y) * P(F1 | Y) * P(Fn | Y). Overfitting occurs when a classifier \nfits the training data very closely but it doesn't generalize well (doesn't perform well \non the test data). Relative frequency parameters will lead to overfitting, so we should \nsmooth or regularize the estimates. Laplace Smoothing --> pretend you saw every outcome once more \nthan you actually did (or maybe k times more). Laplace doesn't perform well for P(X | Y) when \neither |X| or |Y| are very large. Linear Classifiers --> We calculate the weighted sum \nof input feature values and based on whether the result was positive or not, we return +1 or -1 \n(corresponding to the two classes). If we predicted right, no changes. If we predicted \nwrong, we adjust the weight vector by adding or subtracting the feature vector (based on whether \nor not the predition was +1 or -1). Multiclass Classifiers --> We have a weight vector \nfor each class. We calculate the weighted sum of the feature vector for each class and \npredict the one with the highest score. If we predict incorrectly, add the feature vector to the \ncorrect class weight vector and subtract the feature vector from the incorrectly predicted \nclass weight vector. Perceptron Properties: separability (true if some parameters can get the \ntraining set perfectly correct), convergence (if the training is separable, perceptron will \neventually converge (in the binary case)), mistake bound (the max # of mistakes (in the binary case) \nrelated to the margin or degree of separability (mistakes < k / delta^2)). \nYou can always map a feature space to a higher-dimensional feature space where the \ntraining set is separable. Maybe instead of just outputting (w dot x) + bias, we apply \na non-linear function f to z (whose output will be the activation value). We can do this \nwith the sigmoid function, the tanh function, or the rectified linear unit ReLU.\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\nMachine learning classifiers need a feature representation of \neach input from the training set (a feature vector), a classification function (that \npredicts which class this input belongs to), an objective function for learning (usually \ninvolving minimizing error on the training examples), and an algorithm for optimizing the \nobjective function. We learn the weight and bias parameters via learning, which involves two components: \nan objective function (aka loss function) that gives us the distance between the classifier's output and \nwhat the output should be (we use cross-entropy loss), and an algorithm for optimizing \nthe objective function (we use stochastic gradient descent in order to minimize the loss function. \nWe want to maximize the probability of the correct label p(y | x) --> (p(y|x) = yhat^y * (1 -yhat)^(1-y)).\nWe want the loss to be small if the model's estimate is close to the truth and big if \nit's pretty wrong. Gradient Descent --> finds a function minimum via checking what direction the \nfunction's slope is rising most steeply and then going in the opposite direction. \nThe loss function in convex (only one minimum), so gradient descent will always lead us \nto the global minimum for the loss function. The distance we jump by in gradient descent \nis the slope weighted by some learning rate (eta --> weird n). Stochastic gradient \ndescent is where just one random example is chosen at a time and uses it to update its \nweights. Batch training is where the gradient is computed over the entire dataset \n(better estimate of which direction to move the weights but takes a long time). \nMini-batch training involves training on a small batch (usually set based on \nwhatever the computational resources allow). Regularization allows us to penalize \nlarge weights (we add a regularization term to the loss function), which is good for \npreventing features that only happen in one class but are irrelevant from getting \ntoo much importance. The Softmax function takes in an input vector and outputs a \nvector of values normalized into probabilities. Sigmoid neurons output based on a sigmoid activation \nfunction (so their outputs aren't 0 or 1, they more smoothly transition between the two instead \nof a hard swap). Feed-Forward Neural Network --> a multilayer network in which all units \nare fully-connected and don't have any cycles and each layer's outputs are passed to units \nin the next layer and no outputs are passed back to previous layers. To train neural nets, \nwe need a cross entropy loss function, a gradient descent function for optimization, and \nerror back propagation for computing the gradient of the loss function.\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 14 Lecture Notes\nMachine learning classifiers need a feature representation of \neach input from the training set (a feature vector), a classification function (that \npredicts which class this input belongs to), an objective function for learning (usually \ninvolving minimizing error on the training examples), and an algorithm for optimizing the \nobjective function. We learn the weight and bias parameters via learning, which involves two components: \nan objective function (aka loss function) that gives us the distance between the classifier's output and \nwhat the output should be (we use cross-entropy loss), and an algorithm for optimizing \nthe objective function (we use stochastic gradient descent in order to minimize the loss function. \nWe want to maximize the probability of the correct label p(y | x) --> (p(y|x) = yhat^y * (1 -yhat)^(1-y)).\nWe want the loss to be small if the model's estimate is close to the truth and big if \nit's pretty wrong. Gradient Descent --> finds a function minimum via checking what direction the \nfunction's slope is rising most steeply and then going in the opposite direction. \nThe loss function in convex (only one minimum), so gradient descent will always lead us \nto the global minimum for the loss function. The distance we jump by in gradient descent \nis the slope weighted by some learning rate (eta --> weird n). Stochastic gradient \ndescent is where just one random example is chosen at a time and uses it to update its \nweights. Batch training is where the gradient is computed over the entire dataset \n(better estimate of which direction to move the weights but takes a long time). \nMini-batch training involves training on a small batch (usually set based on \nwhatever the computational resources allow). Regularization allows us to penalize \nlarge weights (we add a regularization term to the loss function), which is good for \npreventing features that only happen in one class but are irrelevant from getting \ntoo much importance. The Softmax function takes in an input vector and outputs a \nvector of values normalized into probabilities. Sigmoid neurons output based on a sigmoid activation \nfunction (so their outputs aren't 0 or 1, they more smoothly transition between the two instead \nof a hard swap). Feed-Forward Neural Network --> a multilayer network in which all units \nare fully-connected and don't have any cycles and each layer's outputs are passed to units \nin the next layer and no outputs are passed back to previous layers. To train neural nets, \nwe need a cross entropy loss function, a gradient descent function for optimization, and \nerror back propagation for computing the gradient of the loss function.\n\n## Module 14 Definitions\n* **Concept** - definition\n",
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ]
          },
          "metadata": {}
        }
      ]
    }
  ]
}