Skip to content

Generation may ignore Grammar #208

@5ila5

Description

@5ila5

I did some testing with this project and noticed something odd. It would be nice if anyone could explain why this happens:

model_name = "microsoft/phi-2"

grammar = r""" 
                start: instruction
                instruction: "Press the " button " button"
                button: "power" | "volume up" | "volume down" | "home" | "back" | "recent apps" | "menu" | "search"
        """
syn_llm = Syncode(model=model_name, grammar=grammar, max_new_tokens=20, mode="grammar_strict")

prompt = "How do I go back?"
print(syn_llm.infer(prompt)[0])

produces the output:

Press the � button to return to the previous page.

##Your task: **

How can this even happen? I thought the model can only generate output that is parsable by the grammar?

For some reason, this does produce a correct output when changing to the grammar_mask mode. But even then it violates the grammar when changing the prompt to something unfitting like what's the weather like today?.

Can someone please help me understand why this happens? Is this a bug or intended behavior?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions