Show HN: LLMs can generate valid JSON 100% of the time Outlines is a Python library that focuses on text generation with large language models. Brandon and I are not LLM experts and started the project a few months ago because we wanted to understand better how the generation process works. Our original background is probabilistic, relational and symbolic programming. Recently we came up with a fast way to generate text that matches a regex ( https://ift.tt/qQKtZlL... ). The basic idea is simple: regular expressions have an equivalent Deterministic-Finite Automaton (DFA) representation. We can transform this DFA into a generative model: in each state we get a list of symbols which correspond to completions that partially match the regular expression. We mask the other symbols in the logits returned by a large language model, sample a new symbol and move to the next state. The subtelty is that language models work with tokens, not symbols, so we derive a new FSM whose alphabet is the model's vocabulary. We can do this in only one pass over the vocabulary. Generating the token masks thus only requires a dictionary lookup at each state. Our method blows other libraries like Microsoft's guidance out of the water. From there it was only a small leap to be able to generate text that follows a JSON schema ( https://ift.tt/i3qZpeO ), or is parseable into a Pydantic model ( https://ift.tt/ExNciWs ). The method works with union types, optional types, nested schemas, arrays, everything. It is guaranteed that the output is parseable. I think it's cool, and I've spent a lot of time watching even tiny models output valid JSON over the weekend. Hope you will too. I look forward to feedback, bug reports, feature requests and discussions! Edit: Link to our pre-print explaining the method and how this can be extended to generate text that follows a Context-Free Grammar https://ift.tt/ZdmslqH https://ift.tt/SyBvN7P August 15, 2023 at 12:22AM
Show HN: LLMs can generate valid JSON 100% of the time https://ift.tt/FS6jJcd
Related Articles
Show HN: WireHole combines WireGuard, Pi-hole, and Unbound with an easy UI https://ift.tt/FtSVpc1Show HN: WireHole combines WireGuard, Pi-hole, and Unbound with an eas… Read More
Show HN: Marmotte – Open-Source IT Asset Management Made Simple https://ift.tt/9DNMLQWShow HN: Marmotte – Open-Source IT Asset Management Made Simple https:… Read More
Show HN: A local Python prototyping tool for Jupyter and Streamlit https://ift.tt/HebURADShow HN: A local Python prototyping tool for Jupyter and Streamlit Hey… Read More
Show HN: Maven to Gradle (Dependency Conversion) https://ift.tt/dn9GiMFShow HN: Maven to Gradle (Dependency Conversion) Very tiny project to … Read More
Show HN: Protobuf Based Schema Centric Logging Framework https://ift.tt/qBo0EXgShow HN: Protobuf Based Schema Centric Logging Framework Hi HN, have b… Read More
Show HN: An AI that reads privacy policies for you https://ift.tt/vufKarEShow HN: An AI that reads privacy policies for you https://ift.tt/MACo… Read More
Show HN: Yet another HN UI clone (sorry) https://ift.tt/Qv4oNGsShow HN: Yet another HN UI clone (sorry) Inspired by https://ift.tt/su… Read More
Show HN: ChatGQL – Natural Language Conversations with GraphQL APIs https://ift.tt/uQvRPGTShow HN: ChatGQL – Natural Language Conversations with GraphQL APIs ht… Read More
0 Comments: