Section Insights
Introduction to DSPI
What is DSPI and why was it built?
DSPI is a framework designed to optimize the development of language programs by breaking down complex problems into manageable pieces, allowing for the integration of AI models where traditional programming falls short.
- DSPI stands for a systematic approach to working with language models.
- It emphasizes programming over prompting to enhance clarity and efficiency.
- The framework allows developers to express complex problem structures using standard programming tools.
Challenges in Language Model Pipelines
What challenges do developers face when working with language models?
Developers often encounter difficulties when trying to switch models or methods, such as moving from prompting to fine-tuning, which can require extensive rewrites of existing code.
- Switching language models or methods can be cumbersome and inefficient.
- DSPI aims to streamline the process of modifying language programs.
- The framework promotes a more systematic approach to machine learning.
Understanding Optimization in DSPI
What is being optimized in DSPI and how does it work?
Optimization in DSPI involves defining the context and signatures for queries and responses, allowing for the construction of effective prompts and learning from the model's outputs.
- Optimization focuses on refining how queries and responses are structured.
- DSPI modules can adapt prompting strategies to enhance learning.
- The process is not random; it relies on understanding the context and desired outcomes.
Task Stability vs. Pipeline Flexibility
How does DSPI address the balance between task stability and pipeline flexibility?
DSPI allows developers to maintain a stable task while enabling flexibility in the pipeline, facilitating experimentation and adaptation without altering the core task.
- Tasks are generally fixed, while pipelines should be adaptable.
- DSPI encourages breaking and rebuilding pipelines to optimize performance.
- Learning from outputs is crucial for refining the pipeline.
Positioning DSPI within the AI Framework
How does DSPI fit into the broader landscape of AI development tools?
DSPI serves as a modular framework that provides essential building blocks for creating language programs, similar to how PyTorch and Hugging Face Transformers operate, but with a focus on optimizing language model interactions.
- DSPI is designed to be a foundational layer in AI development, offering modular components.
- It integrates higher-level abstractions with lower-level functionalities.
- The framework is continually evolving to include more optimizers and tools for developers.
Transcript
0:00 before that we can do brief introductions and then jump right into it. So, so my name is Harrison Chase, CEO co-founder of Lingchain, a developer toolkit, making it easy to build LLM applications. thank you Harrison and thanks everyone for joining me. Looks like we have a a lot of folks. I'm Omar. I'm a PhD candidate at Stanford. I work in NLP Broadley. You might know about my work on Kulbear and retrieval. and you know excited to talk about DSPI today which is a framework for developing and optimizing language programs and I'll tell you all about language programs today. All right. So, DSPI, that's how it's pronounced. That puts all the questions to bed.
0:45 Yes. Like, like numi or pytorch. DSPI. All right. So, yeah, I mean, let's jump right into it. What what is DSP? DSPI? why did you build it? How how are people using it? Yeah. So, this is a framework for really thinking about those like this notion of language programs. If you're writing a piece of code and you know you're trying to solve a hard problem and the way you're going to solve that hard problem is not by working really hard at you know teaching that model to understand your task. It's going to be by you know breaking this problem down into pieces and thinking about the problem structure that you have. You could employ you know all standard sorts of tools and we have in programming. So you could have you know loops or recursion or you know assertions or all other sorts of standard programming tools and abstractions. But the key thing is that in this program there are these steps that you don't know how to express in standard code. So there are these kind of fuzzy steps that are generally best tackled by an AI model by a language model in particular. and so DSPI is basically a framework for thinking about that layer. How do we express this type of thing and then how do we actually go from you know a high level declaration of what these you know fuzzy steps are going to do and how how they sort of compose together into a bigger program into an optimized version of the program that runs effectively given any particular language model and any particular program. so one one of the main problems we're trying to tackle is well thinking about you know how do you build a program of this kind like what should you do for different types of problems and then the one that is sort of I think DSP is better known for is now that you've written this program and you want to run it for GPT4 what should the prompts look like to GPT4 so that it does all of these stages in your program effectively. So you have a you're solving a you know you're doing rag for example and let's say you don't want your rag component to rely entirely on this retrieval system because in many cases retrievers are kind of optimized to be fast and and and cheap and scalable but you really want it to be very accurate. So maybe your program is given the user's question I want the language model to generate a bunch of search queries that will you know be optimized one way or another to find as many of the relevant facts as possible. Maybe this is like patent search or something and so you really care about recall. Now that you've generated those queries, you want to basically find the documents that that match those queries and then you want the last stage of your system maybe to summarize the information there with citations.
3:42 In principle, you could just ask a language model to do these steps. But as we're all aware, these models are very very sensitive and they're sensitive in different ways. So over time these models get updated or you want to switch from GPT4 to to quad or you want to sort of go to a smaller model to save costs over time or because you're struggling with the learn with the with the rate limits or some other challenges. and the general problem that you face is that even if you manage to get prompts that more or less declare the behavior that you're interested in and and enforce it, they're very very they're non-transfable, right? They're just tied to the particular system that you built with a particular language model that you built. So the SPI is basically adding this layer in between where you can express those stages in terms of what you want to do rather than how you want the particular language model to do it. and it basically gives you the rest of the pieces of the puzzle to treat this almost like a machine learning extended machine learning problem where you're trying to learn to fill in the blanks of how to use a language model for a particular task.
4:54 And so so one of the terms that I've heard a bunch on Twitter recently is is flow engineering and this idea of like yeah creating or your system being kind of like a flow and there's different stages. Is that essentially what you're talking about with the first part of it like this way of declaring kind of like that system, right? So DSPI stands for declarative self-improving language programs Pythonically which is a which is which is a complex kind of backronym because originally DSP was demonstrate search predict and so that's a 2022 paper we wrote so demonstrate search predict is a particular way to think about designing these these flows if you will.
5:34 so basically search is this notion of to solve a task you basically want to be able to break down how your language system takes the input maybe a question or whatever it's trying to solve and gathers information. And you know if you read if you read the DSP paper not the DSPI paper it basically includes a number of design patterns. What should how should you build a search stage with language models and you know there's a lot of literature on stuff of this kind now like hide and other stuff that for example use language models to generate documents and then search search for them or u multihop retrieval or other sorts of types of that kind of thing. So let me see if I can well hopefully we don't get a lot of that.
6:22 and predict is like well now that you've gathered those stuff how do you you know design the system architecture so that you output grounded answers you know potentially with citations and other other this type of constraint. So DSP was very kind of like retrieval focused, right? DSPI is more general and can be used for kind of like any things or would you say that it's still fairly retrieval focused? No, the DSP is not retrieval focused.
6:54 DSP but the bigger difference the bigger difference was that DSP required you to think about this demonstrate stage. So I said demonstrate search predict and I didn't describe what demonstrate was. you had to manually declare the or define the logic of how your language model will be taught to do the task. So you wouldn't write you wouldn't be writing the prompts but you would be writing the code that that essentially searched over prompts to to define how the program should work. And in DSPI that's kind of we automated that for for for people and we created a bunch of optimizers so that you know the the the standard flows that we saw were very effective could just work. So in DSP you basically just write a Python class.
7:39 maybe this is a good place to to share screen. I don't have slides specifically for today but I have some kind of things I could probably just show. Yeah, I think that might be helpful because one of the things that struck me looking at and I think you've said this is it looks very similar to PyTorch. and so how about So what do you think Harrison? Like what I could do is I could share screen. Slides are slightly not for today, but let's see if we can make this work.
8:10 I have the repo pulled up as well if you want me to share that. Oh, there we go. So I said I started by saying that these language programs are advancing many tasks today. And you know this is part of the in the context of a talk where I discussed language programs I built in like 2020 and 2021 which was not with prompting it was with fine-tuning and it was you know you didn't couldn't really kind of it was hard to figure out how to generate data for them but now it's much easier because you could prompt these language models to build stuff like storm people might be familiar with this cool work from Yia Stanford and and and folks with us basically writes whole Wikipedia articles and the interesting thing about something like storm is not really the language model itself. The language model is more of a device in the background. The interesting thing is how these parts are are are composed together to to solve this hard task and to ensure that you know outputs which in this case are entire Wikipedia articles are planned properly and are citing their sources properly. Another one is Ira with Carl and and and folks. so this is basically a system for classifying long documents but not classifying them into five or 10 classes. It's classifi classifying them into up to I think 15,000 classes. And the challenge is in generally you don't have labels for all these classes and so you're basically bringing in a language model and in this case a retrieval model in an interesting way to solve this.
9:43 And this sort of thing is obviously very very popular in lang chain. You know this is basically all the sorts of chains you guys you guys have popularized dramatically. but lots of folks are building these you know text to SQL stuff. really cool one from Google RA that revises and you know text generation from models alpha codium right this is the flow engineering paper. so this is stuff this stuff is is super popular. And then basically the problem that DSP is solving is that these diagrams are really cool. Like you look at these diagrams and they're very modular.
10:21 They're very attractive. There's lots to like about them. But the problem is because language models are very sensitive to how to how you prompt them. If you think of them as like as as like basically CPUs, it's like their instruction sets are just very different and ad hoc. so under the hood, this stuff looks more like as as we're all familiar, looks like like this. Looks more of you know, here's a long and and very carefully crafted prompt that teaches the model how each of these stages should work. And we really hope that the output of each stage looks good enough to the input of the next stage because if they don't, we're kind of going to have a system that doesn't work. And so people are sort of writing these and and I'm guilty of that as well. you know, we're all kind of writing these you know, tens of kilobytes of raw text files and just kind of trying to do our best with that.
11:11 And and this basically leaves us very dissatisfied in in VSPI because we're thinking these language model pipelines that people are building are so modular in principle and there's lots to love about them and there's something really attractive in moving beyond the world where language models are, you know, are are so important into a model where they're basically devices. you know, you just buy or rent the best one you can get and then you're building the software on top. and you know, we have all these large design spaces, but in reality, this is extremely messy and headlock and it's, you know, that's that's really limiting what you can do.
11:47 So, in particular, you take any of the pipelines or some of the pipelines we looked at and you want to change your language model to a cheaper one or you want to switch from prompting to fine-tuning and you're sort of stuck like do you have to rewrite the prompts? you have to like redesign this whole thing so that you could fine-tune the model. that doesn't feel like you know the right way to go about this especially given how powerful these language models are supposed to be.
12:13 so the goal of DSP is to sort of make working with these language programs more like systematic machine learning. and we have this sort of theme of programming and not prompting language models. so basically you're not going to be writing these long messy prompts which again we're all guilty of writing and in in many cases basically you know you write those like thousand words or 2,000 words and maybe you're not even satisfied with your results at the at the end of this. instead you're going to write a piece of code as you said Harrison that looks like a PyTorch program. so you're basically going to declare a DSPI module and in your DSPI module you're going to define you're going to sort of define one or more subm modules and these subm modules allow you to express internal sort of control flow that declares how signature is going to work. So I'll say more about these terms but basically you're going to declare a bunch of modules here and then you have a forward function that's just using these modules. It's using generate query and using generate answer you know in a loop or whatever to solve an actual problem. And you notice here that we're not writing any prompts anywhere or we're not writing you know like how the models should be used. again the slides are not really meant for today.
13:39 So they're the ordering might not be ideal but we'll try to make it work. the idea then is that we want to take this program and essentially compile it down and compiling in general in in the general sense I'm using here means taking a highle program and sort of generating a lower level language and something that is strikes people as interesting or odd or whatever at first when they see the spy is we're actually compiling computer code in Python to the low-level language which in many cases is like English for example for the promise. So, we're actually treating the natural language that we use to speak to the models as a low-level abstraction.
14:19 And that's not a mistake. That's intentional because the language these models speak is not necessarily the English that you or I understand. It's it's really, you know, it's a much more subtle thing where very small differences to us, you know, or or in some cases even very strange changes to us may impact model quality dramatically. and and maybe I can share some examples of that that like ended up getting really popular. But the idea is that when you compile this this program which is actually shorter than the prompt we had in the last slide you can get better scores. You can get a whole lot of better scores with bigger models. But the same program can be f can be compiled into smaller open models or even tiny language models through fine-tuning. and you're not really changing your code or your description of the problem in any way.
15:08 you're just selecting different optimizers which are the sort of modules in DSPI responsible for turning this this thing as it's being compiled into a highly effective into a highly effective system. And what makes this all possible is two ideas. we want to separate the program logic so what you just call like this information flow from how we're going to teach the language model each of the steps and we want to optimize we want to think about algorithms that can optimize how we will prompt or fine-tune the language models and in general the role the the the approach we'll take here is some sort of discrete search over modular language elements so we don't want to be doing like you know reinforcement learning or something where we need a whole lot of data or other approaches. We we actually want to use the language models themselves to think about hey how should we convert this highle sort of description of our task into something that's effective and obviously language models are not very good at this sort of thing on their own.
16:18 So we want to give them the u the support to to make this to make this effective. so let's see what's a good way to do this. So that's yeah, I think this may be a decent example. a decent example basically is let's say you want to teach three different language models to answer a question after they do some chain of thought. How would you express that? So let's say you want to do this with GPT4. I'd say one way to do this is you would like think about how you would craft an instruction and then you trust that GP4 can answer questions and can do chain of thought.
16:54 So you want to keep this cheap and you don't want to like make the prompt too long unnecessarily. But if you want to do this with like an open model that's a bit smaller, maybe mistrol or or llama to on the smaller side of those models, then maybe you want to start showing examples. And this is trickier than it sounds because your examples should demonstrate the pattern you're trying to to show. So for example, if you want to do a chain of thought, well, you need to think about how do I write the right chain of thought to teach this model how to do this for my types of questions. and let's let's say you write something that looks like this.
17:27 And maybe have several more examples because more is usually more effective. but in some cases, you want to solve the same task but with a much smaller model. And here, you know, with a T5 model, for example, prompting is not going to do much at all. The model is not, you know, in context learning aware. So you're going to have to synthesize or otherwise create maybe a thousand examples of this pattern. so we have questions the train of thought and the answers and you want to actually fine-tune the model on it. But it's what's dissatisfying here is that we're solving the exact same problem and actually we're expressing the exact same control flow although this is just one language model call in three vastly different ways and and the idea is that like instructing models few shop prompting fine-tuning are just different implementations of the idea that I have a question and I want to generate some reasoning and I want to generate an answer and this is actually how you would express this in DSP is you I you know this is like a function signature if you will. So this is my input and these are my outputs and you can have multiple inputs or multiple outputs. and the key question that DSPI is to answer automatically for you is what is a question? Like how do I tell a model this is what a question is and this is what you should do to it you know to generate a reasoning and this is what a reasoning is and this is what an answer is. but this is something that we want to learn from the from the data. So you could have say things like document to summary or context and question to search query. or as we said question to answer. and you can obviously specify a lot more constraints. You don't have to it doesn't have to be a string like this.
19:06 You could have a more like you could say I want the output to be you know integer and and I want you know I want it to behave like this or that. There are various ways to constrain these things. But the key thing is that what will define what a document or search query or reasoning is is something that we want to learn within the context of this program that we built. so I guess maybe we I can stop after this part and and and just make sure we're on you know we we everything makes sense to folks in the audience. but let's say you want to express this simple kind of pipeline. So you have a system that takes questions and it generates search queries. It searches with them and then it like asks further questions. It searches again and then it uses a retriever to find some documents and then uses these documents to finally answer the question. So in DSpay it would express it like this.
20:02 and initialization if you think of this almost like a neural network if you are familiar with that stuff but now each of these layers is actually a language model call. If you're not familiar with neuronet networks and pietorrch and all that, it doesn't matter. You don't you don't need to know that. But if you are familiar, it's a good analogy. So now you're going to declare that you just want a chain of thought that will express each of the blue parts here.
20:26 So both of them take a question and generate a query. but you know, they could also take some context that was retrieved earlier or they could take an empty context at the beginning. And the black sort of box here takes this context that was retrieved and takes the question and generates an answer. And this is the full sort of description of of you know the different blocks on the on the right. You can then sort of compose them together in a forward function where you're calling these modules. So you're generating query and then you're retrieving and then you're dumping the stuff you're retrieving in this context and then you're generating an answer at the end. so this is the the forward function and and this is basically nothing but like a very direct translation of the diagram into a piece of code. with the interesting piece being that we have these signatures that are telling the model what it's supposed to be doing. so these are called natural language signatures. and we touched them we touched on them like a couple minutes ago. how these are or like you know the strategy or the control flow of how these signatures will be expressed are are through what we call modules. So there are several modules in DS5 for all the kind of prompting techniques that people have.
21:41 if you want to do chain of thought in general as we said earlier you kind of have to think of how to teach your particular model this particular reasoning strategy. But in VSPI, it's just a module that you give your signature and there's an actual like module there that is going to learn that particular pattern for us. and I I think I might have a slide on what it's what it does, you know, in the case of chain of thought. But the interesting piece here is that internally this chain of thought is not like a template, although it has a template. it's actually a module that maintains three things. It basically is going to remember what instructions it should use. And so the idea is that it wants to learn the right instructions for your language model for this particular signature. it also wants to learn what input output examples it should show to the model. And if you use fine-tuning then it also wants to know you know what model fine-tune it should be using.
22:39 And there are other notions of constraining the outputs like assertions where you say well you know I don't just want to generate a query. I want this query to have a particular property. For example, I want it to be less than 100 words. and I want the program to learn to generate queries that pass my assertions. so I'll pause here for a bit and then we can continue. And again, apologies that the slides are not really kind of purpose-built. I I wasn't expecting to present them.
23:08 No, this is great. a bunch of questions around optimizers and you mentioned this is kind of like one of the the two big things. what exactly is being optimized and and how how does that work? Yeah, let's do that. so I guess this is another way of asking, you know, what defines a context, a question, a query, like these are terms and if you go to a language model and you say, I want an answer, it kind of has some prior over what that might mean, but it might not be exactly right.
23:39 this is we should go we should get back to this so that people understand. Actually, let's go in order so that we don't forget. So, prompting strategies like chain of thought, they're just DSPI modules, too. The difference is that they're going to take our signature and change it. So, they're going to take our signature and say like, oh, I just want to add a field. that's going to be like, let's think step by step or or whatever. and then I'm going to build kind of a another module with the newer signature.
24:08 And then basically I'm going to like forward all my calls to that to that extended extended signature. And this is nice because now this extended signature is is what we will learn. We're actually going to learn like you specified that you have questions you want and you want answers. But when you have a chain of thought, we're actually going to learn this reasoning field as well when we're optimizing this thing. yeah, this is so the role of of the of the language program optimizers is this process of taking each of your signatures and figuring out how to construct those prompts. and you know there could either be by creating instructions or by creating examples or by building data to fine-tune models for the same signature. and the way this is going to work is not blind. You don't just go to the model and say like give me good prompts, which I'm starting to see out there. That doesn't make sense because language models, you know, they're not necessarily aware of what will work as a good prompt. They give you a long prompt for sure, and odds are it's not completely random, but it might not actually be very effective. instead, what you want is some way to have to get like to get feedback. so you want to build a metric. and you want to have a small number of examples maybe you know 20 some people are successful with as as little as 20 usually around 50 or 100 is is is good sometimes without any labels you can still proceed and you know I don't think we need to like go through the formula but basically the idea is we're trying in these optimizers to search over basically the design space of these prompts to maximize the quality on average over your examples and I say sometimes it's without labels.
25:58 metrics can be something like the output of my let's go back to the pipeline we had here. One metric one set of of of optimizer inputs here could be take this program here are 20 questions and here are their answers and the metric is you know does the answer match what I what I give you. But a different type of of metric could be here's here's a set of 20 questions. I don't know what the right answer is but I do know that I want u my answers to be not based on hallucinations. I want them to be grounded. So my metric is going to be another DSPI program that checks for hallucination. and it says when I get an answer from my system, the text that I'm getting is actually grounded, you know, is is based on the documents or the context that was retrieved. And the nice thing about that being a DSPI program is that we can actually optimize that metric so that it is reliable at detecting hallucination. It's just a classification problem. It's very easy to optimize. and now we have a really good way to optimize this program so that it generates answers that that don't have hall had hallucinations and we did not even need labels for that.
27:12 But in many cases, you know, if you have some labels, you should use them. so the general idea of these optimizers is we want to learn module behavior by generating examples. So you're giving us those inputs. let's actually do this again on the same diagram. you're giving us you're giving us this program here and you're giving us 20 questions and we want to teach the model to generate search queries but we don't know what types of search queries will work for this retriever like you know you just switch from colerv2 to like I don't know kervy3 when it exists or something or to you.com search or some other thing and the types of queries that work for each of them is different So how can you teach a particular language model to generate good queries here?
28:05 Well, one idea is what if we take this question and we actually try to run it through the pipeline in various ways and actually we trace the inputs and outputs of this stage and see if they've been effective in the past at you know getting the retriever to do what we want. And we can in general detect that because we're measuring you know we're measuring the the the metric at the end or because you're giving us those assertions although you know in general you don't need them that sort of give us a signal as to whether things are going right or not. And when we have those examples well we could you know we could go back to the optimizers here and basically use them as generated examples for each of these stages of our system. so this is the notion of bootstrap fshot and then there are extensions of that that you should be using if you want to treat this as an actual optimization problem like bootstrap fshot with random search and so that's basically saying I'll create few shot examples for state for the stages of your pipeline starting from your inputs and to choose which combination you know I I should work with I'll run this random search process trying to maximize your metric bootstrap point tune is just saying Well, since I can create examples now and I have this potentially optimized set of prompts, I can create a lot more data now pretty efficiently and use it to actually update the weights of each of these modules through my pipeline.
29:33 Assuming that you're working with a language model that we have an API to fine-tune it. So not, you know, you can't do this with GPT4, for example, and in general you shouldn't even if they give you an API to fine-tune it, but maybe you can fine-tune a small llama model or a T5 model. or you could do things that actually learn instructions and examples like the recent mero that we released like a couple of months ago and several other other stuff. And I think people look at optimization and they kind of fear that this stuff is expensive. But in reality, you know, partly because LLMs are so cheap if you're doing like 3.5 level models, optimization is something that generally takes a few minutes and, you know, a few dollars for a new kind of setting that you have.
30:17 if you have a couple hundred examples, if you have less, it's even cheaper. but don't, you know, generally start small and generally start with smaller models so you understand what's happening and you can sort of track the quality before adding complexity or scale. so I can tell you how the ME Pro optimizer works. This is, you know, this you could also look at the thread about mero and and other resources. but I'll also pause here and just sort of make sure we're we're doing well on time as well.
30:46 So So just to maybe summarize some of that, and correct me if I'm wrong, but it seems like there's three main ways that you can kind of like optimize some of these programs. You've optimized the instructions, the the examples or the few shots that you're giving, or the weights of the underlying model itself. and sometimes combinations of them. Is is that correct or is is that Yeah, this is a fair question. This is exactly right. What's interesting though is if you take a program and and this is not really changing what you said, Harrison, it's kind of just building on it. if you take this program and you optimize it, generally the easiest way to get started is to optimize over examples. And this is giving you like a pretty powerful boost very quickly.
31:31 and and the idea isn't just adding examples. It's like the notion that they're actually coming from your program and they're things that worked before. And then on top of that, if you want to do random search or you want to do Beijian search or like Beijian optimization to sort of select these things these things together, what's it can be really powerful. But what's really cool here is that when you take this program and you let's say you optimize it for GPT3.5 with Bootstrap Qot with random search for example or with Miro. So let's say you use Miro. So this gives you a setup where each of these modules now learns a new instruction and learns like two or three nice examples in a in a prompt. You can take this exact same optimized program and say well that's my teacher program. Now I want to actually learn again with Bootstrap Fshot or with mero.
32:26 but now I want the examples that are being constructed to come from this pre-optimized version. And so you're basically composing the optimization. And what's really powerful about that is in some cases it means that you can get much better examples because now you're sampling them from this better program. the other thing is now that you've optimized your prompts, you can take this really high quality version and nest nested again into optimizing the weights. So you don't need to start each of these from scratch. You can actually compose the process of optimizing them. And when I say compose the process of optimizing them, I don't know if that sounds scary or not, but in in practice, that's like two lines. You just pass an extra argument somewhere. I can try to find if I have a an example of the of the code for optimizing.
33:11 It's like two lines but it's not in this set of slides. I'll get it at the end if we want. yeah that's hope that answers that question. Yeah, absolutely. Another thing I wanted to highlight because I think it's I think it's a really interesting similarity between kind of like lang chain and and and pie is something you said around kind of like tracing and traces. And just to emphasize why I think this cool is like you could have a program with like 30 different steps in it. And when you're talking about creating these data sets of examples, you're not talking about creating a data set for each of those 30 steps. You're talking about creating one for the whole endto-end pipeline. And then from that you can generate you can generate synthetically examples for each of those 30 steps or instructions for each of those 30 steps. But you do it once for this highle pipeline. and that that all and I you know I I dug around in the DSPI codebase a bit and as far as I like tracing is really important for that and and so do you maybe want to talk a little bit about like what tracing is and why it's needed for that and like what it actually provides?
34:14 Yeah, sure. so the idea there is you've written this program or you know this could have been you know a lang chain chain we have we have done this nice collab in the past where you know you could take an LCL expression and then basically run a DSP optimizer on top and we showed like a nice cool example of I think it was optimizing rag to generate engaging tweets or something for answers data set. so basically you have this this program or this chain that has all these pieces and as you said you have a data set that's describing the task not your pipeline and this is really important because let's say you're you know you're building a you're working on a on a at a startup or you're building a nice project usually the task is not going to change every day. It's like I'm writing this thing that's helping people schedule on email or something. That task is fixed. But your pipeline that you're building is something you want to explore all all all the time. And what that means is we want to enable you to like go and break the pipeline, add pieces, remove pieces. but also we still want to enable some notion of learning of what your task looks like.
35:27 So in general as you said if you have a bunch of inputs and ideally a bunch of good outputs at the end if you don't have that we could rely basically on language model based evaluations. and in some cases that can take you far in other cases it's harder. now the notion of tracing is well given those inputs if we just make an educated guess about the initial setting of each of your prompts of each of your modules then we can simply I don't know set a set a high temperature and run through your pipeline and just see what happens right see if you we're getting good outputs see if we're getting bad outputs and we know that because we have the metric at the end or because we have these assertions but the metric is is the primary thing here and so let's say it's you're answering you're everything a question answering setup.
36:14 Well, what if I just tell the model, please generate search queries and you know it's hit and miss, right? Sometimes it's pretty good as language models, you know, sometimes they s surprise us. They're pretty decent. other times, well, it doesn't really know what we're saying. So it generates I've seen things like it generates SQL queries or it generates you know like queries in this in the archaic kind of like keyword format with pluses and minuses and like you know which many modern retrievers are not really optimized for and it's kind of overkill or even even distracting for these models. But like you can't blame it. It doesn't really know like how would how how is it supposed to know that it's not that it's not to do that? but you know if you sample many sufficiently many of these you know maybe a couple hundred you're bound to find some interesting ones that perform really well. and we can basically collect those traces. So that's what Bootstrap Fshaw does. It's it's will store those traces and then we can plug them back into the prompt and say when I ask you to generate the search query here's actually a good example of me doing that in the past and here's the query you gave me. So how about do more of that? and you know it's basically fot learning but on on this on these traces and it becomes a discrete search over those.
37:32 So assuming we can generate and filter for good examples optimizing with having selected them is actually a pretty simple process from there on. The question just becomes like how do we do this without like trying all possible combinations or you know other stuff and sort of research on hyperparameter optimization for neural networks is actually very useful here because it's kind of a similar type of problem where you have this architecture and then you're trying to plug in those hyperparameters but you don't want to like try all combinations in an expensive way.
38:05 Yeah, that that's a that's a great explanation. I see a bunch of questions in the chat around how to combine lang chain and DSPI. I think that would be really interesting to discuss. Before that, I want to spend maybe like three minutes showing some of the things in Langchain and Lang Smith that we've been working on because I think they're exactly related to tracing and testing and evaluation and data sets. And so I I maybe want to set the stage with that and then we can and then I think the rest of the time would be great to discuss. Okay. like and maybe brainstorm with the audience as well. What is the right kind of like way to put these puzzle pieces together? so let me share my screen really quick and you were just talking about tracing. and and that's one of the main things that we've invested pretty heavily in at Langchain. So so this is a this is a list of chat lang chain queries. so on on we have a chatbot for chat over lang chain documentation. And if I click into one of these, let me find one that has multiple language model steps because that would be interesting.
39:07 so here you can see that this this is a trace of kind of what's happening. And so this this mimics one of the examples that Omar was talking about earlier where you have kind of like this this generation of a query and then there's this retrieval step and you get back you get back a a document and then there's this generation of a response and so this this is a very similar kind of like in this case this is written in LL but it's it's a very it's a very similar program putting aside how it's written and again, I think one of the key important things here is the importance of tracing. And here we we use it for observability. We find that there's huge value in just seeing what's going on in this pipeline. But as Omar talked about, you can also use it to collect all these these examples. one of the things that's that's interesting is when you're collecting them in Langmith, there's actually a difference to how to what we're collecting and it's a very productive difference. traces we collect are like they're kind of synthetic un like you basically hit compile or you run the code with compiling and it's collecting them. But the traces you're collecting here are maybe like interactions with users and they're kind of in production and they increase over time and they kind of get sustained. The traces in our case we build them we optimize we throw them away essentially or we catch them but we we're not you know this is this is a different type of tracing but it's you know very very valuable.
40:35 Yeah. Yeah. No, that's a that's a great point. I think it comes down to like what the data set is, right? Like what's the data you're running it over and in in the case of DSPI, it's a bunch of examples that you've curated and that may and you have some metrics for and maybe you have some labels for. In this case, this is like production traffic. and I think there's pros and cons to each. I would say the pros probably of this and and to be clear we also have this concept of kind of like data sets and testing in language which I can jump to but the pros of that are that you generally have maybe thought a little bit more about metrics and you have maybe have labels as well like you have ground truth labels so you can create better metrics here the pros of this are you you get to see questions that people are ask actually asking kind of like your chatbot in in real life and so I think there's just a broader swath of them for better or or for worse but yeah you're absolutely right that it's different different settings that that this tracing is being done in and and on the concept of kind of like data sets one of the things that we purposefully added since the beginning is this really or is this concept of adding any part of this trace to a data set. So you can add like the highle thing you can add like this individual kind of like component you can click add to data set and you can basically add it to to an existing data set. data sets themselves just showing them really quickly are nothing more than kind of like examples so examples of inputs and optionally outputs. so so as armor said there's a bunch of cool things you can do if even if you don't have outputs and then you can run tests over them. And so I think the tiein here is like just as you would define a metric to kind of like optimize your system here you're defining a very similar metric and a very similar kind of like data set but you're using it for this this kind of just like evaluation of your system as a whole. and so I think very very similar concepts kind of like across the two. We've also this is one thing we've added recently is this way of kind of like moving data automatically from production logs into data sets. and I think one of the things that we wanted to make sure if if you think about what and and tell me tell me if this is a a bad understanding more, but what you're what you're doing in the optimization is you're basically saying I'm going to run it over these highle inputs and high level outputs. I'm going to look at places where it was scored correctly at it was scored correctly and then I'm going to take all the like sub examples for each individual node or thing associated with that and create a data set of fshot examples or a data set to fine-tune on or or somehow update the prompt instructions for those nodes. But basically there's this again there's this this trace which has the association between high level metric low-level actually what went into the prompt what actually are the examples.
43:24 and and that's kind of like the data sets that you want to gather. that's exactly right. That's exactly right. And when you set instructions, you basically are taking this small data set and you're basically getting a language model to say, oh well, the task that is kind of described by those examples is the following instructions and you want to generate several of these so that you can run run a search over those as well. But it's really it's building those mini data sets.
43:51 Yeah. And so that's that's one of the things that we put a lot of effort into. And so when you have filtering here, it's not just filtering on the top level. That's the default. But you can do things you can add filters. So like okay, give me all things where the name is like find find docs or something like this. So this would be a substep. Then you can add a filter on the trace. So you can say okay all places and trace we mean like highle parent level trace.
44:19 So give me like all all all subruns where there's this fine docs where it has this highle user score is one and you can filter for that and then you can set up an automation and you can set up an automation where it automatically adds all of these to a data set over time or something like that. and so kind of like programmatically taking these production data and building and then and this is where this is where I think you know it's maybe a good spot to transition into like how to merge these because we have no concept of optimization. and and so you know that's obviously one really big thing that's missing from things in lang chain lang and and and dsi and the value it provides and and maybe just backtracking even to the beginning I know you mentioned in the beginning there's kind of like two big components. One's like the way of of expressing this program and then the other is kind of like this optimization.
45:16 how with with those things as context, how how can we think about combining lingchain and dsi? So I I and and we've discussed this a couple times har I I like to think of p of dsi as sort of pytorchion the stack. So if you I I like analogies and if you think of deep neural networks as like this wonderfully successful paradigm in in machine learning that you know got us here with language models, it really only I think there was a threshold of crossing from fairly messy space to like something where we can actually all talk about the same thing precisely or or and or and or and or and or and or and or and or and or and or and or and and sort of run the same code with the introduction of like piano and you know cafe and eventually things like PyTorch and TensorFlow and other and other cool frameworks. and PyTorch is kind of really neat in my opinion in a bunch of ways, but it's it's not unique. So, I like to think here of like the stack we have in neural networks. There's something like PyTorch and then there's lower level things like, you know, kernels, you know, you know, MKL for CPUs or, you know, various CUDA stuff. And then on top of that there are higher level things like hugging face transformers which is you know most people I'd argue a lot more people are familiar with using using hugging face transformers than pytorch because you what you just want to get birth or GPT2 or one of these models and you just get it ready from there.
46:43 PyTorch is more of like here are the here are kind of like the modular building pieces. Good luck. here are optimizers and here are like layers and here's convolution layers. here's dropout layers. do something cool. and I kind of like to think of DSP as this the btor of this stack of of basically saying, you know, it's a small framework. We're going to give you these layers. Here's a chain of thought layer. Here's a program of thought layer.
47:08 Here's a React layer that sort of is is is also similarly abstract. And here's the notion of signatures and the notion of optimizers. Here is how you build stuff with them. Good luck sort of you know and and we can help you sort of think about how to construct this these programs if you want but otherwise here's a bunch of optimizers that we're continually expanding to take these programs and give you high quality systems. in my conception and obviously you know please feel free to correct that or otherwise like you know describe your your your framing one of the things it's not necessarily the only thing but one of the things that lang is just outstanding at is kind of how it it brings in higher level pieces of the stack and also lower level pieces of the stack. So you have all these like language models integrated and all these like uniform abstractions around all kinds of tools. That's on the lower level. But on the higher level, you have all these, you know, various chains and various agents and lots of sort of, sort of tracing systems and other things that that say like, well, assuming you know the right prompts or assuming you're given the right prompts in one way or another, or that you're using prompts that are sort of pre pre-built, either from the hub or that are sort of internal to Langchain, you know, or otherwise. here's here's what you could do with it and here's how you could sort of think about streaming and think about these types of these types of of things. In DSP we don't think about almost any of that except to the extent that we strictly need where we're focused is what are the right declarative modules like chain of thought and what are the right sort of fundamental abstractions like assertions or metrics and what are the right optimizers and this is really where we spend most of the time. It's like how can we think about the algorithms that optimize this? So this was a long way of saying in in principle any any lang chain system any any chain is a class of of these language programs and as we've shown together in the demo before that that that like integration we did earlier like kind of a beta level integration it's nothing preventing us from taking that sort of compiling it with BSPI to get like you know to get new prompts, plug them back into Langchain, and then you have a chain that has been optimized with these prompts. But what you showed today with Langsmith is also of the sort where you could also have another plug-in space, which is well, not just the optimizers, building the data set. So you, you know, you're starting out, you have no data set, you've written some initial prompts, you're they're good enough to, to create a demo, and they're good enough to like put in front of your friends and some users to get some feedback. and and that means you can get you start getting a wealth of really really realistic data into the lang traces and if you could export that in a smooth way into like here's a data set for DSPI and maybe here is like a way to think about the metrics I'm not sure what's the best way to to to do that but maybe there are like simple abstractions that we could build in that space so yeah here is a metric here is the chain I have here is the traces from the data you know from putting this is in front of some users or I already have it in production and I already have the traces in some cases. yeah, let's let's see how how much better an optimizer could do at this and kind of like plug it back in. The ways in which this is this requires development effort is lang lang chain gives you a lot of cool things around like I think the main reason you have an expression language or like a graph abstraction is because you want to be able to think about streaming and think about you know kind of production type deployment type things. And so the question is how do we take the you know how do we take prompts that we are producing and not lose that part in in langu plug them back into the chain that you've had and we've had simple stuff you know in in that stage with with the stuff we built before but I'm pretty sure we could kind of also make it more general and more modular and more robust and I'm personally very excited about that type of thing. Yeah, maybe. Okay, maybe maybe taking some of that. It seemed in my mind there's maybe like three main things that are interesting. One, which I think you you said I hadn't thought of until this, but I think is maybe the easiest is just like around like the the data sets and evaluation like you can use those for different things. You can use them for optimization, you can use them for testing and eval. And one of the big pushes we're doing is like you like eval are so important and like they're important not only for knowing how the system's doing but also so you can optimize it. And so I think like having a really seamless kind of like handoff there is incredibly easy and like having a way to export lingchain data sets into DSPI format. having a way to use metrics in one or the other that that seems like a pretty easy kind of like just just compar just yeah just straight up thing there. the other way I I think like you know both if you think about the two big things of DSPI as you said there's one which is like the way of expressing the control flow and then there's the optimizers and LE cell and lingraph are also ways of expressing control flow with different with different benefits right I think they're focused on on kind of like different things and so one I don't know how much work this would be but like one thing is definitely just a way of switching between those two control flows so like you We we did a very simple version of this. but yeah, a much tighter version would be like any program written in kind of like DSPI could could be compiled to LEL or or to Lingraph. and and I yeah and and and that's probably a largeish undertaking, but if anyone in the audience is, you know, I think that's a really cool project that would get you really familiar with the guts of both. And then a third and I don't know how feasible this is. You know, you like the there's there's so many optimizers in DSPI. Could those be applied to a different control flow kind of like thing? So is there a way of using optimizers on like raw langraph syntax?
53:19 I'd assume there need to be some kind of like conditions met. One of the big ones I'm assuming is this concept of tracing which again has been like such kind of like an emphasis for it is that's that's the main reason I'd be bullish on this but I don't I you know the technical details of this way better than I do so like is that even this is this is easier Harrison so optimizing graph is easier I mean at least at least like yeah intellectually for sure probably also in an implementation sense than compiling let's say which I'm very interested in both but compiling or like I mean it's a different sense of compiling so I don't want to confuse people but like taking a a DSP program and emitting an a line graph or LCL l could be hard I don't know how to so so here's here's the here's the thing the challenge is in principle people could put put like exceptions or like recursion or like some really you know like free form things and obviously as you said there's a trade-off. It's kind of like if you think of KAS versus like PyTorch, most neural networks are expressable pretty easily in both.
54:30 But if you do something really crazy in PyTorch, then you're sort of like how do I and and it can be done eventually, right? It can be done. It's just a little harder, especially automating it might be even harder. But the notion of and and you know, I mean, maybe maybe doing it for like the 90% of applications is good enough. I mean, that's that's going to be a pretty big win in general for the community.
54:49 but optimizing lang graph objects is probably like conceptually very simple and we just need to figure out the mechanics and so if somebody's interested to chat like you know somebody in the community wants to help with this I'm sure Harrison and I certainly like on our end we're happy to help you and you know think about how to do that. Yeah, I would I would I mean I we'll chat offline. I want to explore what that looks like because I do think yeah like getting going from DSPI to LE cell 100% is going to be a pretty large undertaking. So if you think it's easier to to apply the optimizations like you know fantastic I we've got two minutes left so I wanted to ask you one other like interesting question. We've talked about optimizing prompts. We've talked about optimizing examples, weights. What about the flow itself? Have you thought about like what it would be like to optimize the flow itself?
55:46 Yeah. I'm sometimes like I I the the context of the stuff I showed today is I like to think about my biggest issue with language models is that they're as as powerful as they are, they're bad at being they're bad at control. I like to control these things when I'm building a system and they're not really ammenable to that. Lots of things in line chain are helping with that. and they are bad at sort of planning or search and like optimization in in the sense we have in the SPI. the issue with optimizing the flow is it's kind of also giving giving up control over the part that's like grounding us in understanding what's supposed to happen.
56:29 in principle, you could have a program synthesis or even just code generation loop where you're asking GPT4 like here are 10 examples of DSP programs, please generate a new one for this task and it will work like it does generate valid programs. but the question is like do we want to do that like at this point at this point I I think language models are so blackbox and the contribution of things like DSP and lang chain is that hey you could actually think about like you could focus on this program or this chain and focus on the composition and focus on like understanding those pieces together and so I'm very reluctant to already move into the world where it's like more blackbox more magic and nobody knows like what the actual program is going to do and I suspect it will not quality. I think there's a lot of value in designing those things. which which is which is back to this notion of like flow engineering, right? Bringing in these pieces, being careful about them.
57:24 Yeah. Yeah. That's a that's a great way to end it as well. We're actually doing a webinar with itar from from the alphaodium paper on flow engineering in a few weeks. So, that's a great way to end it as well. And yeah, optimization and flow engineering are definitely two of the most interesting things that I think are are people are talking about in the space right now. So, Thank you, Omar, for coming on. This was a lot of fun. Thank you everyone for tuning in. I hope I hope you enjoyed it.
57:50 Awesome. Thanks so much. All right. Cheers.
Summary
- DSPI enables the creation of language programs that decompose complex tasks into modular components, enhancing clarity and maintainability.
- The framework automates the optimization of prompts for various language models, allowing for easier transitions between models without rewriting code.
- DSPI emphasizes the importance of "flow engineering," where the control flow of tasks is explicitly defined and optimized.
- The conversation highlights the significance of tracing in both DSPI and Langchain, allowing for the collection of examples and metrics to improve model performance.
- Optimization strategies in DSPI include refining instructions, generating examples, and fine-tuning model weights, which can be combined for enhanced results.
- The potential for integrating DSPI with Langchain is discussed, particularly in terms of data sets, evaluation metrics, and optimizing control flows.
- Omar expresses caution about fully automating flow optimization, advocating for a balance between leveraging language models and maintaining control over program design.
Questions Answered
What is DSPI and why was it built?
DSPI is a framework designed to optimize the development of language programs by breaking down complex problems into manageable pieces, allowing for the integration of AI models where traditional programming falls short.
What challenges do developers face when working with language models?
Developers often encounter difficulties when trying to switch models or methods, such as moving from prompting to fine-tuning, which can require extensive rewrites of existing code.
What is being optimized in DSPI and how does it work?
Optimization in DSPI involves defining the context and signatures for queries and responses, allowing for the construction of effective prompts and learning from the model's outputs.
How does DSPI address the balance between task stability and pipeline flexibility?
DSPI allows developers to maintain a stable task while enabling flexibility in the pipeline, facilitating experimentation and adaptation without altering the core task.
How does DSPI fit into the broader landscape of AI development tools?
DSPI serves as a modular framework that provides essential building blocks for creating language programs, similar to how PyTorch and Hugging Face Transformers operate, but with a focus on optimizing language model interactions.