LLM Code Generation via Sub-Module Clustering

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Large language models (LLMs) struggle with complex and competitive programming tasks as they tend to generate monolithic code blocks instead of decomposing tasks into logical sub-tasks, limiting their effectiveness in solving complex programming problems.

Innovation Solution

A code-chain framework that uses pre-trained LLMs to generate sub-modules representing logical sub-tasks, which are then clustered and filtered based on test cases, iteratively refined to produce a functionally correct program, allowing for the decomposition of complex tasks into manageable components.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Device complexity

If LLM models generate monolithic code blocks, then the code generation process is simple, but the ability to solve complex programming tasks deteriorates

Engineering Contradiction:
Improvecode generation processVSAvoidability to solve complex programming tasks
Core Design Contradiction:
Device complexityVSReliability

Solution Approach 1:

The patent applies segmentation by dividing the code generation process into multiple iterations where LLM models generate sub-modules representing logical sub-tasks. Each sub-module is independently generated, tested, and refined, allowing complex programming tasks to be broken down into manageable components that can be solved more effectively than monolithic code blocks

Inventive Principle:
Principle #1Segmentation

2Reliability

If LLM models decompose tasks into logical sub-tasks, then the ability to solve complex programming tasks improves, but the code generation process complexity increases

Engineering Contradiction:
Improveability to solve complex programming tasksVSAvoidcode generation process
Core Design Contradiction:
ReliabilityVSDevice complexity

Solution Approach 1:

The patent implements feedback mechanisms where generated sub-modules are tested against test cases and evaluation criteria. The results of these tests feed back into the generation process, allowing the system to refine and improve sub-modules iteratively. This feedback loop manages the complexity by providing structured guidance for refinement rather than uncontrolled complexity

Inventive Principle:
Principle #23Feedback

Solution Approach 2:

The system dynamically adapts the code generation process by iteratively refining sub-modules based on test results and evaluation metrics. The generation process is not static but evolves through multiple iterations, adjusting the complexity management as the solution develops and converges toward a working program

Inventive Principle:
Principle #15Dynamics

3Manufacturing precision

If sub-modules are iteratively refined through testing and filtering, then the accuracy of source code generation improves, but the time required for code generation increases

Engineering Contradiction:
Improveaccuracy of source code generationVSAvoidtime required for code generation
Core Design Contradiction:
Manufacturing precisionVSLoss of time

Solution Approach 1:

The patent applies partial action by filtering and selecting representative sub-modules from the generated set rather than refining all sub-modules equally. The system identifies and focuses computational effort on the most promising or critical sub-modules, achieving high accuracy while managing time constraints by not performing exhaustive refinement on every generated component

Inventive Principle:
Principle #16Partial or excessive action

4Productivity

If representative sub-modules are selected through clustering, then the efficiency of code generation improves, but the complexity of the generation process increases

Engineering Contradiction:
Improveefficiency of code generationVSAvoidgeneration process
Core Design Contradiction:
ProductivityVSDevice complexity

Solution Approach 1:

The patent uses copying by creating clusters of similar sub-modules and selecting representative examples from each cluster. Instead of processing every generated sub-module individually, the system creates copies or variations around representative sub-modules, improving efficiency by reducing redundancy while managing complexity through systematic organization of similar components

Inventive Principle:
Principle #26Copying

Data Source

PatentUS20250103300A1Systems and methods for iterative code generation with large language models and representative sub-modules
Publication Date: 2025.03.27 SALESFORCE INC
  • US20250103300A1 patent drawing
  • US20250103300A1 patent drawing
  • US20250103300A1 patent drawing

AI summary

The embodiments are directed to generating source code for a program from a problem description. One or more pre-trained code large language models (LLMs) generate sub-modules from a problem description in a natural language. The sub-modules are filtered based on testing criteria and encoded into sub-module encodings in an embedding space. The sub-module encodings are clustered into multiple clusters. A subset of sub-modules encoding that are close to the centroids of the clusters are selected. The sub-set of sub-modules is decoded into representative sub-modules. The problem description is augmented with the representative sub-modules and fed into one or more pre-trained code LLMs and new sub-modules are generated. The iterations continue until a program is generated from the representative sub-modules.