News for hackers. Stuff that matters.
Re:Introducing Structured Outputs in the API by titzer on Tuesday August 06, 2024 @02:20PM (#41173616)
It's so wild that the bar for AI performance is both absurdly high and absurdly low at the same time. To specify an output format (language or grammar) for solving a computational problem is one of the oldest exercises around. On the one hand, it's breathtakingly mundane that the model can now do the most basic of tasks: conform to an output specification. It's weird reading the kind of self-congratulating blogpost about this, like OpenAI has just discovered flint knives. On the other hand, a computer system can process natural language with extremely ambiguous, open-ended problems, compute solutions to said problems, even correct its own mistakes--and then it can format the output correctly. And then on yet another hand, it only took about 10^25 floating point operations (yeah, just ten million trillion trillion, right!?) to get this outcome.
Re:Introducing Structured Outputs in the API by throwawaymaths on Tuesday August 06, 2024 @03:39PM (#41174452)
> On the one hand, it's breathtakingly mundane that the model can now do the most basic of tasks: conform to an output specification.

I highly doubt it's the model that does this... It's very likely code injected into the token picker. You could put this into any model all the way down to gpt-2.

Re:Introducing Structured Outputs in the API by crowcroft on Tuesday August 06, 2024 @04:04PM (#41174739)
I wonder if you get 90% of the way with prompt engineering, and then the last 10% is just brute force, validate output, if it fails, rerun the prompt.

My assumption is if that's all this is they would have done it a long time ago though.

Re:Introducing Structured Outputs in the API by dilap on Tuesday August 06, 2024 @04:18PM (#41174883)
You just sample from a grammar and you automatically get 100%; who knows but it seems the most likely thing they are doing. llama.cpp has supported this for a while ( using a BNF-style grammar -- https://github.com/ggerganov/llama.cpp/blob/master/grammars/... )

edit: oh actually, we do sort of know -- they call out jsonformer as an inspiration in the acknowledgements

https://github.com/1rgs/jsonformer

Re:Introducing Structured Outputs in the API by senko on Tuesday August 06, 2024 @05:37PM (#41175644)
Using this in a naive way can easily degenerate into the LLM outputting syntactically/gramatically valid tokens that make no sense, like in this example: https://community.openai.com/t/json-format-causes-infinite-n...

This might be even more pronounced when the output is restricted more using the JSON schema.

So the heavy lifting here was most likely to align the model to avoid/minimize such outcomes, not in tweaking the token sampler.

Re:Introducing Structured Outputs in the API by dilap on Tuesday August 06, 2024 @06:03PM (#41175883)
Isn't your example showing an issue w/ the opposite approach, where someone is getting bad output w/ an earlier openAI json mode that worked via training rather than mechanical output restriction to conform to a schema?

FWIW (not too much!) I have used llama.cpp grammars to restrict to specific formats (not particular json, but an expected format), fine-tuned phi2 models, and I didn't hit any issues like this.

I am not intuitively seeing why restricting sampling to tokens matching a schema would cause the LLM to converge on valid tokens that make no sense...

Are there examples of this happening w/ people using e.g. jsonformer?

Re:Introducing Structured Outputs in the API by TheEzEzz on Tuesday August 06, 2024 @07:47PM (#41176750)
You're basically taking the model "off policy" when you bias the decoder, which can definitely make weird things happen.
Re:Introducing Structured Outputs in the API by crowcroft on Tuesday August 06, 2024 @04:31PM (#41174993)
Oh, thanks for the links. Super interesting!
Re:Introducing Structured Outputs in the API by jeeceebees on Tuesday August 06, 2024 @04:16PM (#41174870)
You can just mask the output probabilities for each token based on which options are valid according to a grammar.

There are quite a few open source implementations of this e.g. https://github.com/outlines-dev/outlines

Re:Introducing Structured Outputs in the API by contravariant on Tuesday August 06, 2024 @05:29PM (#41175582)
You could simply censor invalid tokens, but that does rely on 2 assumptions.

1. There is always a valid next token.

2. This greedy algorithm doesn't result in a qualitatively different distribution from a rejection sampling algorithm.

The latter isn't too obvious, and may in fact be (very) false. Look up maze generation algorithms if you want some feeling for the effects this could have.

If you just want a quick argument, consider what happens if picking the most likely token would increase the chance of an invalid token further down the line to nearly 100%. By the time your token-picking algorithm has any effect it would be too late to fix it.

Re:Introducing Structured Outputs in the API by throwawaymaths on Tuesday August 06, 2024 @06:25PM (#41176082)
Sorry, how could there not be a valid next token? Presumably your interface would generate a state machine with appropriate masking arrays, and iirc generally speaking all 256 byte choices are in the token list. There's no way to get stuck in a place where the JSON is invalid? Can you give an example?

If you want to be really clever about your picker, a deterministic result would blat out the all the known possible strings.

For example, if you had an object with defined a defined set of properties, you could just go ahead and not bother generating tokens for all the properties and just tokenize, E.G. `{"foo":"` (6-ish tokens) without even passing through the LLM. As soon as an unescaped `"` arrives, you know the continuation must be `,"bar":"`, for example

> This greedy algorithm doesn't result in a qualitatively different distribution from a rejection sampling algorithm.

It absolutely will. But so will adding an extra newline in your prompt, for example. That sort of thing is part and parcel of how llms work

Re:Introducing Structured Outputs in the API by contravariant on Tuesday August 06, 2024 @06:55PM (#41176345)
Hmm, I think any example where it can get stuck is going to be a bit contrived since really it's a question of how easy it is to recognize a valid prefix. Say for example you want the LLM to generate a valid chess match and it ends up in a situation with just 2 kings left. If you're not careful with your definitions you could end up in an endless loop that never ends.

That said if you know all valid prefixes in your language in advance then you can always realise when a token leaves no valid continuations.

> It absolutely will. But so will adding an extra newline

A newline is less likely to dramatically drop the quality, a greedy method could easily end driving itself into a dead end (if not grammatically then semantically).

Say you want it to give a weather prediction consisting of a description followed by a tag 'sunny' or 'cloudy' and your model is on its way to generate

    { 
      desc: "Strong winds followed by heavy rainfall.", 
      tag: "stormy" 
    }
If it ever gets to the 's' in stormy it will be forced to pick 'sunny', even if that makes no sense in context.
Re:Introducing Structured Outputs in the API by arjvik on Tuesday August 06, 2024 @07:05PM (#41176437)
Schema needs to be a part of the prompt as well so it can associatively recall the options
Re:Introducing Structured Outputs in the API by throwawaymaths on Tuesday August 06, 2024 @06:10PM (#41175943)
Yeah but that's hugely wasteful of tokens.
Re:Introducing Structured Outputs in the API by thruway516 on Tuesday August 06, 2024 @03:32PM (#41174385)
I dont understand your complaint at all. If you develop a new revolutionary technology called an automobile, developing steering, brakes, starter, mufflers for it is a pretty big deal even if reins, clamps, mufflers and keys are mundane and have existed for decades. Structured outputs are a pretty big step in making this magic actually usable by developers as opposed to generating impressive cat pictures or whatever has captured the public imagination.
Re:Introducing Structured Outputs in the API by Bjartr on Tuesday August 06, 2024 @03:36PM (#41174421)
I don't think it was an complaint, just a observation.
Re:Introducing Structured Outputs in the API by thruway516 on Tuesday August 06, 2024 @04:21PM (#41174912)
Yes probably. But considering non-deterministic outputs is the nature of the beast with Llms and we're (mostly) engineers here, calling any part of this mundane sounds almost more like fighting words than just observation
Re:Introducing Structured Outputs in the API by the8thbit on Tuesday August 06, 2024 @04:51PM (#41175218)
Extremely pedantic, but is "non-deterministic" really the right language? The same input will always produce the same output, provided you haven't intentionally configured the system to use the model non-deterministically. It seems like the right way to describe it is as a chaotic deterministic system. The same input will always produce the same output, but small shifts in the input or weights can result in dramatic and difficult to predict changes in outputs.
Re:Introducing Structured Outputs in the API by visarga on Tuesday August 06, 2024 @05:00PM (#41175331)
> The same input will always produce the same output

Not guaranteed even with the same seed. If you don't perform all operations in exactly the same order, even a simple float32 sum, if batched differently, will result in different final value. This depends on the load factor and how resources are allocated.

Re:Introducing Structured Outputs in the API by simonw on Tuesday August 06, 2024 @05:03PM (#41175360)
Yeah, the fact that floating point multiplication isn't associative is a real pain for producing deterministic outputs - especially when you're running massively parallel computations on GPUs (or multiple GPUs) making the order of operations even less predictable.
Re:Introducing Structured Outputs in the API by taneq on Wednesday August 07, 2024 @01:39AM (#41178528)
This doesn’t mean LLMs are inherently non-deterministic, just that current common implementations are non-deterministic.
Re:Introducing Structured Outputs in the API by davedx on Tuesday August 06, 2024 @05:00PM (#41175321)
Llms are indeed non deterministic
Re:Introducing Structured Outputs in the API by jappgar on Tuesday August 06, 2024 @05:46PM (#41175720)
Structured outputs are hard... but they claimed to have solved this a year ago.

They were lying, of course, and meanwhile charged output tokens for malformed JSON.

Re:Introducing Structured Outputs in the API by jiggawatts on Tuesday August 06, 2024 @10:30PM (#41177694)
Structured output is trivial: just select the output tokens from the given list of probability values filtered for the allowed next tokens in the schema.

Other LLM vendors figured this out many months ago.

Re:Introducing Structured Outputs in the API by retinaros on Wednesday August 07, 2024 @06:27PM (#41186218)
they did not . anthropic often sends broken json
Re:Introducing Structured Outputs in the API by ramraj07 on Tuesday August 06, 2024 @03:33PM (#41174395)
This is like saying “we shouldn’t be celebrating a computer that can talk, my parrot can do that!”
Re:Introducing Structured Outputs in the API by thruway516 on Tuesday August 06, 2024 @04:12PM (#41174827)
Lol. You said it better than I.
Re:Introducing Structured Outputs in the API by scarmig on Tuesday August 06, 2024 @04:00PM (#41174693)
I have struggled writing valid YAML before (my tokenizer doesn't handle whitespace very well). And it probably takes me a quadrillion operations on the reals to get a minimal YAML file (I think your 10^25 flops is an overestimate--I think it's more like 10^18-10^19).

It's kind of like an inverse Moravec's paradox.

Re:Introducing Structured Outputs in the API by theturtle32 on Tuesday August 06, 2024 @06:09PM (#41175928)
Relatable!!
Re:Introducing Structured Outputs in the API by m3kw9 on Tuesday August 06, 2024 @04:15PM (#41174849)
It’s doing more, it is allowing user to input using natural language and the output is the json format the API that is defined
Re:Introducing Structured Outputs in the API by tommica on Tuesday August 06, 2024 @03:32PM (#41174380)
For some reason it reminds me of my civilization runs - rush to certain high level tech and then after that discovery writing :D
Re:Introducing Structured Outputs in the API by codingwagie on Tuesday August 06, 2024 @02:34PM (#41173776)
I think it will take a long time for the world at large to realize and then operationalize the potential of this "mundane" technology. It is revolutionary, and also sitting in plain sight. Such a huge technological shift that was considered decades out only a few years ago
Re:Introducing Structured Outputs in the API by ben_w on Tuesday August 06, 2024 @03:32PM (#41174383)
Although I am an optimist* about what this can do, I am very much aware — from personal experience — how easy it is to see more than is really there.

The realisation of the tech might be fantastic new things… or it might be that people like me are Clever Hans-ing the models.

* that may be the wrong word; "strong capabilities" is what I think is present, those can be used for ill effects which is pessimistic.

Re:Introducing Structured Outputs in the API by srcreigh on Tuesday August 06, 2024 @02:41PM (#41173861)
If I wanted to be a silly pedant, I’d say that Turing machines are language specifications and thus it’s theoretically impossible for an LLM or any program to validate output formats in general.
Re:Introducing Structured Outputs in the API by jes5199 on Tuesday August 06, 2024 @03:22PM (#41174285)
in _general_ sure, but if you restricted each token to conform to a Kleene-star grammar you should be able to guarantee that you get something that parses according to a context-free grammar
Re:Introducing Structured Outputs in the API by raincole on Tuesday August 06, 2024 @04:33PM (#41175019)
I don't know, it doesn't sound wild at all to me. Human languages are very imprecise, vague and error-tolerant, which is the opposite of an output format like JSON. So the a model can't do these two things well at the same time is quite an intuitive conclusion.

The wild part is that a model trained with so much human language text can still outputs mostly compilable code.

Re:Introducing Structured Outputs in the API by berkes on Wednesday August 07, 2024 @05:24AM (#41179623)
I am so often surprised by "The AI Communities" software. Often unpleasantly surprised, often just eye-rolling.

When we first started using the OpenAI API's, the first thing I reached for was some way "to be certain that the response is properly formatted". There wasn't one. A common solution was (is?) "just run the query again, untill you can parse the JSON". Really? After decades of software engineering, we still go for the "have you tried turning it off and on again" on all levels.

Then I reached for common, popular tools: everyone's using them, they ought to be good, right? But many of these tools, from langchain's to dify to promptflow are a mess (Edit: to alter the tone: I'm honestly impressed by the breadth and depth of these tools. I'm just suprised about the stability - lack thereof, of them). Nearly all of them suffer from always-outdated-documentation. Several will break right after installing it, due to today's ecosystem updates that haven't been incorporated entirely yet. Understandably: they operate in an ecosystem that changes by the hour. But after decades of software engineering, I want stuff that's stable, predictable, documented. If that means I'm running LLM models from a year ago: fine. At least it'll work. Sure, this constant-state-of-brokeness is fine for a PoC, a demo, or some early stage startup. But terrible for something that I want to ensure to still work in 12 months, or 4 years even without a weekly afternoon of upgrade-all-dependencies-and-hope-it-works-the-update-my-business-logic-code-to-match-the-now-deprecated-apis.

Re:Introducing Structured Outputs in the API by KoolKat23 on Wednesday August 07, 2024 @07:18AM (#41180191)
Well the simple answer is don't use it then.

In the same way people revert to older stable releases. You're welcome to revert to writing boilerplate code yourself.

The reason people are excited and use it, is because they show promise, it already offers significant benefits even if it isn't "stable".

Re:Introducing Structured Outputs in the API by berkes on Wednesday August 07, 2024 @07:37AM (#41180307)
"Just write your own if you aren't happy" doesn't make my critique invalid.

My problem is that this community, and thus the ecosystem, is repeating many mistakes, reinventing wheels, employing known bad software-engineering practices, or lacking any software-engineering practices at all. It is, in short, not learning from decades of work.

It's not standing on shoulders of giants, it's cludging together wobbly ladders to race to the top. Even if "getting to the top first" is the primary goal, it's not the fastest way. But certainly not the most durable way.

(To be clear: I have seen the JS (node) community doing the exact same, racing fast towards cliffs and walls, realizing this, throwing it all out, racing to another cliff and so on. And I see many areas in the Python community doing this too. Problems have been solved! For decades! Learn from these instead of repeating the entire train of failures to maybe finally solve the problems in your niche/language/platform/ecosystem)