Constrained Sampling from Large Language Models: Producing Structured Output

chloewilliams62 89 views 28 slides Oct 17, 2024
Slide 1
Slide 1 of 28
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28

About This Presentation

Large Language Models (LLMs) are typically used to generate free-form text. However, many applications require output with specific structures or formats. This presentation introduces the concept of constrained sampling from LLMs, a method to produce output that adheres to predefined formats or stru...


Slide Content

1 | © Copyright 2024 Zilliz1 1| © Copyright 10/22/23 Zilliz 1| © Copyright 2024 Zilliz
Stefan Webb
Developer Advocate, Zilliz
[email protected]
https://www.linkedin.com/in/stefan-webb
https://x.com/stefan_webb
Unstructured Data Meetup | Host

2 | © Copyright 2024 Zilliz2 2| © Copyright 10/22/23 Zilliz 2| © Copyright 2024 Zilliz
Welcome Speakers
Constrained Sampling
from LLMs: Producing
Structured Output
Infinite World Generation
with Outlines
BAML Cheaper, faster, and
more accurate function
calling - without any
fine-tuning
TECH TALK 1 TECH TALK 2 TECH TALK 3
Stefan Webb
DevRel, Zilliz
Cameron Pfiffer
Developer Relations Engineer, .txt
Vaibhav Gupta
CEO, BoundaryML

3 | © Copyright 2024 Zilliz3
Star Milvus
for a chance
to win a prize
tonight!

4 | © Copyright Zilliz4
01
Introduction to Milvus
and Vector Databases

5 | © Copyright Zilliz5

6 | © Copyright Zilliz6
Why is Semantic Search Difficult?

7 | © Copyright Zilliz7





or
Apple





or
Rising dough





or
Change car tire
Rising Dough
Proofing Bread


Semantic Search vs. Lexical Search

8 | © Copyright Zilliz8
Why is Semantic Search Important?
10%
Other
newly generated data in 2025
will be unstructured data90%
Data Source: The Digitization of the World by IDC

9 | © Copyright Zilliz9
Solution: Deep Learning
Similarity Search

10 | © Copyright Zilliz10
Embeddings and Vector Spaces

11 | © Copyright Zilliz11
New Challenge: Search in Vector Spaces
How to Index and
Search?

●High-dimensional
●> 1000 dims
How to Scale?

●10-100 million vectors?
●Billions?
●Trillions?
●Billions of users?
Multiple Data Types?

●Text
●Images
●Audio
●Graphs
●…

12 | © Copyright Zilliz12
About Milvus
Milvus is an open-source vector database for
GenAI projects. pip install on your laptop, plug into
popular AI dev tools, and push to production with
a single line of code.
30K
GitHub Stars
66M
Docker Pulls
400
Contributors
2.7K
Forks
Easy Setup
Pip-install to start coding in a notebook within seconds
Integration
Plug into OpenAI, Langchain, LlmaIndex, and many more
Reusable Code
Write once, and deploy with one line of code into the production
environment
Feature-rich
Dense & sparse embeddings, filtering, reranking and beyond

13 | © Copyright 2024 Zilliz13
Milvus Users

14 | © Copyright 2024 Zilliz14 14| © Copyright 10/22/23 Zilliz 14| © Copyright 2024 Zilliz
github.com/milvus-io/milvus

zilliz.com/learn/generative-ai

15 | © Copyright Zilliz15
02
Constrained Sampling from LLMs

16 | © Copyright Zilliz16
Basic Multinomial Sampling from LLMs
Willard and Louf, 2023

17 | © Copyright Zilliz17
chessboard
(environment)
context
move
(action)
image instruction
JSON
instruction
code
Agents
Information
Extraction
Coding
Assistant
Classification /
Regression
question domain
class or number

18 | © Copyright Zilliz18
Structured Output by Prompting
“Extract the main details from the following
resume and format your answer as JSON.
Please make it well-formatted - Iʼd be ever so
grateful. Thanks, ta!ˮ
Key Idea: Instruct the model to output a given format.

19 | © Copyright Zilliz19
Structured Output by Guided Sampling
Key Idea: Mask logits of tokens that are not valid next tokens
Willard and Louf, 2023

20 | © Copyright Zilliz20
One Implementation: Finite State Machine
RegEx
r’^\d*(\.\d+)?$’
Key Idea:
●Build FSM of valid strings
●Index valid next tokens for each state in machine.
●Run FSM while generating output, using valid next tokens
to produce mask on logits.
Mask(state)

21 | © Copyright Zilliz21
Simple Example
Sampled: “ˮ
State: 0
Sampled: “.2ˮ
State: 3
Sampled: “1ˮ
State: 1
RegEx / Grammar:
“All numbers with only digits
and decimal point.ˮ

Tokens (vocab.):
“Aˮ, “.ˮ, “42ˮ, “.2ˮ, “1ˮ

22 | © Copyright Zilliz22
Outlines Library (from .txt)

23 | © Copyright Zilliz23
Outlines Library (from .txt)

24 | © Copyright Zilliz24
Try it Out Yourself!
https://github.com/boundaryml/baml

https://github.com/dottxt-ai/outlines

25 | © Copyright Zilliz25
T H A N K Y O U

26 | © Copyright 2024 Zilliz26
https://milvus.io/discord
https://github.com/milvus-io/milvus
https://x.com/milvusio
https://www.linkedin.com/company/the-milvus-project
LET’S STAY CONNECTED!
Stefan Webb
Developer Advocate, Zilliz

27 | © Copyright 2024 Zilliz27
Become a
Speaker!
Interesting in speaking
at and/or sponsoring a
Zilliz Unstructured Data Meetup?
Fill out this form


??????????????????

28 | © Copyright 2024 Zilliz28
Join us at our next meetup!
lu.ma/unstructured-data-meetup
Nov 13, South Bay, Location TBD
“Evaluating Retrieval-Augmented Generationˮ

Nov 19, San Francisco, GitHub Office
“Structured Output from Unstructured Input: Part 2ˮ
Tags