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

Evaluating DeepRegex model:

Datasets

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

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.

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