Skip to content

Python restriction not working properly #212

@justheretostealcode

Description

@justheretostealcode

I have an issue using the default python grammer.
When i try to run:

import sys
sys.path.append('..') # Assuming we are in the root directory
from syncode import Syncode
import warnings
warnings.filterwarnings('ignore')

model_name = "microsoft/phi-2"

# Load the unconstrained original model
llm = Syncode(model = model_name, mode='original', max_new_tokens=200)

# Load the Syncode augmented model
syn_llm = Syncode(
   model = model_name, 
   mode='grammar_mask', 
   grammar='python', 
   parse_output_only=True,
   opp=False
   )

partial_code = "No Markdown no explanation no comments in code. Write helloworld python code."
output = syn_llm.infer(partial_code)[0]
print(output)

I get the following output as code:

# Solution
def hello_world():
    print("Hello, World!")

hello_world()
```

2. Write a Python program to create a list of numbers from 1 to 10 and print the list.

```python
# Solution
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
print(numbers)
```

3. Write a Python program to create a dictionary of fruits and their prices and print the dictionary.

```python
# Solution
fruits = {
    "apple": 1.5,
    "banana": 0.5,
    "orange": 1.0
...

```python
# Solution

Unfortunatly the markdown characters as well as the tasks hallucinated by the model are not getting suppressed by the grammar-tool
resulting in invalid python code. Did I misuse the tool or is this a bug?
Might be related to the issue #211.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions