NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

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

Nicholas Locascio, Karthik Narasimhan, Eduardo DeLeon, Nate Kushman, Regina Barzilay

Abstract

This paper explores the task of translating natural language queries into regular expressions which embody their meaning. In contrast to prior work, the proposed neural model does not utilize domain-specific crafting, learning to translate directly from a parallel corpus. To fully explore the potential of neural models, we propose a methodology for collecting a large corpus of regular expression, natural language pairs. Our resulting model achieves a performance gain of 19.6% over previous state-of-the-art models.

Introduction

Regular expressions (regex) are powerful tools for text processing, yet they are notoriously difficult for humans to write and read. While a system that translates natural language (NL) into regex would be highly valuable, building one has traditionally required "semantic unification"—a process that uses domain-specific engines to calculate the functional equivalence of different regex strings. This paper demonstrates that a domain-agnostic neural sequence-to-sequence model can outperform these heavily engineered systems by treating regex generation as a direct translation task.

Methodology: Sequence-to-Sequence Learning

The researchers employed a Sequence-to-Sequence (seq2seq) architecture using Long Short-Term Memory (LSTM) units and a global attention mechanism. This approach treats the problem similarly to machine translation (e.g., English to French), mapping NL tokens directly to regex characters.

Neural sequence-to-sequence architecture with LSTM encoder and decoder for regex generation.

The model is six layers deep: one word-embedding layer, two encoder layers, two decoder layers, and a final dense output layer. The inclusion of an attention mechanism allows the decoder to "look back" at specific words in the NL query while generating each character of the regex, which is critical for handling long-distance dependencies in formal strings.

Dataset Construction: The NL-RX Corpus

A major contribution of this work is the creation of the NL-RX dataset, a benchmark of 10,000 pairs designed to overcome the limitations of smaller, redundant datasets like KB13. To build this corpus without the high cost of regex experts, the authors utilized a "generate-and-paraphrase" pipeline.

The generate-and-paraphrase pipeline used to create the NL-RX dataset.

As shown in the pipeline, a formal grammar first stochastically generates regexes and "synthetic" (rigid) English descriptions. These clunky descriptions are then rewritten by human workers on Amazon Mechanical Turk into natural, fluid English. This strategy ensures high-quality data and high diversity; while the older KB13 dataset contained only 45% unique regexes, the new NL-RX dataset is 97% unique.

Key Results and Insights

The experimental results highlight that data volume and diversity are more critical than domain-specific engineering:

  • Performance Gain: On the NL-RX dataset, the neural model (Deep-RegEx) achieved 58.2% accuracy, a 19.6% improvement over the previous state-of-the-art "Semantic-Unify" model.
  • Resilience: Even on the small KB13 dataset (824 examples), the neural model matched the performance of domain-specific systems (~65.6% accuracy), proving deep learning is competitive even in resource-constrained environments.
  • Scaling: Accuracy showed a clear logarithmic growth as the number of training examples increased, suggesting that further performance gains are possible with larger datasets.

Conclusion

This research proves that generic neural architectures can outperform specialized systems when paired with a robust data generation strategy. By bypassing the "expert bottleneck" through a generate-and-paraphrase pipeline, the authors have provided a scalable framework for translating natural language into formal logic. Future work will focus on applying this domain-agnostic approach to more complex formal languages such as SQL and Python.

Summary updated

BibTeX
@inproceedings{locascio2016neural,
  author = {Nicholas Locascio and Karthik Narasimhan and Eduardo DeLeon and Nate Kushman and Regina Barzilay},
  title = {{Neural Generation of Regular Expressions from Natural Language with Minimal Domain Knowledge}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2016},
  url = {https://openreview.net/forum?id=Hk4s-zz_-B},
}
Figure