5 ms·
> LLMs can generate valid JSON 100% of the time If that seems surprising, it is worth doing a course like Karpathy's zero to hero NN, and have all the magic pe
by quickthrower2 3y ago
> LLMs can generate valid JSON 100% of the time
If that seems surprising, it is worth doing a course like Karpathy's zero to hero NN, and have all the magic peeled away a layer at a time.
The reason you can do this is because LLMs don't just generate the next word or token, it produces a probability distribution over all tokens. A JSON parser can give you a list of next valid tokens. The tokens in each case might be from a different set, e.g LLM thinks of " The" whereas the JSON parser might think of "{", so you need some conversion there. But if you sample randomly from only the valid tokens, the output must be valid JSON.
What you can't build a parser for though is ... the truth! You may still be told lies or made up stuff.
- mattigames 3y agoIt's not like humans are particularly good at distinguishing truth from lies.
- quickthrower2 3y agoThe word "lie" is probably too anthropic here. I should have just said "made up". There is no intent to lie. And the model isn't try to self-fact-check anyway. (Maybe some do). But if they do they are probably bad at it at the moment, at least from my experience of GPT3.5 (not used 4 much).
- coder543 3y ago> at least from my experience of GPT3.5 (not used 4 much). And 4 is tremendously better than 3.5, in my own experience. Not perfect, but actually useful.
- quickthrower2 3y agoCan anyone recommend a good, and trusted UI so I can use it via the API? I don't want to pay monthly for it, but would be nice to use occasionally. I keep meaning to do this!
- selcuka 3y agoOpenAI has its own playground where you can test all models (I believe GPT-4 is not available to everyone yet): https://platform.openai.com/playground https://platform.openai.com/playground Monthly subscription is only for ChatGPT. When you use the APIs you pay per token.
- coder543 3y ago> I believe GPT-4 is not available to everyone yet I still don't have access, except through the regular ChatGPT interface, which is mildly annoying. It would be interesting to experiment with the API.
- dilawar 3y ago"Its a human nature to mislead others, sometimes knowingly." I read this line in an anthropology book. A similarly non-cynical approach towards your fellow is "trust but verify".
- dwattttt 3y agoIf you're choosing the next token based on a list of valid next tokens, a uniform random distribution can always generate valid JSON too!
- quickthrower2 3y agoYep. So can this: fun generate_valid_json(seed): return "{}"
- neoncontrails 3y agoBut that's not what an LLM does.
- antonvs 3y agoThe point is that if you're "choosing the next token based on a list of valid next tokens," it's not surprising that you'll only generate valid output, since absolutely any choice mechanism will suffice.
- RyEgswuCsn 3y agoHow 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.
- OJFord 3y agoMaybe it's just me, but I'm not doing anything that calls itself 'zero to hero'. Would love some good resources (preferably textbook, or at least written) on LLMs though. I don't even understand the link to 'generative' image/video AI, which seems to have exploded at roughly the same time and surely isn't a coincidence. I studied a little (literally 'intro to') ML at university, about enough to grok it as an application of stats, tie into things seen elsewhere, but not really more than that. Every supposéd tutorial or explainer I've seen posted here or been able to find has been a weird (IMO) mix if simultaneously assuming a decent (at least greater than mine) ML background, but also really dumbed down clone this repo download that model switch between them like this, fine-tune them by cd'ing to this directory and ... Ok but what's actually going on?
- fenomas 3y agoThe zero to hero video series is what you're looking for - look past the name and watch it. It's excellent.
- frontier 3y agoKarpathy's series is many many hours long and really does take you from zero to GPT. It's excellent! You sound triggered by the title - that may not even be the official title - but it definitely deserves it. Go look it up.
- OJFord 3y agoThe title suggests I wouldn't like it, yes. But as a video series it's not 'a textbook or at least written' is i - not really the format I'm looking for personally.
- thatcherthorn 3y agoTruly.. one of the greatest minds in our ML era. Don't get caught up on the format :)
- OJFord 3y ago
- deleted 3y ago[deleted]
- deleted 3y ago[deleted]