Big Five personality traits-based big language model code generation cue word construction method
By constructing a multi-dimensional personality trait parameter mapping model based on the Big Five personality trait theory, a structured prompt word template is automatically generated, which solves the problem of lack of personalized requirements in the prompt word design in the existing technology, and realizes personalized code generation of the large language model in complex software development scenarios.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-10
- Publication Date
- 2026-03-13
AI Technical Summary
Existing technologies lack a systematic consideration of personalized code generation style requirements in prompt word design. They cannot adapt to different application scenarios, different development teams' coding style preferences, and specific requirements of tasks with different complexities. As a result, the generated code cannot meet personalized customization needs and it is difficult to ensure the correctness of code functions while taking into account the diversity and adaptability of coding styles.
Based on the Big Five personality trait theory, a multi-dimensional personality trait parameter mapping model is constructed. By quantifying parameter weights, a mapping relationship between personality trait parameters and code generation style features is established. The model automatically generates structured prompt word templates with the target personality trait style and combines them with a large language model to generate code output that meets expectations.
It enables personalized customization based on different application scenarios, development teams, and tasks of varying complexity. The generated code ensures functional correctness while also taking into account the diversity and adaptability of coding styles, significantly improving the practical value and application flexibility of large language models in complex software development scenarios.
Smart Images

Figure CN121660091A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of artificial intelligence and natural language processing technology, specifically to a method for constructing prompt words for generating code based on a big language model of Big Five personality traits. Background Technology
[0002] With the rapid development of artificial intelligence technology, large language models have made significant progress in the field of automatic code generation. The technology of directly generating executable source code from natural language descriptions has been widely applied in intelligent programming assistants, code auto-completion, and development aids. This technology can significantly improve software development efficiency and reduce manual coding costs. Currently, optimizing the code generation quality of large language models mainly adopts two technical paths: one is to fine-tune the model using domain-specific data to improve the generation accuracy for specific tasks; the other is to guide the model to generate expected code output through prompt word engineering. Prompt word engineering has received widespread attention because it does not require modification of model parameters and can quickly adapt to diverse needs. However, existing prompt word design methods mainly rely on developers' experience and intuition for manual construction, lacking a systematic theoretical framework.
[0003] The main drawback of existing technologies is that the design of prompt words lacks a systematic consideration of the personalized needs of code generation styles. They cannot automatically generate targeted prompt word templates based on different application scenarios, the coding style preferences of different development teams, and the specific requirements of tasks with varying complexity. Specifically, existing methods fail to establish a mapping relationship between personality trait theory and code generation styles. This results in generated code that cannot meet personalized customization needs in terms of comment detail, error handling strategies, algorithm innovation, and readability. It is difficult to ensure code functionality while simultaneously considering the diversity and adaptability of coding styles, thus limiting the practical value of large language models in complex software development scenarios. Summary of the Invention
[0004] The purpose of this invention is to solve the problem that existing technologies cannot meet the needs of personalized customization, and to propose a method for constructing prompt words based on the Big Five personality traits and a large language model code generation method.
[0005] The technical solution of the present invention to solve the above-mentioned technical problems is as follows: The method for constructing prompt words based on the Big Five personality traits in a large language model code generation includes the following steps: S1. Obtain the natural language description information of the code generation task to be processed, perform structured parsing of the description information through natural language processing technology, extract core requirement elements including functional requirements, constraints, programming language type and application scenario, and transform the core requirement elements into a formal requirement representation. S2. Based on the Big Five personality trait theory in psychology, a multi-dimensional personality trait parameter mapping model is constructed. The Big Five personality traits include five dimensions: openness, conscientiousness, extraversion, agreeableness, and neuroticism. By setting quantitative parameter weights for each personality dimension, a mapping relationship between personality trait parameters and code generation style characteristics is established. S3. Based on the personality trait parameter mapping model and the core requirement elements extracted in step S1, and combined with the preset prompt word generation rule library, automatically generate a structured prompt word template with the style of the target personality trait. The prompt word template includes personalized instruction content for code writing style, comment detail, error handling strategy and code readability requirements. S4. Combine and splice the prompt word template generated in step S3 with the original task description information to form a complete input prompt text. Then, input the input prompt text into the pre-trained large language model to drive the large language model to generate code output results of the corresponding style according to the personality traits contained in the prompt word template.
[0006] Based on the above technical solution, the present invention can be further improved as follows.
[0007] Furthermore, in S2, the openness dimension of the Big Five personality trait parameters is used to control the degree of algorithm innovation and technology selection diversity in code generation; the conscientiousness dimension is used to control the rigor of the code and the completeness of error handling; the extraversion dimension is used to control the level of detail in code comments and documentation; the agreeableness dimension is used to control the readability and collaborative friendliness of the code; and the neuroticism dimension is used to control the sensitivity of the code to abnormal situations and the setting of fault tolerance mechanisms.
[0008] Furthermore, the process of constructing a multi-dimensional personality trait parameter mapping model in S2 includes: collecting a large amount of code sample data labeled with personality traits, using machine learning algorithms to analyze the statistical characteristics of code written by programmers with different personality trait types, extracting multi-dimensional quantitative indicators such as code complexity, comment density, exception handling coverage, and function naming standardization through feature engineering, and establishing a non-linear mapping function between personality trait parameter vectors and code style feature vectors.
[0009] Furthermore, the prompt word template generated in S3 is organized in a hierarchical structure, including a system role definition layer, a personality trait description layer, a task goal description layer, and an output format constraint layer. The personality trait description layer explicitly indicates, in natural language form, the programmer personality type and its corresponding coding behavior characteristics that the large language model should simulate during code generation.
[0010] Furthermore, the generation of prompt word templates in S3 supports a mixed configuration mode of multiple personality trait parameters, allowing the system to automatically adjust the weight distribution ratio of the five dimensions of openness, conscientiousness, extraversion, agreeableness and neuroticism according to the complexity of the specific code generation task, security requirements and application domain characteristics, so as to realize personalized prompt word customization for different application scenarios.
[0011] Furthermore, the large language model in S4 adopts a pre-trained model based on the Transformer architecture. This model is jointly pre-trained on a large-scale code corpus and a natural language corpus, and has the ability to understand natural language task descriptions and generate code in multiple programming languages, including but not limited to Python, Java, C++, JavaScript, and Go.
[0012] Furthermore, following S4, there is also a code quality assessment and feedback optimization step S5: the code output generated by the large language model is automatically evaluated in multiple dimensions. The evaluation dimensions include the code's syntactic correctness, logical integrity, running efficiency, security vulnerability risk, and maintainability indicators. The code quality score is calculated based on the evaluation results, and the score is fed back to the prompt word template generation module. The personality trait parameter weights are dynamically adjusted through a reinforcement learning mechanism to achieve continuous optimization and iteration of the prompt word template.
[0013] Furthermore, the prompt word template generation process in S3 supports an interactive parameter configuration interface, allowing developers or end users to manually adjust the parameter values of each dimension of the Big Five personality traits according to personal preferences or team coding standards, and preview sample code snippets generated under different personality trait configurations in real time, thereby achieving personalized customization of code generation style.
[0014] Furthermore, in S1, when the code generation task description information is processed in a structured manner, a natural language understanding model based on deep learning is used to perform semantic parsing on the input text. Key technical terms, data structure types and algorithm requirements involved in the task are extracted through named entity recognition technology. Logical dependencies between functional requirements are identified through dependency parsing analysis. The overall complexity level and application domain category of the task are determined through an intent classification model.
[0015] Furthermore, after the large language model generates code in S4, the system performs static analysis and dynamic testing on the generated code. The static analysis includes code style checking, potential vulnerability scanning, and code complexity assessment. The dynamic testing includes executing the generated code in an isolated sandbox environment and verifying its functional correctness and performance indicators. The test results serve as feedback signals for prompt word optimization, which are used to adjust the prompt word template generation rules in step S3, forming a closed-loop optimization mechanism to continuously improve the quality of code generation.
[0016] Compared with the prior art, the technical solution of this application has the following beneficial technical effects: This invention introduces the Big Five personality trait theory from psychology as a systematic theoretical support. In S2, it constructs a multi-dimensional personality trait parameter mapping model containing five dimensions: openness, conscientiousness, extraversion, agreeableness, and neuroticism. By setting quantitative parameter weights for each personality dimension, a clear mapping relationship is established between personality trait parameters and code generation style characteristics. In S3, this invention combines the personality trait parameter mapping model with extracted core requirement elements and automatically generates structured prompt word templates with the target personality trait style through a preset prompt word generation rule base. This template can provide personalized instruction content for code writing style, comment detail, error handling strategy, and code readability requirements. It realizes a technological leap from relying on human experience to automatic generation based on theoretical models, enabling prompt words to be customized according to different application scenarios, coding style preferences of different development teams, and specific requirements of tasks with different complexities. While ensuring the correctness of code functionality, it effectively takes into account the diversity and adaptability of coding styles, significantly improving the practical value and application flexibility of the large language model in complex software development scenarios. Attached Figure Description
[0017] Figure 1 This is a flowchart of the method for constructing prompt words for a large language model code based on Big Five personality traits, as described in this invention. Detailed Implementation
[0018] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0019] Combination Figure 1 As shown, the method for constructing prompt words for generating code based on the Big Five personality traits of the present invention includes the following steps: S1. Obtain the natural language description information of the code generation task to be processed, perform structured parsing of the description information through natural language processing technology, extract core requirement elements including functional requirements, constraints, programming language type and application scenario, and transform the core requirement elements into a formal requirement representation. S2. Based on the Big Five personality trait theory in psychology, a multi-dimensional personality trait parameter mapping model is constructed. The Big Five personality traits include five dimensions: openness, conscientiousness, extraversion, agreeableness, and neuroticism. By setting quantitative parameter weights for each personality dimension, a mapping relationship between personality trait parameters and code generation style characteristics is established. S3. Based on the personality trait parameter mapping model and the core requirement elements extracted in step S1, and combined with the preset prompt word generation rule library, automatically generate a structured prompt word template with the style of the target personality trait. The prompt word template contains personalized instruction content for code writing style, comment detail, error handling strategy and code readability requirements. S4. Combine and concatenate the prompt word template generated in step S3 with the original task description information to form a complete input prompt text. Input the input prompt text into the pre-trained large language model to drive the large language model to generate code output results of the corresponding style according to the personality traits contained in the prompt word template.
[0020] In S2, the Big Five personality trait parameters are divided into five dimensions: Openness, Conscientiousness, Extraversion, Agreeableness, Neuroticism, and Responsibility. Openness controls the degree of algorithmic innovation and the diversity of technology selection during code generation. The Openness dimension controls the rigor and completeness of error handling in the code. Extraversion controls the comprehensiveness of code comments and documentation. Agreeableness controls the readability and collaborative friendliness of the code. Neuroticism controls the sensitivity of the code to anomalies and the setting of fault tolerance mechanisms. In the construction of the Big Five personality trait parameter mapping model, the parameter settings of these five dimensions have clear technical implications and guide code generation. The Openness dimension, by setting a continuous weight value between 0 and 1, controls the degree of algorithmic innovation and the diversity of technology selection during code generation. A high Openness weight encourages the model to try novel algorithmic solutions and multiple technical implementation paths, while a low Openness weight tends to choose proven traditional algorithms and stable technical solutions. The Conscientiousness weight affects the rigor and completeness of error handling in the code. A high Conscientiousness weight requires the generated code to include complete exception handling mechanisms, boundary condition checks, and input validation logic to ensure the reliability of the code under various operating scenarios. The externality dimension parameter adjusts the level of detail in code comments and documentation. A high externality weight indicates that the model generates a complete documentation system including detailed function descriptions, parameter explanations, return value descriptions, and usage examples. The human-centeredness dimension controls code readability and collaboration friendliness. A high human-centeredness weight requires code to adopt clear naming conventions, reasonable module division, and an easy-to-understand structural design, facilitating team collaboration and later maintenance. The neuroticism dimension parameter affects the code's sensitivity to anomalies and the setting of fault tolerance mechanisms. A high neuroticism weight results in code with stronger error detection capabilities and a robust fault recovery mechanism, maintaining system stability under abnormal conditions.
[0021] The process of constructing a multi-dimensional personality trait parameter mapping model in S2 includes: collecting a large amount of code sample data labeled with personality traits; using machine learning algorithms to analyze the statistical characteristics of code written by programmers with different personality trait types; extracting multi-dimensional quantitative indicators such as code complexity, comment density, exception handling coverage, and function naming conventions through feature engineering; and establishing a non-linear mapping function between personality trait parameter vectors and code style feature vectors. The construction of the multi-dimensional personality trait parameter mapping model adopts a machine learning-based feature engineering method. First, a large dataset of code sample data labeled with personality traits is collected. This data comes from programmer commit records in open-source code repositories. By analyzing programmers' coding habits, comment styles, and project contribution patterns, and combining this with psychological assessment tools, their personality traits are labeled. Machine learning algorithms such as random forest and gradient boosting decision tree are used to perform statistical feature analysis on code written by programmers with different personality traits. Feature engineering is employed to extract multiple quantitative indicators, including code complexity metrics such as cyclomatic complexity and Halstead complexity measures; annotation density metrics such as the ratio of commented lines of code and docstring coverage; exception handling coverage metrics such as the number of try-catch blocks and the range of exception types covered; and function naming conventions such as name length, abbreviation usage, and semantic clarity. A nonlinear mapping function is established between personality trait parameter vectors and code style feature vectors. This mapping function uses a deep neural network architecture. The input layer receives a five-dimensional personality trait parameter vector, which undergoes nonlinear transformations through multiple hidden layers. The output layer generates the corresponding code style feature vector. Extensive training with numerous samples enables the model to accurately capture the complex relationship between personality traits and coding style.
[0022] The prompt word templates generated in S3 are organized in a hierarchical structure, including a system role definition layer, a personality trait description layer, a task objective description layer, and an output format constraint layer. The personality trait description layer explicitly indicates, in natural language, the programmer personality type and corresponding coding behavior characteristics that the large language model should simulate during code generation. The generated prompt word templates employ a hierarchical organizational structure containing four logical levels. The system role definition layer clearly specifies the role and identity played by the large language model during code generation. For example, it might describe the model as a senior software engineer with specific personality traits or a programming expert with a particular coding style, providing a clear task positioning. The personality trait description layer describes in detail the characteristics of the target personality type in natural language. For example, it might describe someone with highly open-minded thinking, who enjoys trying innovative algorithmic solutions and technical implementations, is adept at exploring multiple possible technical paths, or exhibits strong conscientiousness, emphasizes code rigor and completeness, and insists on writing high-quality code with comprehensive error handling mechanisms. The task objective description layer specifically elaborates on the functional requirements, performance requirements, and constraints of the current code generation task, clarifying the technical goals to be achieved and the acceptance criteria. The output format constraint layer specifies the technical requirements for the generated code, including programming language version, code format standards, documentation and commenting standards, and test case requirements, to ensure that the output code meets the expected technical standards and quality requirements.
[0023] S3's prompt word template generation supports a hybrid configuration mode for multiple personality trait parameters. This allows the system to automatically adjust the weight distribution of five dimensions—openness, conscientiousness, extraversion, agreeableness, and neuroticism—based on the complexity, security requirements, and application domain characteristics of the specific code generation task. This enables personalized prompt word customization for different application scenarios. The prompt word template generation process supports a hybrid configuration mode for multiple personality trait parameters, and the system automatically adjusts the weight distribution of the five dimensions according to the specific characteristics of the code generation task. For highly complex algorithm development tasks, the system appropriately increases the weight of the openness dimension to encourage the model to explore innovative solutions, while maintaining a certain weight for the conscientiousness dimension to ensure code quality. For applications in the financial or medical fields with high security requirements, the system significantly increases the weight of the conscientiousness and neuroticism dimensions to ensure that the generated code has robust error handling and fault tolerance mechanisms, while appropriately reducing the weight of the openness dimension to avoid using unverified new technologies. For collaborative development projects, the system increases the weight of the agreeableness and extraversion dimensions, prompting the model to generate code with good readability and complete documentation, facilitating understanding and maintenance by team members. The system has a variety of built-in preset personality trait configuration templates, such as innovative and exploratory, stable and reliable, and team-oriented. Users can choose the appropriate configuration template according to their specific needs, or manually fine-tune the specific weight values of each dimension.
[0024] The large language model in S4 employs a pre-trained model based on the Transformer architecture. This model is jointly pre-trained on a large-scale code corpus and a natural language corpus, enabling it to understand natural language task descriptions and generate code in multiple programming languages, including but not limited to Python, Java, C++, JavaScript, and Go. The code corpus contains millions of high-quality code repositories from platforms such as GitHub and Stack Overflow, covering multiple mainstream programming languages such as Python, Java, C++, JavaScript, and Go, and includes complete code files, comments, and version history information. The natural language corpus contains textual materials such as technical documents, API descriptions, programming tutorials, and Q&A, enabling the model to deeply understand the correspondence between natural language task descriptions and technical implementations. The model uses an encoder-decoder architecture; the encoder is responsible for understanding the input natural language task description and personality trait cues, while the decoder is responsible for generating the required program code. During the pre-training phase, the model learns the syntactic structure, semantic relationships, and programming patterns of the code. During the fine-tuning phase, it undergoes adaptive training for specific personality traits, enabling the model to generate code outputs in the corresponding style based on different trait parameters.
[0025] Following S4, the code quality assessment and feedback optimization step S5 is also included: This step performs a multi-dimensional automated evaluation of the code output generated by the large language model. Evaluation dimensions include the code's syntactic correctness, logical integrity, runtime efficiency, security vulnerability risks, and maintainability. Based on the evaluation results, a code quality score is calculated and fed back to the prompt word template generation module. Through reinforcement learning, the weights of personality trait parameters are dynamically adjusted to achieve continuous optimization and iteration of the prompt word template. The code quality assessment and feedback optimization step employs a multi-dimensional automated evaluation system to comprehensively check the quality of the generated code. Syntactic correctness evaluation uses compilers and static analysis tools to check whether the code conforms to the programming language's syntax specifications and whether there are any syntax errors or type mismatches. Logical integrity evaluation uses code review tools to check the correctness of the algorithm logic, the completeness of boundary condition handling, and the completeness of business requirement implementation. Runtime efficiency evaluation uses performance analysis tools to measure the code's time and space complexity, identifying potential performance bottlenecks and optimization opportunities. Security vulnerability risk assessment uses security scanning tools to detect potential security vulnerabilities in the code, such as SQL injection, cross-site scripting attacks, buffer overflows, and other common security issues. Maintainability metrics are evaluated across multiple dimensions, including code complexity, modularity, comment quality, and test coverage, to comprehensively assess the long-term maintainability of the code. A comprehensive code quality score is calculated based on the evaluation results. This score serves as a reward signal for the reinforcement learning algorithm, dynamically adjusting the weighting of personality trait parameters to gradually improve the generation effectiveness of prompt word templates through multiple iterations.
[0026] The prompt word template generation process in S3 supports an interactive parameter configuration interface, allowing developers or end-users to manually adjust the parameter values of each dimension of the Big Five personality traits according to personal preferences or team coding standards. Users can also preview sample code snippets generated under different personality trait configurations in real time, thus achieving personalized customization of the code generation style. The configuration interface uses an intuitive slider control to display the current weight values of the five dimensions, allowing users to adjust the relative importance of each dimension in real time by dragging the slider. The system provides a real-time preview function, allowing users to immediately view sample code snippets generated based on the current configuration after adjusting parameters, intuitively understanding the impact of different personality trait configurations on the coding style. The configuration interface also provides a variety of preset personality trait configuration schemes, such as the Rigorous Engineer mode (high conscientiousness, high neuroticism), the Innovative Explorer mode (high openness, moderate conscientiousness), and the Team Collaborator mode (high agreeableness, high extroversion), etc. Users can directly select these preset schemes or make fine adjustments based on them. The system supports saving and loading custom configuration schemes, and users can create multiple configuration templates to adapt to different project needs and development scenarios.
[0027] In S1, when structuring the code generation task description information, a deep learning-based natural language understanding model is used to perform semantic parsing of the input text. Named entity recognition technology is used to extract key technical terms, data structure types, and algorithm requirements involved in the task. Dependency parsing is used to identify the logical dependencies between functional requirements. An intent classification model is used to determine the overall complexity level and application domain category of the task. In the same process, natural language understanding technology based on pre-trained language models such as BERT and RoBERTa is used to perform deep semantic parsing of the input text. Named entity recognition technology extracts entity information such as key technical terms, data structure types, algorithm names, and API interfaces involved in the task description. These entities are classified and labeled, and relationships between technical concepts are established. Dependency parsing technology identifies the logical dependencies between functional requirements, including complex relationships such as sequential execution, conditional branching, loop iteration, and data flow dependencies, constructing a structured representation model of the task requirements. An intent classification model determines the overall complexity level of the task, classifying it into three levels—simple, medium, and complex—based on factors such as the level of detail in the requirement description, the complexity of the technical requirements, and the difficulty of implementation. It also identifies the application domain of the task, such as different technical fields like web development, data analysis, machine learning, and embedded systems, providing domain context information for subsequent personality trait parameter configuration.
[0028] After generating code from the large language model in S4, the system further performs static analysis and dynamic testing on the generated code. Static analysis includes code style checks, potential vulnerability scanning, and code complexity assessment. Dynamic testing involves executing the generated code in an isolated sandbox environment to verify its functional correctness and performance metrics. The test results serve as feedback signals for prompt word optimization, adjusting the prompt word template generation rules in step S3 to form a closed-loop optimization mechanism to continuously improve code generation quality. After code generation is complete, the system executes a comprehensive static analysis and dynamic testing verification process. During the static analysis phase, code style checks are performed using code quality tools such as ESLint, Pylint, and Checkstyle to ensure the code conforms to predetermined coding standards and best practices. Potential vulnerability scanning is performed using static analysis tools such as SonarQube and Coverity to detect potential security vulnerabilities, performance issues, and reliability risks in the code. Code complexity assessment uses metrics such as McCabe cyclomatic complexity and Halstead complexity metrics to quantitatively evaluate the structural complexity and maintainability of the code. During the dynamic testing phase, the generated code is executed in an isolated Docker container sandbox environment to verify its functional correctness and performance. The testing process includes multiple levels such as unit testing, integration testing, and performance testing to ensure the correctness and stability of the code under various operating scenarios. Test results generate detailed evaluation reports, including quantitative data from multiple dimensions such as pass rate, coverage, performance metrics, and security scores. This data serves as feedback signals for prompt word optimization, adjusting the prompt word template generation rules to form a closed-loop optimization mechanism for continuous improvement.
[0029] The overall working principle of this invention system is based on the well-established Big Five personality trait theory in psychology. It transforms the five core dimensions (openness, conscientiousness, extraversion, agreeableness, and neuroticism) into quantifiable and adjustable engineering parameters to dynamically shape and guide the code generation behavior of the large language model, ultimately outputting program code that meets specific style and quality requirements. Its workflow begins with deep semantic analysis of the code generation task. The system utilizes natural language processing technology to understand the user's functional goals, technical constraints, and application scenarios, and accordingly generates code for the Big Five language model. Five intelligently assigns initial weights to its five dimensions, forming a parameter vector that defines the personality profile generated by the code. Subsequently, a pre-trained multi-dimensional parameter mapping model within the system begins operation. This model uses machine learning algorithms to establish a complex non-linear mapping relationship between personality trait parameters and specific coding features (such as algorithm innovation, error handling completeness, annotation detail, code readability, and anomaly sensitivity), transforming abstract personality weights into a concrete, executable set of coding instructions. Next, the system combines these instruction sets with the original task requirements, automatically constructing a structured, personalized prompt template. This template not only clearly defines the functional requirements of the code but also guides the large language model to play a role from multiple levels, including role setting, mindset, and output specifications. A virtual developer with specific personality traits is assigned to the system. Upon receiving this reinforcement prompt, the large language model generates code, a process heavily influenced by the personalized settings in the prompt. This results in code that is highly controllable and predictable in terms of style, rigor, innovation, and documentation. Code generation is not the end point. The system then initiates a multi-layered automated evaluation and feedback loop. Through static analysis and dynamic testing, the quality, performance, and security of the generated code are quantitatively scored. This score is then used as a reinforcement learning signal to feed back to the personality trait parameter configuration module, which dynamically adjusts the weight configuration. Through iterative optimization, the entire system continuously improves itself, constantly approaching the optimal code generation strategy tailored to the specific task, thus achieving a leap from generating code to generating high-quality, style-controllable code.
[0030] It should be noted that, in this document, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the statement "comprising a…" does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0031] Although embodiments of the invention have been shown and described, it will be understood by those skilled in the art that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of the invention, the scope of which is defined by the appended claims and their equivalents.
Claims
1. A method for constructing prompt words for code generation based on the Big Five personality traits in a large language model, characterized in that, Includes the following steps: S1. Obtain the natural language description information of the code generation task to be processed, perform structured parsing of the description information through natural language processing technology, extract core requirement elements including functional requirements, constraints, programming language type and application scenario, and transform the core requirement elements into a formal requirement representation. S2. Based on the Big Five personality trait theory in psychology, a multi-dimensional personality trait parameter mapping model is constructed. The Big Five personality traits include five dimensions: openness, conscientiousness, extraversion, agreeableness, and neuroticism. By setting quantitative parameter weights for each personality dimension, a mapping relationship between personality trait parameters and code generation style characteristics is established. S3. Based on the personality trait parameter mapping model and the core requirement elements extracted in step S1, and combined with the preset prompt word generation rule library, automatically generate a structured prompt word template with the style of the target personality trait. The prompt word template includes personalized instruction content for code writing style, comment detail, error handling strategy and code readability requirements. S4. Combine and splice the prompt word template generated in step S3 with the original task description information to form a complete input prompt text. Then, input the input prompt text into the pre-trained large language model to drive the large language model to generate code output results of the corresponding style according to the personality traits contained in the prompt word template.
2. The method for constructing prompt words for a large language model based on Big Five personality traits according to claim 1, characterized in that, In S2, the openness dimension of the Big Five personality trait parameters is used to control the degree of algorithm innovation and technology selection diversity in code generation; the conscientiousness dimension is used to control the rigor of the code and the completeness of error handling; the extraversion dimension is used to control the level of detail in code comments and documentation; the agreeableness dimension is used to control the readability and collaborative friendliness of the code; and the neuroticism dimension is used to control the sensitivity of the code to abnormal situations and the setting of fault tolerance mechanisms.
3. The method for constructing prompt words for a large language model based on Big Five personality traits according to claim 2, characterized in that, The process of constructing a multi-dimensional personality trait parameter mapping model in S2 includes: collecting a large amount of code sample data labeled with personality traits, using machine learning algorithms to analyze the statistical characteristics of code written by programmers with different personality trait types, extracting multi-dimensional quantitative indicators such as code complexity, comment density, exception handling coverage, and function naming standardization through feature engineering, and establishing a non-linear mapping function between personality trait parameter vectors and code style feature vectors.
4. The method for constructing prompt words for a large language model based on Big Five personality traits according to claim 1, characterized in that, The prompt word template generated in S3 is organized in a hierarchical structure, including a system role definition layer, a personality trait description layer, a task goal description layer, and an output format constraint layer. The personality trait description layer explicitly indicates, in natural language form, the programmer personality type and its corresponding coding behavior characteristics that the large language model should simulate during code generation.
5. The method for constructing prompt words for a large language model based on Big Five personality traits according to claim 4, characterized in that, The generation of prompt word templates in S3 supports a mixed configuration mode of multiple personality trait parameters. This allows the system to automatically adjust the weight distribution ratio of the five dimensions of openness, conscientiousness, extraversion, agreeableness, and neuroticism according to the complexity of the specific code generation task, security requirements, and application domain characteristics, thereby achieving personalized prompt word customization for different application scenarios.
6. The method for constructing prompt words for a large language model based on Big Five personality traits according to claim 1, characterized in that, The large language model in S4 adopts a pre-trained model based on the Transformer architecture. This model is jointly pre-trained on a large-scale code corpus and a natural language corpus, and has the ability to understand natural language task descriptions and generate code in multiple programming languages, including but not limited to Python, Java, C++, JavaScript and Go.
7. The method for constructing prompt words for a large language model code generation based on Big Five personality traits according to any one of claims 1 to 6, characterized in that, Following S4, there is also a code quality assessment and feedback optimization step S5: the code output generated by the large language model is automatically evaluated in multiple dimensions. The evaluation dimensions include the code's syntactic correctness, logical integrity, running efficiency, security vulnerability risk, and maintainability indicators. The code quality score is calculated based on the evaluation results and fed back to the prompt word template generation module. The personality trait parameter weights are dynamically adjusted through a reinforcement learning mechanism to achieve continuous optimization and iteration of the prompt word template.
8. The method for constructing prompt words for a large language model based on Big Five personality traits according to claim 5, characterized in that, The prompt word template generation process in S3 supports an interactive parameter configuration interface, allowing developers or end users to manually adjust the parameter values of each dimension of the Big Five personality traits according to personal preferences or team coding standards, and preview sample code snippets generated under different personality trait configurations in real time, thereby achieving personalized customization of code generation style.
9. The method for constructing prompt words for a large language model based on Big Five personality traits according to claim 1, characterized in that, In S1, when the code generation task description information is processed in a structured manner, a natural language understanding model based on deep learning is used to perform semantic parsing on the input text. Key technical terms, data structure types and algorithm requirements involved in the task are extracted through named entity recognition technology. Logical dependencies between functional requirements are identified through dependency parsing analysis. The overall complexity level and application domain category of the task are determined through an intent classification model.
10. The method for constructing prompt words for a large language model based on Big Five personality traits according to claim 7, characterized in that, After the large language model generates code in S4, the system further performs static analysis and dynamic testing on the generated code. The static analysis includes code style checking, potential vulnerability scanning, and code complexity assessment. The dynamic testing includes executing the generated code in an isolated sandbox environment and verifying its functional correctness and performance indicators. The test results serve as feedback signals for prompt word optimization, which are used to adjust the prompt word template generation rules in step S3, forming a closed-loop optimization mechanism to continuously improve the quality of code generation.
Citation Information
Cited By
Backend computer program generation method and apparatus
CN122284967A