Join the conversation

Join the community of Machine Learners and AI enthusiasts.

Sign Up
m-ricย 
posted an update May 24
Post
978
๐๐ž๐ฐ ๐ ๐ฎ๐ข๐๐ž ๐ข๐ง ๐จ๐ฎ๐ซ ๐Ž๐ฉ๐ž๐ง-๐’๐จ๐ฎ๐ซ๐œ๐ž ๐€๐ˆ ๐œ๐จ๐จ๐ค๐›๐จ๐จ๐ค: ๐™Ž๐™ฉ๐™ง๐™ช๐™˜๐™ฉ๐™ช๐™ง๐™š๐™™ ๐™œ๐™š๐™ฃ๐™š๐™ง๐™–๐™ฉ๐™ž๐™ค๐™ฃ! โœจ

Many use LLM use cases involve generating outputs with a specific structure.

โžก๏ธ For instance when using an LLM as a judge to evaluate another model's outputs, you need it to give you not only a score, but also the rationale for this score, and maybe a confidence level.
So you do not need only "score: 1", but more a dictionary like:
{
     "rationale": "The answer does not match the true answer at all."
     "score": 1,
     "confidence_level": 0.85
}


๐Ÿค” How to force your LLM to generate such a structured output?

๐Ÿ—๏ธ ๐—–๐—ผ๐—ป๐˜€๐˜๐—ฟ๐—ฎ๐—ถ๐—ป๐—ฒ๐—ฑ ๐—ฑ๐—ฒ๐—ฐ๐—ผ๐—ฑ๐—ถ๐—ป๐—ด is a great technique to generate structured output: you can specify a grammar (=set of rules) that the output should follow, and ๐—ฐ๐—ผ๐—ป๐˜€๐˜๐—ฟ๐—ฎ๐—ถ๐—ป๐—ฒ๐—ฑ ๐—ฑ๐—ฒ๐—ฐ๐—ผ๐—ฑ๐—ถ๐—ป๐—ด ๐˜๐—ต๐—ฒ๐—ป ๐—ณ๐—ผ๐—ฟ๐—ฐ๐—ฒ๐˜€ ๐˜๐—ต๐—ฒ ๐—ฑ๐—ฒ๐—ฐ๐—ผ๐—ฑ๐—ฒ๐—ฟ ๐˜๐—ผ ๐—ผ๐—ป๐—น๐˜† ๐—ฝ๐—ถ๐—ฐ๐—ธ ๐˜๐—ผ๐—ธ๐—ฒ๐—ป๐˜€ ๐˜๐—ต๐—ฎ๐˜ ๐—ฟ๐—ฒ๐˜€๐—ฝ๐—ฒ๐—ฐ๐˜ ๐˜†๐—ผ๐˜‚๐—ฟ ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ฎ๐—ฟ.

I've created a guide to show you how to use it, both via our Inference API and locally using ๐˜ฐ๐˜ถ๐˜ต๐˜ญ๐˜ช๐˜ฏ๐˜ฆ๐˜ด!

๐Ÿ‘‰ Read it here: https://huggingface.co/learn/cookbook/structured_generation

Thank you @stevhliu for your great help in improving it!
In this post