Skip to content
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

EXAMPLE : Interpreter grounded Neural Program Synthesis [WIP] #81

Merged
merged 15 commits into from
Nov 7, 2022

Conversation

reshinthadithyan
Copy link
Contributor

This PR adds an example of using trlx to ground LMs into the interpreter with a toy list manipulation DSL to make them generate more coherent programs to satisfy IO conditions.

Questions:

  1. I want to do extensive ablation studies on the impact of grounding Models with Interpreter. So would need a folder to add plots and ReadME.md. Does the current directory structure look good ?

Interpreter Grounded Program Synthesis

Program synthesis is the task of automatically generating programs that solve a given task by satisfying an IO condition. In Neural Program Synthesis the synthesizer is a neural network which is a Language Model that takes in an input/output pair and tries to generate the program in the defined toy DSL's Grammar.

Toy List Manipulation DSL Grammar

The DSL has the following grammar:

list_expr := list[int]
integer := -5 | -4 | -3 | -2 | -1 | 0 | 1 | 2 | 3 | 4 | 5
statement :=
          | take(list_expr,integer)
          | drop(list_expr,integer)
          | reverse(list_expr)
          | sort_asc(list_expr)
          | sort_des(list_expr)
          | add_n(list_expr,integer)
          | sub_n(list_expr,integer)
          | mul_n(list_expr,integer)
          | expand_copy(list_expr)


To generate training/testing data run, python3 -m lang. The dataset would be saved in ./dataset/train.json and ./dataset/test.json. To use the processed dataset refer to this google drive link.
Each datapoint in the dataset would look like,

    {"input": "Input: [4, -2, 0, 0, 5, 5] Output: [25, 25, 20, 0, 0, -10] Function:",
    "output": "sort_des(reverse(mul_n(sort_asc(sort_asc([4, -2, 0, 0, 5, 5])),5)))"}

Training with TRLX

Run python3 -m train_trlx.py to run the training with grounded interpreter. The reward_fn, would return -1 if a sample generated is of invalid syntax. it would return 0.5 if the generated syntax is valid but doesn't satisfy IO condition.

@cat-state cat-state self-requested a review November 6, 2022 01:25
Copy link
Collaborator

@cat-state cat-state left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for this example @reshinthadithyan ! it mostly looks good aside from a few things. Could you also format the python files with black?

output.append(value_gen)
return output


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you comment this file more? Maybe to separate the sections and an explanation at the top for the structure of the language/interpreter

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strong agree. The documentation here is not clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding more documentation, thanks for the review.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added more documentation on the sampler.

*Program synthesis* is the task of automatically generating programs that solve a given task by satisfying an IO condition. In Neural Program Synthesis the synthesizer is a neural network which is a Language Model that takes in an input/output pair and tries to generate the program in the defined toy DSL's Grammar.

## Toy List Manipulation DSL Grammar
The DSL has the following grammar:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to the DSL grammar, add some snippets

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added example snippets to showcase the atomic functions.

@LouisCastricato
Copy link
Contributor

This looks fantastic! I think we should upload a trained model to hugging face hub that goes along with this tutorial, and allow people to validate their model against our uploaded one. What do you think Reshinth?

@reshinthadithyan
Copy link
Contributor Author

@LouisCastricato Yes, the idea is to give a fully reproducible script for the anyone to train it by themselves and validate.

@LouisCastricato
Copy link
Contributor

LGTM, ready to merge with your approval @cat-state

@cat-state
Copy link
Collaborator

LGTM! thanks @reshinthadithyan !

@LouisCastricato
Copy link
Contributor

Precommit is failing. Will merge after resolution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants