Step BACK Prompt "Engineering"

1littlecoder · Advanced ·🧠 Large Language Models ·2y ago

Key Takeaways

The video demonstrates the Step Back Prompting technique developed by Google DeepMind for abstraction and reasoning in large language models, utilizing tools such as Lang Chain, Open AI API, and Dr. Go Search API to improve the performance of Retrieval Augmented Generation (RAG) in answering questions.

Full Transcript

we're going to learn a completely new prompt engineering technique that is called stepb back promting developed by Google Deep Mind we're going to quickly learn what is this technique and then we're going to use a cookbook that is been put out by Lang chain and we're going to see a live demo of how you can use step back prompting to improve your rag retrieval retrieval augmented generation let's get started the first thing is we have got a new paper called step back prompting or take a step back evoking reasoning why abstraction in large language models technique is a very simple approach the approach is you have a original question and whenever you have a original question the first step is abstraction and in abstraction you ask the llm to create a step back question something that is higher level so for example if you have got a question that says what happens to pressure B blah blah blah blah blah then you just simply create a step back question that says what are the physics principles behind this question this the first step once you have the step back question ready then you use the step back question as an abstraction guided answer so you use that and create a step back answer and that is what is going to be used as reasoning to create the final answer let's look at another example if you have got a original question that says Estella neopol went to which school between August 1954 and November 1954 then you create a step back question that says what was Estella Leopold's education history and that creates a step back answer and from that you do reasoning to create the final answer it is all the algorithms let's quickly go ahead and then see a very quick demo before we actually do the handson this is a cookbook that has been put out by the L chain team and if you see in this question the question that they are asking is was chat GPT around while Trump was President this is the question was CH GPT around while Trump was president and for this question if you ask this question normally like the Baseline it would say yes chb was around while Donald Trump was president in fact you can see from this paper even Chain of Thought could not answer these questions without step back prompting so if you go back to this demo that they have put together so the Baseline Baseline is it says yes chat gbd was ared while Donald Trump was President while that is not true CHP was launched on November 2022 When Donald Trump was not the US president so how do you manage to do it it actually creates a step back question this is the base question and then from that it creates a step back question that says when was chat GPT developed then you use the Dr go search API rapper to get the information from the internet for both the question and also the question gen which is basically the step back question and you use both the knowledge to create the step back chain that will finally give you the right answer that says no chat GPD was not around while Donald Trump was President chat GPD was launched on November 30222 which is after Donald Trump's presidency as you can see that this question has been rightly answered using rag the retrieval augmented generation from the Internet thanks to the step back prompting let's go look at the Google app notebook to do handshot step by step the first thing if you're doing it on local machine you might already have the open AI AP configured if you do not have you can use this piece of code to configure your open a AP key in your OS environment path once you do that then you need to install four different libraries open AI of course to use open AA model line chain for you to use this entire PL chain duck go search for us to do retrieval augmented generation using internet and L chain hub for us to get the step back prompting prompt chain from the Lang chain Hub or the lsmith as you can see here you can directly get this into your own Lang chain workflow once you have all these things installed ready the next thing that you have to do is you have to import the required particular libraries and the classes from line chain. chat models import chat open AI this is the main the chat model that you're going to use and then you import the prop temp plate and other aspects then you need to also create the few short prompts for it to understand how to create the step back prompts or the step back examples so you use a few short chat message template to do that and then couple of other you know utility functions the first thing that you need to do is you need to give the examples okay whenever you ask a question like this could the members of the police perform lawful arrest then you create a step back question how does a step back question look like for this input the step back question should be slightly higher level slightly an abstraction what can the members of the police do that's the abstraction the higher level question for another question for example input Jan syles or Yan syles was born in what country whenever you have a question like this you tell the llm to create a step back question that sounds like this what is Yan syndel or Jan syndel personal history so when you give these examples then you turn them into the few short example prompt so you use chat prompt template from messages human the input the input that we just saw and the output from Ai and you use this as a few short prompt that can go inside the prompt template in itself then you create the chat prom template from messages the system prom the Bas basic thing like you are an exported World blah blah blah blah and then you have the few short prompt and then the user and the question so this way the large language model knows that whenever question like this is being asked it has to generate an answer like this and then that goes inside this question gen so it the prompt is there and you specify you know the chat GPT or chat open AI with temperature zero and then the final output partiel so once you send that I'll create the question engine for example for a question that says was GPT 4 around while Trump was pred that is a question that we are sending it to it and then we use question gen. invoke to take this question and create this output and once you have this particular output then you use from Lang chain utilities import d. go search APA rapper to go to the Internet and get the answer so you first use the retriever on question then you use the retriever on question gen inw which is going to be what is the timeline of gbd4 existence which is the step back question and then finally you're going to import or pull the step back answer from the L chain Hub and then you create a chain you have got the normal context then you have got the step back context and then you have got the question in itself and you get the response wrong with chbt API and then finally print the output and once you invoke the chain with the question it says no gbd4 was not around while Donald Trump was President according to the provided context the gbd4 was launched on November 30 2022 which is after the time period when Donald Trump was the president of United States and the Baseline is it just says that it cannot provide any information so let me quickly go over the court before I give you a quick demo so import all the required libraries like in this case Lang chain and different glass process create the few short examples of how it should generate the step back question once you have that then that is mainly what you're going to do for a given question what should be the step back question and then use whatever R technique that you have got to get the answer for both the question and also the step back question and then use that in a chain with the step back logic you have got the normal context you've got the step back context and then you have got the question so you're going to retrieve for the normal context retrieve for the step back context and then you're going to get the actual question you're going to send it and once you invoke it you're going to get the right answer so let's go ahead and then ask a different question now instead of this so I going to ask was something like this was um let me ask new question P at laa model laa multimodel model was lava multimodel model around while Donald Trump was was a president we all know that laa was recently launched and would ask the same question again and let's see what it says okay it created a step back question that says what is the timeline of laa multimodel models existence use duck du go search APA raer retrieve the answer for the question we going to ask it to create for the step back question once it is done then you can go here pull the step back answer from the long chain Hub or lsmith and then create the normal context chain the the chain that we discussed about and you ask the question so in some cases I got the answer only in the second attempt that's what I've noted here so once we ask the question we are going to get an answer let's see what is the answer going to be it says based on the given context there is no direct information or relevance uh the information privately provides about lava model by UC Davis and Microsoft research so it didn't give a wrong answer and also it didn't give the right answer so let's go ahead and ask one more question was Joe Biden the president while Trump was the US president and know it's a very weird question let's see let's ask the question again send it to Lang chain retriever so this is the who was the president of United States during a specific time period get the answer get the answer let's see what it does what it does what it does what it is okay here you go you got the answer saying no Joe Biden was not the president while Donald was the president Donald Trump served as the 45th US President Joe Biden on the other hand became the president as the 46th president so succeeding Donald Trump so we have got the right answer the factuality has improved hallucination has reduced it's a bitter rag retrieval augmented generation system all thanks to the paper from Deep mind about step back prompting and also thanks to L chain for putting together this wonderful cookbook that we can use right away for you to start all the required links in the YouTube description you can directly click the link and check it out see you in another video Happy prompting

Original Description

Step Back Prompting - "TAKE A STEP BACK: EVOKING REASONING VIA ABSTRACTION IN LARGE LANGUAGE MODELS" Deep Mind Paper - https://arxiv.org/pdf/2310.06117.pdf Langsmith Prompt - https://smith.langchain.com/hub/langchain-ai/stepback-answer?tab=0 Langchain cookbook - https://github.com/langchain-ai/langchain/blob/master/cookbook/stepback-qa.ipynb ❤️ If you want to support the channel ❤️ Support here: Patreon - https://www.patreon.com/1littlecoder/ Ko-Fi - https://ko-fi.com/1littlecoder 🧭 Follow me on 🧭 Twitter - https://twitter.com/1littlecoder Linkedin - https://www.linkedin.com/in/amrrs/
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from 1littlecoder · 1littlecoder · 0 of 60

← Previous Next →
1 How to create your Free Data Science Blog on Github with Fastpages from Fastai
How to create your Free Data Science Blog on Github with Fastpages from Fastai
1littlecoder
2 Making Interactive Matplotlib Plots for Data Science Visualizations on Jupyter (Python)
Making Interactive Matplotlib Plots for Data Science Visualizations on Jupyter (Python)
1littlecoder
3 Create your first Data Science Web App using R Shiny
Create your first Data Science Web App using R Shiny
1littlecoder
4 How to create a Reproducible Example in R using reprex
How to create a Reproducible Example in R using reprex
1littlecoder
5 No Code Visualization using esquisse with Tableau-like Drag and Drop GUI in R
No Code Visualization using esquisse with Tableau-like Drag and Drop GUI in R
1littlecoder
6 Scrape HTML Table using rvest and Process them for insights using tidyverse in R
Scrape HTML Table using rvest and Process them for insights using tidyverse in R
1littlecoder
7 Google Teachable Machine Learning Build No Code AI solution
Google Teachable Machine Learning Build No Code AI solution
1littlecoder
8 Create meaningful fake tidy datasets in R using fakir [#rstats Package]
Create meaningful fake tidy datasets in R using fakir [#rstats Package]
1littlecoder
9 How to enable using R Programming with Visual Studio VS Code
How to enable using R Programming with Visual Studio VS Code
1littlecoder
10 Python, Community, Books - with Abhiram R - Bangpypers Co-organizers | 1littlecoder podcast
Python, Community, Books - with Abhiram R - Bangpypers Co-organizers | 1littlecoder podcast
1littlecoder
11 Growing a Tech Community across India - Anubha Maneshwar, Founder Girlscript | 1littlecoder Podcast
Growing a Tech Community across India - Anubha Maneshwar, Founder Girlscript | 1littlecoder Podcast
1littlecoder
12 Intro to Google Colab - How to use Colab
Intro to Google Colab - How to use Colab
1littlecoder
13 Intro to Plotly Express - Complex Interactive Charts with One-Line of Python Code
Intro to Plotly Express - Complex Interactive Charts with One-Line of Python Code
1littlecoder
14 Indic NLP Python Toolkit Open Source Development - iNLTK Creator Gaurav Arora | 1littlecoder Podcast
Indic NLP Python Toolkit Open Source Development - iNLTK Creator Gaurav Arora | 1littlecoder Podcast
1littlecoder
15 Do you want a career in Data Science - Tamil Webinar
Do you want a career in Data Science - Tamil Webinar
1littlecoder
16 Android Smartphone Analysis in R [Live Coding Screencast]
Android Smartphone Analysis in R [Live Coding Screencast]
1littlecoder
17 Programmatically create Images, Memes, Watermarks using Python with imgmaker
Programmatically create Images, Memes, Watermarks using Python with imgmaker
1littlecoder
18 Kaggle Walkthrough to get you started with Data Science - Webinar
Kaggle Walkthrough to get you started with Data Science - Webinar
1littlecoder
19 Community, Corporate Job, Coding - Gnana Lakshmi T C aka Gyan, WomenWhoCode Leadership Fellow
Community, Corporate Job, Coding - Gnana Lakshmi T C aka Gyan, WomenWhoCode Leadership Fellow
1littlecoder
20 Easy ggplot2 Theme Customization with {ggeasy} | Data Visualization in R
Easy ggplot2 Theme Customization with {ggeasy} | Data Visualization in R
1littlecoder
21 Excel to R - Pivot + Bar Chart in Excel  & R using tidyverse [Live Coding]
Excel to R - Pivot + Bar Chart in Excel & R using tidyverse [Live Coding]
1littlecoder
22 Excel to R #2 - VLOOKUP in Excel to LEFT_JOIN, MERGE in R
Excel to R #2 - VLOOKUP in Excel to LEFT_JOIN, MERGE in R
1littlecoder
23 5 websites to get Free Real-World Datasets for Data Science/ML Projects
5 websites to get Free Real-World Datasets for Data Science/ML Projects
1littlecoder
24 Excel to R #3 - APPROXIMATE VLOOKUP in Excel to FUZZY LEFT_JOIN in R
Excel to R #3 - APPROXIMATE VLOOKUP in Excel to FUZZY LEFT_JOIN in R
1littlecoder
25 Correlation-alternative PPS (Predictive Power Score) Python Package Demo
Correlation-alternative PPS (Predictive Power Score) Python Package Demo
1littlecoder
26 Automated Website Screenshots in R using {webshot}
Automated Website Screenshots in R using {webshot}
1littlecoder
27 Installing Custom RStudio Theme (Synthwave85)
Installing Custom RStudio Theme (Synthwave85)
1littlecoder
28 Analyse Google Trends Search Data in R using {gtrendsR}
Analyse Google Trends Search Data in R using {gtrendsR}
1littlecoder
29 3 Tips to ask question on Stack Overflow the right way to get answers
3 Tips to ask question on Stack Overflow the right way to get answers
1littlecoder
30 Learn Data Science with R - Mini Projects - Web Scraping Zomato
Learn Data Science with R - Mini Projects - Web Scraping Zomato
1littlecoder
31 Easily make Dumbbell Chart using {ggcharts} | Data Visualization in R
Easily make Dumbbell Chart using {ggcharts} | Data Visualization in R
1littlecoder
32 GET Hackernews Front Page Results using REST API in R
GET Hackernews Front Page Results using REST API in R
1littlecoder
33 Quickly deploy ML WebApps from Google Colab using ngrok
Quickly deploy ML WebApps from Google Colab using ngrok
1littlecoder
34 Use Jupyter Notebooks within VSCode (Visual Studio Code) in 2020
Use Jupyter Notebooks within VSCode (Visual Studio Code) in 2020
1littlecoder
35 Plotly Interactive Plots as Pandas Plotting Backend df.plot()
Plotly Interactive Plots as Pandas Plotting Backend df.plot()
1littlecoder
36 Stack Overflow Developer Survey 2020 Highlights for New Programmers
Stack Overflow Developer Survey 2020 Highlights for New Programmers
1littlecoder
37 Matplotlib Animation Charts in Python using Celluloid
Matplotlib Animation Charts in Python using Celluloid
1littlecoder
38 Coding, Postwoman, Passion Project Book - Liyas Thomas Open Source Developer - 1littlecoder podcast
Coding, Postwoman, Passion Project Book - Liyas Thomas Open Source Developer - 1littlecoder podcast
1littlecoder
39 Aspiring Data Scientist, Tips on How to learn Business Domain Knowledge
Aspiring Data Scientist, Tips on How to learn Business Domain Knowledge
1littlecoder
40 Bokeh Interactive Charts as Pandas Plotting Backend df.plot_bokeh()
Bokeh Interactive Charts as Pandas Plotting Backend df.plot_bokeh()
1littlecoder
41 Easy Fast Python Pandas Summary with Sidetable | Pandas Tips & Tricks
Easy Fast Python Pandas Summary with Sidetable | Pandas Tips & Tricks
1littlecoder
42 Inception, Content Ideas, Consistency - Srivatsan Srinivasan AIEngineering YouTube Content Creator
Inception, Content Ideas, Consistency - Srivatsan Srinivasan AIEngineering YouTube Content Creator
1littlecoder
43 ggplot2 Text Customization with ggtext | Data Visualization in R
ggplot2 Text Customization with ggtext | Data Visualization in R
1littlecoder
44 Penguins Dataset Overview - iris alternative | EDA Data Visualization in R
Penguins Dataset Overview - iris alternative | EDA Data Visualization in R
1littlecoder
45 YouTube Growth Tips, Content Creation - Bhavesh Bhatt, YouTuber (Data Science & Machine Learning) #7
YouTube Growth Tips, Content Creation - Bhavesh Bhatt, YouTuber (Data Science & Machine Learning) #7
1littlecoder
46 Matplotlib Animated Bar Chart Race in Python | Data Visualization
Matplotlib Animated Bar Chart Race in Python | Data Visualization
1littlecoder
47 Simple Python GUI Development using {guietta}
Simple Python GUI Development using {guietta}
1littlecoder
48 #8 Niche, Growth, Monetization - David Langer - YouTuber Dave on Data
#8 Niche, Growth, Monetization - David Langer - YouTuber Dave on Data
1littlecoder
49 Simple Fast 3-step Python OCR using Deep Learning 40+ Languages
Simple Fast 3-step Python OCR using Deep Learning 40+ Languages
1littlecoder
50 Github New Feature Profile Summary/Mini-Resume - Profile Views
Github New Feature Profile Summary/Mini-Resume - Profile Views
1littlecoder
51 Otto ML Assistant, GPT-3 on Philosophers, Nvidia-ARM - 3 ML Tech News
Otto ML Assistant, GPT-3 on Philosophers, Nvidia-ARM - 3 ML Tech News
1littlecoder
52 What is OpenAI GPT-3 - Hype, Examples, Worries
What is OpenAI GPT-3 - Hype, Examples, Worries
1littlecoder
53 Julia 1.5, Datamuse API, Live HDR+ Pixel 4a - Machine Learning Tech News
Julia 1.5, Datamuse API, Live HDR+ Pixel 4a - Machine Learning Tech News
1littlecoder
54 Self-driving Car Engineer sentenced, arXiv Dataset, AI/ML Startup Idea - Machine Learning Tech News
Self-driving Car Engineer sentenced, arXiv Dataset, AI/ML Startup Idea - Machine Learning Tech News
1littlecoder
55 GPT-3 Explorer, Ciphey (Automated Decryption), Py-Sudoku - ML Tech News
GPT-3 Explorer, Ciphey (Automated Decryption), Py-Sudoku - ML Tech News
1littlecoder
56 How to use Advanced Google Search to extract Email Ids from Linkedin
How to use Advanced Google Search to extract Email Ids from Linkedin
1littlecoder
57 Cartoonizer Toon-IT (AI Web App), GPT-3 Advice, Android Earthquake Detection - ML Tech News
Cartoonizer Toon-IT (AI Web App), GPT-3 Advice, Android Earthquake Detection - ML Tech News
1littlecoder
58 Flow - R Package to visualize code logic, functions as a Flow Diagram
Flow - R Package to visualize code logic, functions as a Flow Diagram
1littlecoder
59 Build GPT-3-like Language Model on Google Colab with minGPT [PyTorch]
Build GPT-3-like Language Model on Google Colab with minGPT [PyTorch]
1littlecoder
60 Create a Pencil Sketch Portrait with Python OpenCV
Create a Pencil Sketch Portrait with Python OpenCV
1littlecoder

The video teaches the Step Back Prompting technique for improving the performance of large language models in answering complex questions, and demonstrates its implementation using Lang Chain and other tools. This technique enables more effective abstraction and reasoning in LLMs, leading to improved factuality and reduced hallucination.

Key Takeaways
  1. Configure Open AI API key in OS environment path
  2. Install required libraries (Open AI, Lang Chain, Duck Go Search, L Chain Hub)
  3. Import chat.openai model and prop_templates for step back prompting
  4. Create short prompts for step back questions and use chat prompt template
  5. Invoke question gen to create output and print final response
  6. Use d.go_search to retrieve answer from internet and LChain Hub
💡 The Step Back Prompting technique can significantly improve the performance of large language models in answering complex questions by enabling more effective abstraction and reasoning.

Related Reads

📰
Title: something like "From Reading to Reasoning: Using AI to Prompt Critical Summary and Synthesis"
Learn how to use AI to prompt critical summary and synthesis, enabling more effective literature reviews and gap identification
Dev.to AI
📰
Post 3 - Building AI You Can Trust
Learn how to build trustworthy AI by addressing the challenge of outdated information in AI coding assistants
Dev.to AI
📰
AI's Day: I Asked a Human to Explain the Internet (And It Was Fine)
Learn how an AI assistant like Electra can simplify complex explanations, making it easier for humans to understand the internet and other topics
Dev.to AI
📰
Nvidia, AI And The New Tech Stack: Why This Cycle Is Different
Learn how Nvidia's AI tech stack is revolutionizing the industry and why this cycle is different, with applications in various fields
Forbes Innovation
Up next
5 Levels of AI Agents - From Simple LLM Calls to Multi-Agent Systems
Dave Ebbelaar (LLM Eng)
Watch →