You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Generate JSON with a defined structure ([#140](https://github.com/normal-computing/outlines/pull/140))
50
53
- Prompt-token alignment so you don't have to think about tokenization details ([#201](https://github.com/normal-computing/outlines/pull/201))
51
54
- An infilling DSL ([#182](https://github.com/normal-computing/outlines/issues/182))
52
55
@@ -61,6 +64,172 @@ You can follow [@NormalComputing](https://twitter.com/NormalComputing), [@remilo
61
64
pip install outlines
62
65
```
63
66
67
+
68
+
## Guided generation
69
+
70
+
The first step towards reliability of systems that include large language models
71
+
is to ensure that there is a well-defined interface between their output and
72
+
user-defined code. **Outlines** provides ways to control the generation of
73
+
language models to make their output more predictable.
74
+
75
+
### Early stopping
76
+
77
+
You can stop the generation after a given sequence has been found:
78
+
79
+
```python
80
+
import outlines.text.generate as generate
81
+
import outlines.models as models
82
+
83
+
model = models.transformers("gpt2")
84
+
answer = generate.continuation(model, stop=["."])("Tell me a one-sentence joke.")
85
+
```
86
+
87
+
### Multiple choices
88
+
89
+
You can reduce the completion to a choice between multiple possibilities:
# What is the IP address of the Google DNS servers?
166
+
#
167
+
# Passive DNS servers are at DNS servers that are private.
168
+
# In other words, both IP servers are private. The database
169
+
# does not contain Chelsea Manning
170
+
171
+
print(guided)
172
+
# What is the IP address of the Google DNS servers?
173
+
# 2.2.6.1
174
+
```
175
+
176
+
Unlike other libraries, regex-guided generation in Outlines is almost as fast
177
+
as non-guided generation.
178
+
179
+
### Efficient JSON generation following a Pydantic model
180
+
181
+
Outlines 〰 allows to guide the generation process so the output is *guaranteed* to follow a [JSON schema](https://json-schema.org/) or [Pydantic model](https://docs.pydantic.dev/latest/):
182
+
183
+
```python
184
+
from typing import List
185
+
from enum import Enum
186
+
from pydantic import BaseModel, constr
187
+
188
+
import outlines.models as models
189
+
import outlines.text.generate as generate
190
+
191
+
192
+
classWeapon(str, Enum):
193
+
sword ="sword"
194
+
axe ="axe"
195
+
mace ="mace"
196
+
spear ="spear"
197
+
bow ="bow"
198
+
crossbow ="crossbow"
199
+
200
+
201
+
classArmor(str, Enum):
202
+
leather ="leather"
203
+
chainmail ="chainmail"
204
+
plate ="plate"
205
+
206
+
207
+
classCharacter(BaseModel):
208
+
name: constr(max_length=10)
209
+
age: int
210
+
armor: Armor
211
+
weapon: Weapon
212
+
strength: int
213
+
214
+
215
+
model = models.transformers("gpt2")
216
+
sequence = generate.json(model, Character)("Give me a character description")
The method works with union types, optional types, arrays, nested schemas, etc. Some field constraints are [not supported yet](https://github.com/normal-computing/outlines/issues/215), but everything else should work.
232
+
64
233
## Prompting
65
234
66
235
Writing prompts by concatenating strings in pure Python quickly becomes
@@ -184,117 +353,6 @@ With these prompting primitives **Outlines** makes building agents like
184
353
Agent](https://huggingface.co/docs/transformers/transformers_agents) easier by
185
354
removing boilerplate prompting code.
186
355
187
-
## Guided generation
188
-
189
-
The first step towards reliability of systems that include large language models
190
-
is to ensure that there is a well-defined interface between their output and
191
-
user-defined code. **Outlines** provides ways to control the generation of
192
-
language models to make their output more predictable.
193
-
194
-
### Early stopping
195
-
196
-
You can stop the generation after a given sequence has been found:
197
-
198
-
```python
199
-
import outlines.text.generate as generate
200
-
import outlines.models as models
201
-
202
-
model = models.transformers("gpt2")
203
-
answer = generate.continuation(model, stop=["."])("Tell me a one-sentence joke.")
204
-
```
205
-
206
-
### Multiple choices
207
-
208
-
You can reduce the completion to a choice between multiple possibilities:
0 commit comments