Build SELF-DISCOVER from Scratch with LlamaIndex

LlamaIndex · Beginner ·📄 Research Papers Explained ·2y ago

Key Takeaways

Implements the SELF-DISCOVER paper as a LlamaPack with LlamaIndex to demonstrate self-composed reasoning structures for LLMs

Full Transcript

hello everyone this is Raa developer Advocate engineer at Lama index in this video we'll look into implementing a recent paper which is self-discover uh large language model self composed reasoning structures as a Lama pack so let's start with understanding the approach and what this paper is about so basically uh self-discover is a general framework for llms or you can say prom flow strategy to self-discover the reasoning structures to solve a complex problem that are in general difficult with usual proing mechanism so basically it uses llms to select multiple reasoning modules from a large pool of reasoning modules which you can check towards the end of the paper to compose a reasoning structure for the llm to solve the task or the problem that uh is given to it so they showcased that the approach improves the gp4 and pal to performance on challenging Ben benchmarks by margin of 32% compared to CO2 methods so this is designed from a thought that we as humans if given a new problem we think U about what skills we already have from prayer experience and how can use those skills to solve the particular task or problem so the approach is basically divided into two stages um stage one and stage two basically the broader input is a task which we need to solve and the reasoning module um basically I said as I said uh there are uh some reasoning modules from which you select to solve the task right so these are the two inputs U for the whole process and then yeah let's start with the stage one process which has three modules to say which are select adapt and Implement so select chooses the relevant reasoning modules from a large pool of reasoning modules the paper use some 39 reasoning modules and then once you get a selected modules from the first part uh you sent it to adapt and based on this uh module certain modules reasoning modules refres those descriptions to be task specific and then finally um those rephrased ones are sended to the third part which is Implement which creates an execution plan from the adapted module descript ions uh which is something like a reasoning structure similar to a Json format and then in the stage two we basically give the task as well as this reasoning structure for the llm to solve the task and given an answer for the given task or the problem so now uh let's see how you can implement this in the Lama index as a Lama pack we will actually use Query pipeline to implement it um is a probably a simple sign of proms flow so let's uh see how you can do that essentially we have a task and reasoning modules as inputs and give them to a select prompt so basically in the select prompt we ask the llm to select some of these reasoning modules to solve this task and you basically get selected modules uh as an output and then we have an adapt prom uh for the given task and uh for these uh selected modules you send uh them to the llm and then refres the descriptions of these modules for the specific task and then you have an Implement prompt for which there is a task and send it to llm and get a reasoning structure and finally along with the reasoning structure for the specific task you basically generate an answer so these are the different parts of the the whole process and which is part of stage one and stage two so we'll see so the uh we'll implement this whole flow using query P plane um concept which is available in the Lama index take the input send it to the prompt or get a prompt template and send it to llm get the modules and then have an adap prompt uh send uh send the previous step input output as an input to the next one and continue with that process so you can find the uh the Lama pack file here and then uh so it basically contains a self discore pack and uh so that will have certainly some three more uh three functions get modules run and an IT function where you can initialize the llm and then uh the default reasoning modules and the veros so this the Run function has has basically you need to configure the pipeline as I said there are uh two stages and the first stage has three different parts which is Select adapt and Implement and the second stage is uh use the reasoning structure and for the task to generate an answer so the [Music] pipeline has a pipe uh all these parts to it so for the configuring the pipeline you basically set up the templates whatever we have discussed and then add these modules to it and set up the links and uh have the pipeline ready and once the pipeline is ready you basically give the task and the reasoning modules as a input and basically uh get the answer for the task so here if you can see um these are the templates you have uh select uh prompt template which has which takes task as well as reasoning modules as input and then adapt prom template which T takes uh the um task as well as selected modules from the previous step and the third one is the Implement PR template which takes uh um the adapted modules from the previous step and the task um and finally this is given to the final one the stage two one takes the reasoning structure and then task to give a final answer for the given task or the problem right so and then yeah the core the core has the all these modules here so there is an input component which takes the task and the reasoning modules as a high level input and you have llms for each of these parts like select llm adapt LM Implement LM and reasoning llm and all these uh prompt templates right right uh so we have all these modules available now so we just need to set up uh the links between all these modules that I have shown in earlier in the figure right so you start adding the links like what is the input for the promt template and which is Task and then the reasoning module as the input and you send the promt template to the llm okay and once you get whatever the output you get you basically send the selected modules to the adapt right adapt from template so um that's what you do here and then you even have you even send the task as well as the selected modules to the adapt R template and pass the adap prom template to the llm again and similar case with the Implement prom template you have the adapted uh modules and task to the Implement prom template andm get a reasoning structure and send the reasoning structure to the uh the final reasoning prom template to get an answer so that's how you configure the entire Pipeline and then you run it um by taking the task as well as uh reasoning modules so we have a Lama pack ready and then we'll use this llama pack to solve some of the task so we'll go through this notebook on how you can use the Lama pack to solve a task so we need llm for the for it uh we'll use the default one which is gp4 llm for it and then you can actually use the the Lama pack in two ways uh One downloading the Llama pack and then directly use the cell discard pack from the available llama packs so I'll go with the second option for now you can even test the first one so let's get the Lama pack and pass the LM um we can send the gp4 llm or any other llm you want to test it out but if you don't send any llm as an input um it directly uses the default GB 3.5 Taro as an llm and then uh we have some task defined here so one of the task is like U Michael has 15 oranges and he gives four oranges to his brother and trades three oranges for six apple with his neighbor later he disc got two of them and then goes to Market to buy 12 more oranges and five apples and decides to give two apples to his friend Fin and we want to know how many oranges and apples does Michael have at the end during this process so this is the task question and then we'll uh go through it so you can see how each of these things are running you have the input which is Task and reasoning modules and then send it to select prompt about the task and reasoning module to get a selected uh modules and then use that prompt template which takes the task as and selected modules as input and send it to the llm to get the uh rephrasing versions and then the Imp Implement prompt template as well uh and finally get an answer so so basically it has it the answer says like Michael initially has 15 oranges and zero apples and then after giving 4 oranges to his brother it has he has 11 oranges left and then he basically trade some apples and get uh for oranges and so each step um you basically do some operation and get a final answer that he has 18 oranges and N apples so that's how um it break down the whole problem into different steps and uh did some reasoning and got a final answer in the same way there is another task here where Tom buy some ingredients for dinner and um you want the estimate of uh the cost basically the cost for purchasing these items and so basically he pays with a $50 bill and what is the chain one needs to receive purchasing these items so in the similar way um the task reasoning modules and all these stages it goes through all these stages and finally gets an answer um the actually the time taken for Sol to solve the task depends on how complex the problem is because um the number of selected modules might be more based on the task so that's how you can see now this task is taking more time than the previous one um the previous one hardly took 27 seconds and this took uh more time right and so basically yeah it identified the problem and gathered the information broke down on the problem and did some thinking and solved the problem and uh reviewed that solution and got the changes like $31.5 so that's how you can use uh self-discover to solve a complex problem uh please explore this Lama pack and um see how you can use in your workflow uh see you in the next video with a new llama pack or any other new technique available thank you

Original Description

In this video we will look into implementing recent SELF-DISCOVER paper as LlamaPack with LlamaIndex. OUTLINE: 00:00 - Introduction. 00:17 - SELF-DISCOVER Paper review. 03:06 - Implementation Overview with QueryPipeline. 04:30 - LlamaPack implementation. 08:12 - Notebook walkthrough of using LlamaPack. Paper: https://arxiv.org/abs/2402.03620 LlamaPack: https://github.com/run-llama/llama_index/tree/main/llama-index-packs/llama-index-packs-self-discover Notebook: https://github.com/run-llama/llama_index/blob/main/llama-index-packs/llama-index-packs-self-discover/examples/self_discover.ipynb
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from LlamaIndex · LlamaIndex · 55 of 60

1 LlamaIndex Virtual Meetup (May 4th, 2023)
LlamaIndex Virtual Meetup (May 4th, 2023)
LlamaIndex
2 LlamaIndex + MongoDB Workshop/Fireside Chat
LlamaIndex + MongoDB Workshop/Fireside Chat
LlamaIndex
3 Discover LlamaIndex: Ask Complex Queries over Multiple Documents
Discover LlamaIndex: Ask Complex Queries over Multiple Documents
LlamaIndex
4 Discover LlamaIndex: Document Management
Discover LlamaIndex: Document Management
LlamaIndex
5 Discover LlamaIndex: Joint Text to SQL and Semantic Search
Discover LlamaIndex: Joint Text to SQL and Semantic Search
LlamaIndex
6 Discover LlamaIndex: JSON Query Engine
Discover LlamaIndex: JSON Query Engine
LlamaIndex
7 LlamaIndex Webinar: Active Retrieval Augmented Generation
LlamaIndex Webinar: Active Retrieval Augmented Generation
LlamaIndex
8 LlamaIndex Webinar: Demonstrate-Search-Predict (DSP) with Omar Khattab
LlamaIndex Webinar: Demonstrate-Search-Predict (DSP) with Omar Khattab
LlamaIndex
9 LlamaIndex Sessions: Practical challenges of building a Legal Chatbot over your PDFs
LlamaIndex Sessions: Practical challenges of building a Legal Chatbot over your PDFs
LlamaIndex
10 LlamaIndex Webinar: Graph Databases, Knowledge Graphs, and RAG with Wey (NebulaGraph)
LlamaIndex Webinar: Graph Databases, Knowledge Graphs, and RAG with Wey (NebulaGraph)
LlamaIndex
11 LlamaIndex Webinar: Community Project Showcase (07/07/2023)
LlamaIndex Webinar: Community Project Showcase (07/07/2023)
LlamaIndex
12 LlamaIndex Webinar: LLMs for Investment Research (with Didier Lopes, co-founder/CEO at OpenBB)
LlamaIndex Webinar: LLMs for Investment Research (with Didier Lopes, co-founder/CEO at OpenBB)
LlamaIndex
13 Discover LlamaIndex: Bottoms-Up Development With LLMs (Part 1, LLMs and Prompts)
Discover LlamaIndex: Bottoms-Up Development With LLMs (Part 1, LLMs and Prompts)
LlamaIndex
14 Discover LlamaIndex: Bottoms-Up Development With LLMs (Part 2, Documents and Metadata)
Discover LlamaIndex: Bottoms-Up Development With LLMs (Part 2, Documents and Metadata)
LlamaIndex
15 Discover LlamaIndex: Key Components to build QA Systems
Discover LlamaIndex: Key Components to build QA Systems
LlamaIndex
16 Discover LlamaIndex: Bottoms-Up Development with LLMs (Part 3, Evaluation)
Discover LlamaIndex: Bottoms-Up Development with LLMs (Part 3, Evaluation)
LlamaIndex
17 LlamaIndex Webinar: From Prompt to Schema Engineering with Pydantic  (with @jxnlco)
LlamaIndex Webinar: From Prompt to Schema Engineering with Pydantic (with @jxnlco)
LlamaIndex
18 Discover LlamaIndex: Bottoms-Up Development with LLMs (Part 4, Embeddings)
Discover LlamaIndex: Bottoms-Up Development with LLMs (Part 4, Embeddings)
LlamaIndex
19 Discover LlamaIndex: Custom Retrievers + Hybrid Search
Discover LlamaIndex: Custom Retrievers + Hybrid Search
LlamaIndex
20 LlamaIndex Webinar: Document Metadata and Local Models for Better, Faster Retrieval
LlamaIndex Webinar: Document Metadata and Local Models for Better, Faster Retrieval
LlamaIndex
21 LlamaIndex Webinar: Build Personalized AI Characters with RealChar
LlamaIndex Webinar: Build Personalized AI Characters with RealChar
LlamaIndex
22 LlamaIndex Webinar: Make RAG Production-Ready
LlamaIndex Webinar: Make RAG Production-Ready
LlamaIndex
23 LlamaIndex Workshop: Building RAG with Knowledge Graphs
LlamaIndex Workshop: Building RAG with Knowledge Graphs
LlamaIndex
24 Discover LlamaIndex: Introduction to Data Agents for Developers
Discover LlamaIndex: Introduction to Data Agents for Developers
LlamaIndex
25 LlamaIndex Webinar: Finetuning + RAG
LlamaIndex Webinar: Finetuning + RAG
LlamaIndex
26 Discover LlamaIndex: SEC Insights, End-to-End Guide
Discover LlamaIndex: SEC Insights, End-to-End Guide
LlamaIndex
27 Discover LlamaIndex: Custom Tools for Data Agents
Discover LlamaIndex: Custom Tools for Data Agents
LlamaIndex
28 LlamaIndex Sessions: Building a Lending Criteria Chatbot in Production
LlamaIndex Sessions: Building a Lending Criteria Chatbot in Production
LlamaIndex
29 Discover LlamaIndex: Bottoms-Up Development with LLMs (Part 5, Retrievers + Node Postprocessors)
Discover LlamaIndex: Bottoms-Up Development with LLMs (Part 5, Retrievers + Node Postprocessors)
LlamaIndex
30 LlamaIndex Webinar: How to Win a LLM Hackathon
LlamaIndex Webinar: How to Win a LLM Hackathon
LlamaIndex
31 LlamaIndex Webinar: LLM Challenges in Production (w/ Mayo Oshin, AI Jason, Dylan from Starmorph)
LlamaIndex Webinar: LLM Challenges in Production (w/ Mayo Oshin, AI Jason, Dylan from Starmorph)
LlamaIndex
32 LlamaIndex Webinar: Agents Showcase!
LlamaIndex Webinar: Agents Showcase!
LlamaIndex
33 LlamaIndex Webinar: Learn about DSPy
LlamaIndex Webinar: Learn about DSPy
LlamaIndex
34 LlamaIndex Webinar: Time-based retrieval for RAG (with Timescale)
LlamaIndex Webinar: Time-based retrieval for RAG (with Timescale)
LlamaIndex
35 LlamaIndex Webinar: Build/Break/Test LLM Apps Showcase (co-hosted with TrueEra, Pinecone)
LlamaIndex Webinar: Build/Break/Test LLM Apps Showcase (co-hosted with TrueEra, Pinecone)
LlamaIndex
36 LlamaIndex Workshop: Evaluation-Driven Development (EDD)
LlamaIndex Workshop: Evaluation-Driven Development (EDD)
LlamaIndex
37 LlamaIndex Webinar: Building LLM Apps for Production, Part 1 (co-hosted with Anyscale)
LlamaIndex Webinar: Building LLM Apps for Production, Part 1 (co-hosted with Anyscale)
LlamaIndex
38 LlamaIndex Webinar: Learn about Fine-tuning + RAG (w/ Victoria Lin, author of RA-DIT)
LlamaIndex Webinar: Learn about Fine-tuning + RAG (w/ Victoria Lin, author of RA-DIT)
LlamaIndex
39 LlamaIndex Webinar: What's next for AI after OpenAI Dev Day?
LlamaIndex Webinar: What's next for AI after OpenAI Dev Day?
LlamaIndex
40 Introducing create-llama
Introducing create-llama
LlamaIndex
41 LlamaIndex Webinar: PrivateGPT - Production RAG with Local Models
LlamaIndex Webinar: PrivateGPT - Production RAG with Local Models
LlamaIndex
42 Multi-modal Retrieval Augmented Generation with LlamaIndex
Multi-modal Retrieval Augmented Generation with LlamaIndex
LlamaIndex
43 LlamaIndex Webinar: LLaVa Deep Dive
LlamaIndex Webinar: LLaVa Deep Dive
LlamaIndex
44 A deep dive into Retrieval-Augmented Generation with Llamaindex
A deep dive into Retrieval-Augmented Generation with Llamaindex
LlamaIndex
45 LlamaIndex Workshop: Multimodal + Advanced RAG Workhop with Gemini
LlamaIndex Workshop: Multimodal + Advanced RAG Workhop with Gemini
LlamaIndex
46 LlamaIndex Webinar: Efficient Parallel Function Calling Agents with LLMCompiler
LlamaIndex Webinar: Efficient Parallel Function Calling Agents with LLMCompiler
LlamaIndex
47 Introduction to Query Pipelines (Building Advanced RAG, Part 1)
Introduction to Query Pipelines (Building Advanced RAG, Part 1)
LlamaIndex
48 LLMs for Advanced Question-Answering over Tabular/CSV/SQL Data (Building Advanced RAG, Part 2)
LLMs for Advanced Question-Answering over Tabular/CSV/SQL Data (Building Advanced RAG, Part 2)
LlamaIndex
49 LlamaIndex Webinar: Advanced Tabular Data Understanding with LLMs
LlamaIndex Webinar: Advanced Tabular Data Understanding with LLMs
LlamaIndex
50 Ollama X LlamaIndex Multi-Modal
Ollama X LlamaIndex Multi-Modal
LlamaIndex
51 Build Agents from Scratch (Building Advanced RAG, Part 3)
Build Agents from Scratch (Building Advanced RAG, Part 3)
LlamaIndex
52 LlamaIndex Webinar: Build No-Code RAG with Flowise
LlamaIndex Webinar: Build No-Code RAG with Flowise
LlamaIndex
53 LlamaIndex Sessions: Practical Tips and Tricks for Productionizing RAG (feat. Sisil @ Jasper)
LlamaIndex Sessions: Practical Tips and Tricks for Productionizing RAG (feat. Sisil @ Jasper)
LlamaIndex
54 Introduction to LlamaIndex v0.10
Introduction to LlamaIndex v0.10
LlamaIndex
Build SELF-DISCOVER from Scratch with LlamaIndex
Build SELF-DISCOVER from Scratch with LlamaIndex
LlamaIndex
56 Introducing LlamaCloud (and LlamaParse)
Introducing LlamaCloud (and LlamaParse)
LlamaIndex
57 LlamaIndex Sessions: 12 RAG Pain Points and Solutions
LlamaIndex Sessions: 12 RAG Pain Points and Solutions
LlamaIndex
58 LlamaIndex Webinar: RAG Beyond Basic Chatbots
LlamaIndex Webinar: RAG Beyond Basic Chatbots
LlamaIndex
59 A Comprehensive Cookbook for Claude 3
A Comprehensive Cookbook for Claude 3
LlamaIndex
60 LlamaIndex Webinar: RAPTOR - Tree-Structured Indexing and Retrieval
LlamaIndex Webinar: RAPTOR - Tree-Structured Indexing and Retrieval
LlamaIndex

Related Reads

📰
On July 1, 2026, arXiv will spin out from Cornell University, its home for the past 25 years, to become an independent nonprofit organization. Major funding support from Simons Foundation and Schmidt Sciences. Ditching the red for their website. [N]
arXiv is becoming an independent nonprofit organization after 25 years at Cornell University, backed by major funding, which will impact the future of research and academia
Reddit r/MachineLearning
📰
CS-NRRM™ Official Publications: Paper 1 and Paper 2 Are Now Available
Learn about the CS-NRRM's official publications on a 12-year longitudinal human observation archive and its significance in research and development
Medium · Data Science
📰
Found a potential mistake in an ICLR 2026 blogpost [D]
Verify a potential mistake in an ICLR 2026 blog post and learn how to effectively report errors in academic publications
Reddit r/MachineLearning
📰
Rebuttals Move Peer-Review Scores, but Initial-Review Structure Bounds the Movement
Learn how author rebuttals impact peer-review scores and the factors that influence their effectiveness in ICLR 2024-2025, using LLMs for measurement
ArXiv cs.AI

Chapters (5)

Introduction.
0:17 SELF-DISCOVER Paper review.
3:06 Implementation Overview with QueryPipeline.
4:30 LlamaPack implementation.
8:12 Notebook walkthrough of using LlamaPack.
Up next
Indians Under House Arrest in America? 😱 Immigration Crisis Explained | SumanTV Classroom
SumanTV Classroom
Watch →