This invention discloses a robustness enhancement method for large-scale code models based on
context processing and post-training, selecting the enhancement method according to the type of model to be enhanced. For post-training enhancement, adversarial perturbation samples are first generated from the given
source code using equivalence semantic transformation, greedy search, and
simulated annealing. These perturbation samples are then input into the post-training framework to fine-tune the target large-scale
language model. For context enhancement, a
backup dataset is generated using
backup code. The optimal subset of examples most semantically similar to the current problem is selected by calculating similarity.
Dead code is then normalized, and the optimal subset of examples is adaptively selected. Contextual prompts are dynamically adjusted based on task complexity and input into the target large-scale
language model. Finally, evaluation
metrics and the robustly enhanced target large-scale
language model are output. This invention supports multiple mainstream
programming languages and both open-source and closed-source models, exhibiting good versatility and
scalability.