# Best import of all time
from outlines import models, generate
import torch
from transformers import AutoTokenizer
# Load a language model into memory
model = models.transformers(
"microsoft/Phi-3-mini-4k-instruct",
device="cuda",
model_kwargs={"torch_dtype": torch.bfloat16},
)
tokenizer = AutoTokenizer.from_pretrained("microsoft/Phi-3-mini-4k-instruct")
def to_prompt(text):
return tokenizer.apply_chat_template([text], tokenize=False)
riddle = """
Dr. Smith teaches either Biology or Chemistry.
Prof. Jones teaches the subject Dr. Smith doesn't teach.
If the Biology teacher wears glasses,
and Prof. Jones doesn't wear glasses, who teaches Biology?
"""
# Choices
choices = ["Dr. Smith", "Prof. Jones"]
# Generator
riddler = generate.choice(model, choices)
# Generate a response
response = riddler(to_prompt(riddle))
print(response)
Describe the issue as clearly as possible:
Providing strings that include regex characters like
.
are not escaped, and are directly interpreted when usingoutlines.generate.choice
.For example, this can lead to the choice generator
producing an output like
where the
u
should in fact be the literal.
Steps/code to reproduce the bug:
Expected result:
Error message:
Outlines/Python version information:
Version information
Context for the issue:
No response