Pruning Invalid Code Prefixes for Semantic Correctness

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Machine learning models often generate code with semantic errors, such as undefined variables, syntax errors, and coding conventions issues, which reduces their reliability and increases the workload for human developers.

Innovation Solution

A system that includes a pruner component to identify and prune invalid code prefixes generated by machine learning models, ensuring that only semantically correct code is considered for further generation, using incremental attribute grammars and weight assignment for soft pruning.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Productivity

If machine learning models generate code automatically, then productivity is improved, but semantic errors increase

Engineering Contradiction:
Improvecode generation speedVSAvoidsemantic correctness
Core Design Contradiction:
ProductivityVSReliability

Solution Approach 1:

The system performs preliminary semantic validation on code prefixes during the generation process using attribute grammars. By checking semantic correctness early in the generation pipeline (before complete code execution), the system prevents invalid code from being generated, thus maintaining both high productivity and semantic reliability.

Inventive Principle:
Principle #10Preliminary action

Solution Approach 2:

The patent introduces an intermediary validation layer (attribute grammar checker) between the machine learning model and the final code output. This intermediary component analyzes code prefixes for semantic correctness without requiring full code execution, acting as a mediator that filters out semantically invalid generations while preserving valid ones.

Inventive Principle:
Principle #24Intermediary (Mediator)

2Reliability

If semantic validation is performed on code prefixes, then reliability is improved, but device complexity increases

Engineering Contradiction:
Improvesemantic correctnessVSAvoidvalidation system complexity
Core Design Contradiction:
ReliabilityVSDevice complexity

Solution Approach 1:

The validation system is segmented into modular attribute grammars that can independently validate specific semantic properties of code prefixes. Each attribute grammar handles particular semantic rules (e.g., variable declarations, function definitions), allowing the complex validation task to be divided into manageable, reusable components that reduce overall system complexity.

Inventive Principle:
Principle #1Segmentation

Solution Approach 2:

The attribute grammar validation system is designed to be self-sufficient, using the code prefix itself as input and automatically determining semantic validity without requiring external interpreters or compilers. The system validates its own outputs through built-in semantic rules, eliminating the need for additional complex validation infrastructure.

Inventive Principle:
Principle #25Self-service

3Reliability

If code prefixes are pruned based on semantic properties, then semantic errors are reduced, but loss of information increases

Engineering Contradiction:
Improvesemantic correctnessVSAvoidvalid code variations
Core Design Contradiction:
ReliabilityVSLoss of information

Solution Approach 1:

The system performs partial validation by checking only the necessary semantic properties of code prefixes rather than requiring complete code validation. By validating prefixes incrementally and pruning only those that clearly violate semantic rules, the system removes invalid options while preserving valid code variations, minimizing information loss.

Inventive Principle:
Principle #16Partial or excessive action

Solution Approach 2:

The validation system provides feedback about semantic validity to the generation process, allowing the model to learn from validation results and adjust future generations. This feedback mechanism helps preserve valid code variations by reinforcing patterns that pass semantic checks while gradually eliminating patterns that lead to invalid code.

Inventive Principle:
Principle #23Feedback

Data Source

PatentUS11681510B2Reducing semantic errors in code generated by machine learning models
Publication Date: 2023.06.20 INTERNATIONAL BUSINESS MACHINE CORPORATION
  • US11681510B2 patent drawing
  • US11681510B2 patent drawing
  • US11681510B2 patent drawing

AI summary

Embodiments are disclosed for a method. The method includes identifying a prefix updated by a searcher of a machine learning model. The machine learning model is configured to generate source code in a programming language. The method also includes determining whether the prefix violates a semantic correctness property of the programming language. Additionally, the method includes instructing the searcher, in response to the determination, to prune the prefix from a set of prefixes under consideration by the searcher.