News for hackers. Stuff that matters.
Re:Stanford DSPy: The framework for programming with foundat... by grandma_tea on Thursday September 07, 2023 @10:55AM (#37419809)
This is really cool! It took me a bit to understand what this thing is for so allow me to summarize:

For simple LLM tasks, don't bother using this tool. It won't do much for you.

If you have a more complicated task (eg. knowledge database lookups, chain of thought reasoning, multi-hop lookups...) then DSPy offers 2 things: a clean class-based representation of your workflow, and a way to *solve* for the best prompt structure to solve your problem.

To me, the last part is the most interesting because it promises to eliminate tedious prompt engineering. All you need is a set of examples to "train" your prompts on.

Re:Stanford DSPy: The framework for programming with foundat... by wokwokwok on Thursday September 07, 2023 @11:31AM (#37420421)
Did you actually try it and find it useful or are you just speculating?

I was not particularly impressed by the tutorial notebook. I’m not sure I believe that automatic prompt generation is nearly as easy as it sounds.

What task did you try it on?

Re:Stanford DSPy: The framework for programming with foundat... by okhat on Thursday September 07, 2023 @11:34AM (#37420494)
What did you find underwhelming if I may ask?

It shows you how it takes some ~25 Pythonic lines of code to make GPT-3.5 retrieval accuracy go from the 26-36% range to 60%.

Not a bad deal when you apply it to your own problem?

Re:Stanford DSPy: The framework for programming with foundat... by wokwokwok on Thursday September 07, 2023 @11:48AM (#37420757)
The examples appear to knowledge retrieval and factoids only.

The concept appears to be large scale chain of thought and automatic prompt generate and fine tuning… but there don’t appear to be actual examples of this.

Re:Stanford DSPy: The framework for programming with foundat... by okhat on Thursday September 07, 2023 @11:54AM (#37420843)
Ah okay makes sense, yeah we'll release more examples.

This is just an intro to the key concepts/modules.

Re:Stanford DSPy: The framework for programming with foundat... by wokwokwok on Thursday September 07, 2023 @12:01PM (#37420978)
The problem is, there is a big song and dance about string template prompts.

…but, carefully crafted string templates would be a) simpler and b) arguably better with existing solutions for this task, because it’s a trivial task and you can hand massage your string template prompts for that.

So, the narrative really doesn’t make sense, unless you’re doing something hard, but the example just shows doing something easy in a very complicated way.

I get it, maybe you can scale this up better… but you’re really not showing it off well.

Re:Stanford DSPy: The framework for programming with foundat... by okhat on Thursday September 07, 2023 @12:10PM (#37421135)
@wokwokwok Okay now we disagree. This task is not easy, it's just easy to follow in one notebook. (If it were easy, the RAG score wouldn't be 26%.)

As for "carefully crafted string templates", I'm not sure what your argument here is. Are you saying you could have spent a few hours of trial and error writing 3 long prompts in a pipeline, until you matched what the machine does in 60 seconds?

Yes, you probably could have :-)

Re:Stanford DSPy: The framework for programming with foundat... by simonw on Thursday September 07, 2023 @11:02AM (#37419942)
I really want to understand that second part! I think that's the part I haven't been able to get my head around yet.
Re:Stanford DSPy: The framework for programming with foundat... by okhat on Thursday September 07, 2023 @11:16AM (#37420175)
Here's the key idea.

You give DSPy (1) your free-form code with declarative calls to LMs, (2) a few inputs [labels optional], and (3) some validation metric [e.g., sanity checks].

It simulates your code on the inputs. When there's an LM call, it will make one or more simple zero-shot calls that respect your declarative signature. Think of this like a more general form of "function calling" if you will. It's just trying out things to see what passes your validation logic, but it's a highly-constrained search process.

The constraints enforced by the signature (per LM call) and the validation metric allow the compiler [with some metaprogramming tricks] to gather "good" and "bad" examples of execution for every step in which your code calls an LM. Even if you have no labels for it, because you're just exploring different pipelines. (Who has time to label each step?)

For now, we throw away the bad examples. The good examples become potential demonstrations. The compiler can now do an optimization process to find the best combination of these automatically bootstrapped demonstrations in the prompts. Maybe the best on average, maybe (in principle) the predicted best for a specific input. There's no magic here, it's just optimizing your metric.

The same bootstrapping logic lends itself (with more internal metaprogramming tricks, which you don't need to worry about) to finetuning models for your LM calls, instead of prompting.

In practice, this works really well because even tiny LMs can do powerful things when they see a few well-selected examples.

Re:Stanford DSPy: The framework for programming with foundat... by thelastbender12 on Thursday September 07, 2023 @01:25PM (#37422414)
Hi Omar - thanks for engaging here. I have a similar question to simonw, it _feels_ like there is something useful here but I haven't managed to grok it yet, after sitting through the tutorial notebooks.

Specifically, to your description above, I'd love seeing specific retrieval examples, where you need more-complex pipelines. Zero shot QA (1-step), few-shot QA (2-step), retrieval + few-shot QA (3-step) all make sense, but when the README starts talking about demonstrations, I can't really follow when is that actually needed. Also, it starts feeling too magical when you introduce "smaller LMs" since I don't know what those are.

Re:Stanford DSPy: The framework for programming with foundat... by apstls on Thursday September 07, 2023 @02:36PM (#37423548)
I'm trying to wrap my head around this project too, since it does seem interesting. Similar to what OP wrote, the sense I got from poking around (and of course from reading the bit in the README that basically says exactly this) was that there are two distinct pieces here, the first being a nice, clean library for working directly with LLMs that refreshingly lacks the assumptions and brittle abstractions found in many current LLM frameworks, and the second being everything related to automatic optimization of prompts. The second half is the part I'm trying to better understand - more specifically, I understand that it uses a process to generate and select examples that are then added to the prompt, but am unclear if it's also doing any prompt transformations other than these example-related improvements.

As more of an aside, I gave the paper a quick skim and plan on circling back to it when I have more time - are the ideas in the paper an accurate/complete representation of the under-the-hood workings, and general type of optimizations being performed, of the current state of the project?

As another related aside, I vaguely remember coming across this a month or two ago and coming away with a different impression/understanding of it at the time - has the framing of or documentation for the project changed substantially recently, or perhaps the scope of the project itself? I seem to recall focusing mostly on the LM and RM steps and reading up a bit on retrieval model options afterwards. I could very well be mixing up projects or just had focused on the wrong things the first time around of course.

Re:Stanford DSPy: The framework for programming with foundat... by okhat on Thursday September 07, 2023 @02:49PM (#37423746)
Thanks! Lots to discuss from your excellent response, but I'll address the easy part first: DSPy is v2 of DSP (demonstrate-search-predict).

The DSPy paper hasn't been released yet. DSPy is a completely different thing from DSP. It's a superset. (We actually implemented DSPy _using_ DSPv1. Talk about bootstrapping!)

Reading the DSPv1 paper is still useful to understand the history of these ideas, but it's not a complete picture. DSPy is meant to be much cleaner and more automatic.

Re:Stanford DSPy: The framework for programming with foundat... by apstls on Thursday September 07, 2023 @03:17PM (#37424168)
Ah, gotcha! Do you have a rough idea of when the DSPy paper will be released? I'll keep an eye out.
Re:Stanford DSPy: The framework for programming with foundat... by okhat on Thursday September 07, 2023 @03:29PM (#37424351)
Writing right now. This month :-)
Re:Stanford DSPy: The framework for programming with foundat... by sandGorgon on Friday September 08, 2023 @06:28AM (#37431845)
would love your thoughts on this as well - https://github.com/arakoodev/edgechains

got frustrated in the same way with "Black Box Prompting - every library hides prompts/chains in layers of libraries...while it should have been declarative.

EdgeChains - allows u to specify ur prompt and chain in jsonnet. This why i think Generative AI needs declarative orchestration and not previous generations. https://github.com/arakoodev/edgechains#why-do-you-need-decl...