# Natural Language to Code Translation with Execution

Source: [Natural Language to Code Translation with Execution](<https://www.sota2.com/research/paper/68fa6dc41e209131cea3bf8b>)

Collection index: [llms.txt](<https://www.sota2.com/research/llms.txt>)

Data updated: 2026-01-04T03:38:14.359Z

Authors: Freda Shi, Daniel Fried, Marjan Ghazvininejad, Luke Zettlemoyer, Sida I. Wang

Published: 2022-04-25T06:06:08.000Z

## Abstract

Generative models of code, pretrained on large corpora of programs, have shown great success in translating natural language to code (Chen et al., 2021; Austin et al., 2021; Li et al., 2022, inter alia). While these models do not explicitly incorporate program semantics (i.e., execution results) during training, they are able to generate correct solutions for many problems. However, choosing a single correct program from a generated set for each problem remains challenging. In this work, we introduce execution result--based minimum Bayes risk decoding (MBR-EXEC) for program selection and show that it improves the few-shot performance of pretrained code models on natural-language-to-code tasks. We select output programs from a generated candidate set by marginalizing over program implementations that share the same semantics. Because exact equivalence is intractable, we execute each program on a small number of test inputs to approximate semantic equivalence. Across datasets, execution or simulated execution significantly outperforms the methods that do not involve program semantics. We find that MBR-EXEC consistently improves over all execution-unaware selection methods, suggesting it as an effective approach for natural language to code translation. We open-source our code at github.com/facebookresearch/mbr-exec and data at dl.fbaipublicfiles.com/mbr-exec/mbr-exec-release.zip

## Recorded benchmark results

A research result applies to its stated dataset, split, metric and evaluation configuration. Compare like-for-like settings, preserve the metric's unit and direction, and distinguish paper-reported results from independent reproduction. The best result recorded here is not a claim of exhaustive, current global coverage.

- [Natural Language to Bash on NL2Bash (test)](<https://www.sota2.com/research/sota/natural-language-to-bash-on-nl2bash-test.md>): Natural Language to Bash; NL2Bash (test); BLEU-4 (char): 58.5.

- [Competitive Coding on USACO](<https://www.sota2.com/research/sota/competitive-coding-on-usaco.md>): Competitive Coding; USACO; Best@8: 79.9.

- [Competitive Coding on OJBench](<https://www.sota2.com/research/sota/competitive-coding-on-ojbench.md>): Competitive Coding; OJBench; Best@8 Score: 40.5.

- [Competitive Coding on LiveCodeBench](<https://www.sota2.com/research/sota/competitive-coding-on-livecodebench.md>): Competitive Coding; LiveCodeBench; Best@8: 78.5.

- [Competitive Coding on ICPC-Eval](<https://www.sota2.com/research/sota/competitive-coding-on-icpc-eval.md>): Competitive Coding; ICPC-Eval; Best@8: 26.2.

- [Competitive Coding on CodeForces](<https://www.sota2.com/research/sota/competitive-coding-on-codeforces.md>): Competitive Coding; CodeForces; Best@8: 43.8.

- [Code Verification on HumanEval+](<https://www.sota2.com/research/sota/code-verification-on-humaneval-plus.md>): Code Verification; HumanEval+; Pass@1: 85.31.

- [Code Verification on LiveCodeBench](<https://www.sota2.com/research/sota/code-verification-on-livecodebench.md>): Code Verification; LiveCodeBench; Pass@1: 34.79.

- [Code Verification on MBPP+](<https://www.sota2.com/research/sota/code-verification-on-mbpp-plus.md>): Code Verification; MBPP+; Pass@1: 72.12.

- [Code Generation on HumanEval+ (test)](<https://www.sota2.com/research/sota/code-generation-on-humaneval-plus-test.md>): Code Generation; HumanEval+ (test); Pass@1: 62.12.

- [Code Generation on CodeContests (test)](<https://www.sota2.com/research/sota/code-generation-on-codecontests-test.md>): Code Generation; CodeContests (test); Pass@1: 8.25.

- [Code Generation on MBPP (test)](<https://www.sota2.com/research/sota/code-generation-on-mbpp-test.md>): Code Generation; MBPP (test); Pass@1: 70.79.

- [Code Generation on HumanEval (test)](<https://www.sota2.com/research/sota/code-generation-on-humaneval-test.md>): Code Generation; HumanEval (test); Pass@1: 72.96.

- [Text-to-SQL on Spider (dev)](<https://www.sota2.com/research/sota/text-to-sql-on-spider-dev.md>): Text-to-SQL; Spider (dev); EX: not recorded.

## Original sources and implementation

[Original paper](<https://arxiv.org/abs/2204.11454>)

[PDF](<https://arxiv.org/pdf/2204.11454.pdf>)
