Constrained Decoding for Valid Code Generation

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Current machine-assisted software development techniques, such as PICARD and Synchromesh, face challenges in generating valid code from natural language inputs, often requiring large language models and being computationally expensive, with a risk of not producing valid SQL statements if none of the beams are valid.

Innovation Solution

The implementation of constrained decoding and ranking of language models, using a machine learning trained converter and a ranker model to transform natural language inputs into valid computer language outputs, ensuring only executable and syntactically correct code is generated, even with smaller language models.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Reliability

If large language models are used for code generation, then the quality and validity of generated code is improved, but the computational resource requirements and cost increase

Engineering Contradiction:
Improvecode validityVSAvoidcomputational resource requirements
Core Design Contradiction:
ReliabilityVSUse of energy by moving object

Solution Approach 1:

The code generation process is segmented into multiple stages: initial generation by a smaller language model, followed by validation and refinement stages. This allows the system to use computational resources efficiently by only applying intensive processing where needed, rather than relying on a single large model for all tasks.

Inventive Principle:
Principle #1Segmentation

Solution Approach 2:

An intermediary validation mechanism is introduced between the language model and the final code output. This intermediary layer checks and ensures code validity without requiring the language model itself to be excessively large, thus decoupling the relationship between model size and code quality.

Inventive Principle:
Principle #24Intermediary (Mediator)

2Productivity

If conventional techniques like PICARD are used, then code generation is attempted, but there is a risk that no valid SQL statements are produced if none of the beams are valid

Engineering Contradiction:
Improvecode generation capabilityVSAvoidvalid SQL statement production
Core Design Contradiction:
ProductivityVSReliability

Solution Approach 1:

The system performs preliminary validation checks on candidate code generations before finalizing them. By validating early in the generation process, the system can identify and correct potential validity issues before they result in completely invalid SQL statements, ensuring at least one valid output is produced.

Inventive Principle:
Principle #10Preliminary action

Solution Approach 2:

A feedback mechanism is implemented where the validation results of generated code are fed back into the generation process. This allows the system to learn from validation outcomes and adjust subsequent generations to ensure validity, creating a closed-loop system that guarantees valid SQL statement production.

Inventive Principle:
Principle #23Feedback

3Use of energy by moving object

If smaller language models are used, then computational resource requirements are reduced, but the performance and accuracy of code generation deteriorates

Engineering Contradiction:
Improvecomputational efficiencyVSAvoidcode generation accuracy
Core Design Contradiction:
Use of energy by moving objectVSMeasurement precision

Solution Approach 1:

The system merges the capabilities of a smaller language model with separate validation and refinement components. This combination allows the smaller model to handle the creative generation task efficiently while the additional components ensure the output meets quality and validity standards, achieving both efficiency and accuracy.

Inventive Principle:
Principle #5Merging (Combining)

Data Source

PatentUS20230325154A1Constrained decoding and ranking of language models for code generation
Publication Date: 2023.10.12 OUTSYST SOFTWARE EM REDE
  • US20230325154A1 patent drawing
  • US20230325154A1 patent drawing
  • US20230325154A1 patent drawing

AI summary

In various embodiments, a process for constrained decoding and ranking of language models for code generation includes receiving a natural language input specifying a desired computer task. The process includes using a machine learning trained converter to convert the natural language input to an output in a computer language, including by, based on a specified grammar for the computer language, limiting eligible options for a token to include in the output in the computer language. The process includes providing the output in the computer language for computer execution.