Question and answer method for code information and related equipment
By identifying and counting the sequence of repeated units of answer content in the code Q&A system, and sampling candidate content units according to the number of occurrences during the generation process, the serious problem of repeated content in the code field Q&A is solved, and the generation quality and resource utilization efficiency are improved.
Patent Information
- Application Number
- CN202411857379.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-17
- Publication Date
- 2025-03-11
- Estimated Expiration
- 2044-12-17
AI Technical Summary
In the prior art, in the knowledge Q&A method for the code field, the content in the answer is severely duplicated, resulting in poor user experience, model capabilities being questioned, and repeated outputs occupy inference resources, affecting the quality of generation.
By obtaining the code to process the problem and generating the answer content, we identify the sequence of duplicate content units in the generated answer, count the number of occurrences, and during the subsequent answer generation process, the candidate content units are sampled according to the number of sequence occurrences to reduce the generation of duplicate content.
It effectively reduces the appearance of duplicate content in answers, reduces the use of reasoning resources, and improves the quality of answer generation.
Smart Images

Figure CN119322832B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computers, and in particular to a question-and-answer method for code information and related equipment. The related equipment includes a question-and-answer device for code information, an electronic device, a storage medium, and a program product. Background Art
[0002] With the development of artificial intelligence technology, more and more artificial intelligence systems are widely used, and the automatic question-answering system is one of them. In specific implementation, the user inputs the question into the automatic question-answering system, and the automatic question-answering system then searches for relevant knowledge for the question, and then gives the user feedback on the corresponding content. For example, the user can enter a question about code processing in the automatic question-answering system, and the automatic question-answering system can output the relevant answer content for the code processing question.
[0003] Among the current related technologies, the knowledge question-and-answer methods for the code field have a serious problem of content duplication in the generated answers, which brings a poor user experience and makes users question the ability of the model. At the same time, repetition will cause the model to continuously produce meaningless outputs, which not only occupies reasoning resources but also affects the generation quality. Summary of the invention
[0004] An embodiment of the present application provides a question-and-answer method for code information and related equipment. The related equipment includes a question-and-answer device for code information, an electronic device, a storage medium, and a program product. When generating answers related to codes, the appearance of repeated content in the answers can be reduced, which is conducive to reducing the occupancy of reasoning resources and improving the quality of answer generation.
[0005] The present application embodiment provides a question-and-answer method for code information, including:
[0006] Obtain code processing problems; and generate answers to the code processing problems;
[0007] Obtaining the currently generated answer content for the code processing question, the generated answer content includes at least one content segment, and each content segment includes at least one content unit;
[0008] Based on the content unit sequence at the preset detection position in the generated answer content, at least one reference content unit sequence is determined; and the number of occurrences of each reference content unit sequence at the preset detection position in the generated answer content is counted, and the reference content unit sequence is used to perform repeated detection on the content at the preset detection position;
[0009] When the candidate content units belonging to the preset detection position are sampled during the answer generation process, the target content unit sequence composed of the candidate content units and the associated content units to be sampled is matched with the reference content unit sequences to determine the number of sequence occurrences corresponding to the target content unit sequence, and the associated content unit is the content unit associated with the position of the candidate content unit in the generated answer content;
[0010] According to the number of sequence occurrences, answer content is sampled from each candidate content unit to generate subsequent answer content for the code processing problem based on the sampling results.
[0011] The embodiment of the present application also provides a question-and-answer device for code information, including:
[0012] A question-and-answer unit is used to obtain code processing questions and generate answers to the code processing questions;
[0013] A content acquisition unit, used to acquire the generated answer content for the current code processing problem, the generated answer content includes at least one content segment, and each content segment includes at least one content unit;
[0014] A sequence determination unit, configured to determine at least one reference content unit sequence based on a content unit sequence at a preset detection position in the generated answer content; and to count the number of occurrences of each reference content unit sequence at a preset detection position in the generated answer content, wherein the reference content unit sequence is used to perform repeated detection on the content at the preset detection position;
[0015] A sampling and matching unit, which is used to match a target content unit sequence composed of each candidate content unit and associated content unit to be sampled with each reference content unit sequence when sampling a candidate content unit belonging to a preset detection position during the answer generation process, so as to determine the number of sequence occurrences corresponding to the target content unit sequence, wherein the associated content unit is a content unit associated with the position of the candidate content unit in the generated answer content;
[0016] The sampling determination unit is used to sample the answer content from each candidate content unit according to the number of sequence occurrences, so as to generate subsequent answer content for the code processing problem based on the sampling results.
[0017] In some embodiments, the sampling determination unit is used to:
[0018] Determine the sampling weight of each candidate content unit to be sampled according to the number of occurrences of the sequence;
[0019] The answer content is sampled from each candidate content unit according to the sampling weight.
[0020] In some embodiments, the sampling determination unit is used to:
[0021] Determine the repetition penalty coefficient of each candidate content unit to be sampled according to the number of occurrences of the sequence;
[0022] Based on the repetition penalty coefficient, the sampling weight of each candidate content unit to be sampled is determined.
[0023] In some embodiments, the sequence determination unit is used to:
[0024] When the preset detection position is the segment start position, for each content segment in the generated answer content, starting from the segment start position of the content segment, a content unit sequence of a preset length is cut off for the content segment to obtain at least one reference content unit sequence to be repeatedly detected at the segment start position;
[0025] When the preset detection position is the fragment end position, for each content fragment in the generated answer content, starting from the fragment end position of the content fragment, the content fragment is subjected to a content unit sequence of a preset length interception processing to obtain at least one reference content unit sequence to be repeatedly detected at the fragment end position.
[0026] In some embodiments, the sequence determination unit is used to:
[0027] Taking the preset interception position as the starting point, intercepting a preset number of content units of the generated answer content to obtain a sequence of content units at the preset detection position in the generated answer content;
[0028] Performing sequence division processing of a preset length on the content unit sequence to obtain a plurality of content unit subsequences of the preset length;
[0029] Performing content duplication detection processing on multiple content unit subsequences;
[0030] At least one reference content unit sequence is determined from the content unit subsequences according to the duplication detection result.
[0031] In some embodiments, the sequence determination unit is used to:
[0032] Determine at least one initial reference content unit sequence based on a content unit sequence at a preset detection position in the generated answer content;
[0033] Performing content detection of non-coded language on each initial reference content unit sequence;
[0034] When it is detected that the initial reference content unit sequence contains content in a non-coded language, the initial reference content unit sequence is determined as a reference content unit sequence.
[0035] In some embodiments, the apparatus further comprises a generating interrupt unit:
[0036] A generation interruption unit is used to interrupt the generation of subsequent answer content for the code processing problem when the number of sequence occurrences is greater than a preset number.
[0037] In some embodiments, after interrupting the generation of subsequent answer content for the code processing question when the number of sequence occurrences is greater than a preset number, the device further includes an interruption prompt unit, a question modification unit, and an answer generation unit:
[0038] An interruption prompt unit, used for acquiring information and generating an interruption prompt;
[0039] A problem modification unit, used for generating an interruption prompt based on the information, modifying the code processing problem, and obtaining a modified code processing problem;
[0040] The answer generation unit is used to process the question according to the modified code and generate new answer content.
[0041] In some embodiments, the sequence determination unit is used to:
[0042] Based on the preset length, multiple division scales are determined;
[0043] According to each division scale, the content unit sequence is subjected to sequence division processing to obtain a plurality of content unit subsequences at different division scales.
[0044] In some embodiments, the question-answering unit is used to:
[0045] Generate answers to code processing questions through the question-answering model;
[0046] Before generating the answer content for the code processing question through the question-answering model, the device also includes a model training unit for:
[0047] Obtain training data, the training data including sample code processing problems, and positive sample answer content and negative sample answer content of the sample code processing problems;
[0048] Through the question-answering model, the answer content is generated for the sample code processing question to obtain the predicted answer content;
[0049] According to the predicted answer content, as well as the positive sample answer content and the negative sample answer content of the sample code processing question, the parameters of the question-answering model are adjusted to obtain the trained question-answering model.
[0050] In some embodiments, the model training unit is used to:
[0051] Obtaining candidate answer content for the sample code processing question, the candidate answer content including at least one content segment, each content segment including at least one content unit;
[0052] Determine at least one sample reference content unit sequence based on the content unit sequence of the candidate answer content at the preset detection position; and count the number of occurrences of each sample reference content unit sequence at the preset detection position in the candidate answer content;
[0053] When the number of occurrences is greater than the preset value, the candidate answer content is used as the negative sample answer content for the sample code processing question;
[0054] The content unit sequence at the preset detection position in the negative sample answer content is modified to obtain the positive sample answer content.
[0055] An embodiment of the present application also provides an electronic device, including a processor and a memory, wherein the memory stores multiple instructions; the processor loads instructions from the memory to execute the steps in any one of the question-and-answer methods for code information provided in the embodiments of the present application.
[0056] An embodiment of the present application also provides a computer-readable storage medium, which stores multiple instructions, and the instructions are suitable for a processor to load to execute the steps of any one of the question-and-answer methods for code information provided in the embodiment of the present application.
[0057] An embodiment of the present application also provides a computer program product, including a computer program / instruction, which, when executed by a processor, implements the steps of any one of the question-and-answer methods for code information provided in the embodiments of the present application.
[0058] The embodiment of the present application can obtain a code processing problem; and generate answer content for the code processing problem; obtain the currently generated answer content for the code processing problem, the generated answer content includes at least one content segment, and each content segment includes at least one content unit; based on the content unit sequence at a preset detection position in the generated answer content, determine at least one reference content unit sequence; and count the number of occurrences of each reference content unit sequence at a preset detection position in the generated answer content, the reference content unit sequence is used to repeatedly detect the content at the preset detection position; when sampling candidate content units belonging to the preset detection position during the answer generation process, the target content unit sequence composed of each candidate content unit and the associated content unit to be sampled is matched with each reference content unit sequence to determine the number of sequence occurrences corresponding to the target content unit sequence, the associated content unit is a content unit associated with the position of the candidate content unit in the generated answer content; according to the number of sequence occurrences, the answer content is sampled from each candidate content unit to generate subsequent answer content for the code processing problem based on the sampling results.
[0059] In the present application, after solving the code processing problem and obtaining the generated answer content, the content unit sequence at the preset detection position can be determined from the content units of each content fragment of the generated answer content, and then at least one reference content unit sequence for repeated detection of the content at the preset detection position can be determined from the content unit sequence, and the number of occurrences of each reference content unit sequence at the preset detection position in the generated answer content is counted, so that the repetition of each reference content unit sequence at the preset detection position can be obtained. In the process of continuing to generate the answer content for the code processing problem, when it is necessary to sample the candidate content unit currently belonging to the preset detection position, the target content unit sequence composed of the candidate content unit and the associated content unit is matched with each reference content unit sequence, so that the number of occurrences of the reference content unit sequence matching the target content unit sequence can be obtained, and then the number of sequence occurrences corresponding to the target content unit sequence can be obtained, so that when generating subsequent answer content for the code processing problem, the candidate content units with lower sequence occurrences can be preferentially sampled. This method helps to reduce the occurrence of repeated content in the answer when generating code-related answers, which is beneficial to reducing the occupancy of reasoning resources and improving the quality of generated answers. BRIEF DESCRIPTION OF THE DRAWINGS
[0060] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0061] Figure 1a Schematic diagram of a scenario of a question-and-answer method for code information provided in an embodiment of the present application;
[0062] Figure 1b It is a flowchart of a question-and-answer method for code information provided in an embodiment of the present application;
[0063] Figure 2a It is a flowchart of applying the question-and-answer method for code information provided in an embodiment of the present application to a knowledge question-and-answer scenario in the code field;
[0064] Figure 2b It is a schematic diagram of generating the subsequent answer content provided by the embodiment of the present application;
[0065] Figure 2c It is a schematic diagram of a scenario of the optimized code provided in an embodiment of the present application;
[0066] Figure 2d It is a schematic diagram of a scenario for generating code provided in an embodiment of the present application;
[0067] Figure 2e It is a schematic diagram of a scenario for generating code-related answer content provided by an embodiment of the present application;
[0068] Figure 2f is a schematic diagram of a scene of a starting position of a segment provided in an embodiment of the present application;
[0069] Figure 2g is a schematic diagram of a scene of a segment end position provided in an embodiment of the present application;
[0070] Figure 2h is a schematic diagram of a scene of a preset interception position provided in an embodiment of the present application;
[0071] Figure 3 It is a structural diagram of a question-and-answer device for code information provided in an embodiment of the present application;
[0072] Figure 4 It is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0073] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of this application.
[0074] The embodiment of the present application provides a question-and-answer method for code information and related equipment, and the related equipment includes a question-and-answer device for code information, an electronic device, a storage medium, and a program product.
[0075] The question-and-answer device for code information can be integrated into an electronic device, which can be a terminal, a server, or other devices. The terminal can be a mobile phone, a tablet computer, a smart Bluetooth device, a laptop, or a personal computer (PC), etc. The server can be a single server or a server cluster composed of multiple servers.
[0076] In some embodiments, the question and answer device for code information can also be integrated into multiple electronic devices. For example, the question and answer device for code information can be integrated into multiple servers, and the question and answer method for code information of the present application can be implemented by multiple servers.
[0077] In some embodiments, the terminal may also be used as a server to implement part or all of the functions of the server.
[0078] In the embodiments of the present application, the term "module" or "unit" refers to a computer program or a part of a computer program that has a predetermined function and works together with other related parts to achieve a predetermined goal, and can be implemented in whole or in part by using software, hardware (such as processing circuits or memories), or a combination thereof. Similarly, a processor (or multiple processors or memories) can be used to implement one or more modules or units. In addition, each module or unit can be part of an overall module or unit that includes the function of the module or unit.
[0079] It is understandable that in the specific implementation of this application, data related to code processing issues, etc., when the embodiments of this application are applied to specific products or technologies, user permission or consent is required, and the collection, use and processing of relevant data need to comply with relevant laws, regulations and standards of relevant countries and regions.
[0080] For example, refer to Figure 1a, the electronic device can obtain a code processing problem; and generate answer content for the code processing problem; obtain the currently generated answer content for the code processing problem, the generated answer content includes at least one content segment, and each content segment includes at least one content unit; based on the content unit sequence at the preset detection position in the generated answer content, determine at least one reference content unit sequence; and count the number of occurrences of each reference content unit sequence at the preset detection position in the generated answer content, the reference content unit sequence is used to repeatedly detect the content at the preset detection position; when sampling the candidate content units belonging to the preset detection position during the answer generation process, the target content unit sequence composed of the candidate content units and the associated content units to be sampled is matched with each reference content unit sequence to determine the number of sequence occurrences corresponding to the target content unit sequence, the associated content unit is the content unit associated with the position of the candidate content unit in the generated answer content; according to the number of sequence occurrences, the answer content is sampled from each candidate content unit to generate subsequent answer content for the code processing problem based on the sampling result.
[0081] After solving the code processing problem and obtaining the generated answer content, the present application can first determine the content unit sequence at the preset detection position from the content units of each content fragment of the generated answer content, and then determine at least one reference content unit sequence for repeated detection of the content at the preset detection position from the content unit sequence, and count the number of occurrences of each reference content unit sequence at the preset detection position in the generated answer content, so as to obtain the repetition of each reference content unit sequence at the preset detection position. In the process of continuing to generate the answer content for the code processing problem, when it is necessary to sample the candidate content unit currently belonging to the preset detection position, by matching the target content unit sequence composed of the candidate content unit and the associated content unit with each reference content unit sequence, the number of occurrences of the reference content unit sequence matching the target content unit sequence can be obtained, and then the number of sequence occurrences corresponding to the target content unit sequence can be obtained, so as to give priority to sampling the candidate content units with a lower number of sequence occurrences when generating subsequent answer content for the code processing problem. This method helps to reduce the occurrence of repeated content in the answer when generating code-related answers, which is beneficial to reducing the occupancy of reasoning resources and improving the quality of generated answers.
[0082] It should be noted that the serial numbers of the following embodiments are not intended to limit the preferred order of the embodiments.
[0083] In this embodiment, a question-answering method for code information is provided, such as Figure 1b As shown, the specific process of the question-answering method for code information can be as follows:
[0084] The code information refers to various contents related to the program code. For example, the code information may include at least one of the code itself, code description information, questions about the code, etc. 101. Obtain a code processing problem; and generate an answer content for the code processing problem.
[0085] Among them, code processing questions refer to questions raised in order to obtain knowledge related to the code. For example, code processing questions can be questions raised for optimizing the code, questions raised for generating specific functional codes, questions raised for understanding the code, and so on.
[0086] The answer content is the response generated for the code processing question. For example, when the code processing question is a question about optimizing the code, the answer content may include the optimized code and a detailed explanation of the optimization process, etc. When the code processing question is a question about generating a specific function code, the answer content may include the code to implement the function, with an explanation of the code execution logic. When the code processing question is a question about understanding the code, the answer content may include the various instructions in the code and their functions, etc.
[0087] In some embodiments, the user terminal may generate an answer to the code processing question based on the code processing question input by the user.
[0088] In some embodiments, the server may obtain a code processing problem sent by a user terminal, generate an answer content for the code processing problem, and transmit the generated answer content to the user terminal in real time.
[0089] In some embodiments, in order to enable the question-answering model to answer questions related to code, and to make the answers generated by the question-answering model more inclined to the style of the positive sample answer content, while reducing the generation of the negative sample answer content style, the answer content is generated for the code processing question, including:
[0090] Generate answers to code processing questions through the question-answering model;
[0091] Before generating answers to code processing questions through the question-answering model, it also includes:
[0092] Obtain training data, the training data including sample code processing problems, and positive sample answer content and negative sample answer content of the sample code processing problems;
[0093] Through the question-answering model, the answer content is generated for the sample code processing question to obtain the predicted answer content;
[0094] According to the predicted answer content, as well as the positive sample answer content and the negative sample answer content of the sample code processing question, the parameters of the question-answering model are adjusted to obtain the trained question-answering model.
[0095] Among them, the question-answering model is a model that automatically generates corresponding answers by analyzing the input natural language questions. For example, the question-answering model can be a large language model (LLM), a question-answering model based on knowledge graphs, a question-answering model based on deep learning, and so on.
[0096] Training data is the corpus used to train the question-answering model. Through this training data, the question-answering model can learn how to understand the input natural language questions and generate corresponding answers.
[0097] Sample code processing questions are code processing questions used to train question answering models. For example, sample code processing questions can enable question answering models to understand questions asked to optimize code, questions asked to generate code for specific functions, questions asked to understand code, and so on.
[0098] The positive sample answer content refers to the correct answer content that the question-answering model is expected to generate for sample code processing questions when training the question-answering model.
[0099] Negative sample answer content refers to the incorrect answer content generated by the question-answering model for sample code processing questions when training the question-answering model.
[0100] The predicted answer content refers to the prediction result obtained by the question-answering model after reasoning based on the sample code to process the question.
[0101] The parameters of the question-answering model can control the question-answering model to understand the natural semantics of the input questions and generate appropriate answers.
[0102] A trained question-answering model is one that learns from training data and adjusts the parameters of the question-answering model so that it can accurately understand input questions and generate correct answers.
[0103] In some embodiments, in order to make the answers generated by the question-answering model more inclined to the style of the positive sample answer content and reduce the generation of the negative sample answer content style, the parameters of the question-answering model are adjusted according to the predicted answer content and the positive sample answer content and the negative sample answer content of the sample code processing question to obtain the trained question-answering model, including:
[0104] Determine the positive loss information based on the predicted answer content and the positive sample answer content;
[0105] Determine reverse loss information based on the predicted answer content and the negative sample answer content;
[0106] According to the forward loss information and the reverse loss information, the parameters of the question-answering model are adjusted to obtain the trained question-answering model.
[0107] Among them, the positive loss information refers to the difference between the predicted answer content of the question-answering model and the positive sample answer content. It is used to measure the ability of the question-answering model to generate accurate answers. It is usually used to guide the training of the question-answering model so that it can output the correct answer more accurately.
[0108] The reverse loss information refers to the difference between the predicted answer content of the question-answering model and the negative sample answer content, which is used to guide the question-answering model to avoid generating wrong answers, so that the question-answering model can more accurately exclude incorrect answers.
[0109] In some embodiments, in order to obtain positive sample answer content and negative sample answer content of the sample code processing question, obtaining training data includes:
[0110] Obtaining candidate answer content for the sample code processing question, the candidate answer content including at least one content segment, each content segment including at least one content unit;
[0111] Determine at least one sample reference content unit sequence based on the content unit sequence of the candidate answer content at the preset detection position; and count the number of occurrences of each sample reference content unit sequence at the preset detection position in the candidate answer content;
[0112] When the number of occurrences is greater than the preset value, the candidate answer content is used as the negative sample answer content for the sample code processing question;
[0113] The content unit sequence at the preset detection position in the negative sample answer content is modified to obtain the positive sample answer content.
[0114] The candidate answer content is the answer content provided for the sample code processing question. For example, the candidate answer content can be the answer content generated by the question-answering model based on the sample code processing question, or it can be the answer content provided manually for the sample code processing question, and so on.
[0115] The content segments in the candidate answer content are segments obtained by splitting the candidate answer content according to the content arrangement structure, wherein the content arrangement structure may determine the arrangement of the content units constituting the candidate answer content.
[0116] For example, when the content arrangement structure is a row arrangement structure, the candidate answer content can be split according to the row arrangement structure to obtain multiple row content fragments. When the content arrangement structure is a paragraph arrangement structure, the candidate answer content can be split according to the paragraph arrangement structure to obtain multiple paragraph content fragments. When the content arrangement structure is a sentence arrangement structure, the candidate answer content can be split according to the sentence arrangement structure to obtain multiple sentence content fragments, and so on.
[0117] The content units in the content segments of the candidate answer content are basic semantic units constituting the content segments in the candidate answer content. For example, the content units in the content segments of the candidate answer content can be characters, words with complete semantics, code elements, etc.
[0118] The preset detection position is a pre-set position where content duplication detection is required. For example, the preset detection position can be obtained by locating the segment start position, the segment end position, the preset interception position, etc. The preset detection position can be the position of the first n content units of the content segment through the segment start position, the position of the last x content units of the content segment through the segment end position, or the position of the last i content units in the answer content starting from the preset interception position through the preset interception position.
[0119] The content unit sequence of the candidate answer content at the preset detection position is a sequence obtained by dividing the content of the candidate answer content at the preset detection position into content units.
[0120] The sample reference content unit sequence is a content unit sequence that needs to be repeatedly detected in the content unit sequence of the candidate answer content at the preset detection position. For example, the sample reference content unit sequence can be any content unit sequence of the candidate answer content at the preset detection position, or a content unit sequence of the candidate answer content containing non-coded language content at the preset detection position, etc.
[0121] The number of occurrences refers to the frequency of the same sample reference content unit sequence obtained when counting the sample reference content unit sequences at the same preset detection position.
[0122] For example, when the preset detection position is obtained by locating the segment start position, the segment end position or the preset interception position, first determine the content unit sequence of each content segment in the candidate answer content at the preset detection position, and then determine at least one sample reference content unit sequence from the content unit sequence of each content segment at the preset detection position.
[0123] The preset value is used to measure the frequency of occurrence of each sample reference content unit sequence at the preset detection position. For different preset detection positions, different preset values can be used to evaluate the number of occurrences of each sample reference content unit sequence at the preset detection position.
[0124] 102. Obtain the generated answer content for the current code processing problem, where the generated answer content includes at least one content segment, and each content segment includes at least one content unit.
[0125] The generated answer content is the answer content currently obtained for the code processing problem. For example, the generated answer content may be a partial answer that has not been completely generated so far, or it may be a final answer that has been completely generated.
[0126] The content segments in the generated answer content are segments obtained by splitting the generated answer content according to the content arrangement structure. For example, the content segments in the generated answer content can be segments obtained by splitting the generated answer content according to a certain unit such as line, paragraph, sentence, etc.
[0127] The content unit in the content segment of the generated answer content is the basic semantic unit constituting the content segment in the generated answer content. For example, the content unit in the content segment of the generated answer content can be a character, a word with complete semantics, a code element, etc.
[0128] 103. Based on the content unit sequence at the preset detection position in the generated answer content, determine at least one reference content unit sequence; and count the number of occurrences of each reference content unit sequence at the preset detection position in the generated answer content, the reference content unit sequence is used to repeatedly detect the content at the preset detection position.
[0129] The content unit sequence at the preset detection position in the generated answer content is a content unit sequence constituted by the content units at the preset detection position in the generated answer content.
[0130] The reference content unit sequence is a content unit sequence that needs to be repeatedly detected in the content unit sequence of the generated answer content at the preset detection position. For example, the reference content unit sequence can be any content unit sequence of the generated answer content at the preset detection position, or a content unit sequence of the generated answer content containing non-coded language content at the preset detection position, etc.
[0131] In some embodiments, in order to obtain at least one reference content unit sequence to be repeatedly detected at the beginning position and the end position of each content segment in the generated answer content, based on the content unit sequence at the preset detection position in the generated answer content, determining at least one reference content unit sequence to be repeatedly detected at the preset detection position includes:
[0132] When the preset detection position is the segment start position, for each content segment in the generated answer content, starting from the segment start position of the content segment, a content unit sequence of a preset length is cut off for the content segment to obtain at least one reference content unit sequence to be repeatedly detected at the segment start position;
[0133] When the preset detection position is the fragment end position, for each content fragment in the generated answer content, starting from the fragment end position of the content fragment, the content fragment is subjected to a content unit sequence of a preset length interception processing to obtain at least one reference content unit sequence to be repeatedly detected at the fragment end position.
[0134] The segment start position is used to indicate the first n content units of the content segment. For example, the segment start position can be determined by counting n content units backward from the line head, or by counting n content units backward from the paragraph head, or by counting n content units backward from the sentence head, etc.
[0135] The preset length is a preset sequence length, which is used to divide the content at the preset detection position in the content segment according to the preset length, so as to obtain a content unit sequence of the content segment that meets the preset length at the preset detection position.
[0136] For example, the preset length may include one sequence length, and may also include multiple sequence lengths. When the sequence length is set to b, the generated content unit sequence will include b content units. When the sequence length is set to b to d, it is necessary to perform interception processing of the content unit sequences of the three sequence lengths, b, c and d, from the content unit sequence at the start position of the content segment, respectively, so as to obtain the content unit sequences under each sequence length: including a content unit sequence of length b, a content unit sequence of length c and a content unit sequence of length d.
[0137] The reference content unit sequence to be detected for duplication at the start position of the segment refers to a content unit sequence that needs to be detected for duplication in the content unit sequence at the start position of each content segment in each content segment of the generated answer content.
[0138] The end position of a segment is used to indicate the last x content units of the content segment. For example, the end position of a segment can be determined by counting n content units forward from the end of a line, by counting n content units forward from the end of a paragraph, by counting n content units forward from the end of a sentence, and so on.
[0139] The at least one reference content unit sequence to be repeatedly detected at the end position of the segment refers to a content unit sequence that needs to be repeatedly detected in the content unit sequence at the end position of each content segment in each content segment of the generated answer content.
[0140] For example, when the generated answer content includes multiple content fragments, for each content fragment, a content unit sequence of the content fragment at a preset detection position can be obtained, and then at least one content unit sequence of a preset length can be cut out from the content unit sequence. Each content unit sequence of the preset length can be used as a reference content unit sequence, or a content unit sequence containing non-coded language can be selected from the content unit sequence of the preset length as a reference content unit sequence, or a content unit sequence of a preset length that appears repeatedly, and so on.
[0141] In some embodiments, in order to perform duplicate detection on only a portion of content units in the generated answer, determining at least one reference content unit sequence based on a content unit sequence at a preset detection position in the generated answer content includes:
[0142] Taking the preset interception position as the starting point, intercepting a preset number of content units of the generated answer content to obtain a sequence of content units at the preset detection position in the generated answer content;
[0143] Performing sequence division processing of a preset length on the content unit sequence to obtain a plurality of content unit subsequences of the preset length;
[0144] Performing content duplication detection processing on multiple content unit subsequences;
[0145] At least one reference content unit sequence is determined from the content unit subsequences according to the duplication detection result.
[0146] The preset interception position is pre-set and used to locate the position where content duplication detection is required. For example, the preset interception position can be the position of the last character of the generated answer content, the beginning of the last line of the generated answer content, the beginning of the last paragraph of the generated answer content, the first character of the generated answer content, and so on.
[0147] The starting point is used to identify the starting position in the generated answer content where content duplication detection is required.
[0148] The preset number is the number of content units that need to be detected for content duplication, which are intercepted from the generated answer content starting from the preset interception position. The preset number is not limited here.
[0149] The content unit subsequence refers to a continuous subsequence with a predetermined length obtained by dividing the content unit sequence.
[0150] For example, when the content unit sequence includes "ABCDE" and the preset length is equal to 2 content units, the content unit sequence is divided into 2 content units to obtain multiple content unit subsequences under the preset length including: "AB", "BC", "CD", and "DE".
[0151] The repetition detection result can reflect the degree of repetition of each content unit subsequence. When a reference content unit sequence is determined from a content unit subsequence based on the repetition detection result, the reference content unit sequence can be a content unit subsequence where repetitions occur, or can be all content unit subsequences within a preset length, and so on.
[0152] For example, when the content unit sequence is "avoid statistics subfolders, avoid statistics subfolders files", the preset length is 3 content units, then multiple content unit subsequences may include "avoid, statistics, subfolder", "statistics, subfolder, avoid", "subfolder, avoid, statistics", "avoid, statistics, subfolder", "statistics, subfolder, in", "subfolder, in, files", and in the repeated detection results, "avoid, statistics, subfolder" appears twice, "statistics, subfolder, avoid", "subfolder, avoid, statistics", "statistics, subfolder, in", and "subfolder, in, files" appear once each. The reference content unit sequence can be only "avoid, statistics, subfolder", or it can be "avoid, statistics, subfolder", "statistics, subfolder, avoid", "subfolder, avoid, statistics", "avoid, statistics, subfolder", "statistics, subfolder, in", and "subfolder, in, files".
[0153] In some embodiments, in order to divide the content unit sequence into different scales so as to extract the required subsequences from the sequences of different scales, the content unit sequence is divided into sequences of preset lengths to obtain multiple content unit subsequences of preset lengths, including:
[0154] Based on the preset length, multiple division scales are determined;
[0155] According to each division scale, the content unit sequence is subjected to sequence division processing to obtain a plurality of content unit subsequences at different division scales.
[0156] The division scale is a scale determined from a length range corresponding to a preset length, and the division scale is within the preset length range. For example, when the preset length is 2-5, the division scale is 5, 4, 3, 2.
[0157] In some embodiments, in order to perform repetition detection only on reference content unit sequences in non-coded languages, determining at least one reference content unit sequence based on a content unit sequence at a preset detection position in the generated answer content includes:
[0158] Determine at least one initial reference content unit sequence based on a content unit sequence at a preset detection position in the generated answer content;
[0159] Performing content detection of non-coded language on each initial reference content unit sequence;
[0160] When it is detected that the initial reference content unit sequence contains content in a non-coded language, the initial reference content unit sequence is determined as a reference content unit sequence.
[0161] The initial reference content unit sequence is a subsequence in the content unit sequence at a preset detection position.
[0162] Non-coding languages refer to languages that are not used to write program codes. For example, the language used to write program codes is usually English, and non-coding languages are languages other than English, such as Chinese and other foreign languages.
[0163] In some embodiments, the sequence of reference content units contains only content in a non-encoded language.
[0164] In some embodiments, the sequence of reference content units includes content in a coded language in addition to content in a non-coded language.
[0165] For example, the content units in the reference content unit sequence may specifically be (non-coded language, coded language), (coded language, non-coded language), (non-coded language, coded language, non-coded language), (coded language, non-coded language, coded language), and so on.
[0166] 104. During the answer generation process, when the candidate content units belonging to the preset detection position are sampled, the target content unit sequence composed of the candidate content units and the associated content units to be sampled is matched with the reference content unit sequences to determine the number of sequence occurrences corresponding to the target content unit sequence. The associated content units are content units associated with the positions of the candidate content units in the generated answer content.
[0167] Among them, candidate content units are content units that may be sampled and included in the answer in the process of continuing to generate answers to code processing questions.
[0168] Related content units refer to other content units that are positionally related to the candidate content unit when generating an answer to a code processing question. For example, the related content unit can be a content unit adjacent to the candidate content unit in the generated answer content, or a content unit that has not yet been included in the answer and may be sampled before the candidate content unit, etc.
[0169] The target content unit sequence is a content unit sequence consisting of candidate content units and associated content units.
[0170] The number of sequence occurrences refers to the total number of occurrences of the target content unit sequence combined with the number of occurrences of the reference content unit sequence that matches the target content unit sequence. For example, when the target content unit sequence matches the reference content unit sequence, the number of sequence occurrences is the number of occurrences of the reference content unit sequence plus 1. When the target content unit sequence does not match the reference content unit sequence, the number of sequence occurrences is equal to 1.
[0171] 105. Sample the answer content from each candidate content unit according to the number of sequence occurrences, so as to generate subsequent answer content for the code processing problem based on the sampling results.
[0172] The sampling result may indicate the candidate content units that need to be sampled and included in the answer content, and the candidate content units in the sampling result must appear repeatedly in the generated answer content for a number of times that certain conditions are met. These conditions may include that the number of repetitions of the content unit must not exceed a preset number of times, so as to avoid excessive repetition or illogical redundancy in the generated answer content.
[0173] Subsequent answer content refers to the answer content that is generated immediately after the generated answer content when solving a code processing problem.
[0174] In some embodiments, in order to preferentially sample candidate content units with a lower number of sequence appearances, sampling of answer content from each candidate content unit according to the number of sequence appearances includes:
[0175] Determine the sampling weight of each candidate content unit to be sampled according to the number of occurrences of the sequence;
[0176] The answer content is sampled from each candidate content unit according to the sampling weight.
[0177] The sampling weight reflects the probability of a candidate content unit being selected during sampling, and the sampling weight is negatively correlated with the number of sequence occurrences. For example, the higher the number of sequence occurrences, the lower the sampling weight of the corresponding candidate content unit. Conversely, the lower the number of sequence occurrences, the higher the sampling weight of the corresponding candidate content unit.
[0178] In some embodiments, in order to strengthen the penalty on the relevant candidate content units as the number of sequence appearances increases, so as to reduce the reappearance of the candidate content units in the subsequent answer content, the sampling weight of each candidate content unit to be sampled is determined according to the number of sequence appearances, including:
[0179] Determine the repetition penalty coefficient of each candidate content unit to be sampled according to the number of occurrences of the sequence;
[0180] Based on the repetition penalty coefficient, the sampling weight of each candidate content unit to be sampled is determined.
[0181] Among them, the repetition penalty coefficient is used to control the parameters of the generated content diversity. Its purpose is to reduce the probability of content units that have appeared multiple times being selected in the subsequent generation process, thereby avoiding the generation of duplicate content. Specifically, the repetition penalty coefficient is related to the number of occurrences of the sequence corresponding to the candidate content unit: the more times the sequence appears, the greater the repetition penalty coefficient, and vice versa, when the number of occurrences is small, the repetition penalty coefficient is low. When the number of occurrences of the sequence corresponding to the candidate content unit is 1, the repetition penalty coefficient of the candidate content unit is zero, indicating that no penalty is imposed.
[0182] In some embodiments, in order to prevent invalid answers from being continuously generated, the following steps are also included:
[0183] When the sequence occurs more than a preset number of times, the generation of subsequent answer content for the code processing question is interrupted.
[0184] The preset number of times refers to the number of times set in advance to measure the frequency of repeated occurrence of the content unit sequence. When the number of occurrences of the content unit sequence reaches this limit, the content unit sequence is restricted from further occurrence to avoid excessive repetition and enhance the diversity of generated content.
[0185] In some embodiments, in order to ensure the generation of a better quality answer by adjusting the code processing question after an invalid answer is generated, after interrupting the generation of subsequent answer content for the code processing question when the number of sequence occurrences is greater than a preset number, the method further includes:
[0186] Get information to generate interrupt prompt;
[0187] Generate an interrupt prompt based on the information, modify the code processing problem, and obtain a modified code processing problem;
[0188] Process the question based on the modified code and generate new answer content.
[0189] The information generation interruption prompt is a notification message issued after the generation of the subsequent answer content for the code processing question is interrupted. It is usually used to inform that the generation process has been paused or terminated, and indicates possible problems or adjustments that need to be made.
[0190] For example, the information generation interruption prompt can not only indicate that the generation of subsequent answer content is interrupted, but may also prompt the need to optimize code processing, etc.
[0191] The modified code processing problem refers to a new problem obtained by modifying the code processing problem according to the problem reflected by the information generation interrupt prompt.
[0192] The new answer content is the answer content generated for the modified code processing problem.
[0193] As can be seen from the above, the embodiments of the present application can obtain code processing problems; and generate answer content for the code processing problems; obtain the currently generated answer content for the code processing problems, the generated answer content includes at least one content segment, and each content segment includes at least one content unit; based on the content unit sequence at the preset detection position in the generated answer content, determine at least one reference content unit sequence; and count the number of occurrences of each reference content unit sequence at the preset detection position in the generated answer content, the reference content unit sequence is used to repeatedly detect the content at the preset detection position; when the candidate content units belonging to the preset detection position are sampled during the answer generation process, the target content unit sequence composed of the candidate content units and the associated content units to be sampled is matched with each reference content unit sequence to determine the number of sequence occurrences corresponding to the target content unit sequence, the associated content unit is the content unit associated with the position of the candidate content unit in the generated answer content; according to the number of sequence occurrences, the answer content is sampled from each candidate content unit to generate subsequent answer content for the code processing problem based on the sampling results.
[0194] Therefore, after solving the code processing problem and obtaining the generated answer content, this solution can first determine the content unit sequence at the preset detection position from the content units of each content fragment of the generated answer content, and then determine at least one reference content unit sequence for repeated detection of the content at the preset detection position from the content unit sequence, and count the number of occurrences of each reference content unit sequence at the preset detection position in the generated answer content, so as to obtain the repetition of each reference content unit sequence at the preset detection position. In the process of continuing to generate the answer content for the code processing problem, when it is necessary to sample the candidate content unit currently belonging to the preset detection position, by matching the target content unit sequence composed of the candidate content unit and the associated content unit with each reference content unit sequence, the number of occurrences of the reference content unit sequence matching the target content unit sequence can be obtained, and then the number of sequence occurrences corresponding to the target content unit sequence can be obtained, so that when generating the subsequent answer content for the code processing problem, the candidate content units with lower sequence occurrences can be sampled preferentially. This method helps to reduce the occurrence of repeated content in the answer when generating code-related answers, thereby helping to reduce the occupation of reasoning resources and improve the quality of generated answers.
[0195] The method described in the above embodiment will be further described in detail below.
[0196] In this embodiment, the method of the embodiment of the present application will be described in detail by taking knowledge questions and answers in the field of code as an example.
[0197] like Figure 2a As shown, a question-and-answer method for code information has the following specific process:
[0198] 201. Obtain a code processing problem; and generate an answer content for the code processing problem.
[0199] In some embodiments, generating an answer to a code processing question includes:
[0200] Generate answers to code processing questions through the question-answering model;
[0201] Before generating answers to code processing questions through the question-answering model, it also includes:
[0202] Obtain training data, the training data including sample code processing problems, and positive sample answer content and negative sample answer content of the sample code processing problems;
[0203] Through the question-answering model, the answer content is generated for the sample code processing question to obtain the predicted answer content;
[0204] According to the predicted answer content, as well as the positive sample answer content and the negative sample answer content of the sample code processing question, the parameters of the question-answering model are adjusted to obtain the trained question-answering model.
[0205] In some embodiments, in order to enable the question-answering model to effectively process code-related questions and generate corresponding answers, before obtaining training data, the following steps are also included:
[0206] like Figure 2b As shown in the figure, the initial training data (Supervised Fine-Tuning Data, SFT data) is manually generated and automatically synthesized by the model and annotated. The manual model will basically have no problems because it is manually checked. However, the training data automatically synthesized by the model may cause repeated problems to the question-answering model during the initial training process, resulting in a question-answering model to be optimized. Through repeated detection, the problem training data can be directly detected and the problem training data can be eliminated, or the sample code processing problems in the problem training data can be retained, and the data synthesis sampling can be re-performed to obtain the sample answer content that meets the repetitive requirements corresponding to the sample code processing problems. Using the training data, the question-answering model is directly trained for preference optimization, wherein the sample answer content corresponding to the sample code processing problems in the training data includes positive sample answer content and negative sample answer content.
[0207] In some embodiments, obtaining training data includes:
[0208] Obtaining candidate answer content for the sample code processing question, the candidate answer content including at least one content segment, each content segment including at least one content unit;
[0209] Determine at least one sample reference content unit sequence based on the content unit sequence of the candidate answer content at the preset detection position; and count the number of occurrences of each sample reference content unit sequence at the preset detection position in the candidate answer content;
[0210] When the number of occurrences is greater than the preset value, the candidate answer content is used as the negative sample answer content for the sample code processing question;
[0211] The content unit sequence at the preset detection position in the negative sample answer content is modified to obtain the positive sample answer content.
[0212] In some embodiments, the problem training data detected in the SFT phase is used to construct the sample code processing problem in the problem training data, and the normal answer is regenerated to obtain the positive and negative sample answer content pairs. It is also possible to process the problem based on random sampling code, by performing a large number of generation sampling on the unoptimized question-answering model, and repeatedly detecting and mining the results to construct the positive and negative sample answer content pairs.
[0213] In some embodiments, in order to increase the possibility of generating the content style of the positive sample answer and reduce the possibility of generating the content style of the negative sample answer when the question answering model is generated, the parameters of the question answering model are adjusted according to the predicted answer content and the positive sample answer content and the negative sample answer content of the sample code processing question to obtain the trained question answering model, including:
[0214] Determine the positive loss information based on the predicted answer content and the positive sample answer content;
[0215] Determine reverse loss information based on the predicted answer content and the negative sample answer content;
[0216] According to the forward loss information and the reverse loss information, the parameters of the question-answering model are adjusted to obtain the trained question-answering model.
[0217] Loss Information ,in, is the positive sample answer content, is the negative sample answer content, positive loss information: , reverse loss information: .
[0218] 202. Obtain the generated answer content for the current code processing problem, where the generated answer content includes at least one content segment, and each content segment includes at least one content unit.
[0219] like Figure 2c As shown, the answer content can be generated for the code processing problem raised by the optimized code to obtain the generated answer content. Figure 2d As shown, the answer content can be generated for the code processing problem raised by generating a specific function code, and the generated answer content can be obtained. The generated answer content can be a partial answer that has not been fully generated so far, or it can be a final answer that has been fully generated. Figure 2e As shown, taking the code processing question as "Hello, can you help me write a shell script to count the number of files in the current folder?", the specific content of the generated answer content for the code processing question may include code and content related to the description of the code, and the content related to the description of the code is content in non-coding language.
[0220] 203. Based on the content unit sequence at the starting position of the fragment in the generated answer content and the non-coded language, determine at least one reference content unit sequence to be repeatedly detected at the starting position of the fragment, the reference content unit sequence includes the content of the non-coded language; and count the number of occurrences of each reference content unit sequence at the starting position of the fragment in the generated answer content.
[0221] The execution code of step 203 may be:
[0222] def consecutive_startline_ngram_detect(text, n, patience=0):
[0223] Determine whether the generated answer content has a content unit sequence at the beginning of the segment that is repeated more than a preset number of times (patience).
[0224] text: Enter the generated answer content.
[0225] n: preset length, which is the maximum detected sequence length.
[0226] patience: The preset number of times, which is the maximum number of repetitions detected.
[0227] return: If duplicates are detected, the return is correct (True); if not, the return is misplaced (False).
[0228] lines = [line.strip() for line in text.split(“n”)]
[0229] if len(lines) <patience:
[0230] return False
[0231] else:
[0232] last_line = lines[-1]
[0233] if len(last_line) <n:
[0234] return False
[0235] start_ngram = last_line[:n]
[0236] if not is_contain_chinese(start_ngram):
[0237] return False
[0238] count = 1
[0239] for line in lines[:-1][::-1]:
[0240] if line.startswith(start_ngram):
[0241] count += 1
[0242] else:
[0243] break
[0244] if count == patience:
[0245] return True
[0246] return False.
[0247] A counter that counts the number of occurrences of each reference content unit sequence at the beginning of the fragment in the generated answer content:
[0248] , s i starts with changeline "n", where It includes the content unit sequence at the starting position of the segment in the generated answer content and at each division scale in the preset length. Starts is the starting position of the segment. are multiple content unit subsequences at different division scales, m is the total number of content segments, s i starts with changeline "n" for each content fragment s i Start with a newline character ("n").
[0249] like Figure 2f As shown, a content unit sequence of each content segment in the generated answer content at the starting position of the segment can be obtained.
[0250] 204. Based on the content unit sequence at the end position of the fragment in the generated answer content and the non-coded language, determine at least one reference content unit sequence to be repeatedly detected at the end position of the fragment, where the reference content unit sequence includes content in the non-coded language; and count the number of occurrences of each reference content unit sequence at the end position of the fragment in the generated answer content.
[0251] The execution code of step 204 may be:
[0252] ef consecutive_endline_ngram_detect(text, n, patience=0):
[0253] Determine whether the content unit sequence at the end of the segment in the current generated text is repeated more than patience times.
[0254] text: Enter the generated answer content.
[0255] n: preset length, which is the maximum detected sequence length.
[0256] patience: The preset number of times, which is the maximum number of repetitions detected.
[0257] return: Return True if duplicates are detected, False if not detected
[0258] lines = [line.strip() for line in text.split(“n”) if line.strip()]
[0259] if len(lines) <patience:
[0260] return False
[0261] else:
[0262] last_line = lines[-1]
[0263] if len(last_line) <n:
[0264] return False
[0265] end_ngram = last_line[-n:]
[0266] if not is_contain_chinese(end_ngram):
[0267] return False
[0268] count = 1
[0269] for line in lines[:-1][::-1]:
[0270] if line.endswith(end_ngram):
[0271] count += 1
[0272] else:
[0273] break
[0274] if count == patience:
[0275] return True.
[0276] like Figure 2g As shown, a content unit sequence of each content segment in the generated answer content at the segment end position can be obtained.
[0277] 205. Taking a preset clipping position as a starting point, clip a preset number of content units of the generated answer content to obtain a content unit sequence at the preset clipping position in the generated answer content; and based on a non-coded language, determine at least one reference content unit sequence to be repeatedly detected from the content unit sequence at the preset clipping position, the reference content unit sequence including content in the non-coded language; and count the number of occurrences of each reference content unit sequence at the preset clipping position in the generated answer content.
[0278] The execution code of step 205 may be:
[0279] def consecutive_ngram_detect(text, n, patience=0):
[0280] Determine whether the generated answer content has a repeated sequence of content units at a preset interception position and exceeds a preset number of patience.
[0281] n: preset length, which is the maximum detected sequence length.
[0282] patience: The preset number of times, which is the maximum number of repetitions detected.
[0283] return: detected duplicate return is correct (True), no return misalignment is detected (False)
[0284] if len(text) <n·patience:
[0285] continue
[0286] else:
[0287] ngram = text[-i:]
[0288] if not is_contain_chinese(ngram):
[0289] return False
[0290] if text[-i·patience:].count(ngram) == patience:
[0291] return True
[0292] return False.
[0293] like Figure 2h As shown, a content unit sequence at a preset interception position in the generated answer content can be obtained.
[0294] 206. When the candidate content units belonging to the preset detection position are sampled during the answer generation process, the target content unit sequence composed of the candidate content units and the associated content units to be sampled is matched with the reference content unit sequences at the preset detection position to determine the number of sequence occurrences of the target content unit sequence at the preset detection position. The associated content unit is a content unit associated with the position of the candidate content unit in the generated answer content. The preset detection position is any one of the segment start position, the segment end position and the preset interception position.
[0295] In some embodiments, in order to avoid accidentally hitting the repetitive patterns in normal codes, non-coding language detection is added to the sampled candidate content units, and only when the repeated content unit sequence contains non-coding language content will it be judged as a bad repetition;
[0296] When the candidate content units belonging to the preset detection position are sampled during the answer generation process, the target content unit sequence composed of the candidate content units and the associated content units to be sampled is matched with the reference content unit sequences at the preset detection position to determine the number of occurrences of the sequence corresponding to the target content unit sequence at the preset detection position, including:
[0297] When the candidate content units belonging to the preset detection position are sampled during the answer generation process, the target content unit sequence composed of each candidate content unit to be sampled and the associated content unit is subjected to non-coded language content detection;
[0298] When it is detected that the target content unit sequence contains non-coded language content, the target content unit sequence is matched with each reference content unit sequence at a preset detection position to determine the sequence occurrence number corresponding to the target content unit sequence at the preset detection position.
[0299] 207. Sample answer content from each candidate content unit according to the number of sequence appearances corresponding to the target content unit sequence at the preset detection position, so as to generate subsequent answer content for the code processing problem based on the sampling result.
[0300] In some embodiments, it also includes:
[0301] When the sequence occurs more than a preset number of times, the generation of subsequent answer content for the code processing question is interrupted.
[0302] In some embodiments, after interrupting the generation of subsequent answer content for the code processing question when the number of sequence occurrences is greater than a preset number, the method further includes:
[0303] Get information to generate interrupt prompt;
[0304] Generate an interrupt prompt based on the information, modify the code processing problem, and obtain a modified code processing problem;
[0305] Process the question based on the modified code and generate new answer content.
[0306] During the answer generation process, the candidate content units to be sampled will be checked in real time according to the repetition detection process. When it is found that the repetition exceeds the preset number of times (patience), the current output will be terminated directly, allowing the user to directly fix the code to handle the problem or continue the subsequent dialogue.
[0307] In some embodiments, sampling the answer content from each candidate content unit according to the number of occurrences of the sequence corresponding to the target content unit sequence at the preset detection position includes:
[0308] Determine the repetition penalty coefficient of each candidate content unit to be sampled according to the number of occurrences of the sequence;
[0309] Based on the repetition penalty coefficient, the sampling weight of each candidate content unit to be sampled is determined.
[0310] Among them, the sampling weight , \alpha is the repetition penalty coefficient. When the number of sequence occurrences is greater than 1, a penalty can be imposed to avoid repetition. The above formula will detect if the target content unit sequence has appeared multiple times and increase the penalty. If it has not appeared, it will be \alpha^0=1, which will become the setting for classification in ordinary generation. Here, only the head of the line is penalized, because the current Large Language Model (LLM) class Generative Pre-trained Transformer (GPT) structure generally outputs one-way from front to back, so it is not convenient to intervene in tail repetition.
[0311] like Figure 2bAs shown, after obtaining the generated answer content for the code processing problem, in the process of continuing to generate answers, the generated answer content is subjected to duplicate detection and duplication penalty to provide a reference for the generation of subsequent answer content, thereby reducing the generation of duplicate content.
[0312] Through the technical solution of this application, it is found that the repetition rate can be reduced from 9.7 per thousand to 3.5 per thousand in the test of randomly sampling 10,000 pieces of data in the downstream, as shown in Table 1:
[0313]
[0314] Table 1
[0315] From the testing of bad cases fed back online, it can be confirmed that the question-answering model of this application can effectively solve the common problems of repeated beginning and end of lines in the answer content.
[0316] The question-and-answer method for code information proposed in this application performs duplication detection by considering the repetition of line beginnings and end and the characteristics of code data, and incorporates the repetition detection results into the output content of the question-and-answer model. This not only effectively solves the repetition problem in the generation process of the question-and-answer model, but also introduces relevant signals in the sampling stage, fundamentally alleviating the problem and significantly reducing the situation where the question-and-answer model generates duplicate content.
[0317] From the above, we can see that when generating code-related answers, reducing the appearance of repeated content in the answers is conducive to reducing the occupation of reasoning resources and improving the quality of answer generation.
[0318] In order to better implement the above method, the embodiment of the present application also provides a question-and-answer device for code information, which can be integrated in an electronic device, which can be a terminal, a server, etc. Among them, the terminal can be a mobile phone, a tablet computer, a smart Bluetooth device, a laptop, a personal computer, etc.; the server can be a single server or a server cluster composed of multiple servers.
[0319] For example, in this embodiment, the method of the embodiment of the present application will be described in detail by taking the question and answer device for code information specifically integrated into an electronic device as an example.
[0320] For example, Figure 3 As shown, the question-answering device for code information may include a question-answering unit 301, a content acquisition unit 302, a sequence determination unit 303, a sampling matching unit 304, and a sampling determination unit 305, as follows:
[0321] (I) Question and answer unit 301.
[0322] The question-answering unit 301 is used to obtain code processing questions and generate answers to the code processing questions.
[0323] In some embodiments, the question-answering unit is used to:
[0324] Generate answers to code processing questions through the question-answering model;
[0325] Before generating the answer content for the code processing question through the question-answering model, the device also includes a model training unit for:
[0326] Obtain training data, the training data including sample code processing problems, and positive sample answer content and negative sample answer content of the sample code processing problems;
[0327] Through the question-answering model, the answer content is generated for the sample code processing question to obtain the predicted answer content;
[0328] According to the predicted answer content, as well as the positive sample answer content and the negative sample answer content of the sample code processing question, the parameters of the question-answering model are adjusted to obtain the trained question-answering model.
[0329] In some embodiments, the model training unit is used to:
[0330] Obtaining candidate answer content for the sample code processing question, the candidate answer content including at least one content segment, each content segment including at least one content unit;
[0331] Determine at least one sample reference content unit sequence based on the content unit sequence of the candidate answer content at the preset detection position; and count the number of occurrences of each sample reference content unit sequence at the preset detection position in the candidate answer content;
[0332] When the number of occurrences is greater than the preset value, the candidate answer content is used as the negative sample answer content for the sample code processing question;
[0333] The content unit sequence at the preset detection position in the negative sample answer content is modified to obtain the positive sample answer content.
[0334] (ii) Content acquisition unit 302.
[0335] The content acquisition unit 302 is used to acquire the generated answer content for the current code processing problem, where the generated answer content includes at least one content segment, and each content segment includes at least one content unit.
[0336] (iii) Sequence determination unit 303.
[0337] The sequence determination unit 303 is used to determine at least one reference content unit sequence based on the content unit sequence at the preset detection position in the generated answer content; and count the number of occurrences of each reference content unit sequence at the preset detection position in the generated answer content, and the reference content unit sequence is used to repeatedly detect the content at the preset detection position.
[0338] In some embodiments, the sequence determination unit is used to:
[0339] When the preset detection position is the segment start position, for each content segment in the generated answer content, starting from the segment start position of the content segment, a content unit sequence of a preset length is cut off for the content segment to obtain at least one reference content unit sequence to be repeatedly detected at the segment start position;
[0340] When the preset detection position is the fragment end position, for each content fragment in the generated answer content, starting from the fragment end position of the content fragment, the content fragment is subjected to a content unit sequence of a preset length interception processing to obtain at least one reference content unit sequence to be repeatedly detected at the fragment end position.
[0341] In some embodiments, the sequence determination unit is used to:
[0342] Taking the preset interception position as the starting point, intercepting a preset number of content units of the generated answer content to obtain a sequence of content units at the preset detection position in the generated answer content;
[0343] Performing sequence division processing of a preset length on the content unit sequence to obtain a plurality of content unit subsequences of the preset length;
[0344] Performing content duplication detection processing on multiple content unit subsequences;
[0345] At least one reference content unit sequence is determined from the content unit subsequences according to the duplication detection result.
[0346] In some embodiments, the sequence determination unit is used to:
[0347] Determine at least one initial reference content unit sequence based on a content unit sequence at a preset detection position in the generated answer content;
[0348] Performing content detection of non-coded language on each initial reference content unit sequence;
[0349] When it is detected that the initial reference content unit sequence contains content in a non-coded language, the initial reference content unit sequence is determined as a reference content unit sequence.
[0350] In some embodiments, the sequence determination unit is used to:
[0351] Based on the preset length, multiple division scales are determined;
[0352] According to each division scale, the content unit sequence is subjected to sequence division processing to obtain a plurality of content unit subsequences at different division scales.
[0353] (iv) Sampling matching unit 304.
[0354] The sampling and matching unit 304 is used to match the target content unit sequence composed of the candidate content units and associated content units to be sampled with the reference content unit sequences when sampling the candidate content units belonging to the preset detection position during the answer generation process, so as to determine the number of sequence occurrences corresponding to the target content unit sequence, and the associated content unit is the content unit associated with the position of the candidate content unit in the generated answer content.
[0355] (V) Sampling determination unit 305.
[0356] The sampling determination unit 305 is used to sample the answer content from each candidate content unit according to the number of sequence occurrences, so as to generate subsequent answer content for the code processing problem based on the sampling results.
[0357] In some embodiments, the sampling determination unit is used to:
[0358] Determine the sampling weight of each candidate content unit to be sampled according to the number of occurrences of the sequence;
[0359] The answer content is sampled from each candidate content unit according to the sampling weight.
[0360] In some embodiments, the sampling determination unit is used to:
[0361] Determine the repetition penalty coefficient of each candidate content unit to be sampled according to the number of occurrences of the sequence;
[0362] Based on the repetition penalty coefficient, the sampling weight of each candidate content unit to be sampled is determined.
[0363] In some embodiments, the apparatus further comprises a generating interrupt unit:
[0364] A generation interruption unit is used to interrupt the generation of subsequent answer content for the code processing problem when the number of sequence occurrences is greater than a preset number.
[0365] In some embodiments, after interrupting the generation of subsequent answer content for the code processing question when the number of sequence occurrences is greater than a preset number, the device further includes an interruption prompt unit, a question modification unit, and an answer generation unit:
[0366] An interruption prompt unit, used for acquiring information and generating an interruption prompt;
[0367] A problem modification unit, used for generating an interruption prompt based on the information, modifying the code processing problem, and obtaining a modified code processing problem;
[0368] The answer generation unit is used to process the question according to the modified code and generate new answer content.
[0369] In specific implementation, the above units can be implemented as independent entities, or can be arbitrarily combined to be implemented as the same or several entities. The specific implementation of the above units can refer to the previous method embodiments, which will not be repeated here.
[0370] As can be seen from the above, in the question-and-answer device for code information of this embodiment, the question-and-answer unit obtains the code processing question; and generates the answer content for the code processing question; the content acquisition unit obtains the currently generated answer content for the code processing question, the generated answer content includes at least one content segment, and each content segment includes at least one content unit; the sequence determination unit determines at least one reference content unit sequence based on the content unit sequence at the preset detection position in the generated answer content; and counts the number of occurrences of each reference content unit sequence at the preset detection position in the generated answer content, and the reference content unit sequence is used to repeatedly detect the content at the preset detection position; when the sampling and matching unit samples the candidate content units belonging to the preset detection position during the answer generation process, the target content unit sequence composed of the candidate content units and the associated content units to be sampled is matched with each reference content unit sequence to determine the number of sequence occurrences corresponding to the target content unit sequence, and the associated content unit is a content unit associated with the position of the candidate content unit in the generated answer content; the sampling determination unit samples the answer content from each candidate content unit according to the number of sequence occurrences, so as to generate subsequent answer content for the code processing question based on the sampling result.
[0371] Therefore, the embodiments of the present application can reduce the occurrence of repeated content in the answer, which is beneficial to reducing the occupancy of reasoning resources and improving the quality of generated answers.
[0372] The embodiment of the present application also provides an electronic device, which can be a terminal, a server, etc. The terminal can be a mobile phone, a tablet computer, a smart Bluetooth device, a laptop, a personal computer, etc. The server can be a single server or a server cluster composed of multiple servers, etc.
[0373] In some embodiments, the question and answer device for code information can also be integrated into multiple electronic devices. For example, the question and answer device for code information can be integrated into multiple servers, and the question and answer method for code information of the present application can be implemented by multiple servers.
[0374] In this embodiment, the electronic device of this embodiment is a server as an example for detailed description, for example, Figure 4 As shown, it shows a schematic diagram of the structure of the server involved in the embodiment of the present application, specifically:
[0375] The server may include one or more processing core processors 401, one or more computer-readable storage media memories 402, a power supply 403, an input module 404, and a communication module 405. Those skilled in the art will appreciate that Figure 4 The server structure shown in the figure does not constitute a limitation on the server, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently. Among them:
[0376] The processor 401 is the control center of the server, and uses various interfaces and lines to connect various parts of the entire server. It executes various functions of the server and processes data by running or executing software programs and / or modules stored in the memory 402, and calling data stored in the memory 402. In some embodiments, the processor 401 may include one or more processing cores; in some embodiments, the processor 401 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and application programs, and the modem processor mainly processes wireless communications. It is understandable that the above-mentioned modem processor may not be integrated into the processor 401.
[0377] The memory 402 can be used to store software programs and modules. The processor 401 executes various functional applications and data processing by running the software programs and modules stored in the memory 402. The memory 402 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area may store data created according to the use of the server, etc. In addition, the memory 402 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices. Accordingly, the memory 402 may also include a memory controller to provide the processor 401 with access to the memory 402.
[0378] The server also includes a power supply 403 for supplying power to various components. In some embodiments, the power supply 403 may be logically connected to the processor 401 through a power management system, so that the power management system can manage charging, discharging, power consumption, and other functions. The power supply 403 may also include any components such as one or more DC or AC power supplies, recharging systems, power failure detection circuits, power converters or inverters, and power status indicators.
[0379] The server may further include an input module 404, which may be used to receive input digital or character information and generate keyboard, mouse, joystick, optical or trackball signal input related to user settings and function control.
[0380] The server may further include a communication module 405. In some embodiments, the communication module 405 may include a wireless module. The server may perform short-range wireless transmission through the wireless module of the communication module 405, thereby providing wireless broadband Internet access for the user. For example, the communication module 405 may be used to help the user send and receive emails, browse web pages, and access streaming media.
[0381] Although not shown, the server may also include a display unit, etc., which will not be described in detail herein. Specifically in this embodiment, the processor 401 in the server will load the executable files corresponding to the processes of one or more application programs into the memory 402 according to the following instructions, and the processor 401 will run the application programs stored in the memory 402, thereby implementing the steps in the methods of the embodiments of the present application.
[0382] The specific implementation of the above operations can be found in the previous embodiments, which will not be described in detail here.
[0383] From the above, we can see that when generating subsequent answer content for code processing questions, candidate content units with lower sequence appearance times are prioritized for sampling. This method helps reduce the occurrence of repeated content in answers when generating code-related answers, which helps reduce the occupancy of reasoning resources and improve the quality of generated answers.
[0384] A person of ordinary skill in the art will appreciate that all or part of the steps in the various methods of the above embodiments may be completed by instructions, or by controlling related hardware through instructions. The instructions may be stored in a computer-readable storage medium and loaded and executed by a processor.
[0385] To this end, an embodiment of the present application provides a computer-readable storage medium, in which a plurality of instructions are stored, and the instructions can be loaded by a processor to execute the steps in any one of the question-and-answer methods for code information provided in the embodiment of the present application. For example, the instructions can execute the following steps:
[0386] Obtain code processing problems; and generate answers to the code processing problems;
[0387] Obtaining the currently generated answer content for the code processing question, the generated answer content includes at least one content segment, and each content segment includes at least one content unit;
[0388] Based on the content unit sequence at the preset detection position in the generated answer content, at least one reference content unit sequence is determined; and the number of occurrences of each reference content unit sequence at the preset detection position in the generated answer content is counted, and the reference content unit sequence is used to perform repeated detection on the content at the preset detection position;
[0389] When the candidate content units belonging to the preset detection position are sampled during the answer generation process, the target content unit sequence composed of the candidate content units and the associated content units to be sampled is matched with the reference content unit sequences to determine the number of sequence occurrences corresponding to the target content unit sequence, and the associated content unit is the content unit associated with the position of the candidate content unit in the generated answer content;
[0390] According to the number of sequence occurrences, answer content is sampled from each candidate content unit to generate subsequent answer content for the code processing problem based on the sampling results.
[0391] The storage medium may include: a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.
[0392] According to one aspect of the present application, a computer program product or computer program is provided, the computer program product or computer program including a computer program / instruction, the computer program / instruction being stored in a computer-readable storage medium. A processor of an electronic device reads the computer program / instruction from the computer-readable storage medium, and the processor executes the computer program / instruction, so that the electronic device executes the method provided in various optional implementations of the question-answering aspect of code information provided in the above embodiments.
[0393] Since the instructions stored in the storage medium can execute the steps of any one of the question and answer methods for code information provided in the embodiments of the present application, the beneficial effects that can be achieved by any one of the question and answer methods for code information provided in the embodiments of the present application can be achieved. For details, please refer to the previous embodiments and will not be repeated here.
[0394] The above is a detailed introduction to a question-and-answer method for code information and related equipment provided in an embodiment of the present application. The related equipment includes a question-and-answer device for code information, an electronic device, a storage medium and a program product. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea; at the same time, for technical personnel in this field, according to the idea of the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A question-answering method for code information, characterized in that: include: Get the code to handle the problem; And generate answer content for the code processing problem; Obtaining a currently generated answer content for the code processing problem, wherein the generated answer content includes at least one content segment, and each content segment includes at least one content unit; Determine at least one reference content unit sequence based on a content unit sequence at a preset detection position in the generated answer content; and count the number of occurrences of each reference content unit sequence at a preset detection position in the generated answer content, the reference content unit sequence being used to perform repeated detection on the content at the preset detection position; When the candidate content units belonging to the preset detection position are sampled during the answer generation process, the target content unit sequence composed of the candidate content units and the associated content units to be sampled is matched with the reference content unit sequences to determine the number of sequence occurrences corresponding to the target content unit sequence, wherein the associated content unit is a content unit associated with the position of the candidate content unit in the generated answer content; Answer contents are sampled from the candidate content units according to the number of occurrences of the sequence, so as to generate subsequent answer contents for the code processing problem based on the sampling results, wherein the sampling results indicate candidate content units that need to be sampled and incorporated into the answer contents, and the number of repeated occurrences of the candidate content units in the sampling results in the generated answer contents shall not exceed a preset number.
2. The question-and-answer method for code information according to claim 1, characterized in that: The sampling of answer content from each candidate content unit according to the number of occurrences of the sequence includes: Determining the sampling weight of each candidate content unit to be sampled according to the number of occurrences of the sequence; Answer contents are sampled from the candidate content units according to the sampling weights.
3. The question-and-answer method for code information according to claim 2, characterized in that: The step of determining the sampling weight of each candidate content unit to be sampled according to the number of occurrences of the sequence includes: Determining a repetition penalty coefficient of each candidate content unit to be sampled according to the number of occurrences of the sequence; Based on the repetition penalty coefficient, a sampling weight of each candidate content unit to be sampled is determined.
4. The question-and-answer method for code information according to claim 1, characterized in that: The step of determining at least one reference content unit sequence to be repeatedly detected at the preset detection position based on the content unit sequence at the preset detection position in the generated answer content comprises: When the preset detection position is the segment start position, for each content segment in the generated answer content, starting from the segment start position of the content segment, the content segment is subjected to a content unit sequence interception process of a preset length to obtain at least one reference content unit sequence to be repeatedly detected at the segment start position; When the preset detection position is the fragment end position, for each content fragment in the generated answer content, starting from the fragment end position of the content fragment, the content fragment is subjected to a content unit sequence of a preset length interception processing to obtain at least one reference content unit sequence to be repeatedly detected at the fragment end position.
5. The question-and-answer method for code information according to claim 1, characterized in that: The step of determining at least one reference content unit sequence based on a content unit sequence at a preset detection position in the generated answer content comprises: Taking the preset interception position as the starting point, intercepting a preset number of content units of the generated answer content to obtain a sequence of content units at the preset detection position in the generated answer content; Performing sequence division processing of a preset length on the content unit sequence to obtain a plurality of content unit subsequences of the preset length; Performing content duplication detection processing on the multiple content unit subsequences; At least one reference content unit sequence is determined from the content unit subsequences according to the duplication detection result.
6. The question-and-answer method for code information according to claim 1, characterized in that: The step of determining at least one reference content unit sequence based on a content unit sequence at a preset detection position in the generated answer content comprises: Determining at least one initial reference content unit sequence based on a content unit sequence at a preset detection position in the generated answer content; Performing content detection of non-coded language on each initial reference content unit sequence; When it is detected that the initial reference content unit sequence contains content in a non-coded language, the initial reference content unit sequence is determined as a reference content unit sequence.
7. The question-and-answer method for code information according to claim 1, characterized in that: Also includes: When the sequence occurs more than a preset number of times, the generation of subsequent answer content for the code processing question is interrupted.
8. The question-and-answer method for code information according to claim 7, characterized in that: After interrupting the generation of subsequent answer content for the code processing question when the number of occurrences of the sequence is greater than a preset number, the method further includes: Get information to generate interrupt prompt; Generate an interrupt prompt based on the information, modify the code processing problem, and obtain a modified code processing problem; Process the question according to the modified code to generate new answer content.
9. The question-and-answer method for code information according to claim 5, characterized in that: The step of performing sequence division processing of a preset length on the content unit sequence to obtain a plurality of content unit subsequences of the preset length includes: Based on the preset length, determining a plurality of division scales; According to each division scale, the content unit sequence is subjected to sequence division processing to obtain a plurality of content unit subsequences at different division scales.
10. The question-and-answer method for code information according to claim 1, characterized in that: The generating of the answer content for the code processing question includes: Generate answers to the code processing questions through a question-answering model; Before generating the answer content for the code processing question through the question-answering model, the method further includes: Acquire training data, the training data including sample code processing problems, and positive sample answer content and negative sample answer content of the sample code processing problems; Generate answer content for the sample code processing question through the question-answering model to obtain predicted answer content; According to the predicted answer content, and the positive sample answer content and the negative sample answer content of the sample code processing question, the parameters of the question-answering model are adjusted to obtain a trained question-answering model.
11. The question-and-answer method for code information according to claim 10, characterized in that: The obtaining of training data comprises: Obtain candidate answer content for the sample code processing question, wherein the candidate answer content includes at least one content segment, and each content segment includes at least one content unit; Determine at least one sample reference content unit sequence based on the content unit sequence of the candidate answer content at the preset detection position; and count the number of occurrences of each sample reference content unit sequence at the preset detection position in the candidate answer content; When the number of occurrences is greater than a preset value, the candidate answer content is used as a negative sample answer content for the sample code processing question; The content unit sequence at the preset detection position in the negative sample answer content is modified to obtain the positive sample answer content.
12. A question-and-answer device for code information, characterized in that: include: Question and answer unit, used to obtain code processing questions; And generate answer content for the code processing problem; A content acquisition unit, used to acquire the currently generated answer content for the code processing problem, wherein the generated answer content includes at least one content segment, and each content segment includes at least one content unit; A sequence determination unit, configured to determine at least one reference content unit sequence based on a content unit sequence at a preset detection position in the generated answer content; and to count the number of occurrences of each reference content unit sequence at a preset detection position in the generated answer content, wherein the reference content unit sequence is used to perform repeated detection on the content at the preset detection position; A sampling and matching unit, used for matching a target content unit sequence composed of each candidate content unit and associated content unit to be sampled with each reference content unit sequence when sampling a candidate content unit belonging to a preset detection position during the answer generation process, so as to determine the number of occurrences of the sequence corresponding to the target content unit sequence, wherein the associated content unit is a content unit associated with the position of the candidate content unit in the generated answer content; A sampling determination unit is used to sample answer content from each candidate content unit according to the number of occurrences of the sequence, so as to generate subsequent answer content for the code processing problem based on the sampling results, wherein the sampling results indicate candidate content units that need to be sampled and included in the answer content, and the number of repeated occurrences of the candidate content units in the sampling results in the generated answer content shall not exceed a preset number.
13. The question-and-answer device for code information according to claim 12, characterized in that: The sampling determination unit is used to: Determining the sampling weight of each candidate content unit to be sampled according to the number of occurrences of the sequence; Answer contents are sampled from the candidate content units according to the sampling weights.
14. The question-and-answer device for code information according to claim 13, characterized in that: The sampling determination unit is used to: Determining a repetition penalty coefficient of each candidate content unit to be sampled according to the number of occurrences of the sequence; Based on the repetition penalty coefficient, a sampling weight of each candidate content unit to be sampled is determined.
15. The question-and-answer device for code information according to claim 12, characterized in that: The sequence determination unit is used to: When the preset detection position is the segment start position, for each content segment in the generated answer content, starting from the segment start position of the content segment, the content segment is subjected to a content unit sequence interception process of a preset length to obtain at least one reference content unit sequence to be repeatedly detected at the segment start position; When the preset detection position is the fragment end position, for each content fragment in the generated answer content, starting from the fragment end position of the content fragment, the content fragment is subjected to a content unit sequence of a preset length interception processing to obtain at least one reference content unit sequence to be repeatedly detected at the fragment end position.
16. The question-and-answer device for code information according to claim 12, characterized in that: The sequence determination unit is used to: Taking the preset interception position as the starting point, intercepting a preset number of content units of the generated answer content to obtain a sequence of content units at the preset detection position in the generated answer content; Performing sequence division processing of a preset length on the content unit sequence to obtain a plurality of content unit subsequences of the preset length; Performing content duplication detection processing on the multiple content unit subsequences; At least one reference content unit sequence is determined from the content unit subsequences according to the duplication detection result.
17. The question-and-answer device for code information according to claim 12, characterized in that: The sequence determination unit is used to: Determining at least one initial reference content unit sequence based on a content unit sequence at a preset detection position in the generated answer content; Performing content detection of non-coded language on each initial reference content unit sequence; When it is detected that the initial reference content unit sequence contains content in a non-coded language, the initial reference content unit sequence is determined as a reference content unit sequence.
18. The question-and-answer device for code information according to claim 12, characterized in that: The device also includes an interrupt generating unit: The generation interruption unit is used to interrupt the generation of subsequent answer content for the code processing question when the number of occurrences of the sequence is greater than a preset number.
19. The question-and-answer device for code information according to claim 18, characterized in that: When the number of occurrences of the sequence is greater than a preset number, after interrupting the generation of subsequent answer content for the code processing question, the device further includes an interruption prompt unit, a question modification unit and an answer generation unit: The interruption prompt unit is used to obtain information and generate an interruption prompt; The problem modification unit is used to generate an interruption prompt based on the information, modify the code processing problem, and obtain a modified code processing problem; The answer generation unit is used to process the question according to the modified code and generate new answer content.
20. The question-and-answer device for code information according to claim 16, characterized in that: The sequence determination unit is used to: Based on the preset length, multiple division scales are determined; According to each division scale, the content unit sequence is subjected to sequence division processing to obtain a plurality of content unit subsequences at different division scales.
21. The question-and-answer device for code information according to claim 12, characterized in that: The question-answering unit is used to: Generate answers to the code processing questions through a question-answering model; Before generating the answer content for the code processing question by the question-answering model, the device further includes a model training unit for: Acquire training data, the training data including sample code processing problems, and positive sample answer content and negative sample answer content of the sample code processing problems; Generate answer content for the sample code processing question through the question-answering model to obtain predicted answer content; According to the predicted answer content, and the positive sample answer content and the negative sample answer content of the sample code processing question, the parameters of the question-answering model are adjusted to obtain a trained question-answering model.
22. The question-and-answer device for code information according to claim 21, characterized in that: The model training unit is used to: Obtain candidate answer content for the sample code processing question, wherein the candidate answer content includes at least one content segment, and each content segment includes at least one content unit; Determine at least one sample reference content unit sequence based on the content unit sequence of the candidate answer content at the preset detection position; and count the number of occurrences of each sample reference content unit sequence at the preset detection position in the candidate answer content; When the number of occurrences is greater than a preset value, the candidate answer content is used as a negative sample answer content for the sample code processing question; The content unit sequence at the preset detection position in the negative sample answer content is modified to obtain the positive sample answer content.
23. An electronic device, characterized in that: It includes a processor and a memory, wherein the memory stores a plurality of instructions; the processor loads instructions from the memory to execute the steps in the question-and-answer method for code information as described in any one of claims 1 to 11.
24. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a plurality of instructions, and the instructions are suitable for being loaded by a processor to execute the steps in the question-and-answer method for code information as described in any one of claims 1 to 11.
25. A computer program product comprising a plurality of instructions, characterized in that: When the instructions are executed by the processor, the steps in the question-and-answer method for code information described in any one of claims 1 to 11 are implemented.
Citation Information
Patent Citations
Generative intelligent question and answer method, system and equipment and storage medium
CN117332056A