Code Monkey home page Code Monkey logo

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

nicholaslocascio avatar nelson-liu avatar

Watchers

James Cloos avatar

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.