{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "30b1235c-2f3e-4628-9c90-30385f741550",
   "metadata": {},
   "source": [
    "## This demo app shows:\n",
    "* How to use LangChain's YoutubeLoader to retrieve the caption in a YouTube video\n",
    "* How to ask Llama to summarize the content (per the Llama's input size limit) of the video in a naive way using LangChain's stuff method\n",
    "* How to bypass the limit of Llama's max input token size by using a more sophisticated way using LangChain's map_reduce and refine methods - see [here](https://python.langchain.com/docs/use_cases/summarization) for more info"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c866f6be",
   "metadata": {},
   "source": [
    "We start by installing the necessary packages:\n",
    "- [youtube-transcript-api](https://pypi.org/project/youtube-transcript-api/) API to get transcript/subtitles of a YouTube video\n",
    "- [langchain](https://python.langchain.com/docs/get_started/introduction) provides necessary RAG tools for this demo\n",
    "- [tiktoken](https://github.com/openai/tiktoken) BytePair Encoding tokenizer\n",
    "- [pytube](https://pytube.io/en/latest/) Utility for downloading YouTube videos\n",
    "\n",
    "**Note** This example uses Replicate to host the Llama model. If you have not set up/or used Replicate before, we suggest you take a look at the [HelloLlamaCloud](HelloLlamaCloud.ipynb) example for information on how to set up Replicate before continuing with this example.\n",
    "If you do not want to use Replicate, you will need to make some changes to this notebook as you go along."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "02482167",
   "metadata": {},
   "outputs": [],
   "source": [
    "!pip install langchain youtube-transcript-api tiktoken pytube"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "af3069b1",
   "metadata": {},
   "source": [
    "Let's load the YouTube video transcript using the YoutubeLoader."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "3e4b8598",
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain.document_loaders import YoutubeLoader\n",
    "\n",
    "loader = YoutubeLoader.from_youtube_url(\n",
    "    \"https://www.youtube.com/watch?v=1k37OcjH7BM\", add_video_info=True\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "dca32ebb",
   "metadata": {},
   "outputs": [],
   "source": [
    "# load the youtube video caption into Documents\n",
    "docs = loader.load()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "afba128f-b7fd-4b2f-873f-9b5163455d54",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(26324,\n",
       " \"so let's perhaps talk about each of these areas first deep learning that AI how the basic question how does a person interested in deep learning get started in the field the Atlanta AI is working to create courses to help people break into AI so my machine learning course that I taught through Stanf\")"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# check the docs length and content\n",
    "len(docs[0].page_content), docs[0].page_content[:300]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4af7cc16",
   "metadata": {},
   "source": [
    "We are using Replicate in this example to host our Llama 2 model so you will need to get a Replicate token.\n",
    "\n",
    "To get the Replicate token: \n",
    "\n",
    "- You will need to first sign in with Replicate with your github account\n",
    "- Then create a free API token [here](https://replicate.com/account/api-tokens) that you can use for a while. \n",
    "\n",
    "**Note** After the free trial ends, you will need to enter billing info to continue to use Llama2 hosted on Replicate.\n",
    "\n",
    "Alternatively, you can run Llama locally. See:\n",
    "- [HelloLlamaCloud](HelloLlamaCloud.ipynb) for further information on how to run Llama using Replicate.\n",
    "- [HelloLlamaLocal](HelloLlamaLocal.ipynb) for further information on how to run Llama locally."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "ab3ac00e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " ········\n"
     ]
    }
   ],
   "source": [
    "# enter your Replicate API token, or you can use local Llama. See README for more info\n",
    "from getpass import getpass\n",
    "import os\n",
    "\n",
    "REPLICATE_API_TOKEN = getpass()\n",
    "os.environ[\"REPLICATE_API_TOKEN\"] = REPLICATE_API_TOKEN\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6b911efd",
   "metadata": {},
   "source": [
    "Next we call the Llama 2 model from Replicate. In this example we will use the llama 2 13b chat model. You can find more Llama 2 models by searching for them on the [Replicate model explore page](https://replicate.com/explore?query=llama).\n",
    "\n",
    "You can add them here in the format: model_name/version\n",
    "\n",
    "If you using local Llama, just set llm accordingly - see the [HelloLlamaLocal notebook](HelloLlamaLocal.ipynb)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "adf8cf3d",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "from langchain.llms import Replicate\n",
    "\n",
    "llama2_13b = \"meta/llama-2-13b-chat:f4e2de70d66816a838a89eeeb621910adffb0dd0baba3976c96980970978018d\"\n",
    "llm = Replicate(\n",
    "    model=llama2_13b,\n",
    "    model_kwargs={\"temperature\": 0.01, \"top_p\": 1, \"max_new_tokens\":500}\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8e3baa56",
   "metadata": {},
   "source": [
    "Once everything is set up, we prompt Llama 2 to summarize the first 4000 characters of the transcript for us."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "51739e11",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " Sure! Here's a summary of the text:\n",
      "\n",
      "The speaker is discussing how to get started in deep learning, particularly for those who are self-taught. They recommend starting with the \"Deep Learning Specialization\" offered by Andrew Ng on Coursera, which covers everything from basic neural networks to advanced topics like attention models and sequence models. The prerequisites for the course are basic programming knowledge and high school math (specifically, understanding matrices and algebra).\n",
      "\n",
      "The speaker notes that the course is designed to be accessible to both beginners and those with experience in machine learning, and that it\n"
     ]
    }
   ],
   "source": [
    "from langchain.prompts import ChatPromptTemplate\n",
    "from langchain.chains import LLMChain\n",
    "prompt = ChatPromptTemplate.from_template(\n",
    "    \"Give me a summary of the text below: {text}?\"\n",
    ")\n",
    "chain = LLMChain(llm=llm, prompt=prompt)\n",
    "# be careful of the input text length sent to LLM\n",
    "text = docs[0].page_content[:4000]\n",
    "summary = chain.run(text)\n",
    "# this is the summary of the first 4000 characters of the video content\n",
    "print(summary)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8b684b29",
   "metadata": {},
   "source": [
    "Next we try to summarize all the content of the transcript and we should get a `RuntimeError: Your input is too long. Max input length is 4096 tokens, but you supplied 5597 tokens.`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "88a2c17f",
   "metadata": {},
   "outputs": [
    {
     "ename": "RuntimeError",
     "evalue": "Your input is too long. Max input length is 4096 tokens, but you supplied 5597 tokens.",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mRuntimeError\u001b[0m                              Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[7], line 2\u001b[0m\n\u001b[1;32m      1\u001b[0m text \u001b[38;5;241m=\u001b[39m docs[\u001b[38;5;241m0\u001b[39m]\u001b[38;5;241m.\u001b[39mpage_content\n\u001b[0;32m----> 2\u001b[0m summary \u001b[38;5;241m=\u001b[39m \u001b[43mchain\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrun\u001b[49m\u001b[43m(\u001b[49m\u001b[43mtext\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m      3\u001b[0m \u001b[38;5;28mprint\u001b[39m(summary)\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/chains/base.py:501\u001b[0m, in \u001b[0;36mChain.run\u001b[0;34m(self, callbacks, tags, metadata, *args, **kwargs)\u001b[0m\n\u001b[1;32m    499\u001b[0m     \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(args) \u001b[38;5;241m!=\u001b[39m \u001b[38;5;241m1\u001b[39m:\n\u001b[1;32m    500\u001b[0m         \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m`run` supports only one positional argument.\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m--> 501\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43margs\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcallbacks\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcallbacks\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtags\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtags\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmetadata\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mmetadata\u001b[49m\u001b[43m)\u001b[49m[\n\u001b[1;32m    502\u001b[0m         _output_key\n\u001b[1;32m    503\u001b[0m     ]\n\u001b[1;32m    505\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m kwargs \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m args:\n\u001b[1;32m    506\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m(kwargs, callbacks\u001b[38;5;241m=\u001b[39mcallbacks, tags\u001b[38;5;241m=\u001b[39mtags, metadata\u001b[38;5;241m=\u001b[39mmetadata)[\n\u001b[1;32m    507\u001b[0m         _output_key\n\u001b[1;32m    508\u001b[0m     ]\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/chains/base.py:306\u001b[0m, in \u001b[0;36mChain.__call__\u001b[0;34m(self, inputs, return_only_outputs, callbacks, tags, metadata, run_name, include_run_info)\u001b[0m\n\u001b[1;32m    304\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mBaseException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[1;32m    305\u001b[0m     run_manager\u001b[38;5;241m.\u001b[39mon_chain_error(e)\n\u001b[0;32m--> 306\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m e\n\u001b[1;32m    307\u001b[0m run_manager\u001b[38;5;241m.\u001b[39mon_chain_end(outputs)\n\u001b[1;32m    308\u001b[0m final_outputs: Dict[\u001b[38;5;28mstr\u001b[39m, Any] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mprep_outputs(\n\u001b[1;32m    309\u001b[0m     inputs, outputs, return_only_outputs\n\u001b[1;32m    310\u001b[0m )\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/chains/base.py:300\u001b[0m, in \u001b[0;36mChain.__call__\u001b[0;34m(self, inputs, return_only_outputs, callbacks, tags, metadata, run_name, include_run_info)\u001b[0m\n\u001b[1;32m    293\u001b[0m run_manager \u001b[38;5;241m=\u001b[39m callback_manager\u001b[38;5;241m.\u001b[39mon_chain_start(\n\u001b[1;32m    294\u001b[0m     dumpd(\u001b[38;5;28mself\u001b[39m),\n\u001b[1;32m    295\u001b[0m     inputs,\n\u001b[1;32m    296\u001b[0m     name\u001b[38;5;241m=\u001b[39mrun_name,\n\u001b[1;32m    297\u001b[0m )\n\u001b[1;32m    298\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m    299\u001b[0m     outputs \u001b[38;5;241m=\u001b[39m (\n\u001b[0;32m--> 300\u001b[0m         \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_call\u001b[49m\u001b[43m(\u001b[49m\u001b[43minputs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_manager\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m    301\u001b[0m         \u001b[38;5;28;01mif\u001b[39;00m new_arg_supported\n\u001b[1;32m    302\u001b[0m         \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_call(inputs)\n\u001b[1;32m    303\u001b[0m     )\n\u001b[1;32m    304\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mBaseException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[1;32m    305\u001b[0m     run_manager\u001b[38;5;241m.\u001b[39mon_chain_error(e)\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/chains/llm.py:93\u001b[0m, in \u001b[0;36mLLMChain._call\u001b[0;34m(self, inputs, run_manager)\u001b[0m\n\u001b[1;32m     88\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_call\u001b[39m(\n\u001b[1;32m     89\u001b[0m     \u001b[38;5;28mself\u001b[39m,\n\u001b[1;32m     90\u001b[0m     inputs: Dict[\u001b[38;5;28mstr\u001b[39m, Any],\n\u001b[1;32m     91\u001b[0m     run_manager: Optional[CallbackManagerForChainRun] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[1;32m     92\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Dict[\u001b[38;5;28mstr\u001b[39m, \u001b[38;5;28mstr\u001b[39m]:\n\u001b[0;32m---> 93\u001b[0m     response \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mgenerate\u001b[49m\u001b[43m(\u001b[49m\u001b[43m[\u001b[49m\u001b[43minputs\u001b[49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_manager\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m     94\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcreate_outputs(response)[\u001b[38;5;241m0\u001b[39m]\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/chains/llm.py:103\u001b[0m, in \u001b[0;36mLLMChain.generate\u001b[0;34m(self, input_list, run_manager)\u001b[0m\n\u001b[1;32m    101\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"Generate LLM result from inputs.\"\"\"\u001b[39;00m\n\u001b[1;32m    102\u001b[0m prompts, stop \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mprep_prompts(input_list, run_manager\u001b[38;5;241m=\u001b[39mrun_manager)\n\u001b[0;32m--> 103\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mllm\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mgenerate_prompt\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m    104\u001b[0m \u001b[43m    \u001b[49m\u001b[43mprompts\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m    105\u001b[0m \u001b[43m    \u001b[49m\u001b[43mstop\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m    106\u001b[0m \u001b[43m    \u001b[49m\u001b[43mcallbacks\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_manager\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_child\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mif\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01melse\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[1;32m    107\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mllm_kwargs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m    108\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/llms/base.py:498\u001b[0m, in \u001b[0;36mBaseLLM.generate_prompt\u001b[0;34m(self, prompts, stop, callbacks, **kwargs)\u001b[0m\n\u001b[1;32m    490\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mgenerate_prompt\u001b[39m(\n\u001b[1;32m    491\u001b[0m     \u001b[38;5;28mself\u001b[39m,\n\u001b[1;32m    492\u001b[0m     prompts: List[PromptValue],\n\u001b[0;32m   (...)\u001b[0m\n\u001b[1;32m    495\u001b[0m     \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs: Any,\n\u001b[1;32m    496\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m LLMResult:\n\u001b[1;32m    497\u001b[0m     prompt_strings \u001b[38;5;241m=\u001b[39m [p\u001b[38;5;241m.\u001b[39mto_string() \u001b[38;5;28;01mfor\u001b[39;00m p \u001b[38;5;129;01min\u001b[39;00m prompts]\n\u001b[0;32m--> 498\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mgenerate\u001b[49m\u001b[43m(\u001b[49m\u001b[43mprompt_strings\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstop\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstop\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcallbacks\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcallbacks\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/llms/base.py:647\u001b[0m, in \u001b[0;36mBaseLLM.generate\u001b[0;34m(self, prompts, stop, callbacks, tags, metadata, run_name, **kwargs)\u001b[0m\n\u001b[1;32m    632\u001b[0m         \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\n\u001b[1;32m    633\u001b[0m             \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mAsked to cache, but no cache found at `langchain.cache`.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m    634\u001b[0m         )\n\u001b[1;32m    635\u001b[0m     run_managers \u001b[38;5;241m=\u001b[39m [\n\u001b[1;32m    636\u001b[0m         callback_manager\u001b[38;5;241m.\u001b[39mon_llm_start(\n\u001b[1;32m    637\u001b[0m             dumpd(\u001b[38;5;28mself\u001b[39m),\n\u001b[0;32m   (...)\u001b[0m\n\u001b[1;32m    645\u001b[0m         )\n\u001b[1;32m    646\u001b[0m     ]\n\u001b[0;32m--> 647\u001b[0m     output \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_generate_helper\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m    648\u001b[0m \u001b[43m        \u001b[49m\u001b[43mprompts\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstop\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrun_managers\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mbool\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mnew_arg_supported\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\n\u001b[1;32m    649\u001b[0m \u001b[43m    \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m    650\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m output\n\u001b[1;32m    651\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(missing_prompts) \u001b[38;5;241m>\u001b[39m \u001b[38;5;241m0\u001b[39m:\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/llms/base.py:535\u001b[0m, in \u001b[0;36mBaseLLM._generate_helper\u001b[0;34m(self, prompts, stop, run_managers, new_arg_supported, **kwargs)\u001b[0m\n\u001b[1;32m    533\u001b[0m     \u001b[38;5;28;01mfor\u001b[39;00m run_manager \u001b[38;5;129;01min\u001b[39;00m run_managers:\n\u001b[1;32m    534\u001b[0m         run_manager\u001b[38;5;241m.\u001b[39mon_llm_error(e)\n\u001b[0;32m--> 535\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m e\n\u001b[1;32m    536\u001b[0m flattened_outputs \u001b[38;5;241m=\u001b[39m output\u001b[38;5;241m.\u001b[39mflatten()\n\u001b[1;32m    537\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m manager, flattened_output \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mzip\u001b[39m(run_managers, flattened_outputs):\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/llms/base.py:522\u001b[0m, in \u001b[0;36mBaseLLM._generate_helper\u001b[0;34m(self, prompts, stop, run_managers, new_arg_supported, **kwargs)\u001b[0m\n\u001b[1;32m    512\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_generate_helper\u001b[39m(\n\u001b[1;32m    513\u001b[0m     \u001b[38;5;28mself\u001b[39m,\n\u001b[1;32m    514\u001b[0m     prompts: List[\u001b[38;5;28mstr\u001b[39m],\n\u001b[0;32m   (...)\u001b[0m\n\u001b[1;32m    518\u001b[0m     \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs: Any,\n\u001b[1;32m    519\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m LLMResult:\n\u001b[1;32m    520\u001b[0m     \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m    521\u001b[0m         output \u001b[38;5;241m=\u001b[39m (\n\u001b[0;32m--> 522\u001b[0m             \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_generate\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m    523\u001b[0m \u001b[43m                \u001b[49m\u001b[43mprompts\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m    524\u001b[0m \u001b[43m                \u001b[49m\u001b[43mstop\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstop\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m    525\u001b[0m \u001b[43m                \u001b[49m\u001b[38;5;66;43;03m# TODO: support multiple run managers\u001b[39;49;00m\n\u001b[1;32m    526\u001b[0m \u001b[43m                \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_managers\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mif\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mrun_managers\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01melse\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[1;32m    527\u001b[0m \u001b[43m                \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m    528\u001b[0m \u001b[43m            \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m    529\u001b[0m             \u001b[38;5;28;01mif\u001b[39;00m new_arg_supported\n\u001b[1;32m    530\u001b[0m             \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_generate(prompts, stop\u001b[38;5;241m=\u001b[39mstop)\n\u001b[1;32m    531\u001b[0m         )\n\u001b[1;32m    532\u001b[0m     \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mBaseException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[1;32m    533\u001b[0m         \u001b[38;5;28;01mfor\u001b[39;00m run_manager \u001b[38;5;129;01min\u001b[39;00m run_managers:\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/llms/base.py:1044\u001b[0m, in \u001b[0;36mLLM._generate\u001b[0;34m(self, prompts, stop, run_manager, **kwargs)\u001b[0m\n\u001b[1;32m   1041\u001b[0m new_arg_supported \u001b[38;5;241m=\u001b[39m inspect\u001b[38;5;241m.\u001b[39msignature(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_call)\u001b[38;5;241m.\u001b[39mparameters\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mrun_manager\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m   1042\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m prompt \u001b[38;5;129;01min\u001b[39;00m prompts:\n\u001b[1;32m   1043\u001b[0m     text \u001b[38;5;241m=\u001b[39m (\n\u001b[0;32m-> 1044\u001b[0m         \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_call\u001b[49m\u001b[43m(\u001b[49m\u001b[43mprompt\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstop\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstop\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_manager\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m   1045\u001b[0m         \u001b[38;5;28;01mif\u001b[39;00m new_arg_supported\n\u001b[1;32m   1046\u001b[0m         \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_call(prompt, stop\u001b[38;5;241m=\u001b[39mstop, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[1;32m   1047\u001b[0m     )\n\u001b[1;32m   1048\u001b[0m     generations\u001b[38;5;241m.\u001b[39mappend([Generation(text\u001b[38;5;241m=\u001b[39mtext)])\n\u001b[1;32m   1049\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m LLMResult(generations\u001b[38;5;241m=\u001b[39mgenerations)\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/llms/replicate.py:138\u001b[0m, in \u001b[0;36mReplicate._call\u001b[0;34m(self, prompt, stop, run_manager, **kwargs)\u001b[0m\n\u001b[1;32m    136\u001b[0m prediction\u001b[38;5;241m.\u001b[39mwait()\n\u001b[1;32m    137\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m prediction\u001b[38;5;241m.\u001b[39mstatus \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mfailed\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n\u001b[0;32m--> 138\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mRuntimeError\u001b[39;00m(prediction\u001b[38;5;241m.\u001b[39merror)\n\u001b[1;32m    139\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(prediction\u001b[38;5;241m.\u001b[39moutput, \u001b[38;5;28mstr\u001b[39m):\n\u001b[1;32m    140\u001b[0m     completion \u001b[38;5;241m=\u001b[39m prediction\u001b[38;5;241m.\u001b[39moutput\n",
      "\u001b[0;31mRuntimeError\u001b[0m: Your input is too long. Max input length is 4096 tokens, but you supplied 5597 tokens."
     ]
    }
   ],
   "source": [
    "# try to get a summary of the whole content\n",
    "text = docs[0].page_content\n",
    "summary = chain.run(text)\n",
    "print(summary)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1ad1881a",
   "metadata": {},
   "source": [
    "\n",
    "Let's try some workarounds to see if we can summarize the entire transcript without running into the `RuntimeError`.\n",
    "\n",
    "We will use the LangChain's `load_summarize_chain` and play around with the `chain_type`.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "9bfee2d3-3afe-41d9-8968-6450cc23f493",
   "metadata": {},
   "outputs": [
    {
     "ename": "RuntimeError",
     "evalue": "Your input is too long. Max input length is 4096 tokens, but you supplied 5608 tokens.",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mRuntimeError\u001b[0m                              Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[8], line 5\u001b[0m\n\u001b[1;32m      3\u001b[0m chain \u001b[38;5;241m=\u001b[39m load_summarize_chain(llm, chain_type\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mstuff\u001b[39m\u001b[38;5;124m\"\u001b[39m) \u001b[38;5;66;03m# map_reduce # refine # stuff\u001b[39;00m\n\u001b[1;32m      4\u001b[0m \u001b[38;5;66;03m# using stuff returns \"RuntimeError: Your input is too long. Max input length is 4096 tokens, but you supplied 89151 tokens.\"\u001b[39;00m\n\u001b[0;32m----> 5\u001b[0m \u001b[43mchain\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrun\u001b[49m\u001b[43m(\u001b[49m\u001b[43mdocs\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/chains/base.py:501\u001b[0m, in \u001b[0;36mChain.run\u001b[0;34m(self, callbacks, tags, metadata, *args, **kwargs)\u001b[0m\n\u001b[1;32m    499\u001b[0m     \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(args) \u001b[38;5;241m!=\u001b[39m \u001b[38;5;241m1\u001b[39m:\n\u001b[1;32m    500\u001b[0m         \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m`run` supports only one positional argument.\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m--> 501\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43margs\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcallbacks\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcallbacks\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtags\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtags\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmetadata\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mmetadata\u001b[49m\u001b[43m)\u001b[49m[\n\u001b[1;32m    502\u001b[0m         _output_key\n\u001b[1;32m    503\u001b[0m     ]\n\u001b[1;32m    505\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m kwargs \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m args:\n\u001b[1;32m    506\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m(kwargs, callbacks\u001b[38;5;241m=\u001b[39mcallbacks, tags\u001b[38;5;241m=\u001b[39mtags, metadata\u001b[38;5;241m=\u001b[39mmetadata)[\n\u001b[1;32m    507\u001b[0m         _output_key\n\u001b[1;32m    508\u001b[0m     ]\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/chains/base.py:306\u001b[0m, in \u001b[0;36mChain.__call__\u001b[0;34m(self, inputs, return_only_outputs, callbacks, tags, metadata, run_name, include_run_info)\u001b[0m\n\u001b[1;32m    304\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mBaseException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[1;32m    305\u001b[0m     run_manager\u001b[38;5;241m.\u001b[39mon_chain_error(e)\n\u001b[0;32m--> 306\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m e\n\u001b[1;32m    307\u001b[0m run_manager\u001b[38;5;241m.\u001b[39mon_chain_end(outputs)\n\u001b[1;32m    308\u001b[0m final_outputs: Dict[\u001b[38;5;28mstr\u001b[39m, Any] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mprep_outputs(\n\u001b[1;32m    309\u001b[0m     inputs, outputs, return_only_outputs\n\u001b[1;32m    310\u001b[0m )\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/chains/base.py:300\u001b[0m, in \u001b[0;36mChain.__call__\u001b[0;34m(self, inputs, return_only_outputs, callbacks, tags, metadata, run_name, include_run_info)\u001b[0m\n\u001b[1;32m    293\u001b[0m run_manager \u001b[38;5;241m=\u001b[39m callback_manager\u001b[38;5;241m.\u001b[39mon_chain_start(\n\u001b[1;32m    294\u001b[0m     dumpd(\u001b[38;5;28mself\u001b[39m),\n\u001b[1;32m    295\u001b[0m     inputs,\n\u001b[1;32m    296\u001b[0m     name\u001b[38;5;241m=\u001b[39mrun_name,\n\u001b[1;32m    297\u001b[0m )\n\u001b[1;32m    298\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m    299\u001b[0m     outputs \u001b[38;5;241m=\u001b[39m (\n\u001b[0;32m--> 300\u001b[0m         \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_call\u001b[49m\u001b[43m(\u001b[49m\u001b[43minputs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_manager\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m    301\u001b[0m         \u001b[38;5;28;01mif\u001b[39;00m new_arg_supported\n\u001b[1;32m    302\u001b[0m         \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_call(inputs)\n\u001b[1;32m    303\u001b[0m     )\n\u001b[1;32m    304\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mBaseException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[1;32m    305\u001b[0m     run_manager\u001b[38;5;241m.\u001b[39mon_chain_error(e)\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/chains/combine_documents/base.py:119\u001b[0m, in \u001b[0;36mBaseCombineDocumentsChain._call\u001b[0;34m(self, inputs, run_manager)\u001b[0m\n\u001b[1;32m    117\u001b[0m \u001b[38;5;66;03m# Other keys are assumed to be needed for LLM prediction\u001b[39;00m\n\u001b[1;32m    118\u001b[0m other_keys \u001b[38;5;241m=\u001b[39m {k: v \u001b[38;5;28;01mfor\u001b[39;00m k, v \u001b[38;5;129;01min\u001b[39;00m inputs\u001b[38;5;241m.\u001b[39mitems() \u001b[38;5;28;01mif\u001b[39;00m k \u001b[38;5;241m!=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39minput_key}\n\u001b[0;32m--> 119\u001b[0m output, extra_return_dict \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcombine_docs\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m    120\u001b[0m \u001b[43m    \u001b[49m\u001b[43mdocs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcallbacks\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m_run_manager\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_child\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mother_keys\u001b[49m\n\u001b[1;32m    121\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m    122\u001b[0m extra_return_dict[\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39moutput_key] \u001b[38;5;241m=\u001b[39m output\n\u001b[1;32m    123\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m extra_return_dict\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/chains/combine_documents/stuff.py:171\u001b[0m, in \u001b[0;36mStuffDocumentsChain.combine_docs\u001b[0;34m(self, docs, callbacks, **kwargs)\u001b[0m\n\u001b[1;32m    169\u001b[0m inputs \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_get_inputs(docs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[1;32m    170\u001b[0m \u001b[38;5;66;03m# Call predict on the LLM.\u001b[39;00m\n\u001b[0;32m--> 171\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mllm_chain\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mpredict\u001b[49m\u001b[43m(\u001b[49m\u001b[43mcallbacks\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcallbacks\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43minputs\u001b[49m\u001b[43m)\u001b[49m, {}\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/chains/llm.py:257\u001b[0m, in \u001b[0;36mLLMChain.predict\u001b[0;34m(self, callbacks, **kwargs)\u001b[0m\n\u001b[1;32m    242\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mpredict\u001b[39m(\u001b[38;5;28mself\u001b[39m, callbacks: Callbacks \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs: Any) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28mstr\u001b[39m:\n\u001b[1;32m    243\u001b[0m \u001b[38;5;250m    \u001b[39m\u001b[38;5;124;03m\"\"\"Format prompt with kwargs and pass to LLM.\u001b[39;00m\n\u001b[1;32m    244\u001b[0m \n\u001b[1;32m    245\u001b[0m \u001b[38;5;124;03m    Args:\u001b[39;00m\n\u001b[0;32m   (...)\u001b[0m\n\u001b[1;32m    255\u001b[0m \u001b[38;5;124;03m            completion = llm.predict(adjective=\"funny\")\u001b[39;00m\n\u001b[1;32m    256\u001b[0m \u001b[38;5;124;03m    \"\"\"\u001b[39;00m\n\u001b[0;32m--> 257\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcallbacks\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcallbacks\u001b[49m\u001b[43m)\u001b[49m[\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39moutput_key]\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/chains/base.py:306\u001b[0m, in \u001b[0;36mChain.__call__\u001b[0;34m(self, inputs, return_only_outputs, callbacks, tags, metadata, run_name, include_run_info)\u001b[0m\n\u001b[1;32m    304\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mBaseException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[1;32m    305\u001b[0m     run_manager\u001b[38;5;241m.\u001b[39mon_chain_error(e)\n\u001b[0;32m--> 306\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m e\n\u001b[1;32m    307\u001b[0m run_manager\u001b[38;5;241m.\u001b[39mon_chain_end(outputs)\n\u001b[1;32m    308\u001b[0m final_outputs: Dict[\u001b[38;5;28mstr\u001b[39m, Any] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mprep_outputs(\n\u001b[1;32m    309\u001b[0m     inputs, outputs, return_only_outputs\n\u001b[1;32m    310\u001b[0m )\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/chains/base.py:300\u001b[0m, in \u001b[0;36mChain.__call__\u001b[0;34m(self, inputs, return_only_outputs, callbacks, tags, metadata, run_name, include_run_info)\u001b[0m\n\u001b[1;32m    293\u001b[0m run_manager \u001b[38;5;241m=\u001b[39m callback_manager\u001b[38;5;241m.\u001b[39mon_chain_start(\n\u001b[1;32m    294\u001b[0m     dumpd(\u001b[38;5;28mself\u001b[39m),\n\u001b[1;32m    295\u001b[0m     inputs,\n\u001b[1;32m    296\u001b[0m     name\u001b[38;5;241m=\u001b[39mrun_name,\n\u001b[1;32m    297\u001b[0m )\n\u001b[1;32m    298\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m    299\u001b[0m     outputs \u001b[38;5;241m=\u001b[39m (\n\u001b[0;32m--> 300\u001b[0m         \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_call\u001b[49m\u001b[43m(\u001b[49m\u001b[43minputs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_manager\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m    301\u001b[0m         \u001b[38;5;28;01mif\u001b[39;00m new_arg_supported\n\u001b[1;32m    302\u001b[0m         \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_call(inputs)\n\u001b[1;32m    303\u001b[0m     )\n\u001b[1;32m    304\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mBaseException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[1;32m    305\u001b[0m     run_manager\u001b[38;5;241m.\u001b[39mon_chain_error(e)\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/chains/llm.py:93\u001b[0m, in \u001b[0;36mLLMChain._call\u001b[0;34m(self, inputs, run_manager)\u001b[0m\n\u001b[1;32m     88\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_call\u001b[39m(\n\u001b[1;32m     89\u001b[0m     \u001b[38;5;28mself\u001b[39m,\n\u001b[1;32m     90\u001b[0m     inputs: Dict[\u001b[38;5;28mstr\u001b[39m, Any],\n\u001b[1;32m     91\u001b[0m     run_manager: Optional[CallbackManagerForChainRun] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[1;32m     92\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Dict[\u001b[38;5;28mstr\u001b[39m, \u001b[38;5;28mstr\u001b[39m]:\n\u001b[0;32m---> 93\u001b[0m     response \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mgenerate\u001b[49m\u001b[43m(\u001b[49m\u001b[43m[\u001b[49m\u001b[43minputs\u001b[49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_manager\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m     94\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcreate_outputs(response)[\u001b[38;5;241m0\u001b[39m]\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/chains/llm.py:103\u001b[0m, in \u001b[0;36mLLMChain.generate\u001b[0;34m(self, input_list, run_manager)\u001b[0m\n\u001b[1;32m    101\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"Generate LLM result from inputs.\"\"\"\u001b[39;00m\n\u001b[1;32m    102\u001b[0m prompts, stop \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mprep_prompts(input_list, run_manager\u001b[38;5;241m=\u001b[39mrun_manager)\n\u001b[0;32m--> 103\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mllm\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mgenerate_prompt\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m    104\u001b[0m \u001b[43m    \u001b[49m\u001b[43mprompts\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m    105\u001b[0m \u001b[43m    \u001b[49m\u001b[43mstop\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m    106\u001b[0m \u001b[43m    \u001b[49m\u001b[43mcallbacks\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_manager\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_child\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mif\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01melse\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[1;32m    107\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mllm_kwargs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m    108\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/llms/base.py:498\u001b[0m, in \u001b[0;36mBaseLLM.generate_prompt\u001b[0;34m(self, prompts, stop, callbacks, **kwargs)\u001b[0m\n\u001b[1;32m    490\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mgenerate_prompt\u001b[39m(\n\u001b[1;32m    491\u001b[0m     \u001b[38;5;28mself\u001b[39m,\n\u001b[1;32m    492\u001b[0m     prompts: List[PromptValue],\n\u001b[0;32m   (...)\u001b[0m\n\u001b[1;32m    495\u001b[0m     \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs: Any,\n\u001b[1;32m    496\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m LLMResult:\n\u001b[1;32m    497\u001b[0m     prompt_strings \u001b[38;5;241m=\u001b[39m [p\u001b[38;5;241m.\u001b[39mto_string() \u001b[38;5;28;01mfor\u001b[39;00m p \u001b[38;5;129;01min\u001b[39;00m prompts]\n\u001b[0;32m--> 498\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mgenerate\u001b[49m\u001b[43m(\u001b[49m\u001b[43mprompt_strings\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstop\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstop\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcallbacks\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcallbacks\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/llms/base.py:647\u001b[0m, in \u001b[0;36mBaseLLM.generate\u001b[0;34m(self, prompts, stop, callbacks, tags, metadata, run_name, **kwargs)\u001b[0m\n\u001b[1;32m    632\u001b[0m         \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\n\u001b[1;32m    633\u001b[0m             \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mAsked to cache, but no cache found at `langchain.cache`.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m    634\u001b[0m         )\n\u001b[1;32m    635\u001b[0m     run_managers \u001b[38;5;241m=\u001b[39m [\n\u001b[1;32m    636\u001b[0m         callback_manager\u001b[38;5;241m.\u001b[39mon_llm_start(\n\u001b[1;32m    637\u001b[0m             dumpd(\u001b[38;5;28mself\u001b[39m),\n\u001b[0;32m   (...)\u001b[0m\n\u001b[1;32m    645\u001b[0m         )\n\u001b[1;32m    646\u001b[0m     ]\n\u001b[0;32m--> 647\u001b[0m     output \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_generate_helper\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m    648\u001b[0m \u001b[43m        \u001b[49m\u001b[43mprompts\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstop\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrun_managers\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mbool\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mnew_arg_supported\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\n\u001b[1;32m    649\u001b[0m \u001b[43m    \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m    650\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m output\n\u001b[1;32m    651\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(missing_prompts) \u001b[38;5;241m>\u001b[39m \u001b[38;5;241m0\u001b[39m:\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/llms/base.py:535\u001b[0m, in \u001b[0;36mBaseLLM._generate_helper\u001b[0;34m(self, prompts, stop, run_managers, new_arg_supported, **kwargs)\u001b[0m\n\u001b[1;32m    533\u001b[0m     \u001b[38;5;28;01mfor\u001b[39;00m run_manager \u001b[38;5;129;01min\u001b[39;00m run_managers:\n\u001b[1;32m    534\u001b[0m         run_manager\u001b[38;5;241m.\u001b[39mon_llm_error(e)\n\u001b[0;32m--> 535\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m e\n\u001b[1;32m    536\u001b[0m flattened_outputs \u001b[38;5;241m=\u001b[39m output\u001b[38;5;241m.\u001b[39mflatten()\n\u001b[1;32m    537\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m manager, flattened_output \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mzip\u001b[39m(run_managers, flattened_outputs):\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/llms/base.py:522\u001b[0m, in \u001b[0;36mBaseLLM._generate_helper\u001b[0;34m(self, prompts, stop, run_managers, new_arg_supported, **kwargs)\u001b[0m\n\u001b[1;32m    512\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_generate_helper\u001b[39m(\n\u001b[1;32m    513\u001b[0m     \u001b[38;5;28mself\u001b[39m,\n\u001b[1;32m    514\u001b[0m     prompts: List[\u001b[38;5;28mstr\u001b[39m],\n\u001b[0;32m   (...)\u001b[0m\n\u001b[1;32m    518\u001b[0m     \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs: Any,\n\u001b[1;32m    519\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m LLMResult:\n\u001b[1;32m    520\u001b[0m     \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m    521\u001b[0m         output \u001b[38;5;241m=\u001b[39m (\n\u001b[0;32m--> 522\u001b[0m             \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_generate\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m    523\u001b[0m \u001b[43m                \u001b[49m\u001b[43mprompts\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m    524\u001b[0m \u001b[43m                \u001b[49m\u001b[43mstop\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstop\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m    525\u001b[0m \u001b[43m                \u001b[49m\u001b[38;5;66;43;03m# TODO: support multiple run managers\u001b[39;49;00m\n\u001b[1;32m    526\u001b[0m \u001b[43m                \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_managers\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mif\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mrun_managers\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01melse\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[1;32m    527\u001b[0m \u001b[43m                \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m    528\u001b[0m \u001b[43m            \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m    529\u001b[0m             \u001b[38;5;28;01mif\u001b[39;00m new_arg_supported\n\u001b[1;32m    530\u001b[0m             \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_generate(prompts, stop\u001b[38;5;241m=\u001b[39mstop)\n\u001b[1;32m    531\u001b[0m         )\n\u001b[1;32m    532\u001b[0m     \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mBaseException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[1;32m    533\u001b[0m         \u001b[38;5;28;01mfor\u001b[39;00m run_manager \u001b[38;5;129;01min\u001b[39;00m run_managers:\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/llms/base.py:1044\u001b[0m, in \u001b[0;36mLLM._generate\u001b[0;34m(self, prompts, stop, run_manager, **kwargs)\u001b[0m\n\u001b[1;32m   1041\u001b[0m new_arg_supported \u001b[38;5;241m=\u001b[39m inspect\u001b[38;5;241m.\u001b[39msignature(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_call)\u001b[38;5;241m.\u001b[39mparameters\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mrun_manager\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m   1042\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m prompt \u001b[38;5;129;01min\u001b[39;00m prompts:\n\u001b[1;32m   1043\u001b[0m     text \u001b[38;5;241m=\u001b[39m (\n\u001b[0;32m-> 1044\u001b[0m         \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_call\u001b[49m\u001b[43m(\u001b[49m\u001b[43mprompt\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstop\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstop\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_manager\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m   1045\u001b[0m         \u001b[38;5;28;01mif\u001b[39;00m new_arg_supported\n\u001b[1;32m   1046\u001b[0m         \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_call(prompt, stop\u001b[38;5;241m=\u001b[39mstop, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[1;32m   1047\u001b[0m     )\n\u001b[1;32m   1048\u001b[0m     generations\u001b[38;5;241m.\u001b[39mappend([Generation(text\u001b[38;5;241m=\u001b[39mtext)])\n\u001b[1;32m   1049\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m LLMResult(generations\u001b[38;5;241m=\u001b[39mgenerations)\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/llms/replicate.py:138\u001b[0m, in \u001b[0;36mReplicate._call\u001b[0;34m(self, prompt, stop, run_manager, **kwargs)\u001b[0m\n\u001b[1;32m    136\u001b[0m prediction\u001b[38;5;241m.\u001b[39mwait()\n\u001b[1;32m    137\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m prediction\u001b[38;5;241m.\u001b[39mstatus \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mfailed\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n\u001b[0;32m--> 138\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mRuntimeError\u001b[39;00m(prediction\u001b[38;5;241m.\u001b[39merror)\n\u001b[1;32m    139\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(prediction\u001b[38;5;241m.\u001b[39moutput, \u001b[38;5;28mstr\u001b[39m):\n\u001b[1;32m    140\u001b[0m     completion \u001b[38;5;241m=\u001b[39m prediction\u001b[38;5;241m.\u001b[39moutput\n",
      "\u001b[0;31mRuntimeError\u001b[0m: Your input is too long. Max input length is 4096 tokens, but you supplied 5608 tokens."
     ]
    }
   ],
   "source": [
    "from langchain.chains.summarize import load_summarize_chain\n",
    "# see https://python.langchain.com/docs/use_cases/summarization for more info\n",
    "chain = load_summarize_chain(llm, chain_type=\"stuff\") # other supported methods are map_reduce and refine\n",
    "chain.run(docs)\n",
    "# same RuntimeError: Your input is too long. but stuff works for shorter text with input length <= 4096 tokens"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "682799a8-3846-41b1-a908-02ab5ac3ecee",
   "metadata": {},
   "outputs": [
    {
     "ename": "RuntimeError",
     "evalue": "Your input is too long. Max input length is 4096 tokens, but you supplied 5608 tokens.",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mRuntimeError\u001b[0m                              Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[9], line 3\u001b[0m\n\u001b[1;32m      1\u001b[0m chain \u001b[38;5;241m=\u001b[39m load_summarize_chain(llm, chain_type\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mrefine\u001b[39m\u001b[38;5;124m\"\u001b[39m) \u001b[38;5;66;03m# map_reduce # refine # stuff\u001b[39;00m\n\u001b[1;32m      2\u001b[0m \u001b[38;5;66;03m# using stuff returns \"RuntimeError: Your input is too long. Max input length is 4096 tokens, but you supplied 89151 tokens.\"\u001b[39;00m\n\u001b[0;32m----> 3\u001b[0m \u001b[43mchain\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrun\u001b[49m\u001b[43m(\u001b[49m\u001b[43mdocs\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/chains/base.py:501\u001b[0m, in \u001b[0;36mChain.run\u001b[0;34m(self, callbacks, tags, metadata, *args, **kwargs)\u001b[0m\n\u001b[1;32m    499\u001b[0m     \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(args) \u001b[38;5;241m!=\u001b[39m \u001b[38;5;241m1\u001b[39m:\n\u001b[1;32m    500\u001b[0m         \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m`run` supports only one positional argument.\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m--> 501\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43margs\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcallbacks\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcallbacks\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtags\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtags\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmetadata\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mmetadata\u001b[49m\u001b[43m)\u001b[49m[\n\u001b[1;32m    502\u001b[0m         _output_key\n\u001b[1;32m    503\u001b[0m     ]\n\u001b[1;32m    505\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m kwargs \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m args:\n\u001b[1;32m    506\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m(kwargs, callbacks\u001b[38;5;241m=\u001b[39mcallbacks, tags\u001b[38;5;241m=\u001b[39mtags, metadata\u001b[38;5;241m=\u001b[39mmetadata)[\n\u001b[1;32m    507\u001b[0m         _output_key\n\u001b[1;32m    508\u001b[0m     ]\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/chains/base.py:306\u001b[0m, in \u001b[0;36mChain.__call__\u001b[0;34m(self, inputs, return_only_outputs, callbacks, tags, metadata, run_name, include_run_info)\u001b[0m\n\u001b[1;32m    304\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mBaseException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[1;32m    305\u001b[0m     run_manager\u001b[38;5;241m.\u001b[39mon_chain_error(e)\n\u001b[0;32m--> 306\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m e\n\u001b[1;32m    307\u001b[0m run_manager\u001b[38;5;241m.\u001b[39mon_chain_end(outputs)\n\u001b[1;32m    308\u001b[0m final_outputs: Dict[\u001b[38;5;28mstr\u001b[39m, Any] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mprep_outputs(\n\u001b[1;32m    309\u001b[0m     inputs, outputs, return_only_outputs\n\u001b[1;32m    310\u001b[0m )\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/chains/base.py:300\u001b[0m, in \u001b[0;36mChain.__call__\u001b[0;34m(self, inputs, return_only_outputs, callbacks, tags, metadata, run_name, include_run_info)\u001b[0m\n\u001b[1;32m    293\u001b[0m run_manager \u001b[38;5;241m=\u001b[39m callback_manager\u001b[38;5;241m.\u001b[39mon_chain_start(\n\u001b[1;32m    294\u001b[0m     dumpd(\u001b[38;5;28mself\u001b[39m),\n\u001b[1;32m    295\u001b[0m     inputs,\n\u001b[1;32m    296\u001b[0m     name\u001b[38;5;241m=\u001b[39mrun_name,\n\u001b[1;32m    297\u001b[0m )\n\u001b[1;32m    298\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m    299\u001b[0m     outputs \u001b[38;5;241m=\u001b[39m (\n\u001b[0;32m--> 300\u001b[0m         \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_call\u001b[49m\u001b[43m(\u001b[49m\u001b[43minputs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_manager\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m    301\u001b[0m         \u001b[38;5;28;01mif\u001b[39;00m new_arg_supported\n\u001b[1;32m    302\u001b[0m         \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_call(inputs)\n\u001b[1;32m    303\u001b[0m     )\n\u001b[1;32m    304\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mBaseException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[1;32m    305\u001b[0m     run_manager\u001b[38;5;241m.\u001b[39mon_chain_error(e)\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/chains/combine_documents/base.py:119\u001b[0m, in \u001b[0;36mBaseCombineDocumentsChain._call\u001b[0;34m(self, inputs, run_manager)\u001b[0m\n\u001b[1;32m    117\u001b[0m \u001b[38;5;66;03m# Other keys are assumed to be needed for LLM prediction\u001b[39;00m\n\u001b[1;32m    118\u001b[0m other_keys \u001b[38;5;241m=\u001b[39m {k: v \u001b[38;5;28;01mfor\u001b[39;00m k, v \u001b[38;5;129;01min\u001b[39;00m inputs\u001b[38;5;241m.\u001b[39mitems() \u001b[38;5;28;01mif\u001b[39;00m k \u001b[38;5;241m!=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39minput_key}\n\u001b[0;32m--> 119\u001b[0m output, extra_return_dict \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcombine_docs\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m    120\u001b[0m \u001b[43m    \u001b[49m\u001b[43mdocs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcallbacks\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m_run_manager\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_child\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mother_keys\u001b[49m\n\u001b[1;32m    121\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m    122\u001b[0m extra_return_dict[\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39moutput_key] \u001b[38;5;241m=\u001b[39m output\n\u001b[1;32m    123\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m extra_return_dict\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/chains/combine_documents/refine.py:151\u001b[0m, in \u001b[0;36mRefineDocumentsChain.combine_docs\u001b[0;34m(self, docs, callbacks, **kwargs)\u001b[0m\n\u001b[1;32m    138\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"Combine by mapping first chain over all, then stuffing into final chain.\u001b[39;00m\n\u001b[1;32m    139\u001b[0m \n\u001b[1;32m    140\u001b[0m \u001b[38;5;124;03mArgs:\u001b[39;00m\n\u001b[0;32m   (...)\u001b[0m\n\u001b[1;32m    148\u001b[0m \u001b[38;5;124;03m    element returned is a dictionary of other keys to return.\u001b[39;00m\n\u001b[1;32m    149\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m    150\u001b[0m inputs \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_construct_initial_inputs(docs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[0;32m--> 151\u001b[0m res \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43minitial_llm_chain\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mpredict\u001b[49m\u001b[43m(\u001b[49m\u001b[43mcallbacks\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcallbacks\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43minputs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m    152\u001b[0m refine_steps \u001b[38;5;241m=\u001b[39m [res]\n\u001b[1;32m    153\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m doc \u001b[38;5;129;01min\u001b[39;00m docs[\u001b[38;5;241m1\u001b[39m:]:\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/chains/llm.py:257\u001b[0m, in \u001b[0;36mLLMChain.predict\u001b[0;34m(self, callbacks, **kwargs)\u001b[0m\n\u001b[1;32m    242\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mpredict\u001b[39m(\u001b[38;5;28mself\u001b[39m, callbacks: Callbacks \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs: Any) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28mstr\u001b[39m:\n\u001b[1;32m    243\u001b[0m \u001b[38;5;250m    \u001b[39m\u001b[38;5;124;03m\"\"\"Format prompt with kwargs and pass to LLM.\u001b[39;00m\n\u001b[1;32m    244\u001b[0m \n\u001b[1;32m    245\u001b[0m \u001b[38;5;124;03m    Args:\u001b[39;00m\n\u001b[0;32m   (...)\u001b[0m\n\u001b[1;32m    255\u001b[0m \u001b[38;5;124;03m            completion = llm.predict(adjective=\"funny\")\u001b[39;00m\n\u001b[1;32m    256\u001b[0m \u001b[38;5;124;03m    \"\"\"\u001b[39;00m\n\u001b[0;32m--> 257\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcallbacks\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcallbacks\u001b[49m\u001b[43m)\u001b[49m[\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39moutput_key]\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/chains/base.py:306\u001b[0m, in \u001b[0;36mChain.__call__\u001b[0;34m(self, inputs, return_only_outputs, callbacks, tags, metadata, run_name, include_run_info)\u001b[0m\n\u001b[1;32m    304\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mBaseException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[1;32m    305\u001b[0m     run_manager\u001b[38;5;241m.\u001b[39mon_chain_error(e)\n\u001b[0;32m--> 306\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m e\n\u001b[1;32m    307\u001b[0m run_manager\u001b[38;5;241m.\u001b[39mon_chain_end(outputs)\n\u001b[1;32m    308\u001b[0m final_outputs: Dict[\u001b[38;5;28mstr\u001b[39m, Any] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mprep_outputs(\n\u001b[1;32m    309\u001b[0m     inputs, outputs, return_only_outputs\n\u001b[1;32m    310\u001b[0m )\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/chains/base.py:300\u001b[0m, in \u001b[0;36mChain.__call__\u001b[0;34m(self, inputs, return_only_outputs, callbacks, tags, metadata, run_name, include_run_info)\u001b[0m\n\u001b[1;32m    293\u001b[0m run_manager \u001b[38;5;241m=\u001b[39m callback_manager\u001b[38;5;241m.\u001b[39mon_chain_start(\n\u001b[1;32m    294\u001b[0m     dumpd(\u001b[38;5;28mself\u001b[39m),\n\u001b[1;32m    295\u001b[0m     inputs,\n\u001b[1;32m    296\u001b[0m     name\u001b[38;5;241m=\u001b[39mrun_name,\n\u001b[1;32m    297\u001b[0m )\n\u001b[1;32m    298\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m    299\u001b[0m     outputs \u001b[38;5;241m=\u001b[39m (\n\u001b[0;32m--> 300\u001b[0m         \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_call\u001b[49m\u001b[43m(\u001b[49m\u001b[43minputs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_manager\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m    301\u001b[0m         \u001b[38;5;28;01mif\u001b[39;00m new_arg_supported\n\u001b[1;32m    302\u001b[0m         \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_call(inputs)\n\u001b[1;32m    303\u001b[0m     )\n\u001b[1;32m    304\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mBaseException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[1;32m    305\u001b[0m     run_manager\u001b[38;5;241m.\u001b[39mon_chain_error(e)\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/chains/llm.py:93\u001b[0m, in \u001b[0;36mLLMChain._call\u001b[0;34m(self, inputs, run_manager)\u001b[0m\n\u001b[1;32m     88\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_call\u001b[39m(\n\u001b[1;32m     89\u001b[0m     \u001b[38;5;28mself\u001b[39m,\n\u001b[1;32m     90\u001b[0m     inputs: Dict[\u001b[38;5;28mstr\u001b[39m, Any],\n\u001b[1;32m     91\u001b[0m     run_manager: Optional[CallbackManagerForChainRun] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[1;32m     92\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Dict[\u001b[38;5;28mstr\u001b[39m, \u001b[38;5;28mstr\u001b[39m]:\n\u001b[0;32m---> 93\u001b[0m     response \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mgenerate\u001b[49m\u001b[43m(\u001b[49m\u001b[43m[\u001b[49m\u001b[43minputs\u001b[49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_manager\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m     94\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcreate_outputs(response)[\u001b[38;5;241m0\u001b[39m]\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/chains/llm.py:103\u001b[0m, in \u001b[0;36mLLMChain.generate\u001b[0;34m(self, input_list, run_manager)\u001b[0m\n\u001b[1;32m    101\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"Generate LLM result from inputs.\"\"\"\u001b[39;00m\n\u001b[1;32m    102\u001b[0m prompts, stop \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mprep_prompts(input_list, run_manager\u001b[38;5;241m=\u001b[39mrun_manager)\n\u001b[0;32m--> 103\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mllm\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mgenerate_prompt\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m    104\u001b[0m \u001b[43m    \u001b[49m\u001b[43mprompts\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m    105\u001b[0m \u001b[43m    \u001b[49m\u001b[43mstop\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m    106\u001b[0m \u001b[43m    \u001b[49m\u001b[43mcallbacks\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_manager\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_child\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mif\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01melse\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[1;32m    107\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mllm_kwargs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m    108\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/llms/base.py:498\u001b[0m, in \u001b[0;36mBaseLLM.generate_prompt\u001b[0;34m(self, prompts, stop, callbacks, **kwargs)\u001b[0m\n\u001b[1;32m    490\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mgenerate_prompt\u001b[39m(\n\u001b[1;32m    491\u001b[0m     \u001b[38;5;28mself\u001b[39m,\n\u001b[1;32m    492\u001b[0m     prompts: List[PromptValue],\n\u001b[0;32m   (...)\u001b[0m\n\u001b[1;32m    495\u001b[0m     \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs: Any,\n\u001b[1;32m    496\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m LLMResult:\n\u001b[1;32m    497\u001b[0m     prompt_strings \u001b[38;5;241m=\u001b[39m [p\u001b[38;5;241m.\u001b[39mto_string() \u001b[38;5;28;01mfor\u001b[39;00m p \u001b[38;5;129;01min\u001b[39;00m prompts]\n\u001b[0;32m--> 498\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mgenerate\u001b[49m\u001b[43m(\u001b[49m\u001b[43mprompt_strings\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstop\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstop\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcallbacks\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcallbacks\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/llms/base.py:647\u001b[0m, in \u001b[0;36mBaseLLM.generate\u001b[0;34m(self, prompts, stop, callbacks, tags, metadata, run_name, **kwargs)\u001b[0m\n\u001b[1;32m    632\u001b[0m         \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\n\u001b[1;32m    633\u001b[0m             \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mAsked to cache, but no cache found at `langchain.cache`.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m    634\u001b[0m         )\n\u001b[1;32m    635\u001b[0m     run_managers \u001b[38;5;241m=\u001b[39m [\n\u001b[1;32m    636\u001b[0m         callback_manager\u001b[38;5;241m.\u001b[39mon_llm_start(\n\u001b[1;32m    637\u001b[0m             dumpd(\u001b[38;5;28mself\u001b[39m),\n\u001b[0;32m   (...)\u001b[0m\n\u001b[1;32m    645\u001b[0m         )\n\u001b[1;32m    646\u001b[0m     ]\n\u001b[0;32m--> 647\u001b[0m     output \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_generate_helper\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m    648\u001b[0m \u001b[43m        \u001b[49m\u001b[43mprompts\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstop\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrun_managers\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mbool\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mnew_arg_supported\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\n\u001b[1;32m    649\u001b[0m \u001b[43m    \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m    650\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m output\n\u001b[1;32m    651\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(missing_prompts) \u001b[38;5;241m>\u001b[39m \u001b[38;5;241m0\u001b[39m:\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/llms/base.py:535\u001b[0m, in \u001b[0;36mBaseLLM._generate_helper\u001b[0;34m(self, prompts, stop, run_managers, new_arg_supported, **kwargs)\u001b[0m\n\u001b[1;32m    533\u001b[0m     \u001b[38;5;28;01mfor\u001b[39;00m run_manager \u001b[38;5;129;01min\u001b[39;00m run_managers:\n\u001b[1;32m    534\u001b[0m         run_manager\u001b[38;5;241m.\u001b[39mon_llm_error(e)\n\u001b[0;32m--> 535\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m e\n\u001b[1;32m    536\u001b[0m flattened_outputs \u001b[38;5;241m=\u001b[39m output\u001b[38;5;241m.\u001b[39mflatten()\n\u001b[1;32m    537\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m manager, flattened_output \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mzip\u001b[39m(run_managers, flattened_outputs):\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/llms/base.py:522\u001b[0m, in \u001b[0;36mBaseLLM._generate_helper\u001b[0;34m(self, prompts, stop, run_managers, new_arg_supported, **kwargs)\u001b[0m\n\u001b[1;32m    512\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_generate_helper\u001b[39m(\n\u001b[1;32m    513\u001b[0m     \u001b[38;5;28mself\u001b[39m,\n\u001b[1;32m    514\u001b[0m     prompts: List[\u001b[38;5;28mstr\u001b[39m],\n\u001b[0;32m   (...)\u001b[0m\n\u001b[1;32m    518\u001b[0m     \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs: Any,\n\u001b[1;32m    519\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m LLMResult:\n\u001b[1;32m    520\u001b[0m     \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m    521\u001b[0m         output \u001b[38;5;241m=\u001b[39m (\n\u001b[0;32m--> 522\u001b[0m             \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_generate\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m    523\u001b[0m \u001b[43m                \u001b[49m\u001b[43mprompts\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m    524\u001b[0m \u001b[43m                \u001b[49m\u001b[43mstop\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstop\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m    525\u001b[0m \u001b[43m                \u001b[49m\u001b[38;5;66;43;03m# TODO: support multiple run managers\u001b[39;49;00m\n\u001b[1;32m    526\u001b[0m \u001b[43m                \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_managers\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mif\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mrun_managers\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01melse\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[1;32m    527\u001b[0m \u001b[43m                \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m    528\u001b[0m \u001b[43m            \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m    529\u001b[0m             \u001b[38;5;28;01mif\u001b[39;00m new_arg_supported\n\u001b[1;32m    530\u001b[0m             \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_generate(prompts, stop\u001b[38;5;241m=\u001b[39mstop)\n\u001b[1;32m    531\u001b[0m         )\n\u001b[1;32m    532\u001b[0m     \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mBaseException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[1;32m    533\u001b[0m         \u001b[38;5;28;01mfor\u001b[39;00m run_manager \u001b[38;5;129;01min\u001b[39;00m run_managers:\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/llms/base.py:1044\u001b[0m, in \u001b[0;36mLLM._generate\u001b[0;34m(self, prompts, stop, run_manager, **kwargs)\u001b[0m\n\u001b[1;32m   1041\u001b[0m new_arg_supported \u001b[38;5;241m=\u001b[39m inspect\u001b[38;5;241m.\u001b[39msignature(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_call)\u001b[38;5;241m.\u001b[39mparameters\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mrun_manager\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m   1042\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m prompt \u001b[38;5;129;01min\u001b[39;00m prompts:\n\u001b[1;32m   1043\u001b[0m     text \u001b[38;5;241m=\u001b[39m (\n\u001b[0;32m-> 1044\u001b[0m         \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_call\u001b[49m\u001b[43m(\u001b[49m\u001b[43mprompt\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstop\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstop\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_manager\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m   1045\u001b[0m         \u001b[38;5;28;01mif\u001b[39;00m new_arg_supported\n\u001b[1;32m   1046\u001b[0m         \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_call(prompt, stop\u001b[38;5;241m=\u001b[39mstop, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[1;32m   1047\u001b[0m     )\n\u001b[1;32m   1048\u001b[0m     generations\u001b[38;5;241m.\u001b[39mappend([Generation(text\u001b[38;5;241m=\u001b[39mtext)])\n\u001b[1;32m   1049\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m LLMResult(generations\u001b[38;5;241m=\u001b[39mgenerations)\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/llms/replicate.py:138\u001b[0m, in \u001b[0;36mReplicate._call\u001b[0;34m(self, prompt, stop, run_manager, **kwargs)\u001b[0m\n\u001b[1;32m    136\u001b[0m prediction\u001b[38;5;241m.\u001b[39mwait()\n\u001b[1;32m    137\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m prediction\u001b[38;5;241m.\u001b[39mstatus \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mfailed\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n\u001b[0;32m--> 138\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mRuntimeError\u001b[39;00m(prediction\u001b[38;5;241m.\u001b[39merror)\n\u001b[1;32m    139\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(prediction\u001b[38;5;241m.\u001b[39moutput, \u001b[38;5;28mstr\u001b[39m):\n\u001b[1;32m    140\u001b[0m     completion \u001b[38;5;241m=\u001b[39m prediction\u001b[38;5;241m.\u001b[39moutput\n",
      "\u001b[0;31mRuntimeError\u001b[0m: Your input is too long. Max input length is 4096 tokens, but you supplied 5608 tokens."
     ]
    }
   ],
   "source": [
    "chain = load_summarize_chain(llm, chain_type=\"refine\")\n",
    "# still get the \"RuntimeError: Your input is too long. Max input length is 4096 tokens\"\n",
    "chain.run(docs)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "aecf6328",
   "metadata": {},
   "source": [
    "\n",
    "Since the transcript is bigger than the model can handle, we can split the transcript into chunks instead and use the [`refine`](https://python.langchain.com/docs/modules/chains/document/refine) `chain_type` to iteratively create an answer."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "3be1236a-fe6a-4bf6-983f-0e72dde39fee",
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain.text_splitter import RecursiveCharacterTextSplitter\n",
    "\n",
    "# we need to split the long input text\n",
    "text_splitter = RecursiveCharacterTextSplitter.from_tiktoken_encoder(\n",
    "    chunk_size=3000, chunk_overlap=0\n",
    ")\n",
    "split_docs = text_splitter.split_documents(docs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "12ae9e9d-3434-4a84-a298-f2b98de9ff01",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(2, 1, 15519, 26324)"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# check the splitted docs lengths\n",
    "len(split_docs), len(docs), len(split_docs[0].page_content), len(docs[0].page_content)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "127f17fe-d5b7-43af-bd2f-2b47b076d0b1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "' Sure! Here is a revised version of the summary based on the additional information provided:\\n\\nAndrew Ng, co-founder of Coursera, discusses deep learning and AI. He emphasizes the importance of understanding the basics of machine learning before diving into deep learning. He also highlights the challenges students face when learning deep learning, such as struggling with concepts and overfitting. To overcome these challenges, he suggests breaking down complex topics into smaller, more manageable parts and using practical projects to build intuition. Additionally, he recommends a balanced approach to learning, including rein'"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# now get the summary of the whole docs - the whole youtube content\n",
    "chain = load_summarize_chain(llm, chain_type=\"refine\")\n",
    "chain.run(split_docs)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c3976c92",
   "metadata": {},
   "source": [
    "You can also use [`map_reduce`](https://python.langchain.com/docs/modules/chains/document/map_reduce) `chain_type` to implement a map reduce like architecture while summarizing the documents."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "8991df49-8578-46de-8b30-cb2cd11e30f1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "d19de177343041f4a475815adee07dea",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading (…)olve/main/vocab.json:   0%|          | 0.00/1.04M [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "deed086d9afe4494927a95b67e0d3ce5",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading (…)olve/main/merges.txt:   0%|          | 0.00/456k [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "88b1830afc2048958cb25c60812b918d",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading (…)/main/tokenizer.json:   0%|          | 0.00/1.36M [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "373568881948486da9f9ccb644dac1f5",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading (…)lve/main/config.json:   0%|          | 0.00/665 [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "' Andrew Ng, an expert in deep learning and AI, offers advice for those interested in pursuing a career in this field. He stresses the importance of understanding the fundamentals of machine learning before delving into deep learning. He also highlights common challenges faced by students, such as grasping complex concepts and overfitting, and provides tips for overcoming these obstacles. Additionally, he emphasizes the value of developing a diverse skill set and building a strong network of peers and mentors.'"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# another method is map_reduce\n",
    "chain = load_summarize_chain(llm, chain_type=\"map_reduce\")\n",
    "chain.run(split_docs)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "77d580de",
   "metadata": {},
   "source": [
    "To investigate further, let's turn on Langchain's debug mode on to get an idea of how many calls are made to the model and the details of the inputs and outputs.\n",
    "We will then run our summary using the `stuff` and `refine` `chain_types` and take a look at our output."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "f2138911-d2b9-41f3-870f-9bc37e2043d9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[32;1m\u001b[1;3m[chain/start]\u001b[0m \u001b[1m[1:chain:StuffDocumentsChain] Entering Chain run with input:\n",
      "\u001b[0m[inputs]\n",
      "\u001b[32;1m\u001b[1;3m[chain/start]\u001b[0m \u001b[1m[1:chain:StuffDocumentsChain > 2:chain:LLMChain] Entering Chain run with input:\n",
      "\u001b[0m{\n",
      "  \"text\": \"so let's perhaps talk about each of these areas first deep learning that AI how the basic question how does a person interested in deep learning get started in the field the Atlanta AI is working to create courses to help people break into AI so my machine learning course that I taught through Stanford means one of the most popular causes on Coursera to this day it's probably one of the courses sort of if I ask somebody how did you get into machine learning or how did you fall in love with machine learning or will get you interested it always goes back to rain and you rang at some point you were employing the amount of people you influence is Ruchika so for that I'm sure I speak for a lot of people say big thank you know yeah thank you you know I was once reading a news article I think it was tech review and I'm gonna mess up the statistic but I remember reading article that said um something like one-third of all programmers are self-taught I may have the number one third Romney was two-thirds but I read that article I thought this doesn't make sense everyone is self-taught because you teach yourself I don't teach people and it's no good huh oh yeah so how does one get started in deep learning and word is deep learning that AI fit into that so the define specialization offered by today is is this I think one it was called service specialization it might still be so it's very popular way for people to take that specialization to learn about everything from new networks to how to tune in your network so what is it confident to what is a RNA nor sequence model or what is an attention model and so the design specialization um steps everyone's through those algorithms so you deeply understand it and can implement it and use it you know for whatever from the very beginning so what would you say the prerequisites for somebody to take the deep learning specialization in terms of maybe math or programming background you know need to understand basic programming since there are Pro exercises in Python and the map prereq is quite basic so no calculus is needed if you know calculus is great you get better intuitions but deliberately try to teach that specialization without requirement calculus so I think high school math would be sufficient if you know how to Mouse by two matrices I think I think that that deaths that desperates so little basically in your algebra it's great basically algebra even very very basically the algebra and some programming I think that people that done the machine learning also finds a deep learning specialization that bit easier but is also possible to jump into the divine specialization directly but it'll be a little bit harder since we tend to you know go over faster concepts like how does gradient descent work and what is an objective function which which is covered most lowly in the machine learning course could you briefly mention some of the key concepts in deep learning that students should learn that you envision them learning in the first few months in the first year or so so if you take the d-line specialization you learned foundations of what is in your network how do you build up in your network from you know single it's just a unit stack of layers to different activation functions you don't have a trained in your networks one thing I'm very proud of in that specialization is we go through a lot of practical know-how of how to actually make these things work so one of the differences between different optimization algorithms so what do you do the algorithm overfit so how do you tell the algorithm is overfitting when you collect more data when should you not bother to collect more data I find that some even today unfortunately there are your engineers that will spend six months trying to pursue a particular direction such as collect more data because we heard more data is valuable but sometimes you could run some tests and could have figured out six months earlier therefore this problem collecting more data isn't gonna cut it so just don't spend seconds collecting more data spend your time modifying the architecture or trying something also go through a lot of the practical know-how also that when when when when someone when you take the deviant specialization you have those skills to be very efficient in how you build is net so dive right in to play with the network to train it to do the inference on a particular data set to build an intuition about it without without building it up too big to where you spend like you said six months learning building up your big project without building any intuition of a small small aspect of the data that could already tell you everything needs you know about that date yes and also the systematic frameworks of thinking for how to go about building practical machine learning maybe to make an analogy um when we learn to code we have to learn the syntax of some very language right be a Python or C++ or octave or whatever but that equally important or maybe even more important part of coding is to understand how to string together these lines of code into coherent things so you know when should you put something in the function call and why should you not how do you think about abstraction so those frameworks are what makes a programmer efficient even more than understanding two syntax I remember when I was an undergrad at Carnegie Mellon um one of my friends would debug their codes by first trying to compile it and then it was sleepless code and then every line in the syntax error they want to give her the syntax errors as quickly as possible so how do you do that well they would delete every single line of code with a syntax so really efficient for general syntax errors were horrible service so I think so we learned how the debug and I think in machine learning the way you debug a machine learning program is very different than the way you you know like do binary search or whatever use a debugger I traced through the code in traditional software engineering so isn't evolving discipline but I find that the people that are really good at debugging machine learning algorithms are easily 10x maybe 100x faster at getting something to work so in a basic process the debugging is so the the bug in this case why is in this thing learning learning improving sort of going into the questions of overfitting and all those kinds of things that's that's the logical space that the debugging is happening in with neural network yeah the often question is why doesn't it work yet well can I expect it eventually work and what are the things I could try change the architecture malteaser more regularization different optimization algorithm you know different types of data are so to answer those questions systematically so that you don't heading down the so you don't spend six months hitting down a blind alley before someone comes and says why should you spend six months doing this what concepts in deep learning do you think students struggle the most with or sort of this is the biggest challenge for them was to get over that hill it's it hooks them and it inspires them and they really get it similar to learning mathematics I think one of the challenges of deep learning is that there are lot of concepts that build on top of each other if you ask me what's hard about mathematics I have a hard time pinpointing one thing is it addition subtraction is it carry is it multiplication law this is law stuff I think when the challenges of learning math and of learning certain technical fields is that a lot of concepts and you miss a concept then you're kind of missing the prerequisite for something that comes later so in the deep learning specialization try to break down the concepts to maximize the odds of you know each component being understandable so when you move on to the more advanced thing we learn your confidence hopefully you have enough intuitions from the earlier sections didn't understand why we structure confidence in a certain certain way and then eventually why we build you know our n ends and L STM's or attention more than a certain way building on top of the earlier concepts I'm curious you you you do a lot of teaching as well do you have a do you have a favorite this is the hard concept moment in your teaching well I don't think anyone's ever turned the interview on me I think that's a really good question yeah it's it's really hard to capture the moment when they struggle I think you put a really eloquently I do think there's moments that are like aha moments that really inspire people I think for some reason reinforcement learning especially deep reinforcement learning is a really great way to really inspire people and get what the use of neural networks can do even though you know networks really are just a part of the deep RL framework but it's a really nice way to the to paint the entirety of the picture of a neural network being able to learn from scratch knowing nothing and explore the world and pick up lessons I find that a lot of the aha moments happen when you use deep RL to teach people about neural networks which is counterintuitive I find like a lot of the inspired sort of fire and people's passion people's eyes is comes from the RL world do you find I mean first of all learning to be a useful part of the teaching process or not I still teach me forceful learning and one of my Stanford classes and my PhD thesis will endure for some writings thank you I find it if I'm trying to teach students the most useful techniques for them to use today I end up shrinking the amount of time and talk about reinforcement learning it's not what's working today now our world changes so fast maybe it does be totally different in a couple years I think we need a couple more things for reinforcement learning to get there if you get there yeah one of my teams is looking to reinforce the learning for some robotic control tasks so I see the applications but if you look at it as a percentage of all of the impact of you know the types of things we do is it's at least today outside of you know playing video games right in a few of the games the the scope I said numerous the bunch of us was standing around saying hey what's your best example of an actual deploy reinforcement learning application and you know among your like scene in machine learning researchers right and again there are some emerging but there are there are not that many great examples but I think you're absolutely right the sad thing is there hasn't been a big application impactful real-world application reinforcement learning I think its biggest impact to me has been in the toy domain in the game domain in a small example that's what I mean for educational purpose it seems to be a fun thing to explore new networks with but I think from your perspective and I think that might be the best perspective is if you're trying to educate with a simple example in order to illustrate how this can actually be grown to scale and have a real world impact then perhaps focusing on the fundamentals of supervised learning in the context of you know a simple data set even like an eminence data set is the right way is the right path to take I just the amount of fun I've seen people have with reinforcement learning it's been great but not in the applied impact on the real-world setting so it's a it's a trade-off how much impact you want to have versus how much fun you want to have yeah that's really cool and I feel like you know the world actually needs also even within machine learning I feel like deep learning is so exciting but the AI team shouldn't just use deep learning I find that my team's use a portfolio of tools and maybe that's not the exciting thing to say but some days we use internet some days we use a you know the PC a the other day are sitting down with my team looking at PC residuals trying to figure out what's going on with PC applied to manufacturing problem and sometimes we use the promising graphical models sometimes to use a knowledge trough where some of the things that has tremendous industry impact but the amount of chat about knowledge drops in academia has really thin compared to the actual rower impact so so I think reinforcement learning should be in that portfolio and then it's about balancing how much we teach all of these things and the world the world should have diverse skills if he said if you know everyone just learn one one narrow thing yeah the diverse skill help you discover the right tool for the job so if we could return to maybe talk quickly about the specifics of deep learning that AI the deep learning specialization perhaps how long does it take to complete the course would you say the official length of the divine specialization is I think 16 weeks so about 4 months but is go at your own pace so if you subscribe to the divine specialization there are people that finish that in less than a month by working more intensely and study more intensely so it really depends on on the individual who created the divine specialization we wanted to make it very accessible and very affordable and with you know Coursera and even higher education mission one of the things that's really important to me is that if there's someone for whom paying anything is a is a financial hardship then just apply for financial aid and get it for free if you were to recommend a daily schedule for people in learning whether it's through the deep learning that a a specialization or just learning in the world of deep learning what would you recommend how do they go about day 2 days or a specific advice about learning about their journey in the world of deep learning machine learning I think I'm getting the habit of learning is key and that means regularity so for example we send out our weekly newsletter the batch every Wednesday so people know it's coming Wednesday you can spend a little time on Wednesday catching up on the latest news through the batch on the on on on Wednesday and for myself I've picked up a habit of spending some time every Saturday and every Sunday reading or studying and so I don't wake up on a Saturday and have to make a decision do I feel like reading or studying today or not it's just it's just what I do and the fact is a habit makes it easier so I think if someone can get in that habit it's like you know just like we brush our teeth every morning I don't think about it if I thought about this a little bit annoying to have to spend two minutes doing that but it's a habit that it takes no cognitive loads but there's be so much harder if we have to make a decision every morning so and actually that's the reason why we're the same thing every day as well it's just one less decision I just get out in there where I'm sure so if I think you can get that habit that consistency of steady then that she feels easier so yeah it's kind of amazing in my own life like I play guitar every day for life forced myself to at least for five minutes play guitar it's it's a ridiculously short period of time but because I've gotten into that habit it's incredible what you can accomplish in a period of a year or two years you could become you know exceptionally good at certain aspects of a thing by just doing it everyday for a very short period of time it's kind of a miracle that that is how it works it's adds up over time yeah and I think is often not about the births of sustained efforts and the all-nighters because you can only\\n\\ndo that in a limited number of times it's the sustained effort over a long time I think you know reading two research papers there's a nice thing to do but the power is not reading two research papers this meeting through research papers a week for a year then you've read a hundred papers and you actually learn a lot we read a hundred papers so regularity and making learning a habit give do you have general other study tips for particularly deep learning that people should in in their process of learning is there some kind of recommendations or tips you have as they learn one thing I still do when I'm trying to study something really deeply is take handwritten notes it varies I know there are a lot of people that take the deep learning courses during a commutes or something where may be more awkward to take notes so I know it's may not work for everyone but when I'm taking courses on Coursera you know and that still takes someone every now and then the most recent I took was a was a course on clinical trials because interest about that I call up my little moleskin notebook and I was sitting at my desk is just taking down notes so what the instructor was saying and that act we know that that act of taking notes preferably handwritten notes increases retention so as you're sort of watching the video just kind of pausing maybe and then taking the basic insights down on paper yeah so I should have been a few studies if you know search online you find some of these studies that taking handwritten notes because handwriting is slower as we're saying just now it causes you to recode the knowledge in your own words more and that process of recoding promotes long-term attention this is as opposed to typing which is fine again typing is better than nothing or in taking a class and not the canals is better than nothing any cause law but comparing handwritten notes and typing you can usually type faster for a lot of people you can hand write notes and so when people type they're more likely to transcribe verbatim what they heard and that reduces the amount of recoding and that actually results in less long-term retention I don't know what the psychological effect there is but so true there's something fundamentally different about writing hand handwriting I wonder what that is I wonder if it is as simple as just the time it takes to write is slower yeah and and and because because you can't write as many words you have to take whatever they said and summarize it into fewer words and that summarization process requires deeper processing of the meaning which then results in better attention that's fascinating oh and then I spent I think yeah because the Coursera spent so much time studying in pedagogy is that human passions I really love learning how to more efficiently help others learn yeah one of the things I do both in creating videos or when we write the batch is I try to think is one minute spent of us going to be a more efficient learning experience than one minute spent anywhere else and we really try to you know make a time efficient for the learning it's good to know everyone's busy so when when we're editing them I often tell my teams everywhere it needs to fight for his life and if can delete awareness easily to then not wait let's not waste than during this time wow that's so it's so amazing that you think that way because there is millions of people that are impacted by your teaching and sort of that one minute spent has a ripple effect right through years of time which is just fascinating talk about how does one make a career out of an interest in deep learning give advice for people we just talked about sort of the beginning early steps but if you want to make it at entire life's journey or at least a journey of a decade or two how did it how do you do it so most important thing is to get started right and ever I think in the early parts of a career coursework like the deviant specialization or it's a very efficient way to master this material so because you know instructors be it me or someone else or you know Laurence Moroney teaches on tensor field specialization and other things were working on spend effort to try to make a time efficient for you to learn new concepts so coursework is actually a very efficient way for people that learn concepts and the becoming parts of break into new fields in fact one thing I see at Stanford some of my PhD students want to jump in the research right away and actually tend to say look when you first come for us the peer student spend time taking courses because it lays the foundation it's fine if you're less productive in your first couple of years you'd be better off in the long term um beyond a certain point there's materials that doesn't exist in courses because it's too cutting edge the courses we created yeah there's some practical experience that we're not yet that good as teaching in a in a course the thing after exhausting the efficient course were then most people need to go on to either ideally work on projects and then maybe also continue their learning by reading blog polls and research papers and things like that um doing practice is really important and again I think is important to start spawns just do something today you read about deep learning if you say all these people doing such exciting things what about not building a neural network they change the world and what's the point well the point is sometimes building that time in your network you know be it m-miss or upgrade to a fashion em this to whatever doing your own fun hobby project that's how you gain the skills to let you do bigger and bigger projects I find this to be true at the individual level and also at the organizational level for a company to become clear that machine learning sometimes the right thing to do is not tackle the giant project is instead to do the small project that lets the organization learn and then build up from there but just true both for individuals and and for and for companies to taking the first step and then taking small steps is the key should students pursue a PhD do you think you can do so much that's the one of the fascinating things in machine learning you can have so much impact without ever getting a PhD so what are your thoughts should people go to grad school should people get a PhD I think that there are multiple good options of which doing a PhD could be one of them I think that if someone's admitted to a top ph.d program you know that MIT Stanford top schools I think that's a very good experience or someone gets a job at a top organization at the top of AI team I think that's also very good experience there are some things you still need a PhD to do if someone's aspiration is to be a professor here at the top academic University you just need a piece you do that but if it goes to you know start a completely build a company to create technical work I think a PhD is a good experience but I would look at the different options available to someone you know where the places where you can get a job where the place isn't getting a ph.d program and kind of weigh the pros and cons of those so just to linger on that for a little bit longer what final dreams and goals do you think people should have so the what options for they explore so you can work in industry so for a large company like Google Facebook buy do all these large companies already have huge teams of machine learning engineers you can also do with an industry sort of more research groups that kind of like Google research Google brain then you can also do like we say the professor neck as in academia and what else oh you can still build your own company you can do a start-up is there anything that stands out between those options or are they all beautiful different journeys that people should consider I think the thing that affects your experience more is less are you in discomfort versus that company your academia versus industry I think the thing that affects to experience Moses who are the people you're interacting with you know in a daily basis so even if you look at some of the large companies the experience of individuals and and he was very different and what matters most is not the logo above the door when you walk into the giant building every day what matters and Moses who are the 10 people who are the 30 people you interact with every day so I should tend to advise people if you get a job from from a company also who is your manager who are your peers who actually talk to you we're all social creatures we tend to you know become more like the people around us and if you're working with great people you will learn faster or if you get admitted if you get a job and a great company or a great university maybe the logo you walking know is great but you're actually stuck on some team doing really worth it doesn't excite you and then that's actually really bad experience so this is true both for universities and for large companies for small companies you can kind of figure out who you work quite quickly and I tend to advise people if a company refuses to tell you who you work with sometimes say Oh join us the rotation system will figure out I think that that that's a worrying answer because it because it means you may not get sense to you mean not actually get to team with with great peers and great people to work with it's actually really profound advice that we kind of sometimes sweep we don't consider to rigorously or carefully the people around you are really often this especially when you accomplish great things it seems the great things are accomplished because of the people around you so that that's a it's not about the the worry whether you learn this thing or that thing or like you said the logo that hangs up top it's the people that's a fascinating and it's such a hard search process of finding just like finding the right friends and somebody to get married with and that kind of thing it's a very hard search process of people search problem yeah but I think when someone interviews you know at a university or the research lab at a large corporation it's good to insist on just asking who are the people who is my manager and if you refuse to tell me I'm gonna think well maybe that's because you don't have a good answer it may not be someone I like and if you don't particularly connect if something feels off for the people then don't - you know that's a really important signal to consider yeah and actually I am in my standard cause cs2 30s was an ACN talk I think I gave like a hour long talk on career advice including on the job search process and then some of these cells of yours if you can find those videos on the oscillator pointers I'll point people to them beautiful you\"\n",
      "}\n",
      "\u001b[32;1m\u001b[1;3m[llm/start]\u001b[0m \u001b[1m[1:chain:StuffDocumentsChain > 2:chain:LLMChain > 3:llm:Replicate] Entering LLM run with input:\n",
      "\u001b[0m{\n",
      "  \"prompts\": [\n",
      "    \"Write a concise summary of the following:\\n\\n\\n\\\"so let's perhaps talk about each of these areas first deep learning that AI how the basic question how does a person interested in deep learning get started in the field the Atlanta AI is working to create courses to help people break into AI so my machine learning course that I taught through Stanford means one of the most popular causes on Coursera to this day it's probably one of the courses sort of if I ask somebody how did you get into machine learning or how did you fall in love with machine learning or will get you interested it always goes back to rain and you rang at some point you were employing the amount of people you influence is Ruchika so for that I'm sure I speak for a lot of people say big thank you know yeah thank you you know I was once reading a news article I think it was tech review and I'm gonna mess up the statistic but I remember reading article that said um something like one-third of all programmers are self-taught I may have the number one third Romney was two-thirds but I read that article I thought this doesn't make sense everyone is self-taught because you teach yourself I don't teach people and it's no good huh oh yeah so how does one get started in deep learning and word is deep learning that AI fit into that so the define specialization offered by today is is this I think one it was called service specialization it might still be so it's very popular way for people to take that specialization to learn about everything from new networks to how to tune in your network so what is it confident to what is a RNA nor sequence model or what is an attention model and so the design specialization um steps everyone's through those algorithms so you deeply understand it and can implement it and use it you know for whatever from the very beginning so what would you say the prerequisites for somebody to take the deep learning specialization in terms of maybe math or programming background you know need to understand basic programming since there are Pro exercises in Python and the map prereq is quite basic so no calculus is needed if you know calculus is great you get better intuitions but deliberately try to teach that specialization without requirement calculus so I think high school math would be sufficient if you know how to Mouse by two matrices I think I think that that deaths that desperates so little basically in your algebra it's great basically algebra even very very basically the algebra and some programming I think that people that done the machine learning also finds a deep learning specialization that bit easier but is also possible to jump into the divine specialization directly but it'll be a little bit harder since we tend to you know go over faster concepts like how does gradient descent work and what is an objective function which which is covered most lowly in the machine learning course could you briefly mention some of the key concepts in deep learning that students should learn that you envision them learning in the first few months in the first year or so so if you take the d-line specialization you learned foundations of what is in your network how do you build up in your network from you know single it's just a unit stack of layers to different activation functions you don't have a trained in your networks one thing I'm very proud of in that specialization is we go through a lot of practical know-how of how to actually make these things work so one of the differences between different optimization algorithms so what do you do the algorithm overfit so how do you tell the algorithm is overfitting when you collect more data when should you not bother to collect more data I find that some even today unfortunately there are your engineers that will spend six months trying to pursue a particular direction such as collect more data because we heard more data is valuable but sometimes you could run some tests and could have figured out six months earlier therefore this problem collecting more data isn't gonna cut it so just don't spend seconds collecting more data spend your time modifying the architecture or trying something also go through a lot of the practical know-how also that when when when when someone when you take the deviant specialization you have those skills to be very efficient in how you build is net so dive right in to play with the network to train it to do the inference on a particular data set to build an intuition about it without without building it up too big to where you spend like you said six months learning building up your big project without building any intuition of a small small aspect of the data that could already tell you everything needs you know about that date yes and also the systematic frameworks of thinking for how to go about building practical machine learning maybe to make an analogy um when we learn to code we have to learn the syntax of some very language right be a Python or C++ or octave or whatever but that equally important or maybe even more important part of coding is to understand how to string together these lines of code into coherent things so you know when should you put something in the function call and why should you not how do you think about abstraction so those frameworks are what makes a programmer efficient even more than understanding two syntax I remember when I was an undergrad at Carnegie Mellon um one of my friends would debug their codes by first trying to compile it and then it was sleepless code and then every line in the syntax error they want to give her the syntax errors as quickly as possible so how do you do that well they would delete every single line of code with a syntax so really efficient for general syntax errors were horrible service so I think so we learned how the debug and I think in machine learning the way you debug a machine learning program is very different than the way you you know like do binary search or whatever use a debugger I traced through the code in traditional software engineering so isn't evolving discipline but I find that the people that are really good at debugging machine learning algorithms are easily 10x maybe 100x faster at getting something to work so in a basic process the debugging is so the the bug in this case why is in this thing learning learning improving sort of going into the questions of overfitting and all those kinds of things that's that's the logical space that the debugging is happening in with neural network yeah the often question is why doesn't it work yet well can I expect it eventually work and what are the things I could try change the architecture malteaser more regularization different optimization algorithm you know different types of data are so to answer those questions systematically so that you don't heading down the so you don't spend six months hitting down a blind alley before someone comes and says why should you spend six months doing this what concepts in deep learning do you think students struggle the most with or sort of this is the biggest challenge for them was to get over that hill it's it hooks them and it inspires them and they really get it similar to learning mathematics I think one of the challenges of deep learning is that there are lot of concepts that build on top of each other if you ask me what's hard about mathematics I have a hard time pinpointing one thing is it addition subtraction is it carry is it multiplication law this is law stuff I think when the challenges of learning math and of learning certain technical fields is that a lot of concepts and you miss a concept then you're kind of missing the prerequisite for something that comes later so in the deep learning specialization try to break down the concepts to maximize the odds of you know each component being understandable so when you move on to the more advanced thing we learn your confidence hopefully you have enough intuitions from the earlier sections didn't understand why we structure confidence in a certain certain way and then eventually why we build you know our n ends and L STM's or attention more than a certain way building on top of the earlier concepts I'm curious you you you do a lot of teaching as well do you have a do you have a favorite this is the hard concept moment in your teaching well I don't think anyone's ever turned the interview on me I think that's a really good question yeah it's it's really hard to capture the moment when they struggle I think you put a really eloquently I do think there's moments that are like aha moments that really inspire people I think for some reason reinforcement learning especially deep reinforcement learning is a really great way to really inspire people and get what the use of neural networks can do even though you know networks really are just a part of the deep RL framework but it's a really nice way to the to paint the entirety of the picture of a neural network being able to learn from scratch knowing nothing and explore the world and pick up lessons I find that a lot of the aha moments happen when you use deep RL to teach people about neural networks which is counterintuitive I find like a lot of the inspired sort of fire and people's passion people's eyes is comes from the RL world do you find I mean first of all learning to be a useful part of the teaching process or not I still teach me forceful learning and one of my Stanford classes and my PhD thesis will endure for some writings thank you I find it if I'm trying to teach students the most useful techniques for them to use today I end up shrinking the amount of time and talk about reinforcement learning it's not what's working today now our world changes so fast maybe it does be totally different in a couple years I think we need a couple more things for reinforcement learning to get there if you get there yeah one of my teams is looking to reinforce the learning for some robotic control tasks so I see the applications but if you look at it as a percentage of all of the impact of you know the types of things we do is it's at least today outside of you know playing video games right in a few of the games the the scope I said numerous the bunch of us was standing around saying hey what's your best example of an actual deploy reinforcement learning application and you know among your like scene in machine learning researchers right and again there are some emerging but there are there are not that many great examples but I think you're absolutely right the sad thing is there hasn't been a big application impactful real-world application reinforcement learning I think its biggest impact to me has been in the toy domain in the game domain in a small example that's what I mean for educational purpose it seems to be a fun thing to explore new networks with but I think from your perspective and I think that might be the best perspective is if you're trying to educate with a simple example in order to illustrate how this can actually be grown to scale and have a real world impact then perhaps focusing on the fundamentals of supervised learning in the context of you know a simple data set even like an eminence data set is the right way is the right path to take I just the amount of fun I've seen people have with reinforcement learning it's been great but not in the applied impact on the real-world setting so it's a it's a trade-off how much impact you want to have versus how much fun you want to have yeah that's really cool and I feel like you know the world actually needs also even within machine learning I feel like deep learning is so exciting but the AI team shouldn't just use deep learning I find that my team's use a portfolio of tools and maybe that's not the exciting thing to say but some days we use internet some days we use a you know the PC a the other day are sitting down with my team looking at PC residuals trying to figure out what's going on with PC applied to manufacturing problem and sometimes we use the promising graphical models sometimes to use a knowledge trough where some of the things that has tremendous industry impact but the amount of chat about knowledge drops in academia has really thin compared to the actual rower impact so so I think reinforcement learning should be in that portfolio and then it's about balancing how much we teach all of these things and the world the world should have diverse skills if he said if you know everyone just learn one one narrow thing yeah the diverse skill help you discover the right tool for the job so if we could return to maybe talk quickly about the specifics of deep learning that AI the deep learning specialization perhaps how long does it take to complete the course would you say the official length of the divine specialization is I think 16 weeks so about 4 months but is go at your own pace so if you subscribe to the divine specialization there are people that finish that in less than a month by working more intensely and study more intensely so it really depends on on the individual who created the divine specialization we wanted to make it very accessible and very affordable and with you know Coursera and even higher education mission one of the things that's really important to me is that if there's someone for whom paying anything is a is a financial hardship then just apply for financial aid and get it for free if you were to recommend a daily schedule for people in learning whether it's through the deep learning that a a specialization or just learning in the world of deep learning what would you recommend how do they go about day 2 days or a specific advice about learning about their journey in the world of deep learning machine learning I think I'm getting the habit of learning is key and that means regularity so for example we send out our weekly newsletter the batch every Wednesday so people know it's coming Wednesday you can spend a little time on Wednesday catching up on the latest news through the batch on the on on on Wednesday and for myself I've picked up a habit of spending some time every Saturday and every Sunday reading or studying and so I don't wake up on a Saturday and have to make a decision do I feel like reading or studying today or not it's just it's just what I do and the fact is a habit makes it easier so I think if someone can get in that habit it's like you know just like we brush our teeth every morning I don't think about it if I thought about this a little bit annoying to have to spend two minutes doing that but it's a habit that it takes no cognitive loads but there's be so much harder if we have to make a decision every morning so and actually that's the reason why we're the same thing every day as well it's just one less decision I just get out in there where I'm sure so if I think you can get that habit that consistency of steady then that she feels easier so yeah it's kind of amazing in my own life like I play guitar every day for life forced myself to at least for five minutes play guitar it's it's a ridiculously short period of time but because I've gotten into that habit it's incredible what you can accomplish in a period of a year or two years you could become you know exceptionally good at certain aspects of a thing by just doing it everyday for a very short period of time it's kind of a miracle that that is how it works it's adds up over time yeah and I think is often not about the births of sustained efforts and the all-nighters because you can only\\n\\ndo that in a limited number of times it's the sustained effort over a long time I think you know reading two research papers there's a nice thing to do but the power is not reading two research papers this meeting through research papers a week for a year then you've read a hundred papers and you actually learn a lot we read a hundred papers so regularity and making learning a habit give do you have general other study tips for particularly deep learning that people should in in their process of learning is there some kind of recommendations or tips you have as they learn one thing I still do when I'm trying to study something really deeply is take handwritten notes it varies I know there are a lot of people that take the deep learning courses during a commutes or something where may be more awkward to take notes so I know it's may not work for everyone but when I'm taking courses on Coursera you know and that still takes someone every now and then the most recent I took was a was a course on clinical trials because interest about that I call up my little moleskin notebook and I was sitting at my desk is just taking down notes so what the instructor was saying and that act we know that that act of taking notes preferably handwritten notes increases retention so as you're sort of watching the video just kind of pausing maybe and then taking the basic insights down on paper yeah so I should have been a few studies if you know search online you find some of these studies that taking handwritten notes because handwriting is slower as we're saying just now it causes you to recode the knowledge in your own words more and that process of recoding promotes long-term attention this is as opposed to typing which is fine again typing is better than nothing or in taking a class and not the canals is better than nothing any cause law but comparing handwritten notes and typing you can usually type faster for a lot of people you can hand write notes and so when people type they're more likely to transcribe verbatim what they heard and that reduces the amount of recoding and that actually results in less long-term retention I don't know what the psychological effect there is but so true there's something fundamentally different about writing hand handwriting I wonder what that is I wonder if it is as simple as just the time it takes to write is slower yeah and and and because because you can't write as many words you have to take whatever they said and summarize it into fewer words and that summarization process requires deeper processing of the meaning which then results in better attention that's fascinating oh and then I spent I think yeah because the Coursera spent so much time studying in pedagogy is that human passions I really love learning how to more efficiently help others learn yeah one of the things I do both in creating videos or when we write the batch is I try to think is one minute spent of us going to be a more efficient learning experience than one minute spent anywhere else and we really try to you know make a time efficient for the learning it's good to know everyone's busy so when when we're editing them I often tell my teams everywhere it needs to fight for his life and if can delete awareness easily to then not wait let's not waste than during this time wow that's so it's so amazing that you think that way because there is millions of people that are impacted by your teaching and sort of that one minute spent has a ripple effect right through years of time which is just fascinating talk about how does one make a career out of an interest in deep learning give advice for people we just talked about sort of the beginning early steps but if you want to make it at entire life's journey or at least a journey of a decade or two how did it how do you do it so most important thing is to get started right and ever I think in the early parts of a career coursework like the deviant specialization or it's a very efficient way to master this material so because you know instructors be it me or someone else or you know Laurence Moroney teaches on tensor field specialization and other things were working on spend effort to try to make a time efficient for you to learn new concepts so coursework is actually a very efficient way for people that learn concepts and the becoming parts of break into new fields in fact one thing I see at Stanford some of my PhD students want to jump in the research right away and actually tend to say look when you first come for us the peer student spend time taking courses because it lays the foundation it's fine if you're less productive in your first couple of years you'd be better off in the long term um beyond a certain point there's materials that doesn't exist in courses because it's too cutting edge the courses we created yeah there's some practical experience that we're not yet that good as teaching in a in a course the thing after exhausting the efficient course were then most people need to go on to either ideally work on projects and then maybe also continue their learning by reading blog polls and research papers and things like that um doing practice is really important and again I think is important to start spawns just do something today you read about deep learning if you say all these people doing such exciting things what about not building a neural network they change the world and what's the point well the point is sometimes building that time in your network you know be it m-miss or upgrade to a fashion em this to whatever doing your own fun hobby project that's how you gain the skills to let you do bigger and bigger projects I find this to be true at the individual level and also at the organizational level for a company to become clear that machine learning sometimes the right thing to do is not tackle the giant project is instead to do the small project that lets the organization learn and then build up from there but just true both for individuals and and for and for companies to taking the first step and then taking small steps is the key should students pursue a PhD do you think you can do so much that's the one of the fascinating things in machine learning you can have so much impact without ever getting a PhD so what are your thoughts should people go to grad school should people get a PhD I think that there are multiple good options of which doing a PhD could be one of them I think that if someone's admitted to a top ph.d program you know that MIT Stanford top schools I think that's a very good experience or someone gets a job at a top organization at the top of AI team I think that's also very good experience there are some things you still need a PhD to do if someone's aspiration is to be a professor here at the top academic University you just need a piece you do that but if it goes to you know start a completely build a company to create technical work I think a PhD is a good experience but I would look at the different options available to someone you know where the places where you can get a job where the place isn't getting a ph.d program and kind of weigh the pros and cons of those so just to linger on that for a little bit longer what final dreams and goals do you think people should have so the what options for they explore so you can work in industry so for a large company like Google Facebook buy do all these large companies already have huge teams of machine learning engineers you can also do with an industry sort of more research groups that kind of like Google research Google brain then you can also do like we say the professor neck as in academia and what else oh you can still build your own company you can do a start-up is there anything that stands out between those options or are they all beautiful different journeys that people should consider I think the thing that affects your experience more is less are you in discomfort versus that company your academia versus industry I think the thing that affects to experience Moses who are the people you're interacting with you know in a daily basis so even if you look at some of the large companies the experience of individuals and and he was very different and what matters most is not the logo above the door when you walk into the giant building every day what matters and Moses who are the 10 people who are the 30 people you interact with every day so I should tend to advise people if you get a job from from a company also who is your manager who are your peers who actually talk to you we're all social creatures we tend to you know become more like the people around us and if you're working with great people you will learn faster or if you get admitted if you get a job and a great company or a great university maybe the logo you walking know is great but you're actually stuck on some team doing really worth it doesn't excite you and then that's actually really bad experience so this is true both for universities and for large companies for small companies you can kind of figure out who you work quite quickly and I tend to advise people if a company refuses to tell you who you work with sometimes say Oh join us the rotation system will figure out I think that that that's a worrying answer because it because it means you may not get sense to you mean not actually get to team with with great peers and great people to work with it's actually really profound advice that we kind of sometimes sweep we don't consider to rigorously or carefully the people around you are really often this especially when you accomplish great things it seems the great things are accomplished because of the people around you so that that's a it's not about the the worry whether you learn this thing or that thing or like you said the logo that hangs up top it's the people that's a fascinating and it's such a hard search process of finding just like finding the right friends and somebody to get married with and that kind of thing it's a very hard search process of people search problem yeah but I think when someone interviews you know at a university or the research lab at a large corporation it's good to insist on just asking who are the people who is my manager and if you refuse to tell me I'm gonna think well maybe that's because you don't have a good answer it may not be someone I like and if you don't particularly connect if something feels off for the people then don't - you know that's a really important signal to consider yeah and actually I am in my standard cause cs2 30s was an ACN talk I think I gave like a hour long talk on career advice including on the job search process and then some of these cells of yours if you can find those videos on the oscillator pointers I'll point people to them beautiful you\\\"\\n\\n\\nCONCISE SUMMARY:\"\n",
      "  ]\n",
      "}\n",
      "\u001b[31;1m\u001b[1;3m[chain/error]\u001b[0m \u001b[1m[1:chain:StuffDocumentsChain > 2:chain:LLMChain > 3:llm:Replicate] [1.50s] Llm run errored with error:\n",
      "\u001b[0m\"RuntimeError('Your input is too long. Max input length is 4096 tokens, but you supplied 5610 tokens.')\"\n",
      "\u001b[31;1m\u001b[1;3m[chain/error]\u001b[0m \u001b[1m[1:chain:StuffDocumentsChain > 2:chain:LLMChain] [1.50s] Chain run errored with error:\n",
      "\u001b[0m\"RuntimeError('Your input is too long. Max input length is 4096 tokens, but you supplied 5610 tokens.')\"\n",
      "\u001b[31;1m\u001b[1;3m[chain/error]\u001b[0m \u001b[1m[1:chain:StuffDocumentsChain] [1.50s] Chain run errored with error:\n",
      "\u001b[0m\"RuntimeError('Your input is too long. Max input length is 4096 tokens, but you supplied 5610 tokens.')\"\n"
     ]
    },
    {
     "ename": "RuntimeError",
     "evalue": "Your input is too long. Max input length is 4096 tokens, but you supplied 5610 tokens.",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mRuntimeError\u001b[0m                              Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[15], line 4\u001b[0m\n\u001b[1;32m      2\u001b[0m langchain\u001b[38;5;241m.\u001b[39mdebug \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mTrue\u001b[39;00m\n\u001b[1;32m      3\u001b[0m chain \u001b[38;5;241m=\u001b[39m load_summarize_chain(llm, chain_type\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mstuff\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m----> 4\u001b[0m \u001b[43mchain\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrun\u001b[49m\u001b[43m(\u001b[49m\u001b[43msplit_docs\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/chains/base.py:501\u001b[0m, in \u001b[0;36mChain.run\u001b[0;34m(self, callbacks, tags, metadata, *args, **kwargs)\u001b[0m\n\u001b[1;32m    499\u001b[0m     \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(args) \u001b[38;5;241m!=\u001b[39m \u001b[38;5;241m1\u001b[39m:\n\u001b[1;32m    500\u001b[0m         \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m`run` supports only one positional argument.\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m--> 501\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43margs\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcallbacks\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcallbacks\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtags\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtags\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmetadata\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mmetadata\u001b[49m\u001b[43m)\u001b[49m[\n\u001b[1;32m    502\u001b[0m         _output_key\n\u001b[1;32m    503\u001b[0m     ]\n\u001b[1;32m    505\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m kwargs \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m args:\n\u001b[1;32m    506\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m(kwargs, callbacks\u001b[38;5;241m=\u001b[39mcallbacks, tags\u001b[38;5;241m=\u001b[39mtags, metadata\u001b[38;5;241m=\u001b[39mmetadata)[\n\u001b[1;32m    507\u001b[0m         _output_key\n\u001b[1;32m    508\u001b[0m     ]\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/chains/base.py:306\u001b[0m, in \u001b[0;36mChain.__call__\u001b[0;34m(self, inputs, return_only_outputs, callbacks, tags, metadata, run_name, include_run_info)\u001b[0m\n\u001b[1;32m    304\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mBaseException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[1;32m    305\u001b[0m     run_manager\u001b[38;5;241m.\u001b[39mon_chain_error(e)\n\u001b[0;32m--> 306\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m e\n\u001b[1;32m    307\u001b[0m run_manager\u001b[38;5;241m.\u001b[39mon_chain_end(outputs)\n\u001b[1;32m    308\u001b[0m final_outputs: Dict[\u001b[38;5;28mstr\u001b[39m, Any] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mprep_outputs(\n\u001b[1;32m    309\u001b[0m     inputs, outputs, return_only_outputs\n\u001b[1;32m    310\u001b[0m )\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/chains/base.py:300\u001b[0m, in \u001b[0;36mChain.__call__\u001b[0;34m(self, inputs, return_only_outputs, callbacks, tags, metadata, run_name, include_run_info)\u001b[0m\n\u001b[1;32m    293\u001b[0m run_manager \u001b[38;5;241m=\u001b[39m callback_manager\u001b[38;5;241m.\u001b[39mon_chain_start(\n\u001b[1;32m    294\u001b[0m     dumpd(\u001b[38;5;28mself\u001b[39m),\n\u001b[1;32m    295\u001b[0m     inputs,\n\u001b[1;32m    296\u001b[0m     name\u001b[38;5;241m=\u001b[39mrun_name,\n\u001b[1;32m    297\u001b[0m )\n\u001b[1;32m    298\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m    299\u001b[0m     outputs \u001b[38;5;241m=\u001b[39m (\n\u001b[0;32m--> 300\u001b[0m         \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_call\u001b[49m\u001b[43m(\u001b[49m\u001b[43minputs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_manager\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m    301\u001b[0m         \u001b[38;5;28;01mif\u001b[39;00m new_arg_supported\n\u001b[1;32m    302\u001b[0m         \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_call(inputs)\n\u001b[1;32m    303\u001b[0m     )\n\u001b[1;32m    304\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mBaseException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[1;32m    305\u001b[0m     run_manager\u001b[38;5;241m.\u001b[39mon_chain_error(e)\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/chains/combine_documents/base.py:119\u001b[0m, in \u001b[0;36mBaseCombineDocumentsChain._call\u001b[0;34m(self, inputs, run_manager)\u001b[0m\n\u001b[1;32m    117\u001b[0m \u001b[38;5;66;03m# Other keys are assumed to be needed for LLM prediction\u001b[39;00m\n\u001b[1;32m    118\u001b[0m other_keys \u001b[38;5;241m=\u001b[39m {k: v \u001b[38;5;28;01mfor\u001b[39;00m k, v \u001b[38;5;129;01min\u001b[39;00m inputs\u001b[38;5;241m.\u001b[39mitems() \u001b[38;5;28;01mif\u001b[39;00m k \u001b[38;5;241m!=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39minput_key}\n\u001b[0;32m--> 119\u001b[0m output, extra_return_dict \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcombine_docs\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m    120\u001b[0m \u001b[43m    \u001b[49m\u001b[43mdocs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcallbacks\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m_run_manager\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_child\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mother_keys\u001b[49m\n\u001b[1;32m    121\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m    122\u001b[0m extra_return_dict[\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39moutput_key] \u001b[38;5;241m=\u001b[39m output\n\u001b[1;32m    123\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m extra_return_dict\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/chains/combine_documents/stuff.py:171\u001b[0m, in \u001b[0;36mStuffDocumentsChain.combine_docs\u001b[0;34m(self, docs, callbacks, **kwargs)\u001b[0m\n\u001b[1;32m    169\u001b[0m inputs \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_get_inputs(docs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[1;32m    170\u001b[0m \u001b[38;5;66;03m# Call predict on the LLM.\u001b[39;00m\n\u001b[0;32m--> 171\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mllm_chain\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mpredict\u001b[49m\u001b[43m(\u001b[49m\u001b[43mcallbacks\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcallbacks\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43minputs\u001b[49m\u001b[43m)\u001b[49m, {}\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/chains/llm.py:257\u001b[0m, in \u001b[0;36mLLMChain.predict\u001b[0;34m(self, callbacks, **kwargs)\u001b[0m\n\u001b[1;32m    242\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mpredict\u001b[39m(\u001b[38;5;28mself\u001b[39m, callbacks: Callbacks \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs: Any) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28mstr\u001b[39m:\n\u001b[1;32m    243\u001b[0m \u001b[38;5;250m    \u001b[39m\u001b[38;5;124;03m\"\"\"Format prompt with kwargs and pass to LLM.\u001b[39;00m\n\u001b[1;32m    244\u001b[0m \n\u001b[1;32m    245\u001b[0m \u001b[38;5;124;03m    Args:\u001b[39;00m\n\u001b[0;32m   (...)\u001b[0m\n\u001b[1;32m    255\u001b[0m \u001b[38;5;124;03m            completion = llm.predict(adjective=\"funny\")\u001b[39;00m\n\u001b[1;32m    256\u001b[0m \u001b[38;5;124;03m    \"\"\"\u001b[39;00m\n\u001b[0;32m--> 257\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcallbacks\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcallbacks\u001b[49m\u001b[43m)\u001b[49m[\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39moutput_key]\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/chains/base.py:306\u001b[0m, in \u001b[0;36mChain.__call__\u001b[0;34m(self, inputs, return_only_outputs, callbacks, tags, metadata, run_name, include_run_info)\u001b[0m\n\u001b[1;32m    304\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mBaseException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[1;32m    305\u001b[0m     run_manager\u001b[38;5;241m.\u001b[39mon_chain_error(e)\n\u001b[0;32m--> 306\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m e\n\u001b[1;32m    307\u001b[0m run_manager\u001b[38;5;241m.\u001b[39mon_chain_end(outputs)\n\u001b[1;32m    308\u001b[0m final_outputs: Dict[\u001b[38;5;28mstr\u001b[39m, Any] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mprep_outputs(\n\u001b[1;32m    309\u001b[0m     inputs, outputs, return_only_outputs\n\u001b[1;32m    310\u001b[0m )\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/chains/base.py:300\u001b[0m, in \u001b[0;36mChain.__call__\u001b[0;34m(self, inputs, return_only_outputs, callbacks, tags, metadata, run_name, include_run_info)\u001b[0m\n\u001b[1;32m    293\u001b[0m run_manager \u001b[38;5;241m=\u001b[39m callback_manager\u001b[38;5;241m.\u001b[39mon_chain_start(\n\u001b[1;32m    294\u001b[0m     dumpd(\u001b[38;5;28mself\u001b[39m),\n\u001b[1;32m    295\u001b[0m     inputs,\n\u001b[1;32m    296\u001b[0m     name\u001b[38;5;241m=\u001b[39mrun_name,\n\u001b[1;32m    297\u001b[0m )\n\u001b[1;32m    298\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m    299\u001b[0m     outputs \u001b[38;5;241m=\u001b[39m (\n\u001b[0;32m--> 300\u001b[0m         \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_call\u001b[49m\u001b[43m(\u001b[49m\u001b[43minputs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_manager\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m    301\u001b[0m         \u001b[38;5;28;01mif\u001b[39;00m new_arg_supported\n\u001b[1;32m    302\u001b[0m         \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_call(inputs)\n\u001b[1;32m    303\u001b[0m     )\n\u001b[1;32m    304\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mBaseException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[1;32m    305\u001b[0m     run_manager\u001b[38;5;241m.\u001b[39mon_chain_error(e)\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/chains/llm.py:93\u001b[0m, in \u001b[0;36mLLMChain._call\u001b[0;34m(self, inputs, run_manager)\u001b[0m\n\u001b[1;32m     88\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_call\u001b[39m(\n\u001b[1;32m     89\u001b[0m     \u001b[38;5;28mself\u001b[39m,\n\u001b[1;32m     90\u001b[0m     inputs: Dict[\u001b[38;5;28mstr\u001b[39m, Any],\n\u001b[1;32m     91\u001b[0m     run_manager: Optional[CallbackManagerForChainRun] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[1;32m     92\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Dict[\u001b[38;5;28mstr\u001b[39m, \u001b[38;5;28mstr\u001b[39m]:\n\u001b[0;32m---> 93\u001b[0m     response \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mgenerate\u001b[49m\u001b[43m(\u001b[49m\u001b[43m[\u001b[49m\u001b[43minputs\u001b[49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_manager\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m     94\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcreate_outputs(response)[\u001b[38;5;241m0\u001b[39m]\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/chains/llm.py:103\u001b[0m, in \u001b[0;36mLLMChain.generate\u001b[0;34m(self, input_list, run_manager)\u001b[0m\n\u001b[1;32m    101\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"Generate LLM result from inputs.\"\"\"\u001b[39;00m\n\u001b[1;32m    102\u001b[0m prompts, stop \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mprep_prompts(input_list, run_manager\u001b[38;5;241m=\u001b[39mrun_manager)\n\u001b[0;32m--> 103\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mllm\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mgenerate_prompt\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m    104\u001b[0m \u001b[43m    \u001b[49m\u001b[43mprompts\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m    105\u001b[0m \u001b[43m    \u001b[49m\u001b[43mstop\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m    106\u001b[0m \u001b[43m    \u001b[49m\u001b[43mcallbacks\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_manager\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_child\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mif\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01melse\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[1;32m    107\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mllm_kwargs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m    108\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/llms/base.py:498\u001b[0m, in \u001b[0;36mBaseLLM.generate_prompt\u001b[0;34m(self, prompts, stop, callbacks, **kwargs)\u001b[0m\n\u001b[1;32m    490\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mgenerate_prompt\u001b[39m(\n\u001b[1;32m    491\u001b[0m     \u001b[38;5;28mself\u001b[39m,\n\u001b[1;32m    492\u001b[0m     prompts: List[PromptValue],\n\u001b[0;32m   (...)\u001b[0m\n\u001b[1;32m    495\u001b[0m     \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs: Any,\n\u001b[1;32m    496\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m LLMResult:\n\u001b[1;32m    497\u001b[0m     prompt_strings \u001b[38;5;241m=\u001b[39m [p\u001b[38;5;241m.\u001b[39mto_string() \u001b[38;5;28;01mfor\u001b[39;00m p \u001b[38;5;129;01min\u001b[39;00m prompts]\n\u001b[0;32m--> 498\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mgenerate\u001b[49m\u001b[43m(\u001b[49m\u001b[43mprompt_strings\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstop\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstop\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcallbacks\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcallbacks\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/llms/base.py:647\u001b[0m, in \u001b[0;36mBaseLLM.generate\u001b[0;34m(self, prompts, stop, callbacks, tags, metadata, run_name, **kwargs)\u001b[0m\n\u001b[1;32m    632\u001b[0m         \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\n\u001b[1;32m    633\u001b[0m             \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mAsked to cache, but no cache found at `langchain.cache`.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m    634\u001b[0m         )\n\u001b[1;32m    635\u001b[0m     run_managers \u001b[38;5;241m=\u001b[39m [\n\u001b[1;32m    636\u001b[0m         callback_manager\u001b[38;5;241m.\u001b[39mon_llm_start(\n\u001b[1;32m    637\u001b[0m             dumpd(\u001b[38;5;28mself\u001b[39m),\n\u001b[0;32m   (...)\u001b[0m\n\u001b[1;32m    645\u001b[0m         )\n\u001b[1;32m    646\u001b[0m     ]\n\u001b[0;32m--> 647\u001b[0m     output \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_generate_helper\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m    648\u001b[0m \u001b[43m        \u001b[49m\u001b[43mprompts\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstop\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrun_managers\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mbool\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mnew_arg_supported\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\n\u001b[1;32m    649\u001b[0m \u001b[43m    \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m    650\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m output\n\u001b[1;32m    651\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(missing_prompts) \u001b[38;5;241m>\u001b[39m \u001b[38;5;241m0\u001b[39m:\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/llms/base.py:535\u001b[0m, in \u001b[0;36mBaseLLM._generate_helper\u001b[0;34m(self, prompts, stop, run_managers, new_arg_supported, **kwargs)\u001b[0m\n\u001b[1;32m    533\u001b[0m     \u001b[38;5;28;01mfor\u001b[39;00m run_manager \u001b[38;5;129;01min\u001b[39;00m run_managers:\n\u001b[1;32m    534\u001b[0m         run_manager\u001b[38;5;241m.\u001b[39mon_llm_error(e)\n\u001b[0;32m--> 535\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m e\n\u001b[1;32m    536\u001b[0m flattened_outputs \u001b[38;5;241m=\u001b[39m output\u001b[38;5;241m.\u001b[39mflatten()\n\u001b[1;32m    537\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m manager, flattened_output \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mzip\u001b[39m(run_managers, flattened_outputs):\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/llms/base.py:522\u001b[0m, in \u001b[0;36mBaseLLM._generate_helper\u001b[0;34m(self, prompts, stop, run_managers, new_arg_supported, **kwargs)\u001b[0m\n\u001b[1;32m    512\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_generate_helper\u001b[39m(\n\u001b[1;32m    513\u001b[0m     \u001b[38;5;28mself\u001b[39m,\n\u001b[1;32m    514\u001b[0m     prompts: List[\u001b[38;5;28mstr\u001b[39m],\n\u001b[0;32m   (...)\u001b[0m\n\u001b[1;32m    518\u001b[0m     \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs: Any,\n\u001b[1;32m    519\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m LLMResult:\n\u001b[1;32m    520\u001b[0m     \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m    521\u001b[0m         output \u001b[38;5;241m=\u001b[39m (\n\u001b[0;32m--> 522\u001b[0m             \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_generate\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m    523\u001b[0m \u001b[43m                \u001b[49m\u001b[43mprompts\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m    524\u001b[0m \u001b[43m                \u001b[49m\u001b[43mstop\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstop\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m    525\u001b[0m \u001b[43m                \u001b[49m\u001b[38;5;66;43;03m# TODO: support multiple run managers\u001b[39;49;00m\n\u001b[1;32m    526\u001b[0m \u001b[43m                \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_managers\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mif\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mrun_managers\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01melse\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[1;32m    527\u001b[0m \u001b[43m                \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m    528\u001b[0m \u001b[43m            \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m    529\u001b[0m             \u001b[38;5;28;01mif\u001b[39;00m new_arg_supported\n\u001b[1;32m    530\u001b[0m             \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_generate(prompts, stop\u001b[38;5;241m=\u001b[39mstop)\n\u001b[1;32m    531\u001b[0m         )\n\u001b[1;32m    532\u001b[0m     \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mBaseException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[1;32m    533\u001b[0m         \u001b[38;5;28;01mfor\u001b[39;00m run_manager \u001b[38;5;129;01min\u001b[39;00m run_managers:\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/llms/base.py:1044\u001b[0m, in \u001b[0;36mLLM._generate\u001b[0;34m(self, prompts, stop, run_manager, **kwargs)\u001b[0m\n\u001b[1;32m   1041\u001b[0m new_arg_supported \u001b[38;5;241m=\u001b[39m inspect\u001b[38;5;241m.\u001b[39msignature(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_call)\u001b[38;5;241m.\u001b[39mparameters\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mrun_manager\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m   1042\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m prompt \u001b[38;5;129;01min\u001b[39;00m prompts:\n\u001b[1;32m   1043\u001b[0m     text \u001b[38;5;241m=\u001b[39m (\n\u001b[0;32m-> 1044\u001b[0m         \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_call\u001b[49m\u001b[43m(\u001b[49m\u001b[43mprompt\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstop\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstop\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrun_manager\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_manager\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m   1045\u001b[0m         \u001b[38;5;28;01mif\u001b[39;00m new_arg_supported\n\u001b[1;32m   1046\u001b[0m         \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_call(prompt, stop\u001b[38;5;241m=\u001b[39mstop, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[1;32m   1047\u001b[0m     )\n\u001b[1;32m   1048\u001b[0m     generations\u001b[38;5;241m.\u001b[39mappend([Generation(text\u001b[38;5;241m=\u001b[39mtext)])\n\u001b[1;32m   1049\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m LLMResult(generations\u001b[38;5;241m=\u001b[39mgenerations)\n",
      "File \u001b[0;32m~/anaconda3/envs/llama-demo-apps/lib/python3.8/site-packages/langchain/llms/replicate.py:138\u001b[0m, in \u001b[0;36mReplicate._call\u001b[0;34m(self, prompt, stop, run_manager, **kwargs)\u001b[0m\n\u001b[1;32m    136\u001b[0m prediction\u001b[38;5;241m.\u001b[39mwait()\n\u001b[1;32m    137\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m prediction\u001b[38;5;241m.\u001b[39mstatus \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mfailed\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n\u001b[0;32m--> 138\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mRuntimeError\u001b[39;00m(prediction\u001b[38;5;241m.\u001b[39merror)\n\u001b[1;32m    139\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(prediction\u001b[38;5;241m.\u001b[39moutput, \u001b[38;5;28mstr\u001b[39m):\n\u001b[1;32m    140\u001b[0m     completion \u001b[38;5;241m=\u001b[39m prediction\u001b[38;5;241m.\u001b[39moutput\n",
      "\u001b[0;31mRuntimeError\u001b[0m: Your input is too long. Max input length is 4096 tokens, but you supplied 5610 tokens."
     ]
    }
   ],
   "source": [
    "# to find how many calls to Llama have been made and the details of inputs and outputs of each call, set langchain to debug\n",
    "import langchain\n",
    "langchain.debug = True\n",
    "\n",
    "# stuff method will cause the error in the end\n",
    "chain = load_summarize_chain(llm, chain_type=\"stuff\")\n",
    "chain.run(split_docs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "60d1a531-ab48-45cc-a7de-59a14e18240d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[32;1m\u001b[1;3m[chain/start]\u001b[0m \u001b[1m[1:chain:RefineDocumentsChain] Entering Chain run with input:\n",
      "\u001b[0m[inputs]\n",
      "\u001b[32;1m\u001b[1;3m[chain/start]\u001b[0m \u001b[1m[1:chain:RefineDocumentsChain > 2:chain:LLMChain] Entering Chain run with input:\n",
      "\u001b[0m{\n",
      "  \"text\": \"so let's perhaps talk about each of these areas first deep learning that AI how the basic question how does a person interested in deep learning get started in the field the Atlanta AI is working to create courses to help people break into AI so my machine learning course that I taught through Stanford means one of the most popular causes on Coursera to this day it's probably one of the courses sort of if I ask somebody how did you get into machine learning or how did you fall in love with machine learning or will get you interested it always goes back to rain and you rang at some point you were employing the amount of people you influence is Ruchika so for that I'm sure I speak for a lot of people say big thank you know yeah thank you you know I was once reading a news article I think it was tech review and I'm gonna mess up the statistic but I remember reading article that said um something like one-third of all programmers are self-taught I may have the number one third Romney was two-thirds but I read that article I thought this doesn't make sense everyone is self-taught because you teach yourself I don't teach people and it's no good huh oh yeah so how does one get started in deep learning and word is deep learning that AI fit into that so the define specialization offered by today is is this I think one it was called service specialization it might still be so it's very popular way for people to take that specialization to learn about everything from new networks to how to tune in your network so what is it confident to what is a RNA nor sequence model or what is an attention model and so the design specialization um steps everyone's through those algorithms so you deeply understand it and can implement it and use it you know for whatever from the very beginning so what would you say the prerequisites for somebody to take the deep learning specialization in terms of maybe math or programming background you know need to understand basic programming since there are Pro exercises in Python and the map prereq is quite basic so no calculus is needed if you know calculus is great you get better intuitions but deliberately try to teach that specialization without requirement calculus so I think high school math would be sufficient if you know how to Mouse by two matrices I think I think that that deaths that desperates so little basically in your algebra it's great basically algebra even very very basically the algebra and some programming I think that people that done the machine learning also finds a deep learning specialization that bit easier but is also possible to jump into the divine specialization directly but it'll be a little bit harder since we tend to you know go over faster concepts like how does gradient descent work and what is an objective function which which is covered most lowly in the machine learning course could you briefly mention some of the key concepts in deep learning that students should learn that you envision them learning in the first few months in the first year or so so if you take the d-line specialization you learned foundations of what is in your network how do you build up in your network from you know single it's just a unit stack of layers to different activation functions you don't have a trained in your networks one thing I'm very proud of in that specialization is we go through a lot of practical know-how of how to actually make these things work so one of the differences between different optimization algorithms so what do you do the algorithm overfit so how do you tell the algorithm is overfitting when you collect more data when should you not bother to collect more data I find that some even today unfortunately there are your engineers that will spend six months trying to pursue a particular direction such as collect more data because we heard more data is valuable but sometimes you could run some tests and could have figured out six months earlier therefore this problem collecting more data isn't gonna cut it so just don't spend seconds collecting more data spend your time modifying the architecture or trying something also go through a lot of the practical know-how also that when when when when someone when you take the deviant specialization you have those skills to be very efficient in how you build is net so dive right in to play with the network to train it to do the inference on a particular data set to build an intuition about it without without building it up too big to where you spend like you said six months learning building up your big project without building any intuition of a small small aspect of the data that could already tell you everything needs you know about that date yes and also the systematic frameworks of thinking for how to go about building practical machine learning maybe to make an analogy um when we learn to code we have to learn the syntax of some very language right be a Python or C++ or octave or whatever but that equally important or maybe even more important part of coding is to understand how to string together these lines of code into coherent things so you know when should you put something in the function call and why should you not how do you think about abstraction so those frameworks are what makes a programmer efficient even more than understanding two syntax I remember when I was an undergrad at Carnegie Mellon um one of my friends would debug their codes by first trying to compile it and then it was sleepless code and then every line in the syntax error they want to give her the syntax errors as quickly as possible so how do you do that well they would delete every single line of code with a syntax so really efficient for general syntax errors were horrible service so I think so we learned how the debug and I think in machine learning the way you debug a machine learning program is very different than the way you you know like do binary search or whatever use a debugger I traced through the code in traditional software engineering so isn't evolving discipline but I find that the people that are really good at debugging machine learning algorithms are easily 10x maybe 100x faster at getting something to work so in a basic process the debugging is so the the bug in this case why is in this thing learning learning improving sort of going into the questions of overfitting and all those kinds of things that's that's the logical space that the debugging is happening in with neural network yeah the often question is why doesn't it work yet well can I expect it eventually work and what are the things I could try change the architecture malteaser more regularization different optimization algorithm you know different types of data are so to answer those questions systematically so that you don't heading down the so you don't spend six months hitting down a blind alley before someone comes and says why should you spend six months doing this what concepts in deep learning do you think students struggle the most with or sort of this is the biggest challenge for them was to get over that hill it's it hooks them and it inspires them and they really get it similar to learning mathematics I think one of the challenges of deep learning is that there are lot of concepts that build on top of each other if you ask me what's hard about mathematics I have a hard time pinpointing one thing is it addition subtraction is it carry is it multiplication law this is law stuff I think when the challenges of learning math and of learning certain technical fields is that a lot of concepts and you miss a concept then you're kind of missing the prerequisite for something that comes later so in the deep learning specialization try to break down the concepts to maximize the odds of you know each component being understandable so when you move on to the more advanced thing we learn your confidence hopefully you have enough intuitions from the earlier sections didn't understand why we structure confidence in a certain certain way and then eventually why we build you know our n ends and L STM's or attention more than a certain way building on top of the earlier concepts I'm curious you you you do a lot of teaching as well do you have a do you have a favorite this is the hard concept moment in your teaching well I don't think anyone's ever turned the interview on me I think that's a really good question yeah it's it's really hard to capture the moment when they struggle I think you put a really eloquently I do think there's moments that are like aha moments that really inspire people I think for some reason reinforcement learning especially deep reinforcement learning is a really great way to really inspire people and get what the use of neural networks can do even though you know networks really are just a part of the deep RL framework but it's a really nice way to the to paint the entirety of the picture of a neural network being able to learn from scratch knowing nothing and explore the world and pick up lessons I find that a lot of the aha moments happen when you use deep RL to teach people about neural networks which is counterintuitive I find like a lot of the inspired sort of fire and people's passion people's eyes is comes from the RL world do you find I mean first of all learning to be a useful part of the teaching process or not I still teach me forceful learning and one of my Stanford classes and my PhD thesis will endure for some writings thank you I find it if I'm trying to teach students the most useful techniques for them to use today I end up shrinking the amount of time and talk about reinforcement learning it's not what's working today now our world changes so fast maybe it does be totally different in a couple years I think we need a couple more things for reinforcement learning to get there if you get there yeah one of my teams is looking to reinforce the learning for some robotic control tasks so I see the applications but if you look at it as a percentage of all of the impact of you know the types of things we do is it's at least today outside of you know playing video games right in a few of the games the the scope I said numerous the bunch of us was standing around saying hey what's your best example of an actual deploy reinforcement learning application and you know among your like scene in machine learning researchers right and again there are some emerging but there are there are not that many great examples but I think you're absolutely right the sad thing is there hasn't been a big application impactful real-world application reinforcement learning I think its biggest impact to me has been in the toy domain in the game domain in a small example that's what I mean for educational purpose it seems to be a fun thing to explore new networks with but I think from your perspective and I think that might be the best perspective is if you're trying to educate with a simple example in order to illustrate how this can actually be grown to scale and have a real world impact then perhaps focusing on the fundamentals of supervised learning in the context of you know a simple data set even like an eminence data set is the right way is the right path to take I just the amount of fun I've seen people have with reinforcement learning it's been great but not in the applied impact on the real-world setting so it's a it's a trade-off how much impact you want to have versus how much fun you want to have yeah that's really cool and I feel like you know the world actually needs also even within machine learning I feel like deep learning is so exciting but the AI team shouldn't just use deep learning I find that my team's use a portfolio of tools and maybe that's not the exciting thing to say but some days we use internet some days we use a you know the PC a the other day are sitting down with my team looking at PC residuals trying to figure out what's going on with PC applied to manufacturing problem and sometimes we use the promising graphical models sometimes to use a knowledge trough where some of the things that has tremendous industry impact but the amount of chat about knowledge drops in academia has really thin compared to the actual rower impact so so I think reinforcement learning should be in that portfolio and then it's about balancing how much we teach all of these things and the world the world should have diverse skills if he said if you know everyone just learn one one narrow thing yeah the diverse skill help you discover the right tool for the job so if we could return to maybe talk quickly about the specifics of deep learning that AI the deep learning specialization perhaps how long does it take to complete the course would you say the official length of the divine specialization is I think 16 weeks so about 4 months but is go at your own pace so if you subscribe to the divine specialization there are people that finish that in less than a month by working more intensely and study more intensely so it really depends on on the individual who created the divine specialization we wanted to make it very accessible and very affordable and with you know Coursera and even higher education mission one of the things that's really important to me is that if there's someone for whom paying anything is a is a financial hardship then just apply for financial aid and get it for free if you were to recommend a daily schedule for people in learning whether it's through the deep learning that a a specialization or just learning in the world of deep learning what would you recommend how do they go about day 2 days or a specific advice about learning about their journey in the world of deep learning machine learning I think I'm getting the habit of learning is key and that means regularity so for example we send out our weekly newsletter the batch every Wednesday so people know it's coming Wednesday you can spend a little time on Wednesday catching up on the latest news through the batch on the on on on Wednesday and for myself I've picked up a habit of spending some time every Saturday and every Sunday reading or studying and so I don't wake up on a Saturday and have to make a decision do I feel like reading or studying today or not it's just it's just what I do and the fact is a habit makes it easier so I think if someone can get in that habit it's like you know just like we brush our teeth every morning I don't think about it if I thought about this a little bit annoying to have to spend two minutes doing that but it's a habit that it takes no cognitive loads but there's be so much harder if we have to make a decision every morning so and actually that's the reason why we're the same thing every day as well it's just one less decision I just get out in there where I'm sure so if I think you can get that habit that consistency of steady then that she feels easier so yeah it's kind of amazing in my own life like I play guitar every day for life forced myself to at least for five minutes play guitar it's it's a ridiculously short period of time but because I've gotten into that habit it's incredible what you can accomplish in a period of a year or two years you could become you know exceptionally good at certain aspects of a thing by just doing it everyday for a very short period of time it's kind of a miracle that that is how it works it's adds up over time yeah and I think is often not about the births of sustained efforts and the all-nighters because you can only\"\n",
      "}\n",
      "\u001b[32;1m\u001b[1;3m[llm/start]\u001b[0m \u001b[1m[1:chain:RefineDocumentsChain > 2:chain:LLMChain > 3:llm:Replicate] Entering LLM run with input:\n",
      "\u001b[0m{\n",
      "  \"prompts\": [\n",
      "    \"Write a concise summary of the following:\\n\\n\\n\\\"so let's perhaps talk about each of these areas first deep learning that AI how the basic question how does a person interested in deep learning get started in the field the Atlanta AI is working to create courses to help people break into AI so my machine learning course that I taught through Stanford means one of the most popular causes on Coursera to this day it's probably one of the courses sort of if I ask somebody how did you get into machine learning or how did you fall in love with machine learning or will get you interested it always goes back to rain and you rang at some point you were employing the amount of people you influence is Ruchika so for that I'm sure I speak for a lot of people say big thank you know yeah thank you you know I was once reading a news article I think it was tech review and I'm gonna mess up the statistic but I remember reading article that said um something like one-third of all programmers are self-taught I may have the number one third Romney was two-thirds but I read that article I thought this doesn't make sense everyone is self-taught because you teach yourself I don't teach people and it's no good huh oh yeah so how does one get started in deep learning and word is deep learning that AI fit into that so the define specialization offered by today is is this I think one it was called service specialization it might still be so it's very popular way for people to take that specialization to learn about everything from new networks to how to tune in your network so what is it confident to what is a RNA nor sequence model or what is an attention model and so the design specialization um steps everyone's through those algorithms so you deeply understand it and can implement it and use it you know for whatever from the very beginning so what would you say the prerequisites for somebody to take the deep learning specialization in terms of maybe math or programming background you know need to understand basic programming since there are Pro exercises in Python and the map prereq is quite basic so no calculus is needed if you know calculus is great you get better intuitions but deliberately try to teach that specialization without requirement calculus so I think high school math would be sufficient if you know how to Mouse by two matrices I think I think that that deaths that desperates so little basically in your algebra it's great basically algebra even very very basically the algebra and some programming I think that people that done the machine learning also finds a deep learning specialization that bit easier but is also possible to jump into the divine specialization directly but it'll be a little bit harder since we tend to you know go over faster concepts like how does gradient descent work and what is an objective function which which is covered most lowly in the machine learning course could you briefly mention some of the key concepts in deep learning that students should learn that you envision them learning in the first few months in the first year or so so if you take the d-line specialization you learned foundations of what is in your network how do you build up in your network from you know single it's just a unit stack of layers to different activation functions you don't have a trained in your networks one thing I'm very proud of in that specialization is we go through a lot of practical know-how of how to actually make these things work so one of the differences between different optimization algorithms so what do you do the algorithm overfit so how do you tell the algorithm is overfitting when you collect more data when should you not bother to collect more data I find that some even today unfortunately there are your engineers that will spend six months trying to pursue a particular direction such as collect more data because we heard more data is valuable but sometimes you could run some tests and could have figured out six months earlier therefore this problem collecting more data isn't gonna cut it so just don't spend seconds collecting more data spend your time modifying the architecture or trying something also go through a lot of the practical know-how also that when when when when someone when you take the deviant specialization you have those skills to be very efficient in how you build is net so dive right in to play with the network to train it to do the inference on a particular data set to build an intuition about it without without building it up too big to where you spend like you said six months learning building up your big project without building any intuition of a small small aspect of the data that could already tell you everything needs you know about that date yes and also the systematic frameworks of thinking for how to go about building practical machine learning maybe to make an analogy um when we learn to code we have to learn the syntax of some very language right be a Python or C++ or octave or whatever but that equally important or maybe even more important part of coding is to understand how to string together these lines of code into coherent things so you know when should you put something in the function call and why should you not how do you think about abstraction so those frameworks are what makes a programmer efficient even more than understanding two syntax I remember when I was an undergrad at Carnegie Mellon um one of my friends would debug their codes by first trying to compile it and then it was sleepless code and then every line in the syntax error they want to give her the syntax errors as quickly as possible so how do you do that well they would delete every single line of code with a syntax so really efficient for general syntax errors were horrible service so I think so we learned how the debug and I think in machine learning the way you debug a machine learning program is very different than the way you you know like do binary search or whatever use a debugger I traced through the code in traditional software engineering so isn't evolving discipline but I find that the people that are really good at debugging machine learning algorithms are easily 10x maybe 100x faster at getting something to work so in a basic process the debugging is so the the bug in this case why is in this thing learning learning improving sort of going into the questions of overfitting and all those kinds of things that's that's the logical space that the debugging is happening in with neural network yeah the often question is why doesn't it work yet well can I expect it eventually work and what are the things I could try change the architecture malteaser more regularization different optimization algorithm you know different types of data are so to answer those questions systematically so that you don't heading down the so you don't spend six months hitting down a blind alley before someone comes and says why should you spend six months doing this what concepts in deep learning do you think students struggle the most with or sort of this is the biggest challenge for them was to get over that hill it's it hooks them and it inspires them and they really get it similar to learning mathematics I think one of the challenges of deep learning is that there are lot of concepts that build on top of each other if you ask me what's hard about mathematics I have a hard time pinpointing one thing is it addition subtraction is it carry is it multiplication law this is law stuff I think when the challenges of learning math and of learning certain technical fields is that a lot of concepts and you miss a concept then you're kind of missing the prerequisite for something that comes later so in the deep learning specialization try to break down the concepts to maximize the odds of you know each component being understandable so when you move on to the more advanced thing we learn your confidence hopefully you have enough intuitions from the earlier sections didn't understand why we structure confidence in a certain certain way and then eventually why we build you know our n ends and L STM's or attention more than a certain way building on top of the earlier concepts I'm curious you you you do a lot of teaching as well do you have a do you have a favorite this is the hard concept moment in your teaching well I don't think anyone's ever turned the interview on me I think that's a really good question yeah it's it's really hard to capture the moment when they struggle I think you put a really eloquently I do think there's moments that are like aha moments that really inspire people I think for some reason reinforcement learning especially deep reinforcement learning is a really great way to really inspire people and get what the use of neural networks can do even though you know networks really are just a part of the deep RL framework but it's a really nice way to the to paint the entirety of the picture of a neural network being able to learn from scratch knowing nothing and explore the world and pick up lessons I find that a lot of the aha moments happen when you use deep RL to teach people about neural networks which is counterintuitive I find like a lot of the inspired sort of fire and people's passion people's eyes is comes from the RL world do you find I mean first of all learning to be a useful part of the teaching process or not I still teach me forceful learning and one of my Stanford classes and my PhD thesis will endure for some writings thank you I find it if I'm trying to teach students the most useful techniques for them to use today I end up shrinking the amount of time and talk about reinforcement learning it's not what's working today now our world changes so fast maybe it does be totally different in a couple years I think we need a couple more things for reinforcement learning to get there if you get there yeah one of my teams is looking to reinforce the learning for some robotic control tasks so I see the applications but if you look at it as a percentage of all of the impact of you know the types of things we do is it's at least today outside of you know playing video games right in a few of the games the the scope I said numerous the bunch of us was standing around saying hey what's your best example of an actual deploy reinforcement learning application and you know among your like scene in machine learning researchers right and again there are some emerging but there are there are not that many great examples but I think you're absolutely right the sad thing is there hasn't been a big application impactful real-world application reinforcement learning I think its biggest impact to me has been in the toy domain in the game domain in a small example that's what I mean for educational purpose it seems to be a fun thing to explore new networks with but I think from your perspective and I think that might be the best perspective is if you're trying to educate with a simple example in order to illustrate how this can actually be grown to scale and have a real world impact then perhaps focusing on the fundamentals of supervised learning in the context of you know a simple data set even like an eminence data set is the right way is the right path to take I just the amount of fun I've seen people have with reinforcement learning it's been great but not in the applied impact on the real-world setting so it's a it's a trade-off how much impact you want to have versus how much fun you want to have yeah that's really cool and I feel like you know the world actually needs also even within machine learning I feel like deep learning is so exciting but the AI team shouldn't just use deep learning I find that my team's use a portfolio of tools and maybe that's not the exciting thing to say but some days we use internet some days we use a you know the PC a the other day are sitting down with my team looking at PC residuals trying to figure out what's going on with PC applied to manufacturing problem and sometimes we use the promising graphical models sometimes to use a knowledge trough where some of the things that has tremendous industry impact but the amount of chat about knowledge drops in academia has really thin compared to the actual rower impact so so I think reinforcement learning should be in that portfolio and then it's about balancing how much we teach all of these things and the world the world should have diverse skills if he said if you know everyone just learn one one narrow thing yeah the diverse skill help you discover the right tool for the job so if we could return to maybe talk quickly about the specifics of deep learning that AI the deep learning specialization perhaps how long does it take to complete the course would you say the official length of the divine specialization is I think 16 weeks so about 4 months but is go at your own pace so if you subscribe to the divine specialization there are people that finish that in less than a month by working more intensely and study more intensely so it really depends on on the individual who created the divine specialization we wanted to make it very accessible and very affordable and with you know Coursera and even higher education mission one of the things that's really important to me is that if there's someone for whom paying anything is a is a financial hardship then just apply for financial aid and get it for free if you were to recommend a daily schedule for people in learning whether it's through the deep learning that a a specialization or just learning in the world of deep learning what would you recommend how do they go about day 2 days or a specific advice about learning about their journey in the world of deep learning machine learning I think I'm getting the habit of learning is key and that means regularity so for example we send out our weekly newsletter the batch every Wednesday so people know it's coming Wednesday you can spend a little time on Wednesday catching up on the latest news through the batch on the on on on Wednesday and for myself I've picked up a habit of spending some time every Saturday and every Sunday reading or studying and so I don't wake up on a Saturday and have to make a decision do I feel like reading or studying today or not it's just it's just what I do and the fact is a habit makes it easier so I think if someone can get in that habit it's like you know just like we brush our teeth every morning I don't think about it if I thought about this a little bit annoying to have to spend two minutes doing that but it's a habit that it takes no cognitive loads but there's be so much harder if we have to make a decision every morning so and actually that's the reason why we're the same thing every day as well it's just one less decision I just get out in there where I'm sure so if I think you can get that habit that consistency of steady then that she feels easier so yeah it's kind of amazing in my own life like I play guitar every day for life forced myself to at least for five minutes play guitar it's it's a ridiculously short period of time but because I've gotten into that habit it's incredible what you can accomplish in a period of a year or two years you could become you know exceptionally good at certain aspects of a thing by just doing it everyday for a very short period of time it's kind of a miracle that that is how it works it's adds up over time yeah and I think is often not about the births of sustained efforts and the all-nighters because you can only\\\"\\n\\n\\nCONCISE SUMMARY:\"\n",
      "  ]\n",
      "}\n",
      "\u001b[36;1m\u001b[1;3m[llm/end]\u001b[0m \u001b[1m[1:chain:RefineDocumentsChain > 2:chain:LLMChain > 3:llm:Replicate] [8.93s] Exiting LLM run with output:\n",
      "\u001b[0m{\n",
      "  \"generations\": [\n",
      "    [\n",
      "      {\n",
      "        \"text\": \" Sure! Here is a concise summary of the text:\\n\\nAndrew Ng, co-founder of Coursera, discusses deep learning and AI. He emphasizes the importance of understanding the basics of machine learning before diving into deep learning. He also highlights the challenges students face when learning deep learning, such as struggling with concepts and overfitting. To overcome these challenges, he suggests breaking down complex topics into smaller, more manageable parts and using practical projects to build intuition. Additionally, he recommends a diverse skill set and encourages learners to apply financial aid if necessary\",\n",
      "        \"generation_info\": null\n",
      "      }\n",
      "    ]\n",
      "  ],\n",
      "  \"llm_output\": null,\n",
      "  \"run\": null\n",
      "}\n",
      "\u001b[36;1m\u001b[1;3m[chain/end]\u001b[0m \u001b[1m[1:chain:RefineDocumentsChain > 2:chain:LLMChain] [8.93s] Exiting Chain run with output:\n",
      "\u001b[0m{\n",
      "  \"text\": \" Sure! Here is a concise summary of the text:\\n\\nAndrew Ng, co-founder of Coursera, discusses deep learning and AI. He emphasizes the importance of understanding the basics of machine learning before diving into deep learning. He also highlights the challenges students face when learning deep learning, such as struggling with concepts and overfitting. To overcome these challenges, he suggests breaking down complex topics into smaller, more manageable parts and using practical projects to build intuition. Additionally, he recommends a diverse skill set and encourages learners to apply financial aid if necessary\"\n",
      "}\n",
      "\u001b[32;1m\u001b[1;3m[chain/start]\u001b[0m \u001b[1m[1:chain:RefineDocumentsChain > 4:chain:LLMChain] Entering Chain run with input:\n",
      "\u001b[0m{\n",
      "  \"text\": \"do that in a limited number of times it's the sustained effort over a long time I think you know reading two research papers there's a nice thing to do but the power is not reading two research papers this meeting through research papers a week for a year then you've read a hundred papers and you actually learn a lot we read a hundred papers so regularity and making learning a habit give do you have general other study tips for particularly deep learning that people should in in their process of learning is there some kind of recommendations or tips you have as they learn one thing I still do when I'm trying to study something really deeply is take handwritten notes it varies I know there are a lot of people that take the deep learning courses during a commutes or something where may be more awkward to take notes so I know it's may not work for everyone but when I'm taking courses on Coursera you know and that still takes someone every now and then the most recent I took was a was a course on clinical trials because interest about that I call up my little moleskin notebook and I was sitting at my desk is just taking down notes so what the instructor was saying and that act we know that that act of taking notes preferably handwritten notes increases retention so as you're sort of watching the video just kind of pausing maybe and then taking the basic insights down on paper yeah so I should have been a few studies if you know search online you find some of these studies that taking handwritten notes because handwriting is slower as we're saying just now it causes you to recode the knowledge in your own words more and that process of recoding promotes long-term attention this is as opposed to typing which is fine again typing is better than nothing or in taking a class and not the canals is better than nothing any cause law but comparing handwritten notes and typing you can usually type faster for a lot of people you can hand write notes and so when people type they're more likely to transcribe verbatim what they heard and that reduces the amount of recoding and that actually results in less long-term retention I don't know what the psychological effect there is but so true there's something fundamentally different about writing hand handwriting I wonder what that is I wonder if it is as simple as just the time it takes to write is slower yeah and and and because because you can't write as many words you have to take whatever they said and summarize it into fewer words and that summarization process requires deeper processing of the meaning which then results in better attention that's fascinating oh and then I spent I think yeah because the Coursera spent so much time studying in pedagogy is that human passions I really love learning how to more efficiently help others learn yeah one of the things I do both in creating videos or when we write the batch is I try to think is one minute spent of us going to be a more efficient learning experience than one minute spent anywhere else and we really try to you know make a time efficient for the learning it's good to know everyone's busy so when when we're editing them I often tell my teams everywhere it needs to fight for his life and if can delete awareness easily to then not wait let's not waste than during this time wow that's so it's so amazing that you think that way because there is millions of people that are impacted by your teaching and sort of that one minute spent has a ripple effect right through years of time which is just fascinating talk about how does one make a career out of an interest in deep learning give advice for people we just talked about sort of the beginning early steps but if you want to make it at entire life's journey or at least a journey of a decade or two how did it how do you do it so most important thing is to get started right and ever I think in the early parts of a career coursework like the deviant specialization or it's a very efficient way to master this material so because you know instructors be it me or someone else or you know Laurence Moroney teaches on tensor field specialization and other things were working on spend effort to try to make a time efficient for you to learn new concepts so coursework is actually a very efficient way for people that learn concepts and the becoming parts of break into new fields in fact one thing I see at Stanford some of my PhD students want to jump in the research right away and actually tend to say look when you first come for us the peer student spend time taking courses because it lays the foundation it's fine if you're less productive in your first couple of years you'd be better off in the long term um beyond a certain point there's materials that doesn't exist in courses because it's too cutting edge the courses we created yeah there's some practical experience that we're not yet that good as teaching in a in a course the thing after exhausting the efficient course were then most people need to go on to either ideally work on projects and then maybe also continue their learning by reading blog polls and research papers and things like that um doing practice is really important and again I think is important to start spawns just do something today you read about deep learning if you say all these people doing such exciting things what about not building a neural network they change the world and what's the point well the point is sometimes building that time in your network you know be it m-miss or upgrade to a fashion em this to whatever doing your own fun hobby project that's how you gain the skills to let you do bigger and bigger projects I find this to be true at the individual level and also at the organizational level for a company to become clear that machine learning sometimes the right thing to do is not tackle the giant project is instead to do the small project that lets the organization learn and then build up from there but just true both for individuals and and for and for companies to taking the first step and then taking small steps is the key should students pursue a PhD do you think you can do so much that's the one of the fascinating things in machine learning you can have so much impact without ever getting a PhD so what are your thoughts should people go to grad school should people get a PhD I think that there are multiple good options of which doing a PhD could be one of them I think that if someone's admitted to a top ph.d program you know that MIT Stanford top schools I think that's a very good experience or someone gets a job at a top organization at the top of AI team I think that's also very good experience there are some things you still need a PhD to do if someone's aspiration is to be a professor here at the top academic University you just need a piece you do that but if it goes to you know start a completely build a company to create technical work I think a PhD is a good experience but I would look at the different options available to someone you know where the places where you can get a job where the place isn't getting a ph.d program and kind of weigh the pros and cons of those so just to linger on that for a little bit longer what final dreams and goals do you think people should have so the what options for they explore so you can work in industry so for a large company like Google Facebook buy do all these large companies already have huge teams of machine learning engineers you can also do with an industry sort of more research groups that kind of like Google research Google brain then you can also do like we say the professor neck as in academia and what else oh you can still build your own company you can do a start-up is there anything that stands out between those options or are they all beautiful different journeys that people should consider I think the thing that affects your experience more is less are you in discomfort versus that company your academia versus industry I think the thing that affects to experience Moses who are the people you're interacting with you know in a daily basis so even if you look at some of the large companies the experience of individuals and and he was very different and what matters most is not the logo above the door when you walk into the giant building every day what matters and Moses who are the 10 people who are the 30 people you interact with every day so I should tend to advise people if you get a job from from a company also who is your manager who are your peers who actually talk to you we're all social creatures we tend to you know become more like the people around us and if you're working with great people you will learn faster or if you get admitted if you get a job and a great company or a great university maybe the logo you walking know is great but you're actually stuck on some team doing really worth it doesn't excite you and then that's actually really bad experience so this is true both for universities and for large companies for small companies you can kind of figure out who you work quite quickly and I tend to advise people if a company refuses to tell you who you work with sometimes say Oh join us the rotation system will figure out I think that that that's a worrying answer because it because it means you may not get sense to you mean not actually get to team with with great peers and great people to work with it's actually really profound advice that we kind of sometimes sweep we don't consider to rigorously or carefully the people around you are really often this especially when you accomplish great things it seems the great things are accomplished because of the people around you so that that's a it's not about the the worry whether you learn this thing or that thing or like you said the logo that hangs up top it's the people that's a fascinating and it's such a hard search process of finding just like finding the right friends and somebody to get married with and that kind of thing it's a very hard search process of people search problem yeah but I think when someone interviews you know at a university or the research lab at a large corporation it's good to insist on just asking who are the people who is my manager and if you refuse to tell me I'm gonna think well maybe that's because you don't have a good answer it may not be someone I like and if you don't particularly connect if something feels off for the people then don't - you know that's a really important signal to consider yeah and actually I am in my standard cause cs2 30s was an ACN talk I think I gave like a hour long talk on career advice including on the job search process and then some of these cells of yours if you can find those videos on the oscillator pointers I'll point people to them beautiful you\",\n",
      "  \"existing_answer\": \" Sure! Here is a concise summary of the text:\\n\\nAndrew Ng, co-founder of Coursera, discusses deep learning and AI. He emphasizes the importance of understanding the basics of machine learning before diving into deep learning. He also highlights the challenges students face when learning deep learning, such as struggling with concepts and overfitting. To overcome these challenges, he suggests breaking down complex topics into smaller, more manageable parts and using practical projects to build intuition. Additionally, he recommends a diverse skill set and encourages learners to apply financial aid if necessary\"\n",
      "}\n",
      "\u001b[32;1m\u001b[1;3m[llm/start]\u001b[0m \u001b[1m[1:chain:RefineDocumentsChain > 4:chain:LLMChain > 5:llm:Replicate] Entering LLM run with input:\n",
      "\u001b[0m{\n",
      "  \"prompts\": [\n",
      "    \"Your job is to produce a final summary.\\nWe have provided an existing summary up to a certain point:  Sure! Here is a concise summary of the text:\\n\\nAndrew Ng, co-founder of Coursera, discusses deep learning and AI. He emphasizes the importance of understanding the basics of machine learning before diving into deep learning. He also highlights the challenges students face when learning deep learning, such as struggling with concepts and overfitting. To overcome these challenges, he suggests breaking down complex topics into smaller, more manageable parts and using practical projects to build intuition. Additionally, he recommends a diverse skill set and encourages learners to apply financial aid if necessary\\nWe have the opportunity to refine the existing summary (only if needed) with some more context below.\\n------------\\ndo that in a limited number of times it's the sustained effort over a long time I think you know reading two research papers there's a nice thing to do but the power is not reading two research papers this meeting through research papers a week for a year then you've read a hundred papers and you actually learn a lot we read a hundred papers so regularity and making learning a habit give do you have general other study tips for particularly deep learning that people should in in their process of learning is there some kind of recommendations or tips you have as they learn one thing I still do when I'm trying to study something really deeply is take handwritten notes it varies I know there are a lot of people that take the deep learning courses during a commutes or something where may be more awkward to take notes so I know it's may not work for everyone but when I'm taking courses on Coursera you know and that still takes someone every now and then the most recent I took was a was a course on clinical trials because interest about that I call up my little moleskin notebook and I was sitting at my desk is just taking down notes so what the instructor was saying and that act we know that that act of taking notes preferably handwritten notes increases retention so as you're sort of watching the video just kind of pausing maybe and then taking the basic insights down on paper yeah so I should have been a few studies if you know search online you find some of these studies that taking handwritten notes because handwriting is slower as we're saying just now it causes you to recode the knowledge in your own words more and that process of recoding promotes long-term attention this is as opposed to typing which is fine again typing is better than nothing or in taking a class and not the canals is better than nothing any cause law but comparing handwritten notes and typing you can usually type faster for a lot of people you can hand write notes and so when people type they're more likely to transcribe verbatim what they heard and that reduces the amount of recoding and that actually results in less long-term retention I don't know what the psychological effect there is but so true there's something fundamentally different about writing hand handwriting I wonder what that is I wonder if it is as simple as just the time it takes to write is slower yeah and and and because because you can't write as many words you have to take whatever they said and summarize it into fewer words and that summarization process requires deeper processing of the meaning which then results in better attention that's fascinating oh and then I spent I think yeah because the Coursera spent so much time studying in pedagogy is that human passions I really love learning how to more efficiently help others learn yeah one of the things I do both in creating videos or when we write the batch is I try to think is one minute spent of us going to be a more efficient learning experience than one minute spent anywhere else and we really try to you know make a time efficient for the learning it's good to know everyone's busy so when when we're editing them I often tell my teams everywhere it needs to fight for his life and if can delete awareness easily to then not wait let's not waste than during this time wow that's so it's so amazing that you think that way because there is millions of people that are impacted by your teaching and sort of that one minute spent has a ripple effect right through years of time which is just fascinating talk about how does one make a career out of an interest in deep learning give advice for people we just talked about sort of the beginning early steps but if you want to make it at entire life's journey or at least a journey of a decade or two how did it how do you do it so most important thing is to get started right and ever I think in the early parts of a career coursework like the deviant specialization or it's a very efficient way to master this material so because you know instructors be it me or someone else or you know Laurence Moroney teaches on tensor field specialization and other things were working on spend effort to try to make a time efficient for you to learn new concepts so coursework is actually a very efficient way for people that learn concepts and the becoming parts of break into new fields in fact one thing I see at Stanford some of my PhD students want to jump in the research right away and actually tend to say look when you first come for us the peer student spend time taking courses because it lays the foundation it's fine if you're less productive in your first couple of years you'd be better off in the long term um beyond a certain point there's materials that doesn't exist in courses because it's too cutting edge the courses we created yeah there's some practical experience that we're not yet that good as teaching in a in a course the thing after exhausting the efficient course were then most people need to go on to either ideally work on projects and then maybe also continue their learning by reading blog polls and research papers and things like that um doing practice is really important and again I think is important to start spawns just do something today you read about deep learning if you say all these people doing such exciting things what about not building a neural network they change the world and what's the point well the point is sometimes building that time in your network you know be it m-miss or upgrade to a fashion em this to whatever doing your own fun hobby project that's how you gain the skills to let you do bigger and bigger projects I find this to be true at the individual level and also at the organizational level for a company to become clear that machine learning sometimes the right thing to do is not tackle the giant project is instead to do the small project that lets the organization learn and then build up from there but just true both for individuals and and for and for companies to taking the first step and then taking small steps is the key should students pursue a PhD do you think you can do so much that's the one of the fascinating things in machine learning you can have so much impact without ever getting a PhD so what are your thoughts should people go to grad school should people get a PhD I think that there are multiple good options of which doing a PhD could be one of them I think that if someone's admitted to a top ph.d program you know that MIT Stanford top schools I think that's a very good experience or someone gets a job at a top organization at the top of AI team I think that's also very good experience there are some things you still need a PhD to do if someone's aspiration is to be a professor here at the top academic University you just need a piece you do that but if it goes to you know start a completely build a company to create technical work I think a PhD is a good experience but I would look at the different options available to someone you know where the places where you can get a job where the place isn't getting a ph.d program and kind of weigh the pros and cons of those so just to linger on that for a little bit longer what final dreams and goals do you think people should have so the what options for they explore so you can work in industry so for a large company like Google Facebook buy do all these large companies already have huge teams of machine learning engineers you can also do with an industry sort of more research groups that kind of like Google research Google brain then you can also do like we say the professor neck as in academia and what else oh you can still build your own company you can do a start-up is there anything that stands out between those options or are they all beautiful different journeys that people should consider I think the thing that affects your experience more is less are you in discomfort versus that company your academia versus industry I think the thing that affects to experience Moses who are the people you're interacting with you know in a daily basis so even if you look at some of the large companies the experience of individuals and and he was very different and what matters most is not the logo above the door when you walk into the giant building every day what matters and Moses who are the 10 people who are the 30 people you interact with every day so I should tend to advise people if you get a job from from a company also who is your manager who are your peers who actually talk to you we're all social creatures we tend to you know become more like the people around us and if you're working with great people you will learn faster or if you get admitted if you get a job and a great company or a great university maybe the logo you walking know is great but you're actually stuck on some team doing really worth it doesn't excite you and then that's actually really bad experience so this is true both for universities and for large companies for small companies you can kind of figure out who you work quite quickly and I tend to advise people if a company refuses to tell you who you work with sometimes say Oh join us the rotation system will figure out I think that that that's a worrying answer because it because it means you may not get sense to you mean not actually get to team with with great peers and great people to work with it's actually really profound advice that we kind of sometimes sweep we don't consider to rigorously or carefully the people around you are really often this especially when you accomplish great things it seems the great things are accomplished because of the people around you so that that's a it's not about the the worry whether you learn this thing or that thing or like you said the logo that hangs up top it's the people that's a fascinating and it's such a hard search process of finding just like finding the right friends and somebody to get married with and that kind of thing it's a very hard search process of people search problem yeah but I think when someone interviews you know at a university or the research lab at a large corporation it's good to insist on just asking who are the people who is my manager and if you refuse to tell me I'm gonna think well maybe that's because you don't have a good answer it may not be someone I like and if you don't particularly connect if something feels off for the people then don't - you know that's a really important signal to consider yeah and actually I am in my standard cause cs2 30s was an ACN talk I think I gave like a hour long talk on career advice including on the job search process and then some of these cells of yours if you can find those videos on the oscillator pointers I'll point people to them beautiful you\\n------------\\nGiven the new context, refine the original summary.\\nIf the context isn't useful, return the original summary.\"\n",
      "  ]\n",
      "}\n",
      "\u001b[36;1m\u001b[1;3m[llm/end]\u001b[0m \u001b[1m[1:chain:RefineDocumentsChain > 4:chain:LLMChain > 5:llm:Replicate] [3.97s] Exiting LLM run with output:\n",
      "\u001b[0m{\n",
      "  \"generations\": [\n",
      "    [\n",
      "      {\n",
      "        \"text\": \" Sure! Here is a revised version of the summary based on the additional information provided:\\n\\nAndrew Ng, co-founder of Coursera, discusses deep learning and AI. He emphasizes the importance of understanding the basics of machine learning before diving into deep learning. He also highlights the challenges students face when learning deep learning, such as struggling with concepts and overfitting. To overcome these challenges, he suggests breaking down complex topics into smaller, more manageable parts and using practical projects to build intuition. Additionally, he recommends a diverse skill set and encourages learners\",\n",
      "        \"generation_info\": null\n",
      "      }\n",
      "    ]\n",
      "  ],\n",
      "  \"llm_output\": null,\n",
      "  \"run\": null\n",
      "}\n",
      "\u001b[36;1m\u001b[1;3m[chain/end]\u001b[0m \u001b[1m[1:chain:RefineDocumentsChain > 4:chain:LLMChain] [3.98s] Exiting Chain run with output:\n",
      "\u001b[0m{\n",
      "  \"text\": \" Sure! Here is a revised version of the summary based on the additional information provided:\\n\\nAndrew Ng, co-founder of Coursera, discusses deep learning and AI. He emphasizes the importance of understanding the basics of machine learning before diving into deep learning. He also highlights the challenges students face when learning deep learning, such as struggling with concepts and overfitting. To overcome these challenges, he suggests breaking down complex topics into smaller, more manageable parts and using practical projects to build intuition. Additionally, he recommends a diverse skill set and encourages learners\"\n",
      "}\n",
      "\u001b[36;1m\u001b[1;3m[chain/end]\u001b[0m \u001b[1m[1:chain:RefineDocumentsChain] [12.91s] Exiting Chain run with output:\n",
      "\u001b[0m{\n",
      "  \"output_text\": \" Sure! Here is a revised version of the summary based on the additional information provided:\\n\\nAndrew Ng, co-founder of Coursera, discusses deep learning and AI. He emphasizes the importance of understanding the basics of machine learning before diving into deep learning. He also highlights the challenges students face when learning deep learning, such as struggling with concepts and overfitting. To overcome these challenges, he suggests breaking down complex topics into smaller, more manageable parts and using practical projects to build intuition. Additionally, he recommends a diverse skill set and encourages learners\"\n",
      "}\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "' Sure! Here is a revised version of the summary based on the additional information provided:\\n\\nAndrew Ng, co-founder of Coursera, discusses deep learning and AI. He emphasizes the importance of understanding the basics of machine learning before diving into deep learning. He also highlights the challenges students face when learning deep learning, such as struggling with concepts and overfitting. To overcome these challenges, he suggests breaking down complex topics into smaller, more manageable parts and using practical projects to build intuition. Additionally, he recommends a diverse skill set and encourages learners'"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# but refine works\n",
    "chain = load_summarize_chain(llm, chain_type=\"refine\")\n",
    "chain.run(split_docs)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "61ccd0fb-5cdb-43c4-afaf-05bc9f7cf959",
   "metadata": {},
   "source": [
    "\n",
    "As you can see, `stuff` fails because it tries to treat all the split documents as one and \"stuffs\" it into one prompt which leads to a much larger prompt than Llama 2 can handle while `refine` iteratively runs over the documents updating its answer as it goes."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.18"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
