Optimization Method for Large Model Code Generation Based on Same-Target Suffix Reconstruction

By constructing a contrastive reconstruction sequence and utilizing a forward propagation scoring model, the lexical support difference is calculated and back-mapped to the constraint phrases in the task description. This solves the problem of semantic incompleteness in large language models when generating code, and achieves efficient and accurate code generation.

CN123114473APending Publication Date: 2026-11-17ZHEJIANG UNIV +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611291421.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-25
Publication Date
2026-11-17

AI Technical Summary

Technical Problem

Existing large language models struggle to accurately identify and respond to low-frequency logical connections, combinatorial conditions, boundary cases, and multi-condition relationships when generating code, resulting in incomplete semantics in the generated initial source code. Furthermore, existing optimization schemes rely on external data or multiple rounds of generation, increasing inference overhead and making it difficult to directly compare the matching of lexical probabilities with task constraints.

Method used

By constructing contrastive reconstruction sequences containing the initial source code and those without, a forward propagation scoring model is used to calculate lexical support differences, which are then back-mapped to constraint phrases in the task description, forming enhanced hints and generating the final source code.

Benefits of technology

Without relying on external knowledge bases and large-scale retraining, it improves the task compliance of generated code, reduces inference overhead, directly identifies semantic gaps and forms executable feedback, thereby improving the accuracy and efficiency of generated code.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123114473A_ABST
    Figure CN123114473A_ABST
Patent Text Reader

Abstract

This invention discloses a large-scale model code generation optimization method based on reconstruction of the same target suffix; the method includes the following steps: obtaining programming task description text; inputting it into an initial generation model to obtain initial source code; constructing first and second comparative reconstruction sequences, using the programming task description text as a known target suffix, inputting the first and second comparative reconstruction sequences into a scoring model respectively, and performing forward scoring on each sequence using forward propagation to obtain lexical scores; calculating code conditional support differences for each target lexical based on the lexical scores and determining candidate lexicals; back-mapping the candidate lexicals to the original words or semantic units in the programming task description text, and then clustering the original words or semantic units into constraint phrases based on grammatical rules; calculating phrase-level constraint gap scores based on the constraint phrases and selecting gap phrases, and generating constraint explanations; forming enhanced prompts with the programming task description text, inputting them into the final generation model to generate the final source code.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the fields of artificial intelligence, natural language processing, program synthesis, and automatic computer software generation, and in particular to an optimization method for generating large model code based on reconstructing the same target suffix. Background Technology

[0002] Large language models and code generation models can generate source code based on programming task descriptions in natural language. For common syntactic structures, algorithm templates, and high-frequency constraints, the model can usually provide an executable implementation; however, for low-frequency logical connections, combinatorial conditions, boundary cases, input / output formats, and relationships between multiple conditions, the model may generate syntactically correct but semantically incomplete initial source code that does not fully cover the task description.

[0003] Existing code generation optimization schemes mainly include fine-tuning, retrieval enhancement, chained inference, hint engineering, candidate sampling, unit test feedback, and re-ranking or correction based on model confidence. These schemes either require external data and additional training, or rely on multiple rounds of generation and execution, which can easily increase inference overhead; among them, directly requiring the generative model to point out its own omitted constraints may still be affected by its original prior distribution.

[0004] Another approach utilizes lexical probabilities, log probabilities, hidden states, or other confidence scores during the generation process to evaluate code generation quality. However, the absolute lexical probability in a single sequence is simultaneously influenced by factors such as prior lexical frequency, grammatical collocation, cue wording, context length, and position. Relying solely on absolute probability makes it difficult to distinguish between situations where "the lexical itself is rare" and "the initial source code does not implement the constraints expressed by that lexical."

[0005] Back-translation or reconstruction between code and natural language can obtain information about task semantics from the code side. However, if the model is allowed to generate back-translated text freely, different back-translation results usually have different numbers and positions of lexical units, making it difficult to directly compare the lexical unit probabilities under code conditions with those under no-code conditions position by position. At the same time, the differences in the expression of the back-translated text itself may also mask the supporting or inhibiting effect of the source code on specific task constraints.

[0006] Therefore, a technical solution is needed that can treat "whether initial source code is provided" as a controlled conditional variable while maintaining complete consistency with the target task description being scored. This would allow for the measurement of conditional support changes caused by the initial source code at the same target lexical position, and the backtracking of these changes to the constraint phrases in the original task description. Furthermore, the following issues need to be addressed: how to reduce the systematic impact of differences in context length and prefix structure between two comparison paths on the probability; how to restore the sub-word-level anomalies generated by the tokenizer to the semantic constraints in the original task; and how to feed back the detected constraint gaps into the code generation process to improve the task compliance of the final source code without relying on external knowledge bases and large-scale retraining. Summary of the Invention

[0007] This invention addresses at least the following technical problems: First, how to establish code conditional paths and reference paths with word-by-word comparability to avoid target misalignment caused by free back-translation; second, how to measure the conditional support changes of the initial source code for each word in the original task description by comparing forward propagation, rather than using only absolute probabilities; third, how to map word-level negative support changes to constraint phrases that are not fully implemented in the initial source code; and fourth, how to form the constraint gaps into executable generative feedback to generate the final source code that satisfies the original constraints with lower additional inference costs.

[0008] To address the aforementioned technical problems, this invention provides a large model code generation optimization method based on reconstructing with the same target suffix, executed by at least one processor, comprising the following steps: Obtain the programming task description text Q; input the programming task description text Q into the initial generation model to obtain the initial source code C; construct a first comparative reconstruction sequence and a second comparative reconstruction sequence, wherein the first comparative reconstruction sequence includes a code condition prefix containing the initial source code C and the programming task description text Q as a target suffix, and the second comparative reconstruction sequence includes a reference prefix not containing code content used to express the program semantics of the initial source code C and the same programming task description text Q as a target suffix, such that the target suffixes of the two comparative reconstruction sequences have the same target word sequence corresponding to each position; using the programming task description text Q as a known target suffix, input the first and second comparative reconstruction sequences into the scoring model respectively, and perform forward scoring on them respectively using forward propagation to obtain the corresponding word score of the same target word under code condition and reference condition; and assign each target word score according to the word score. The calculation code supports differential conditions. The process involves identifying candidate lexical units with decreasing support; mapping these candidate lexical units back to the original words or semantic units in the programming task description text Q; clustering the original words or semantic units into constraint phrases s based on grammatical rules; calculating phrase-level constraint gap scores G(s) based on the constraint phrases; and selecting the top K gap phrases. The system generates a constraint interpretation E for the model; it then combines this with the programming task description text Q to create an enhanced hint; finally, the enhanced hint is input into the final generation model to generate the final source code.

[0009] Furthermore, the programming task description text Q consists of multiple target terms. Composition, Q=( , ,…, The programming task description text Q includes a natural language task description, function signature, input / output format, examples, constraints, dependency library information, and target programming language.

[0010] Furthermore, the first control reconstructed sequence According to the code-based question generation instructions The initial source code C, the target delimiter D, and the programming task description text Q are arranged in the following order; the second comparison reconstruction sequence. Follow the instructions to directly generate questions The optional baseline balancing prefix B, the target separator D, and the same programming task description text Q are arranged in that order; wherein, the code-based question generation instruction... The direct question generation instruction is used to enable the scoring model to enter a conditional reconstruction state based on the source code or a description of the original programming task after receiving the initial source code C. The program semantics of the initial source code C are not introduced; the code condition prefix includes at least a code-generated task instruction for instructing the refactoring of the programming task description text Q based on the initial source code C. The initial source code C and the delimiter D are included. The code condition prefix also includes at least one of the following: an abstract syntax tree, compilation result, execution trace, or static analysis result directly obtained from the initial source code C; the reference prefix includes at least the direct problem generation instruction. and target separator D; The baseline balancing prefix B is empty, or includes neutral placeholder content that matches the initial source code C in at least one of lexical length, character length, paragraph structure, number of lines of code, or positional occupancy, and does not describe the task constraints corresponding to the initial source code C, so that the target delimiter D and the programming task description text Q tend to be consistent in context length or absolute position in the two contrasting reconstruction sequences. The same target suffix refers to: the first control reconstruction sequence and the second control reconstruction sequence obtain completely consistent target tokens using the same tokenizer after the target starting position, and the relative positions of each target token in the respective target suffix are in one-to-one correspondence; when performing the forward scoring, the programming task description text Q is input into the scoring model token by token as a known label sequence, and only the target token scores corresponding to the target suffix are collected.

[0011] Further, the forward propagation manner includes teacher-forced forward propagation; the code condition is the first control reconstruction sequence, the reference condition is the second control reconstruction sequence, for the i-th target token in the programming task description text Q , acquiring the code condition token score and the reference token score ; where, represents the prediction score for under the condition that the code condition prefix and the target prefix q<i are given represents the prediction score for under the condition that the program semantics of the initial source code C are not provided and the same target prefix q<i is given; the token score includes at least one of a softmax probability, a log probability, a logit, a calibrated confidence score, or a score monotonically corresponding to the probability; the reference condition adopts a plurality of reference prefixes that do not contain the program semantics of the initial source code C to respectively obtain a plurality of reference token scores, and the plurality of reference token scores are subjected to averaging, median taking or weighted combination; when the complete probability distribution of the target token cannot be directly obtained, an interface capable of returning the log probability of the candidate word, a proxy scoring model or a distillation scoring model is used to obtain the token score of the target token, wherein the scoring models for the two control paths are the same and the target suffix remains consistent; After obtaining the token scores, position calibration or normalization is performed on the token scores of the first control reconstruction sequence and the second control reconstruction sequence according to at least one of the target token position, the condition prefix length, the reference prefix length, or the reference task statistic, and the calibrated comparison object is still the score difference of the same target token under the two conditions of including the program semantics of the initial source code C and not including the program semantics of the initial source code C.

[0012] Further, the code condition supports differentiation using a probability difference - , a relative change rate ( - ) / ( +ε), a probability ratio ( +ε) / ( +ε), logarithmic probability difference log( +ε)-log( +ε), normalized difference, rank difference, standardized score, or a combination thereof; the code condition supports differencing. Both are based on positional comparisons of the same target word in the first and second contrast-reconstructed sequences; A support descent threshold is determined based on at least one of a fixed threshold, mean, standard deviation, median absolute deviation, quantile, or task length, and target lexical units whose code conditional support difference satisfies the support descent threshold are selected as candidate lexical units. Before calculating or sorting the code conditions to support differential, a low probability filtering ratio is set according to a fixed probability threshold, percentile threshold, quantile threshold, or adaptive statistical threshold to exclude target words with reference scores lower than preset conditions, so as to reduce differential amplification caused by extremely low reference probabilities; wherein, the low probability filtering ratio is 0.5% to 8%.

[0013] Furthermore, the reverse mapping of candidate lexical units specifically involves: merging the candidate lexical set W into words or semantic units according to word rules; aggregating the lexical units in the lexical set W into words based on grammatical rules; performing part-of-speech tagging, entity recognition, and sentence boundary detection on the candidate options; locating the character position and sentence in which the candidate option is located in the programming task description text Q; and expanding a single candidate option into a phrase according to preset syntactic rules. The method of clustering original words or semantic units into constraint phrases based on grammatical rules includes: performing part-of-speech tagging, entity recognition, and sentence boundary detection on the programming task description text Q; retaining at least one candidate part of speech among nouns, adjectives, verbs, pronouns, determiners, numerals, adverbs, and conjunctions or prepositions related to logical relations; excluding pure punctuation, whitespace, and format markers without task semantics; and obtaining the complete sentence containing the candidate part of speech; further including: expanding the candidate part of speech into at least one of noun phrases, verb phrases, adverb phrases, prepositional phrases, quantifier phrases, comparative phrases, coordinate relation phrases, or alternative relation phrases according to dependency syntax, constituent syntax, or preset syntax patterns; the preset syntax rules include at least one of adjective and noun combinations, noun and noun combinations, adverb and verb combinations, numeral and noun combinations, determiner and adjective and noun combinations, preposition and determiner, adjective or noun combinations, and conjunction and noun or verb phrase combinations; When the candidate lexical is a logical connector or is located near a logical connection, the arguments on both sides of the logical connector are determined based on the syntactic relationship of the statement containing the candidate lexical, and the logical connector and the corresponding arguments are expanded together into a complete constraint phrase of parallel, alternative, or comparative relationship.

[0014] Furthermore, the phrase-level constraint gap score G(s) is calculated based on the code condition support difference of the target lexical units covered by the constraint phrase s. The phrase-level constraint gap score is calculated using the maximum, minimum, mean, weighted mean, cumulative negative logarithmic difference, quantile, or a combination thereof of the negative support difference. The phrase-level constraint gap score increases as the decrease in code condition support increases. According to the code conditions, the top k constraint phrases are retained differentially, where k is between 3 and 20. These constraint phrases are merged and sorted based on at least one of phrase-level constraint gap scores, task-topic consistency, phrase completeness, and repetition. A rule system, classification model, or generative model is used to distinguish between realized constraints, insufficiently realized constraints, task-related but non-constraint words, and meaningless structural words. The top K insufficiently realized constraint phrases are selected as gap phrases. K ranges from 1 to 7; The constraint interpretation is used to describe the specific impact of the constraint phrase on at least one of program control flow, data conditions, boundary judgments, quantitative relationships, or output format, and does not introduce new constraints outside of the programming task description text Q; The enhanced prompt is formed by combining the programming task description text Q, the gap phrase and the corresponding constraint explanation, and placing at least one of the gap phrase and the constraint explanation after the programming task description text Q, at the end of the prompt, or near the corresponding statement in the programming task description text Q.

[0015] Furthermore, the initial generation model, the scoring model that performs the forward scoring, and the final generation model are the same model, model instances sharing parameters, or different models; at least one of the initial source code C and the final source code is decoded at a generation temperature of 0 to 1, preferably at a generation temperature of 0, and the maximum number of newly added lexical units is set according to the programming task, preferably 1024; after generating the final source code, at least one of syntax parsing, compilation, unit testing, static analysis, or constraint checking can be performed, and if the preset conditions are not met, the source code is regenerated or the comparison reconstruction and forward scoring are repeated with new source code.

[0016] Secondly, the present invention provides a code constraint gap detection and enhancement generation system based on the same-target suffix comparison reconstruction method, comprising: a task acquisition module for acquiring programming task description text Q; an initial generation module for generating initial source code C based on the programming task description text Q; a comparison sequence construction module for constructing a first comparison reconstruction sequence and a second comparison reconstruction sequence, such that the first comparison reconstruction sequence has a code condition prefix containing the initial source code C, the second comparison reconstruction sequence has a reference prefix not containing code content expressing the program semantics of the initial source code C, and the two comparison reconstruction sequences have the same programming task description text Q corresponding to each position as a same-target suffix; and a forward scoring module for scoring the programming task description text Q. The plain text Q is used as a known target suffix. A teacher-mandated or equivalent controlled forward propagation method is used to perform forward scoring on two contrasting reconstruction sequences to obtain the corresponding lexical scores for the same target lexical under code conditions and reference conditions. A difference analysis module is supported to calculate the code condition support difference based on the corresponding lexical scores and identify candidate lexicals whose support decreases after the introduction of the initial source code C. A constraint back-location module is used to back-map the candidate lexicals to their positions in the programming task description text Q and identify constraint phrases that are not fully implemented in the initial source code C. A constraint feedback enhancement module is used to generate enhancement prompts based on the constraint phrases and optional corresponding constraint interpretations. Finally, a final generation module is used to generate the final source code based on the enhancement prompts. The comparison sequence construction module is further configured to generate a baseline balanced prefix that does not carry the task semantics of the initial source code C and matches the initial source code C in at least one of lexical length, character length, paragraph structure, or positional occupancy; the differential analysis support module is further configured to perform reference score filtering, support descent threshold determination, and phrase-level constraint gap aggregation; the constraint reverse positioning module is further configured to perform at least one of character or byte offset alignment, subword merging, part-of-speech filtering, sentence boundary detection, and syntactic phrase expansion.

[0017] Compared with the prior art, the present invention has at least the following beneficial effects: By making the code condition path and the reference path have the exact same target task description suffix, this invention fixes the comparison object to the same set of target words, avoiding the misalignment of word quantity, expression mode and position caused by free back translation, so that the word-by-word scores of the two paths have direct comparability at the same position.

[0018] By simply changing whether the initial source code semantic condition is injected and comparing the conditional support changes of the same target lexical, this invention can weaken the influence of lexical prior frequency and some syntactic factors on absolute probability, making the differential signal more directly reflect the consistency or conflict relationship between the initial source code and the specific task semantics.

[0019] This invention does not require the model to freely generate back-translated text to obtain semantic diagnostic signals on the code side. It only requires performing a limited number of forward propagations on known target suffixes, reducing the overhead of additional decoding of lexical units and multiple rounds of long text inference.

[0020] By using a baseline balancing prefix, the impact of differences in context length, position occupancy, and cue structure on probability comparisons can be further reduced, improving stability under different task lengths and code lengths.

[0021] By using character offset recovery, lexical filtering, syntactic phrase expansion, and phrase-level gap aggregation, this invention transforms negative differences in the model's lexical space into interpretable constraint phrases in the original task description, enabling the identification of logical relationships such as "left end or right end," rather than simply outputting isolated high-frequency object words.

[0022] By re-injecting the detected constraint gaps and their interpretations into the original task description, this invention forms a constraint feedback loop driven by the model's own initial code, enabling secondary generation for specific omissions in the current task without the need for external knowledge bases or additional fine-tuning.

[0023] Compared to wide candidate search, long-chain reflection, or multi-round test-driven correction, this invention can improve the constraint compliance and first-time generation success rate of the final code under the condition of limited forward scoring and one or a few re-decodings, and reduce the computing resources occupied by invalid generation and repeated execution. Attached Figure Description

[0024] Figure 1 This is a flowchart of a large model code generation optimization method based on same-target suffix reconstruction according to an embodiment of the present invention; Figure 2 This is a schematic diagram of same-target suffix comparison reconstruction and position-by-position probability comparison according to an embodiment of the present invention; Figure 3 This is a flowchart illustrating the reverse localization and prompt word enhancement at the word level supporting differential to constraint phrases, according to an embodiment of the present invention. Figure 4 This is a schematic diagram of the code generation system structure for code constraint gap detection and enhancement according to an embodiment of the present invention; Figure 5 This is a schematic diagram comparing the constraint gap location with the initial code and the final code logic in one embodiment of the present invention; Figure reference numerals: Code generation system-400, Task acquisition module-401, Initial generation module-402, Control sequence construction module-403, Forward scoring module-404, Support for differential analysis module-405, Constraint reverse localization module-406, Constraint feedback enhancement module-407, Final generation module-408. Detailed Implementation

[0025] The present invention will be further described below with reference to the accompanying drawings. It should be understood that the following embodiments are used to explain the present invention and are not intended to limit the scope of protection of the present invention.

[0026] Unless otherwise stated, “lexical” includes subwords, characters, words, symbols or combinations thereof generated by the model segmenter; “lexical score” includes logit, probability, log probability or confidence score corresponding to its monotonicity; “constraint” includes logical relations, boundary conditions, quantitative relations, input / output formats, order requirements, resource limitations and other task semantics that affect the behavior of the source code.

[0027] This invention provides a method, system, electronic device, storage medium, and computer program product that, while keeping the target lexical sequence of the programming task description unchanged, constructs reconstructed sequences with and without the initial source code conditions, respectively, using teacher-forced forward propagation to obtain positional lexical scores, calculates the code condition support difference of the initial source code for the task semantics, locates constraint phrases that are not fully implemented by the initial source code, and enhances the task description accordingly to generate the final source code.

[0028] Example 1: Overall Method Firstly, such as Figure 1 As shown, the present invention provides a large model code generation optimization method based on the reconstruction of the same target suffix, the method including steps S101 to S110.

[0029] S101, obtain the programming task description text Q.

[0030] The programming task description text Q consists of multiple target terms. Composition, Q=( , ,…, The programming task description text Q may include a natural language task description, function signature, input / output format, examples, constraints, dependency library information, and target programming language. The system can perform character encoding standardization, line break preservation, code segment marking, and maximum length control on Q, but without altering the task semantics or the relative order of its terms.

[0031] S102, Input the programming task description text Q into the initial generator model. This yields the initial source code C.

[0032] The initial generation model is an autoregressive generation model capable of generating the target programming language and with configurable decoding parameters. To reduce the randomness of the initial code, deterministic decoding with a temperature of 0 or other low-randomness decoding methods can be used; the maximum number of newly added lexical units can be set according to the task, for example, 1024.

[0033] S103, Construct the first control reconstruction sequence .

[0034] The first comparative reconstruction sequence is the concatenation of the code generated by the model with the original problem. Specifically, the first comparative reconstruction sequence... Commands to generate questions based on code The initial source code (C), the target separator (D), and the programming task description text (Q) are arranged in sequence.

[0035] = ⊕C⊕D⊕Q The symbol ⊕ indicates sequence concatenation.

[0036] The code-based question generation instruction The scoring model, upon receiving the initial source code C, enters a conditional reconstruction state based on the code to reconstruct or describe the original programming task. The target separator D clearly identifies the start position of the target task description. The first set of comparative reconstruction sequences includes a code condition prefix and a target suffix. The code condition prefix includes at least a code-based question generation instruction indicating the reconstruction of the programming task description text Q based on the initial source code C. The code condition prefix includes the initial source code C and the delimiter D. The code condition prefix also includes at least one of the abstract syntax tree, compilation result, execution trace or static analysis result directly obtained from the initial source code C. The target suffix is ​​the programming task description text Q.

[0037] S104, Construct the second control reconstructed sequence .

[0038] Second contrast reconstructed sequence Direct question generation command The optional baseline balancing prefix B, the same target separator D, and the same programming task description text Q are formed in sequence.

[0039] = ⊕B⊕D⊕Q Without carrying the program semantics expressed by the initial source code C, the direct problem generation instructions... The program semantics of the initial source code C are not introduced. Can be used with code-based question generation commands The same tone, similar length or identical system prompt is adopted, and only the semantics of the initial source code are removed. The baseline balanced prefix B is empty, or the baseline balanced prefix B is replaced with neutral placeholder content that matches at least one of the token length, character length, paragraph structure, number of code lines or position occupation of the initial source code C, and does not describe the task constraints corresponding to the initial source code C, so that the context lengths or absolute positions of the target delimiter D and the programming task description text Q in the two control reconstruction sequences tend to be consistent. The second control reconstruction sequence comprises a reference prefix and the same target suffix as the first control reconstruction sequence, and the reference prefix at least includes a directly generated question instruction and the target delimiter D.

[0040] The first control reconstruction sequence and the second control reconstruction sequence have completely identical programming task description text Q after the target start position.

[0041] In S105, and are respectively input into the scoring model to perform teacher-forced forward propagation.

[0042] may be the same model as , or may be an independent scoring model with an identical or compatible tokenizer. The system only collects the token score of each target token of the first control reconstruction sequence and the second control reconstruction sequence corresponding to the programming task description text Q after the target delimiter D, and does not require the model to freely generate the programming task description text Q.

[0043] Taking the first control reconstruction sequence as the code condition and the second control reconstruction sequence as the reference condition, the corresponding token scores of the same target token under the code condition and the reference condition are obtained. For the reference condition, a plurality of reference prefixes that do not contain the program semantics of the initial source code C are used to respectively obtain a plurality of reference scores, and an average value, median value or weighted combination is performed on the plurality of reference scores.

[0044] Specifically, for the i-th target token in the programming task description text Q , the code condition token score is acquired and the reference token score , where characterizes the prediction score for under the condition that the code condition prefix and the target prefix q<i are given characterizes the prediction score for The predicted score; the word score includes at least one of softmax probability, log probability, logit, calibrated confidence score, or score that monotonically corresponds to the probability.

[0045] When the lexical score of the target lexical cannot be obtained directly, the lexical score of the target lexical can be obtained using an interface that can return the log probabilities of candidate words, a proxy scoring model, or a distillation scoring model.

[0046] After obtaining the lexical score, position calibration or normalization is performed on the lexical scores of the first and second contrastive reconstruction sequences based on at least one of the target lexical position, conditional prefix length, reference prefix length, or reference task statistics. The calibrated comparison object is still the difference in score of the same target lexical under two conditions: program semantics containing the initial source code C and program semantics not containing the initial source code C.

[0047] S106, based on the lexical score, for each target lexical unit... The calculation code supports differential conditions. The system filters out terms with extremely low reference probability, pure format terms, and numerical outliers. Sort by smallest to largest, or by negative support strength. Sort from largest to smallest, when When the value is less than a preset threshold or falls within a preset low percentile range, the corresponding target word is identified as a candidate word whose support level has decreased, thus obtaining a candidate word set W.

[0048] The code conditions support differential coding. The following methods can be used to obtain: logarithmic probability difference, probability difference ( - ), relative rate of change ( - ) / ( +ε), probability ratio ( +ε) / ( +ε), normalized difference, rank difference, standardized score or a combination thereof. The logarithmic probability difference is specifically: =log( +ε)-log( +ε) Where ε is a non-negative stable term.

[0049] The code conditions support differential. Both are based on positional comparisons of the same target word in the first and second contrastive reconstruction sequences. Used to indicate the target lexical after introducing the initial source code. The predictions support the changes that occur relative to the reference path. A significant positive value indicates that the initial source code improves support for this term; A value close to zero indicates that the initial source code has a weak impact on the word; A significantly negative value indicates that the initial source code reduces support for the term and considers it as a candidate term that may correspond to a code constraint gap.

[0050] When determining the candidate lexical units, a support descent threshold is determined based on at least one of a fixed threshold, mean, standard deviation, median absolute deviation, quantile, or task length, and target lexical units whose code condition support difference satisfies the support preset threshold are selected as candidate lexical units.

[0051] Furthermore, before calculating or sorting the code conditions to support differentials, a low-probability filtering ratio is set according to a fixed probability threshold, percentile threshold, quantile threshold, or adaptive statistical threshold to exclude reference scores. Target words below the preset conditions are filtered to reduce differential amplification caused by extremely low reference probabilities; in a specific embodiment, the low probability filtering ratio is 0.5% to 8%, preferably 2.5%.

[0052] S107, based on the lexical information provided by the word segmenter, the candidate lexical units in the candidate lexical set W are back-mapped to the original words or semantic units in the programming task description text Q; then, based on the grammatical rules, the original words or semantic units are clustered into constraint phrases s, and the phrase set S is obtained.

[0053] Specifically, the candidate lexical reverse mapping involves: merging the candidate lexical set W into words or semantic units according to word rules; aggregating the lexical units in the lexical set W into words based on grammatical rules; performing part-of-speech tagging, entity recognition, and sentence boundary detection on the candidate options; locating the character position and sentence in which the candidate option is located in the programming task description text Q; and expanding a single candidate option into a phrase according to preset syntactic rules.

[0054] The method of clustering original words or semantic units into constraint phrases based on grammatical rules involves: performing part-of-speech tagging, entity recognition, and sentence boundary detection on the programming task description text Q; retaining at least one candidate part of speech among nouns, adjectives, verbs, pronouns, determiners, numerals, adverbs, and conjunctions or prepositions related to logical relations; excluding pure punctuation, whitespace, and format markers without task semantics; and obtaining sentence-level reference information where the candidate parts of speech are located. It also includes: expanding the candidate parts of speech into at least one of noun phrases, verb phrases, adverb phrases, prepositional phrases, quantifier phrases, comparative phrases, coordinate phrases, or alternative phrases based on dependency syntax, constituent syntax, or a preset syntactic pattern; the preset syntactic rules include at least one of adjective and noun combinations, noun and noun combinations, adverb and verb combinations, numeral and noun combinations, determiner and adjective / noun combinations, preposition and determiner combinations, adjective or noun combinations, and conjunction and noun or verb phrase combinations.

[0055] When the candidate lexical is a logical connector or is located near a logical connection, the arguments on both sides of the logical connector are determined based on the syntactic relationship of the statement containing the candidate lexical, and the logical connector and the corresponding arguments are expanded together into a complete constraint phrase of parallel, alternative, or comparative relationship.

[0056] S108: Based on the code conditions of the target lexical units covered by the constraint phrases s in the phrase set S, the phrase-level constraint gap score G(s) is calculated using differential support. Then, phrases irrelevant or meaningless to the solution are removed using rule or model classification, and the top K gap phrases are selected. And generate an accurate constraint interpretation E for it.

[0057] The phrase-level constraint gap score is calculated using the maximum, minimum, mean, weighted mean, cumulative negative logarithmic difference, quantile, or a combination thereof of the negative support difference; and the phrase-level constraint gap score increases as the decrease in code condition support increases. Preferably, G(s) increases as the decrease in code condition support increases, and is used to sort the constraint phrases.

[0058] According to the code conditions, the top k constraint phrases are retained differentially, where k is 3 to 20, preferably 5. For these constraint phrases, they are merged and sorted based on at least one of the phrase-level constraint gap score, task-topic consistency, phrase completeness, and repetition. A rule system, classification model, or generative model is used to distinguish between realized constraints, insufficiently realized constraints, task-related but non-constraint words, and meaningless structural words. The top K insufficiently realized constraint phrases are selected as gap phrases. K can be 1 to 7, preferably 3.

[0059] The constraint interpretation is used to describe the specific impact of the constraint phrase on at least one of program control flow, data conditions, boundary judgments, quantitative relationships, or output format, and does not introduce new constraints outside of the programming task description text Q.

[0060] S109, the programming task description text Q, And the constraint interpretation E combination receives enhanced hints .

[0061] The programming task description text Q, the gap phrase, and the corresponding constraint explanation are combined, and at least one of the constraint phrase and the constraint explanation is placed after the programming task description text Q, at the end of the prompt, or near the corresponding statement in the programming task description text Q to obtain an enhanced prompt.

[0062] Preferably, adding "Please specifically check and implement the following constraints" or an equivalent control statement at the end of the prompt causes the generative model to explicitly focus on the task semantics suppressed by the initial source code during re-decoding. Additionally, control instructions can be added to require the model to focus on checking the constraints.

[0063] S110, the enhanced prompt Input the final generative model Obtain the final source code . Can be with Same. Optionally, for Perform at least one of syntax parsing, compilation, unit testing, static analysis, or constraint checking, and output code that passes preset verification conditions.

[0064] At least one of the initial source code C and the final source code is decoded using a generation temperature of 0 to 1, preferably 0. The maximum number of newly added lexical units is set according to the programming task, preferably 1024.

[0065] Example 2: Reconstruction and Forward Scoring Based on Target Suffix Comparison like Figure 2 As shown, the programming task description text Q consists of a sequence of terms (q1, q2, ..., q...). n Composed of... (The rest of the text appears to be a list of keywords or tags, possibly related to code generation and question instructions.) The following semantic template can be used: "The following is the source code generated for a certain programming task. Please describe the original task requirements based on this code: {C}. The original task is as follows: --start--{Q}". The following semantic template can be used to directly generate the task instruction: "Please describe a programming task. The task is as follows: --start--{Q}". These templates are merely examples; the key is that the target suffix Q after --start-- in both paths must be exactly the same.

[0066] In the inference framework, the system does not allow the model to perform free decoding after --start--, but feeds Q into the model as a known label sequence. For the i-th target token qi, the forward propagation uses the target prefixes q1 to q_{i-1} to calculate the next token distribution and extract the logit or probability corresponding to qi, so the two paths can be directly compared at the same i.

[0067] The code conditional probability of the first group of control reconstruction sequences can be expressed as Pc(qi)=P(qi|Ic,C,D,q_<i); the reference probability of the second group of control reconstruction sequences can be expressed as Pb(qi)=P(qi|Ib,B,D,q_<i). Since q_<i and the qi to be compared both come from the same original task specification in the two paths, the difference is mainly caused by the initial source code semantics in the conditional prefix and the allowed baseline structure difference.

[0068] When the model directly outputs the logit z i , softmax can be performed on the vocabulary dimension to obtain the target token probability; when the interface only provides the log probability of candidate words, the logprob of the target token can be directly used; when the complete probability distribution cannot be accessed, a proxy model or a distillation scoring model that can return the score of each token can also be adopted.

[0069] Different from free back-translation, this embodiment limits "back-translation" to a conditional reconstruction scoring process, that is, the code is used to change the conditional likelihood of the fixed original task specification, rather than generating another freely rewritable task text. Therefore, this solution does not need to solve the problem of semantic alignment or edit distance matching between two freely generated texts.

[0070] In a preferred implementation, M s adopts the same model weights and tokenizer as the initial generation model, so that initial code generation, code conditional scoring and reference scoring are in the same model distribution. In another implementation, an independent scoring model with a compatible tokenizer or a mappable token space can be used.

[0071] When the code C is long, the second group of control reconstruction sequences can be added with a baseline balancing prefix B. B can be composed of repeated neutral placeholder tokens, meaningless placeholder text with a similar number of lines to the code, or other content that does not describe task constraints, so that the absolute positions or relative context lengths of D and Q in the two input sequences are as close as possible.

[0072] Embodiment 3: Code condition support difference and constraint gap calculation This embodiment preferably adopts the log probability difference Support for differencing as a code condition. The logarithmic form can convert probability ratios into additive differences, facilitating the aggregation of multiple tokens while reducing comparability issues at different absolute probability scales.

[0073] =log( +ε)-log( +ε) when If the value of qi is less than a preset threshold τ, or falls within a preset low quantile range of the differences between all tokens in the current task, qi can be recorded as a negative support candidate. The threshold τ can be a fixed value, or it can be adaptively determined based on the mean, standard deviation, absolute deviation of the median, quantiles, or task length.

[0074] To avoid distortion of numerical differences when Pb(qi) is extremely low, a certain percentage of words with the lowest reference probability can be excluded first. In one embodiment, the filtering percentage is 0.5% to 8%, preferably 2.5%; alternatively, Pb(qi) can be required to be higher than an absolute threshold before participating in differential sorting.

[0075] When an original word consists of multiple sub-words t1, ..., tm, the support difference of the word can be set as the minimum, mean, length-weighted mean, or cumulative value of each sub-word's Δ. Preferably, for scenarios aimed at discovering constraint gaps, minimum or negatively weighted aggregation that can preserve significant negative anomalies can be used.

[0076] For a constraint phrase s, the set of terms it covers is denoted as T(s). The phrase-level constraint gap score can be defined as G(s) = Agg({-Δi|qi∈T(s),Δi<0}). Agg can be the maximum value, mean value, weighted mean value, or cumulative value. Terms in the phrase that are in logical connection, comparison relationship, or quantity limit position can also be assigned higher weights.

[0077] In one implementation, the system can also add the absolute levels of Pc and Pb to G(s) so that minimal differences caused only by noise are not amplified; it can also merge overlapping parts of multiple candidate phrases in the same sentence to reduce the repeated counting of the same constraint.

[0078] The purpose of the aforementioned code conditional support differencing is not, in the general sense, model confidence estimation, but rather to measure the gain or suppression of the initial source code conditions on the semantics of a fixed task. When a constraint phrase is relatively natural in the reference path, but its corresponding lexical shows a significant decrease in support after C is given, this negative change is used to characterize the coverage gap of C on that constraint.

[0079] Example 4: Reverse Positioning of Constraint Phrase like Figure 3As shown, the system first obtains candidate tokens by differential sorting based on code conditions. For the sub-words generated by the tokenizer, the system restores the original text range in Q based on the character offset, byte offset, or reversible segmentation result returned by the tokenizer, ensuring that subsequent analysis always returns to the actual task description provided by the user.

[0080] In one implementation, lexical filtering retains nouns, adjectives, verbs, pronouns, determiners, numerals, adverbs, and conjunctions or prepositions related to logical relationships, while excluding pure punctuation, whitespace, and formatting tags without task semantics. For entity types such as PERSON, GPE, ORG, and LOC, retention or exclusion can be determined based on the task domain.

[0081] The system retrieves the complete sentence containing each candidate word and expands isolated lexical units into complete constraint phrases based on dependency syntax, constituent syntax, or preset patterns. Available rules include: ADJ+NOUN → noun phrase, NOUN+NOUN → noun phrase, ADV+VERB → verb phrase, NUM+NOUN → quantity phrase, DET+ADJ+NOUN → noun phrase, PREP+(DET|ADJ|NOUN)+ → prepositional phrase, and CONJ+(NP|VP) → coordinate or alternative relational phrase.

[0082] For long phrases, low-scoring words may only contain partial words. The system expands these words into complete selection phrases containing both left and right arguments by considering the context and syntactic relations. This allows subsequent feedback to express executable program logic, rather than simply indicating isolated connectives.

[0083] When truncating candidates, the first k words or semantic units can be retained, where k can be 3 to 20, preferably 5. After generating one or more phrases for each candidate, they are then merged and sorted based on constraint gap score, topic consistency, phrase completeness and repetition.

[0084] The classification model can be asked to classify between "constraints implemented", "constraints not fully implemented", "task-related but not constrained", and "meaningless words". This classification step is not responsible for detecting negative anomalies, but only performs semantic processing on candidates that have already been screened out by the control forward scoring, so its output does not replace code conditional support differencing.

[0085] Finally, select the first K missing constraint phrases, where K can be 1 to 7, preferably 3. For cases where K is greater than 1, further deduplication and coverage optimization can be performed to avoid multiple phrases describing the same constraint from crowding out other important gaps.

[0086] Example 5: Constraint Feedback and Final Code Generation For the selected constraint phrase, the interpretation model or rule module generates an explicit constraint interpretation. The interpretation should preferably describe the specific impact of the phrase on program control flow, data conditions, boundary judgments, or output format, without introducing new constraints beyond the original task description.

[0087] Enhanced prompts The structure can be "original task description + constraint gap list + constraint explanation + regeneration instruction". To improve the visibility of the supplemented constraints in the context, the constraint gap list and explanation can be placed at the end of the prompt, or an emphasis can be inserted near the corresponding statement in the original task.

[0088] Final model generation If the initial model and the final model are the same, this method forms a self-feedback closed loop of "initial output - comparison scoring - constraint feedback - re-output"; if they are different, the scoring result is still determined by the comparison difference between the original task and the initial code.

[0089] Optionally, the system for Perform compilation or unit tests. If verification fails, you can either retain the detected constraint gaps and regenerate, or regenerate with new ones. The scores were reconstructed as conditional repeat controls to determine whether significant negative support phrases still existed.

[0090] Example 6: Code Generation System like Figure 4 As shown, the code generation system 400 includes a task acquisition module 401, an initial generation module 402, a control sequence construction module 403, a forward scoring module 404, a differential analysis support module 405, a constraint reverse localization module 406, a constraint feedback enhancement module 407, and a final generation module 408.

[0091] Task acquisition module 401 is used to receive programming task description text Q; initial generation module 402 is used to call the generation model to obtain C according to the programming task description text Q; comparison sequence construction module 403 is used to construct programming task description texts Q with the same target suffix. and It can also generate baseline balanced prefix B; the forward scoring module 404 is used to perform teacher-forced forward propagation and extract co-position lexical scores.

[0092] Supports the differential analysis module 405 for calculation The module performs reference probability filtering and candidate sorting; the constraint reverse positioning module 406 performs character alignment, subword merging, lexical filtering, syntactic expansion, and phrase-level gap aggregation; the constraint feedback enhancement module 407 selects missing constraints and forms... The final generation module 408 is used to generate... It can also call compilation, testing, or static analysis tools.

[0093] System 400 can be deployed on a single server, developer workstation, edge device, or distributed inference cluster. Model weights, tokenizers, prompt templates, balanced prefix rules, difference thresholds, syntactic rules, and test cases can be stored in local or remote storage.

[0094] Example 7: Deleting tasks from both ends of the list like Figure 5 As shown, the task requirement of this embodiment is: given a list of length n, each time you can only delete elements no greater than k from either the leftmost or rightmost end of the list, find the maximum number of elements that can be deleted. The code generated by the initial model incorrectly implements "leftmost or rightmost" as "both leftmost and rightmost elements are satisfied simultaneously," as shown in the following example logic: A code-conditional path is constructed using the initial code C, and a reference path that does not contain the semantics of C is used as a contrast. After performing teacher-mandated forward propagation on the same original task description Q, the support of terms related to "leftmost or rightmost" in the code-conditional path decreases significantly relative to the reference path, thus forming negative candidates.

[0095] The system maps negative terms back to the original task statement and expands the conjunction and its left and right arguments into the complete constraint phrase "leftmost or rightmost". The constraint interpretation states that the left and right ends of the list should be checked separately, and deletion is allowed as long as either end satisfies a value not greater than k; the process stops only when neither end satisfies the condition.

[0096] After feeding this constraint gap back into the original task description, the final generated model yields the following logic: The revised code determines the left and right endpoints respectively, thus realizing the selection relationship in the original task. This example illustrates that this method identifies the negative support changes caused by the initial code conditions to the semantics of a specific task, and can further restore the complete logical constraints, rather than simply selecting the word with the lowest absolute probability.

[0097] Example 8: Parameter Setting and Experimental Verification In an experimental implementation, an open-source code model capable of outputting word-by-word logit or logprob was used. The parameter settings are shown in Table 1. The initial code generation temperature was set to 0, the maximum number of newly added lexical units was set to 1024, the candidate truncation k was preferably 5, the final number of constraint phrases K was preferably 3, and the extremely low reference probability filtering percentage was preferably 2.5%, which could be set within the range of 0.5% to 8%.

[0098] On code generation datasets such as APPS, MBPP, HumanEval, and BigCodeBench, Pass@1 can be used as a metric for single-generation accuracy. Experimental results described in the original specification show that this approach can improve the average Pass@1 on generation models of different sizes and structures; specifically, on an 8B parameter model, the average relative improvement compared to direct generation can reach approximately 11.62%. This data is used to illustrate the technical effect and does not constitute a limitation on the scope of protection.

[0099] The ablation results also show that: using only the absolute probability of the code-conditional path is less effective than the probability change of the code-conditional path relative to the reference path; analyzing only the prior distribution of the original task is less effective than the control change after using the initial code as a condition; and not using meaningless word classification reduces the quality of constraint phrase selection. These results support using "comparison with the same target suffix" as a source of diagnostic signals, rather than using any absolute probability itself as a constraint gap.

[0100] Table 1 Parameter Setting Table The parameters mentioned above can be adjusted based on model size, task language, average code length, and scoring interface capabilities. The parameter ranges are used to describe possible implementations and do not imply that only specific values ​​constitute the same-target suffix comparison reconstruction mechanism of this invention.

[0101] The above steps can be implemented by software, hardware, firmware, or a combination thereof. The module division is for functional description only. A module can be implemented by multiple processing units, and multiple modules can also be implemented by the same processing unit. Without changing the technical logic of "same target suffix comparison and reconstruction - position-by-position forward scoring - code condition support differential - constraint gap reverse positioning - constraint feedback generation", the steps can be merged, parallelized, or adjusted in sequence.

Claims

1. A method for code constraint gap detection and enhancement generation based on reconstructing with the same target suffix, characterized in that, Includes the following steps: Obtain the programming task description text Q; input the programming task description text Q into the initial generation model to obtain the initial source code C; construct a first comparative reconstruction sequence and a second comparative reconstruction sequence, wherein the first comparative reconstruction sequence includes a code condition prefix containing the initial source code C and the programming task description text Q as a target suffix, and the second comparative reconstruction sequence includes a reference prefix not containing code content used to express the program semantics of the initial source code C and the same programming task description text Q as a target suffix, such that the target suffixes of the two comparative reconstruction sequences have the same target word sequence corresponding to each position; using the programming task description text Q as a known target suffix, input the first and second comparative reconstruction sequences into the scoring model respectively, and perform forward scoring on them respectively using forward propagation to obtain the corresponding word score of the same target word under code condition and reference condition; and assign each target word score according to the word score. The calculation code supports differential conditions. And identify candidate nodules with decreasing support; back-map the candidate nodules to the original words or semantic units in the programming task description text Q, and then cluster the original words or semantic units into constraint phrases s based on grammatical rules; Calculate the phrase-level constraint gap score G(s) based on the constraint phrases, and select the top K gap phrases. It generates a constraint interpretation E for it; and forms an enhanced hint with the programming task description text Q; The enhanced prompts are input into the final generated model to generate the final source code.

2. The method according to claim 1, characterized in that, The programming task description text Q consists of multiple target terms. Composition, Q=( , ,…, The programming task description text Q includes a natural language task description, function signature, input / output format, examples, constraints, dependency library information, and target programming language.

3. The method according to claim 1, characterized in that, First-comparison reconstructed sequence According to the code-based question generation instructions The initial source code C, the target delimiter D, and the programming task description text Q are arranged in the following order; the second comparison reconstruction sequence. Follow the instructions to directly generate questions The optional baseline balancing prefix B, the target separator D, and the same programming task description text Q are arranged in that order; wherein, the code-based question generation instruction... The direct question generation instruction is used to enable the scoring model to enter a conditional reconstruction state based on the source code or a description of the original programming task after receiving the initial source code C. The program semantics of the initial source code C are not introduced; the code condition prefix includes at least a code-generated task instruction for instructing the refactoring of the programming task description text Q based on the initial source code C. The initial source code C and the delimiter D are included. The code condition prefix also includes at least one of the following: an abstract syntax tree, compilation result, execution trace, or static analysis result directly obtained from the initial source code C; the reference prefix includes at least the direct problem generation instruction. and target separator D; The baseline balancing prefix B is empty, or includes neutral placeholder content that matches the initial source code C in at least one of lexical length, character length, paragraph structure, number of lines of code, or positional occupancy, and does not describe the task constraints corresponding to the initial source code C, so that the target delimiter D and the programming task description text Q tend to be consistent in context length or absolute position in the two contrasting reconstruction sequences. The same target suffix means that the first and second contrastive reconstruction sequences obtain completely identical target words after the target starting position using the same word segmenter, and the relative positions of each target word in its respective target suffix correspond one-to-one; when performing the forward scoring, the programming task description text Q is used as a known label sequence to input word-by-word into the scoring model, and only the target word scores corresponding to the target suffix are collected.

4. The method according to claim 1, characterized in that, The forward propagation manner includes teacher-forced forward propagation; the code condition is a first control reconstruction sequence, and the reference condition is a second control reconstruction sequence. For the i-th target token in the programming task description text Q , a code condition token score is acquired and a reference token score ; where represents the prediction score for under the condition that the code condition prefix and the target prefix q<i are given represents the prediction score for under the condition that the program semantics of the initial source code C are not provided and the same target prefix q<i is given; the token score includes at least one of a softmax probability, a logarithmic probability, a logit, a calibrated confidence score, or a score monotonically corresponding to the probability; the reference condition adopts a plurality of reference prefixes that do not contain the program semantics of the initial source code C to respectively obtain a plurality of reference token scores, and an average value, a median value or a weighted combination is performed on the plurality of reference token scores; when the complete probability distribution of the target token cannot be directly obtained, an interface capable of returning the logarithmic probability of a candidate word, a proxy scoring model or a distillation scoring model is used to obtain the token score of the target token, wherein the scoring models for the two control paths are the same and the target suffix remains consistent After obtaining the lexical score, position calibration or normalization is performed on the lexical scores of the first and second contrastive reconstruction sequences based on at least one of the target lexical position, conditional prefix length, reference prefix length, or reference task statistics. The calibrated comparison object is still the difference in score of the same target lexical under two conditions: program semantics containing the initial source code C and program semantics not containing the initial source code C.

5. The method according to claim 1, characterized in that, The code conditions support differential. Using probability difference - Relative rate of change ( - ) / ( +ε), probability ratio ( +ε) / ( +ε), logarithmic probability difference log( +ε)-log( +ε), normalized difference, rank difference, standardized score or a combination thereof; The code conditions support differential. Both are based on positional comparisons of the same target word in the first and second contrast-reconstructed sequences; A support descent threshold is determined based on at least one of a fixed threshold, mean, standard deviation, median absolute deviation, quantile, or task length, and target lexical units whose code conditional support difference satisfies the support descent threshold are selected as candidate lexical units. Before calculating or sorting the code conditions to support differential, a low probability filtering ratio is set according to a fixed probability threshold, percentile threshold, quantile threshold, or adaptive statistical threshold to exclude target words with reference scores lower than preset conditions, so as to reduce differential amplification caused by extremely low reference probabilities; wherein, the low probability filtering ratio is 0.5% to 8%.

6. The method according to claim 1, characterized in that, The reverse mapping of candidate lexical units specifically involves: merging the candidate lexical unit set W into words or semantic units according to word rules; and aggregating the lexical units in the lexical unit set W into words based on grammatical rules. Perform part-of-speech tagging, entity recognition, and sentence boundary detection on the candidate options; locate the character position and sentence containing the candidate option in the programming task description text Q; Expand individual candidate options into phrases according to preset syntax rules; The method of clustering original words or semantic units into constraint phrases based on grammatical rules includes: performing part-of-speech tagging, entity recognition, and sentence boundary detection on the programming task description text Q; retaining at least one candidate part of speech among nouns, adjectives, verbs, pronouns, determiners, numerals, adverbs, and conjunctions or prepositions related to logical relations; excluding pure punctuation, whitespace, and format markers without task semantics; and obtaining the complete sentence containing the candidate part of speech; further including: expanding the candidate part of speech into at least one of noun phrases, verb phrases, adverb phrases, prepositional phrases, quantifier phrases, comparative phrases, coordinate relation phrases, or alternative relation phrases according to dependency syntax, constituent syntax, or preset syntax patterns; the preset syntax rules include at least one of adjective and noun combinations, noun and noun combinations, adverb and verb combinations, numeral and noun combinations, determiner and adjective and noun combinations, preposition and determiner, adjective or noun combinations, and conjunction and noun or verb phrase combinations; When the candidate lexical is a logical connector or is located near a logical connection, the arguments on both sides of the logical connector are determined based on the syntactic relationship of the statement containing the candidate lexical, and the logical connector and the corresponding arguments are expanded together into a complete constraint phrase of parallel, alternative, or comparative relationship.

7. The method according to claim 1, characterized in that, The phrase-level constraint gap score G(s) is calculated based on the code condition support difference of the target lexical units covered by the constraint phrase s. The phrase-level constraint gap score is calculated using the maximum, minimum, mean, weighted mean, cumulative negative logarithmic difference, quantile, or a combination thereof of the negative support difference. Furthermore, the phrase-level constraint gap score increases as the decrease in code condition support increases. According to the code conditions, the top k constraint phrases are retained differentially, where k is between 3 and 20. These constraint phrases are merged and sorted based on at least one of phrase-level constraint gap scores, task-topic consistency, phrase completeness, and repetition. A rule system, classification model, or generative model is used to distinguish between realized constraints, insufficiently realized constraints, task-related but non-constraint words, and meaningless structural words. The top K insufficiently realized constraint phrases are selected as gap phrases. K ranges from 1 to 7; The constraint interpretation is used to describe the specific impact of the constraint phrase on at least one of program control flow, data conditions, boundary judgments, quantitative relationships, or output format, and does not introduce new constraints outside of the programming task description text Q; The enhanced prompt is formed by combining the programming task description text Q, the gap phrase and the corresponding constraint explanation, and placing at least one of the gap phrase and the constraint explanation after the programming task description text Q, at the end of the prompt, or near the corresponding statement in the programming task description text Q.

8. The method according to claim 1, characterized in that, The initial generation model, the scoring model that performs the forward scoring, and the final generation model are the same model, model instances with shared parameters, or different models; at least one of the initial source code C and the final source code is decoded at a generation temperature of 0 to 1, preferably at a generation temperature of 0, and the maximum number of newly added lexical units is set according to the programming task, preferably 1024; after generating the final source code, at least one of syntax parsing, compilation, unit testing, static analysis, or constraint checking can be performed, and if the verification does not meet the preset conditions, the model can be regenerated or the comparison reconstruction and forward scoring can be repeated with new source code.

9. A code constraint gap detection and enhancement generation system based on the method of any one of claims 1 to 8, characterized in that, include: The task acquisition module is used to acquire the programming task description text Q; the initial generation module is used to generate the initial source code C based on the programming task description text Q. A contrast sequence construction module is used to construct a first contrast reconstruction sequence and a second contrast reconstruction sequence, such that the first contrast reconstruction sequence has a code condition prefix containing the initial source code C, and the second contrast reconstruction sequence has a reference prefix that does not contain code content used to express the program semantics of the initial source code C, and the two contrast reconstruction sequences have the same programming task description text Q corresponding to each position as the same target suffix; a forward scoring module is used to use the programming task description text Q as a known target suffix, and to perform forward scoring on the two contrast reconstruction sequences respectively using a teacher-mandated or equivalent controlled forward propagation method to obtain the corresponding word score of the same target word under code condition and reference condition; A differential analysis module is supported, which is used to calculate the code condition support difference based on the corresponding word unit score, and to determine the candidate words whose support level decreases after the initial source code C is introduced; The constraint reverse localization module is used to reverse map the candidate nouns to the text positions in the programming task description text Q, and to determine the constraint phrases that are not fully implemented in the initial source code C; The constraint feedback enhancement module is used to generate enhanced prompts based on the constraint phrase and the optional corresponding constraint interpretation; And a final generation module, used to generate the final source code based on the enhanced prompts; The contrast sequence construction module is also configured to generate a baseline balanced prefix that does not carry the task semantics of the initial source code C and matches the initial source code C in at least one of the following: lexical length, character length, paragraph structure, or positional occupancy. The differential analysis support module is also configured to perform reference score filtering, support descent threshold determination, and phrase-level constraint gap aggregation; the constraint reverse positioning module is also configured to perform at least one of character or byte offset alignment, sub-word merging, part-of-speech filtering, sentence boundary detection, and syntactic phrase expansion.

10. An electronic device, characterized in that, It includes at least one processor and a memory, wherein the memory stores a computer program, which, when executed by the at least one processor, causes the at least one processor to perform the method of any one of claims 1 to 8.