TL;DR
This paper demonstrates that a generic sequence-to-sequence neural network can translate natural language queries into regular expressions without relying on any domain-specific engineering. To train this model, the authors introduced NL-RX, a new dataset of 10,000 regular expression pairs generated via a novel crowd-sourced paraphrasing pipeline, ultimately outperforming previous state-of-the-art domain-specific models by up to 19.6%.
What Problem Does This Paper Address?
Regular expressions (regex) are incredibly powerful tools for text processing, yet they are notoriously difficult for humans to write correctly. While building a system that automatically translates natural language (NL) into regex would be highly valuable, prior attempts have hit a wall due to two main challenges:
- Over-engineering: Previous state-of-the-art systems relied heavily on hand-crafted, domain-specific components (such as semantic unification to check if two regexes are functionally equivalent). This specialized logic makes it difficult to adapt these systems to other programming or formal languages.
- Data Scarcity: Existing datasets were tiny (fewer than 1,000 examples). Because writing regex requires specialized knowledge, standard crowd-sourcing methods (like Amazon Mechanical Turk) couldn't be easily used to scale up data collection.
The authors set out to answer a fundamental question: Can a generic deep learning architecture eliminate the need for domain-specific engineering, and if so, how can we efficiently gather enough data to train it?
Methods
Instead of building a custom semantic parser, the authors treated regex generation as a standard machine translation problem. They utilized a standard Sequence-to-Sequence (seq2seq) architecture with global attention, powered by a 6-layer deep stacked LSTM network.
The model takes a natural language string as input, encodes it, and decodes it directly into a regex character sequence. Crucially, the model has zero intrinsic knowledge of regex syntax or semantic equivalence; it learns the mapping entirely from the data.
Datasets
To train a data-hungry neural network, the authors introduced NL-RX, a new dataset containing 10,000 regular expressions paired with both synthetic and natural language descriptions.
To bypass the need for regex experts, they developed a clever generate-and-paraphrase pipeline:
- Generate: They used a small, manually crafted grammar to stochastically generate complex regular expressions alongside rigid, "synthetic" language descriptions.
- Paraphrase: They hired Mechanical Turk workers to rewrite these rigid synthetic descriptions into fluid, natural language.
An example of this pipeline in action:
- Synthetic:
lines not words with starting with a capital letter - Paraphrased (Natural):
lines that do not contain words that begin with a capital letter - Regex:
~ (\b([A-Z])(.*)\b)
For evaluation, they compared their model on this new NL-RX dataset as well as KB13, a benchmark dataset from prior work containing only 814 examples.
Key Insights and Ideas
- Data Diversity Matters More Than Size Alone: While analyzing the older KB13 dataset, the authors discovered that only 45% of its regular expressions were unique. This meant over half of the test set consisted of exact repetitions from the training set, explaining why simpler baseline models performed deceptively well on it. In contrast, the new NL-RX dataset features 97% unique regular expressions.
- End-to-End Beats Hand-Crafted: Generic neural architectures can completely replace heavily engineered semantic components. By providing a model with enough varied data, it naturally learns the underlying structure of the formal language without needing hardcoded rules.
- The Scalability of Paraphrasing: Asking non-experts to paraphrase rigid text is far more scalable and cost-effective than asking experts to write code or formal logic from scratch.
Key Results
The authors evaluated performance using DFA-Equal accuracy, which checks if the generated regex is functionally equivalent to the target regex, even if the literal strings differ (e.g., recognizing that (a|b) is identical to (b|a)).
- On the small KB13 dataset: The generic
Deep-RegExmodel matched the previous state-of-the-art engineered model (Semantic-Unify), achieving 65.6% accuracy vs 65.5%. - On the larger NL-RX-Turk dataset:
Deep-RegExvastly outperformed the engineered baseline, achieving 58.2% accuracy compared toSemantic-Unify's 38.6%—a massive 19.6% absolute performance gain.
Limitations and Future Work
While the model excels when given synthetic descriptions (achieving 88.7% accuracy), performance drops to 58.2% when faced with natural, human-paraphrased language. This highlights a lingering sensitivity to the sheer variety and ambiguity of natural human speech.
The authors note that the success of this generic translation approach opens the door for future work in mapping natural language to even broader, more complex formal languages, such as full programming scripts.
Summary updated