Giter Site home page Giter Site logo

nicholaslocascio / deep-regex Goto Github PK

View Code? Open in Web Editor NEW
426.0 24.0 66.0 11.74 MB

Code for the paper Neural Generation of Regular Expressions from Natural Language with Minimal Domain Knowledge (EMNLP 2016). http://arxiv.org/abs/1608.03000

License: MIT License

Python 50.22% Lua 46.54% Shell 3.23%

deep-regex's Introduction

Neural Generation of Regular Expressions from Natural Language with Minimal Domain Knowledge

Code for the paper Neural Generation of Regular Expressions from Natural Language with Minimal Domain Knowledge (EMNLP 2016).


Model Diagram

Summary

Our neural model translates natural language queries into regular expressions which embody their meaning. We model the problem as a sequence-to-sequence mapping task using attention-based LSTM's. Our model achieves a performance gain of 19.6% over previous state-of-the-art models.

We also present a methodology for collecting a large corpus of regular expression, natural language pairs using Mechanical Turk and grammar generation. We utilize this methology to create the NL-RX dataset.

This dataset is open and available in this repo.

Installation

Requirements

Python

pip install -r requirements.txt

Lua

  1. Install torch (http://torch.ch/docs/getting-started.html)
  2. Install packages:
luarocks install nn
luarocks install nngraph
luarocks install hdf5

Usage

Training DeepRegex model

  • From /deep-regex-model/, run bash train_single.sh $full_data_directory

Evaluating DeepRegex model:

  • From /deep-regex-model/, run bash eval_single.sh $data_directory $model_file_name

    • There are 3 valid $full_data_directory strings:
      1. data_kushman_eval_kushman
      2. data_turk_eval_turk
      3. data_synth_eval_synth
    • There are 3 valid $data_directory strings (after training):
      1. data_kushman_eval_kushman/data_100
      2. data_turk_eval_turk/data_100
      3. data_synth_eval_synth/data_100

Datasets

Datasets are provided in 3 folders within /datasets/: KB13, NL-RX-Synth, NL-RX-Turk. Datasets are open source under MIT license.

  • KB13 is the data from Kushman and Barzilay, 2013.
  • NL-RX-Synth is data from NL-RX1 with original synthetic descriptions.
  • NL-RX-Turk is data from NL-RX1 with Mechanical-Turk paraphrased descriptions.

1 NL-RX is the dataset from our paper.

Dataset Notes

The data is a parallel corpus, so the folder is split into 2 files: src.txt and targ.txt. src.txt is the natural language descriptions. targ.text is the corresponding regular expressions.

  • Note - all models (ours and previous) that perform this task perform string replacement of any string in quotation marks. This means that "lines that contain 'blue'" and "lines that contain 'red'", will both be identical in some form "lines that contain ".
    • Our datasets have this already pre-computed - for each example, the words in quotations appear in the order 'dog', 'truck', 'ring', 'lake' to universally indicate their position.

Data Generation

Code used to generate new data (Regexes and Synthetic Descriptions) is in /data_gen/ folder.

To generate new data:

From /data_gen/, run python generate_regex_data.py to run the generation process described in the paper.

Acknowledgments

Licence

MIT

deep-regex's People

Contributors

nelson-liu avatar nicholaslocascio avatar

Stargazers

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

Watchers

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

deep-regex's Issues

the dataset file are mismatch

mldl@ub1604:/ub16_prj/deep-regex/deep-regex-model$ bash train_single.sh ../datasets/KB13
[100]
Traceback (most recent call last):
File "split_data_into_size_subfolders.py", line 87, in
sys.exit(main(sys.argv[1:]))
File "split_data_into_size_subfolders.py", line 23, in main
make_splits(data_dir, splits, optimal)
File "split_data_into_size_subfolders.py", line 29, in make_splits
process_file('src-train.txt', data_dir, split, optimal=optimal)
File "split_data_into_size_subfolders.py", line 54, in process_file
with open(f_path) as f:
IOError: [Errno 2] No such file or directory: '../datasets/KB13/src-train.txt'
First pass through data to get vocab...
Traceback (most recent call last):
File "preprocess.py", line 346, in
sys.exit(main(sys.argv[1:]))
File "preprocess.py", line 343, in main
get_data(args)
File "preprocess.py", line 256, in get_data
args.seqlength, 0, args.chars)
File "preprocess.py", line 79, in make_vocab
enumerate(itertools.izip(open(srcfile,'r'), open(targetfile,'r'))):
IOError: [Errno 2] No such file or directory: '../datasets/KB13/data_100/src-train.txt'
mldl@ub1604:
/ub16_prj/deep-regex/deep-regex-model$ 2
1
0.25
loading data...
HDF5-DIAG: Error detected in HDF5 (1.8.16) thread 140393315931968:
#000: ../../../src/H5F.c line 604 in H5Fopen(): unable to open file
major: File accessibilty
minor: Unable to open file
#1: ../../../src/H5Fint.c line 992 in H5F_open(): unable to open file: time = Fri Sep 21 17:14:34 2018
, name = '/home/mldl/ub16_prj/deep-regex/datasets/KB13/data_100/out_demo-train.hdf5', tent_flags = 0
major: File accessibilty
minor: Unable to open file
#2: ../../../src/H5FD.c line 993 in H5FD_open(): open failed
major: Virtual File Layer
minor: Unable to initialize object
#3: ../../../src/H5FDsec2.c line 339 in H5FD_sec2_open(): unable to open file: name = '/home/mldl/ub16_prj/deep-regex/datasets/KB13/data_100/out_demo-train.hdf5', errno = 2, error message = 'No such file or directory', flags = 0, o_flags = 0
major: File accessibilty
minor: Unable to open file
/home/mldl/torch/install/bin/luajit: /home/mldl/torch/install/share/lua/5.1/hdf5/file.lua:12: HDF5File: fileID -1 is not valid
stack traceback:
[C]: in function 'error'
/home/mldl/torch/install/share/lua/5.1/hdf5/file.lua:12: in function '__init'
/home/mldl/torch/install/share/lua/5.1/torch/init.lua:91: in function </home/mldl/torch/install/share/lua/5.1/torch/init.lua:87>
[C]: in function 'open'
/home/mldl/ub16_prj/deep-regex/deep-regex-model/data.lua:8: in function '__init'
/home/mldl/torch/install/share/lua/5.1/torch/init.lua:91: in function 'new'
train.lua:592: in function 'main'
train.lua:651: in main chunk
[C]: in function 'dofile'
...mldl/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:150: in main chunk
[C]: at 0x00405d50

mldl@ub1604:~/ub16_prj/deep-regex/deep-regex-model$

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.