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
Some of the results in the docs are difficult to reproduce. Prompt
engineering and better model recommendations are applied here to
alleviate that.
fixes#586
- Update docs: never recommend `mistralai/Mistral-7B-v0.1`, always
prefer `WizardLM/WizardMath-7B-V1.1` for math above kindergarten level
and `mistralai/Mistral-7B-Instruct-v0.2` for everything else.
- Smoke tested all `README.md` and `quickstart.md` examples. Replaced
model with `mistralai/Mistral-7B-Instruct-v0.2`, generation quality was
equal or better in all cases.
- fixes#612 (see
#612 (comment))
- don't force `device="cuda"` in any `outlines.models.transformers`
- fix arithmetic grammar to not have recursion issue (fixes#580)
---------
Co-authored-by: Andrew Lapp <[email protected]>
The method works with union types, optional types, arrays, nested schemas, etc. Some field constraints are [not supported yet](https://github.com/outlines-dev/outlines/issues/215), but everything else should work.
@@ -232,9 +225,9 @@ schema = '''{
232
225
}
233
226
}'''
234
227
235
-
model = outlines.models.transformers("mistralai/Mistral-7B-v0.1", device="cuda")
228
+
model = outlines.models.transformers("mistralai/Mistral-7B-Instruct-v0.2")
236
229
generator = outlines.generate.json(model, schema)
237
-
sequence= generator("Give me a character description")
230
+
character= generator("Give me a character description")
238
231
```
239
232
240
233
### Using context-free grammars to guide generation
@@ -245,34 +238,25 @@ Formal grammars rule the world, and Outlines makes them rule LLMs too. You can p
245
238
import outlines
246
239
247
240
arithmetic_grammar ="""
248
-
?start: sum
241
+
?start: expression
249
242
250
-
?sum: product
251
-
| sum "+" product -> add
252
-
| sum "-" product -> sub
243
+
?expression: term (("+" | "-") term)*
253
244
254
-
?product: atom
255
-
| product "*" atom -> mul
256
-
| product "/" atom -> div
245
+
?term: factor (("*" | "/") factor)*
257
246
258
-
?atom: NUMBER -> number
259
-
| "-" atom -> neg
260
-
| "(" sum ")"
247
+
?factor: NUMBER
248
+
| "-" factor
249
+
| "(" expression ")"
261
250
262
251
%import common.NUMBER
263
-
%import common.WS_INLINE
264
-
265
-
%ignore WS_INLINE
266
252
"""
267
253
268
-
model = outlines.models.transformers("mistralai/Mistral-7B-v0.1", device="cuda")
254
+
model = outlines.models.transformers("WizardLM/WizardMath-7B-V1.1")
sequence = generator("Write a formula that returns 5 using only additions and subtractions.")
271
-
272
-
# It looks like Mistral is not very good at arithmetics :)
256
+
sequence = generator("Alice had 4 apples and Bob ate 2. Write an expression for Alice's apples:")
273
257
274
258
print(sequence)
275
-
#1+3-2-4+5-7+8-6+9-6+4-2+3+5-1+1
259
+
#(8-2)
276
260
```
277
261
278
262
This was a very simple grammar, and you can use `outlines.generate.cfg` to generate syntactically valid Python, SQL, and much more than this. Any kind of structured text, really. All you have to do is search for "X EBNF grammar" on the web, and take a look at the [Outlines Grammars repository](https://github.com/outlines-dev/grammars).
@@ -288,9 +272,9 @@ import outlines
288
272
defadd(a: int, b: int):
289
273
return a + b
290
274
291
-
model = outlines.models.transformers("mistralai/Mistral-7B-v0.1")
275
+
model = outlines.models.transformers("WizardLM/WizardMath-7B-V1.1")
292
276
generator = outlines.generate.json(model, add)
293
-
result = generator("Return two integers named a and b respectively. a is odd and b even.")
277
+
result = generator("Return json with two integers named a and b respectively. a is odd and b even.")
This will by default start a server at `http://127.0.0.1:8000` (check what the console says, though) with the OPT-125M model. If you want to specify another model:
You can then query the model in shell by passing a prompt and a [JSON Schema][jsonschema]{:target="_blank"} specification for the structure of the output:
252
252
253
253
```bash
254
-
curl http://0.0.0.1:8000 \
254
+
curl http://127.0.0.1:8000/generate \
255
255
-d '{
256
-
"prompt": "What is the capital of France?",
256
+
"prompt": "Question: What is a language model? Answer:",
257
257
"schema": {"type": "string"}
258
258
}'
259
259
```
@@ -329,25 +329,28 @@ Once you are done experimenting with a prompt and an output structure, it is use
329
329
330
330
@outlines.prompt
331
331
def tell_a_joke(topic):
332
-
"""Tell me a joke about {{ topic }}."
332
+
"""Tell me a joke about {{ topic }}."""
333
333
334
334
class Joke(BaseModel):
335
335
setup: str
336
336
punchline: str
337
337
338
-
fn = outlines.Function(
338
+
generate_joke = outlines.Function(
339
339
tell_a_joke,
340
340
Joke,
341
-
"mistralai/Mistral-7B-v0.1"
341
+
"mistralai/Mistral-7B-Instruct-v0.2"
342
342
)
343
343
```
344
344
345
345
=== "Call a function"
346
346
347
347
```python
348
-
from .function import fn as joke
348
+
from .function import generate_joke
349
349
350
-
response = joke("baseball")
350
+
response = generate_joke("baseball")
351
+
352
+
# haha
353
+
# Joke(setup='Why was the baseball in a bad mood?', punchline='Because it got hit around a lot.')
0 commit comments