An Iterative Code Generation and Optimization Framework Based on Dynamic Few-Shot Learning for Medical Information Processing
摘要
In the field of medical information processing, automatic code generation has become increasingly important for handling complex healthcare data analysis tasks. This paper proposes an iterative code generation and optimization framework that leverages large language models (LLMs) with dynamic few-shot learning. Our approach consists of three main components: (1) an initial code generation module that produces diverse test cases covering both positive and negative scenarios, (2) a dynamic few-shot learning mechanism that constructs contextual prompts using question, FHIR_FSH, FHIR_SERVICE_CODE, and NLP_CODE inputs, and (3) an automated evaluation and optimization pipeline that identifies code issues and refines the generation process. The framework iteratively improves code quality through continuous testing and prompt refinement. We implement our framework using DeepSeek v3.1 as the code generation model. Experimental results demonstrate that our approach achieves substantial performance improvements, with F1 scores increasing from 0.12 in the initial iteration to 0.42 after 5 iterations, representing a 250% improvement. The dynamic few-shot mechanism contributes significantly, providing a Δ + 0.13 improvement over baseline iterative approaches. The system shows promising results in medical natural language processing tasks, particularly in FHIR (Fast Healthcare Interoperability Resources) data processing scenarios.