Re:Show HN: LLMs can generate valid JSON 100% of the time
by joshuanapoli on Monday August 14, 2023 @05:55PM
(#37127292)
Isn't the Function Calling feature meant for this purpose? It guides the LLM to output according to the given schema. The name of the feature is a little misleading.
https://platform.openai.com/docs/guides/gpt/function-calling
Re:Show HN: LLMs can generate valid JSON 100% of the time
by tornato7 on Monday August 14, 2023 @05:58PM
(#37127322)
Function Calling is fine-tuned to a certain output format, but it very often strays from that format. My function-calling-handling code has a mess of edge case handlers that catch when GPT-4 is calling functions incorrectly.
Re:Show HN: LLMs can generate valid JSON 100% of the time
by M4v3R on Monday August 14, 2023 @06:04PM
(#37127376)
It’s not though, they even say it in their docs that sending a schema does not guarantee that the model will actually adhere to the scheme or even produce valid JSON
Re:Show HN: LLMs can generate valid JSON 100% of the time
by simonw on Monday August 14, 2023 @06:03PM
(#37127359)
Surprisingly the function calling mechanism doesn't appear to use this trick - apparently it's still possible to get the wrong JSON structure back from it occasionally.
Re:Show HN: LLMs can generate valid JSON 100% of the time
by potatoman22 on Monday August 14, 2023 @05:58PM
(#37127320)
They recently added logit biases, so that's a start.
Re:Show HN: LLMs can generate valid JSON 100% of the time
by remilouf on Tuesday August 15, 2023 @12:30PM
(#37135968)
It's limited to 300 logit biases at a time. Knowing GPT4's vocabulary is ~100k tokens it's not nearly enough to get reliable guided generation. Although it could work in some cases, and another advantage of this work is that we can determine that before generating.
Being able to pass up some kind of grammar (a regular expression, or a JSON schema, or some other format) and have this trick run during their token sampling process to ensure the output was compliant would be incredibly useful.