3 ms·
How does the LLM know what valid JSON tokens are? What if the training data contains malformed JSON? There ought to be a non-zero chance of the LLM producing
by RyEgswuCsn 3y ago
How does the LLM know what valid JSON tokens are?
What if the training data contains malformed JSON? There ought to be a non-zero chance of the LLM producing invalid JSON, no?
- catlifeonmars 3y agoI think the idea is that it’s easy to filter the result set to restrict to just valid JSON.
- MereInterest 3y agoLLMs work by outputting a value for each token, then using those values to generate a probability distribution. Usually, this will be through a function like softmax [0], but there's nothing preventing you from doing some post-processing first. That post processing could be aware of the tokens that would be valid as the next token in a JSON format, and set the probabilities of all other tokens to zero. That way, even if the training data contains malformed JSON, the generator is still constrained to produce valid JSON. [0] https://en.wikipedia.org/wiki/Softmax_function https://en.wikipedia.org/wiki/Softmax_function
- RyEgswuCsn 3y agoBut that is not the LLM learning to produce valid JSON —— as some other commenters mentioned, you can get valid json without the LLM. Sure it could be useful, but not really impressive.