Abstract
Translating natural language into executable code, such as Bash commands, is a challenging task in semantic parsing. Traditional sequence-to-sequence models often treat input as flat token strings, ignoring the underlying linguistic structure. We present the Segmented Invocation Transformer (SIT), which utilizes constituency parse trees to group tokens into semantically coherent segments. This structural inductive bias allows SIT to outperform larger models on the NL2Bash benchmark while being 5x smaller and 1.8x faster on standard CPUs.
Introduction
Translating natural language (NL) to Bash commands is a critical task for improving developer productivity. While Bash is an incredibly powerful tool, its complex syntax and steep learning curve often hinder its effective use. Previous deep learning approaches have largely treated this as a standard sequence-to-sequence problem, processing the NL input as a flat string of tokens.
However, this approach ignores the inherent structure of the problem. A request like "delete files with inode number specified by REGEX under current directory" is composed of nested concepts that map directly to specific command components (e.g., find, -inum, and .). By ignoring this structure, standard models navigate a larger search space, leading to higher parameter counts and slower inference performance.
The Segmented Invocation Transformer (SIT)
The core innovation of this work is the Segmented Invocation Transformer (SIT), which incorporates linguistic structure into the model architecture through a three-stage process:
- Segmentation via Parsing: The input is first normalized by replacing specific file paths or regex with generic placeholders. A constituency parser then generates a tree structure of the sentence. By "cutting" this tree at a specific height threshold (e.g., height $\le 3$), individual words are grouped into meaningful segments.
- The Averaging Layer: Instead of feeding every word token into the Transformer encoder, SIT employs an averaging layer. This layer computes the mean of the embeddings for all tokens within a single segment.
- Structural Encoder-Decoder: The Transformer encoder processes these $k$ segment embeddings rather than the original $n$ word tokens. Since $k$ is significantly smaller than $n$, the decoder’s cross-attention mechanism has fewer keys and values to process, drastically accelerating the generation process.
Experimental Setup
The researchers evaluated SIT using the NL2Bash dataset, which contains approximately 10,000 pairs of English invocations and Bash commands. This dataset served as the basis for the NeurIPS 2020 NLC2CMD contest, providing a rigorous benchmark against existing top-tier models like Magnum, T5, and CodeT5.
Results and Discussion
SIT demonstrates that structural inductive bias can lead to significant gains in both accuracy and efficiency:
- Accuracy: SIT achieved a score of 0.438 on the NLC2CMD metric, surpassing the contest-winning "Magnum" model (0.428) and significantly outperforming larger pre-trained models like T5 (0.316) and CodeT5 (0.355).
- Efficiency: The model is highly parameter-efficient, using only 9 million parameters—a 5x reduction compared to Magnum’s 45 million. Furthermore, it achieved a 1.8x median speedup in inference time on a standard 6-core Intel i5 CPU, making it suitable for local deployment.
- Interpretability: Using attribution analysis (Integrated Gradients), the authors found that the model correctly attributes Bash utilities and flags to the corresponding NL segments approximately 70% of the time.
Conclusion and Future Work
While SIT offers a more efficient path for NL-to-Bash translation, some limitations remain. The current implementation relies on the Stanford CoreNLP parser, which can be a bottleneck for total system latency. Additionally, the model still struggles with complex logic involving pipes (|) or multiple utilities like sed and awk. Future work will explore more modern parsers and investigate whether the tree-cutting approach generalizes to other languages like SQL or Python.
Summary updated