-
Notifications
You must be signed in to change notification settings - Fork 485
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use gen fields in outlines? #176
Comments
Would something like this work? import outlines.models as models
import outlines.text as text
@text.prompt
def unit_test_prompt(description, unit_test):
"""Given the description of a task, generate a python program that solves it, and the completes the unit test.
Description: {{description}}
Unit Test: {{unit_test}}
Code: {{gen 'code' do_sample=True temperature=0.5 max_tokens=300 stop='Description'}}
"""
prompt = unit_test_prompt("A function to create 10 fibonacci numbers", "xxxxxx")
complete = models.text_completion.transformers('gpt2')
out = complete(prompt) |
Yes, this works. This is quite simple. Another requirement would be to sample multiple completions at once. I think this could be specified like: "{{ gen 'code' samples=10 temperature=0.5}}"
...
out = complete(...)
...
codes = out['code']
Although this can be a tricky if there are many |
Should work with out = complete(prompt, num_samples=10) Then you just pass |
This could work. Just to clarify, this gen field construct is not yet supported right? It doesn't work rn. |
If you're asking whether outlines has an infilling DSL like guidance or LMQL have, no. It would be however easy to implement. I sketched it here and you just reminded me to open an issue to track progress on this. Also, may I ask why you'd want a DSL like guidance's? |
I envision a prompt template to actually have fields that are user provided or generated, aka via gen fields. Running a infilling model on it to generate outputs, and then later access them via a dictionary output. I do not want anything more than that, I do not want if-else-then block creation inside the prompt (hence called a program in guidance) to modify the prompt at will. We should perhaps implement all the prompt modifying business using regular python functions + jinja templating. I did not find |
In tree based searches, for example if we want to solve the problem and guarantee a structured evaluation process, we can use the template:
One way to get the outputs, is to simply run a next token prediction and complete fields until The only way to get multiple combinations of step1, step2, step3, ans is to sample each of the fields given the previous completed fields, which can take |
From what I understand you would like three different things:
In summary (2) looks like it's already doable (3) is convenient but non-blocking, and we should see together how we can prioritise (1). Did I get this right? |
Yup you did. Indeed solving (1) will be most RoI. I think users would want an (3) infilling api, to me it seems natural for text-completion tasks, can you show how one can do it in outlines in a simple fashion? Same for (2) - Will successive calling of |
Try the following. You can step through the program and look at the shape of the outputs, import outlines.models as models
import outlines.text as text
import numpy as np
@text.prompt
def arithmetic_prompt(input):
"""Use these numbers and basic arithmetic to get 24
Input: {{input}}
Steps: """
add = np.char.add
model = models.text_completion.openai("text-davinci-003")
prompt = arithmetic_prompt("input")
step_1 = model(prompt, stop_at=["\n"], samples=10)
prompt = add(add(prompt, step_1), "\nStep 2: ")
step_2 = model(prompt, stop_at=["\n"], samples=10)
prompt = add(add(prompt, step_2), "\nStep 3: ")
step_3 = model(prompt, stop_at=["\n"], samples=10)
prompt = add(add(prompt, step_3), "\nOutput: ")
ans = model(prompt, samples=10) |
I opened #182 to track the infilling DSL implementation. Feel free to take a stab at it. |
One aspect of guidance programs that I like are
gen
fields. Consider this:And then we can extract the output as
out['code']
.How can I do this intuitively in outlines? Does outlines plan to support a gen field syntax?
The text was updated successfully, but these errors were encountered: