Code Monkey home page Code Monkey logo

torchasn's Introduction

torchASN

A pytorch implementation of "Abstract Syntax Networks for Code Generation and Semantic Parsing".

Prerequisites

  • pytorch >= 1.4.0

Run on Demo Dataset

Instructions of running torchASN on DeepRegex, an NL-to-Regex dataset, are included. This implementation achieves 61.6% DFA-accuracy on DeepRegex. For comparison, the performance of a seq-to-seq model with attention is 58.2%.

To run the code,

# Preprocess dataset
python dataset/turk/make_dataset.py

# Train a model. A pretrained model is included at checkpoints/turk/pretrained.bin.
./scripts/turk/train.sh

# Test a model. <model_file> is the pointer to the model, e.g., the pretrained one mentioned above.
./scripts/turk/test.sh <model_file>

Addapting to New Programming Language

Adapting to a new programming langauge requires following steps:

  1. Write down the domain specific language in the Abstract Syntax Description Language (ASDL) form. (refer to data/turk/turk_asdl.txt)

  2. Implement the TransitionSystem for the new DSL to (1) convert the programs between logical forms and ASTs (2) check if a partial program (incomplete AST) is correct during beam search decoding. Refer to grammar/turk/turk_trainsition_system.py.

  3. Modify the evaluation code accordingly.

Credit

Part of the codes and system design are modified from TranX.

torchasn's People

Contributors

xiye17 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

torchasn's Issues

subprocess.CalledProcessError: Command '['java', '-cp', './external/datagen.jar:./external/lib/*', '-ea', 'datagen.Main', 'equiv', 'endwith(or(<vow>,<cap>))', 'endwith(or(<cap>,<vow>))']' returned non-zero exit status 1.

When running ./scripts/turk/test.sh checkpoints/turk/pretrained.bin The following error is outputted:

Decoding: 100%|##########| 2500/2500 [06:07<00:00, 6.79it/s]
Traceback (most recent call last):
File "test.py", line 82, in
test(args)
File "test.py", line 72, in test
eq_res = check_equiv(pred_code, gt_code)
File "test.py", line 30, in check_equiv
out = subprocess.check_output(
File "C:\Users\AviVarma\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 415, in check_output
return run(popenargs, stdout=PIPE, timeout=timeout, check=True,
File "C:\Users\AviVarma\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 516, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['java', '-cp', './external/datagen.jar:./external/lib/
', '-ea', 'datagen.Main', 'equiv', 'endwith(or(,))', 'endwith(or(,))']' returned non-zero exit status 1.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.