Code writing error correction method and device
By comparing the complete code output from the code completion model and detecting and correcting typing errors, the typing error problem of programmers when writing code is solved, improving development efficiency and program stability, and enhancing user experience.
Patent Information
- Application Number
- CN202411032940.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-30
- Publication Date
- 2024-12-17
- Estimated Expiration
- 2044-07-30
AI Technical Summary
During the software development process, programmers are prone to typing errors when writing code, resulting in reduced development efficiency, program stability and maintainability affected, and the existing technology lacks effective detection and error correction methods.
By comparing the completion code output from the code completion model with the target code input in real time, we can detect whether the key value of the mismatched character meets the preset position conditions, and use the mismatched characters to perform error correction processing to generate the corrected target Code, sends error correction revocation prompt information to the user, allowing the user to cancel the error correction operation.
It automatically recognizes and corrects typing errors during code writing, improves development efficiency, program stability and maintainability, and enhances user experience.
Smart Images

Figure CN119149391A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the technical field of large language models, and in particular to a method and device for correcting errors in code writing. Background Art
[0002] In the process of software development, programmers need to write a lot of code to implement specific functions. However, due to some reasons such as fast editing speed, programmers may make typing errors during the code writing process, such as accidentally pressing the wrong key when entering the code. These errors will not only interrupt the programmer's work ideas and reduce development efficiency, but may also introduce potential bugs, affecting the stability and maintainability of the program.
[0003] However, in the prior art, there is no effective means to detect whether there are typing errors during the code writing process. Summary of the invention
[0004] In view of this, the present disclosure proposes a code writing error correction method and device to solve the problems existing in the prior art such as reduced development efficiency due to typing errors, affecting program stability and maintainability, etc.
[0005] The first aspect of the present disclosure provides a method for correcting errors in code writing, the method comprising:
[0006] In response to a code input operation, comparing the completed code output by the code completion model with the target code input in real time;
[0007] If the completion code is different from the target code, detecting whether the key value corresponding to the character in the completion code that does not match the character in the target code satisfies a preset position condition, wherein the character that does not match the character in the completion code is the same as the character position of the second character in the target code, but has different contents;
[0008] If the position of the key value corresponding to the unmatched character on the keyboard meets the preset position condition, the target code is used as the code to be corrected;
[0009] The first character is used to perform error correction processing on the code to be corrected to obtain a target code after error correction.
[0010] The disclosed embodiment compares the completed code output by the code completion model with the target code input in real time, and when the completed code is different from the target code, detects whether the key value corresponding to the character in the completed code that does not match the target code meets the preset position condition, and uses the first character to perform error correction processing on the code to be corrected. It can automatically identify typing errors in the code writing process and automatically modify its error code, thereby greatly improving the user experience.
[0011] In an embodiment of the present disclosure, the detecting whether the key value corresponding to the character in the completion code that does not match the character in the target code satisfies a preset position condition includes:
[0012] Determine a first character from the complement code and determine a second character from the target code, wherein the character position of the first character in the complement code is the same as the character position of the second character in the target code, but the content is different;
[0013] Determine whether a first position on the keyboard of the key value corresponding to the first character and a second position on the keyboard of the key value corresponding to the second character meet the preset position condition.
[0014] In an embodiment of the present disclosure, the preset position condition includes: the first position is the same as or adjacent to the second position.
[0015] The disclosed embodiment limits the preset position condition, that is, the first position is the same as or adjacent to the second position, so as to accurately determine whether an error occurring during the code writing process is a typing error, thereby improving the accuracy of determining typing errors.
[0016] In the embodiment of the present disclosure, using the first character to perform error correction processing on the to-be-corrected code to obtain a target code after error correction includes:
[0017] The first character is used to replace the second character in the code to be corrected, so as to generate the corrected target code.
[0018] In the embodiment of the present disclosure, the method further includes:
[0019] After obtaining the error-corrected target code, sending an error correction cancellation prompt message to the user terminal;
[0020] If an error correction cancellation instruction sent by the user terminal is received, the first character in the error-corrected target code is replaced with the second character to obtain the target code.
[0021] The disclosed embodiment obtains the target code by sending an error correction cancellation prompt message to the user terminal after obtaining the target code after error correction, and by replacing the first character in the target code after error correction with the second character after receiving the error correction cancellation instruction sent by the user terminal, so as to facilitate the user to understand the current changes and improve the user experience; and allows the user to cancel the previous error correction operation and restore to the state before error correction, which provides flexibility for the user and allows them to reconsider their previous decisions.
[0022] In the embodiment of the present disclosure, the method further includes:
[0023] Get multiple source codes;
[0024] For any one of the multiple source codes, perform word segmentation processing on the source code to generate a character sequence corresponding to the source code, thereby obtaining multiple character sequences corresponding to the multiple source codes one by one;
[0025] The initial model is trained according to the multiple character sequences to obtain the code completion model.
[0026] In the embodiment of the present disclosure, the initial model is trained according to the multiple character sequences to obtain the code completion model, including:
[0027] For any character sequence among the multiple character sequences, randomly delete part of the character sequence in the character sequence to obtain a target character sequence;
[0028] Determine the target position of the deleted character sequence in the target character sequence;
[0029] According to the target position, a first character sequence and a second character sequence are determined from the target character sequence; the first character sequence represents a character sequence of a preceding portion of the target position of the target character sequence, and the second character sequence represents a character sequence of a succeeding portion of the target position of the target character sequence;
[0030] The initial model is trained to predict the deleted character sequence based on the first character sequence and the second character sequence.
[0031] The disclosed embodiment determines the first character sequence and the second character sequence from the target character sequence through the target position, and trains the initial model to predict the deleted character sequence based on the first character sequence and the second character sequence. This enables the model to consider the preceding and subsequent contexts of the code to better understand the logical flow and structure of the code, thereby optimizing the model performance and achieving the purpose of improving the prediction accuracy of the completion structure.
[0032] In an embodiment of the present disclosure, after training the initial model to predict the deleted character sequence based on the first character sequence and the second character sequence, the method further includes:
[0033] Inputting a first character sequence and a second character sequence corresponding to any target character sequence into the initial model to obtain a complementary character sequence output by the initial model;
[0034] If the completion character sequence is the same as the deleted character sequence in any one of the target character sequences, the initial model is determined as the code completion model.
[0035] In the embodiment of the present disclosure, the method further includes:
[0036] If the complement character sequence is different from the deleted character sequence in any one of the target character sequences, the initial model is optimized according to a plurality of character sequences corresponding one-to-one to the plurality of source codes.
[0037] The embodiment of the second aspect of the present disclosure provides a code writing error correction device, including:
[0038] A code comparison module, for comparing the completed code output by the code completion model with the target code input in real time in response to a code input operation;
[0039] a conditional judgment module, configured to detect whether a key value corresponding to a character in the completion code that does not match the character in the target code satisfies a preset position condition if the completion code is different from the target code, wherein the character that does not match the character in the completion code is a character whose character position in the completion code is the same as the character position of the second character in the target code but whose content is different;
[0040] A module for determining a code to be corrected, configured to use the target code as the code to be corrected if the position of the key value corresponding to the unmatched character on the keyboard satisfies the preset position condition;
[0041] The code error correction module is used to use the first character to perform error correction processing on the code to be corrected to obtain a target code after error correction.
[0042] An embodiment of the third aspect of the present disclosure provides a computer device, which includes a memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the code writing and error correction method described in the first aspect by executing the computer instructions.
[0043] An embodiment of the fourth aspect of the present disclosure provides a computer-readable storage medium, on which computer instructions are stored, and the computer instructions are used to enable a computer to execute the code writing and error correction method described in the first aspect.
[0044] Additional aspects and advantages of the present disclosure will be given in part in the following description and in part will become apparent from the following description or be learned through practice of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] By reading the detailed description of the preferred embodiment below, various other advantages and benefits will become clear to those of ordinary skill in the art. The accompanying drawings are only used for the purpose of illustrating the preferred embodiment and are not considered to be limitations of the present disclosure. In addition, the same reference symbols are used to represent the same components throughout the accompanying drawings.
[0046] In the attached picture:
[0047] Figure 1 A schematic diagram of a flow chart of a code writing and error correction method provided by an embodiment of the present disclosure is shown;
[0048] Figure 2 A schematic diagram showing error correction revocation provided by an embodiment of the present disclosure is shown;
[0049] Figure 3 A schematic diagram of the structure of a code writing and error correction device provided by an embodiment of the present disclosure is shown;
[0050] Figure 4 A schematic diagram of the structure of a computer device provided by an embodiment of the present disclosure is shown;
[0051] Figure 5 A schematic diagram of a storage medium provided by an embodiment of the present disclosure is shown. DETAILED DESCRIPTION
[0052] The exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments described herein. On the contrary, these embodiments are provided in order to enable a more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.
[0053] It should be noted that, unless otherwise specified, the technical terms or scientific terms used in the present disclosure should have the common meanings understood by those skilled in the art to which the present disclosure belongs.
[0054] The following describes the technical scenarios involved in the embodiments of the present disclosure.
[0055] Software developers often make typing errors when writing programs. Going back to correct typing errors will take unnecessary time and interrupt normal work flow; some typing errors do not violate syntax and remain in the program, causing potential bugs; some typing errors neither violate syntax nor cause bugs, but result in strange naming of variables or functions, affecting the readability of the program.
[0056] There are various types of typing errors. As far as the currently typed characters are concerned, they do not violate any programming specifications, and only by connecting the context can we tell whether it is a typing error. Existing technologies cannot solve the problem of how to distinguish whether it is a typing error.
[0057] In view of the above problems, the present invention provides a method for correcting errors in code writing, which can identify typing errors by combining keyboard position and the correlation between Chinese and English characters, and give suggestions for correcting errors. In the process of user writing a program, the typing errors can be automatically corrected without the user having to roll back and modify them.
[0058] According to an embodiment of the present disclosure, an embodiment of a code writing error correction method is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0059] In this embodiment, a method for correcting errors in coding is provided. Figure 1 is a flowchart of a method for correcting errors in writing code according to an embodiment of the present disclosure, such as Figure 1 As shown, the process includes the following steps:
[0060] Step S101 , in response to a code input operation, comparing the completed code output by the code completion model with the target code input in real time.
[0061] Specifically, while the user is writing code, the code completion model will predict the subsequent code (i.e., the completed code) in real time based on the context of the code already written by the user; at the same time, it will compare the completed code with the target code entered by the user. If the two are the same, it can be determined that the user did not make any writing errors during the code writing process and no error correction is required.
[0062] In some specific embodiments, the code completion model may be a character-level code completion model, and its model training steps may include: obtaining multiple software source code projects, performing word segmentation on the source code of each software source code project according to characters, and obtaining a character sequence based on character-level word segmentation; using the character sequence as a training set for model training to obtain a character-level code completion model.
[0063] Step S102: If the completion code is different from the target code, it is detected whether the key value corresponding to the character in the completion code that does not match the character in the target code meets the preset position condition.
[0064] Specifically, when the completion code is different from the target code, it can be preliminarily determined that the user made an error in the code writing process, and it is necessary to further determine whether the error is a typing error based on whether the key values corresponding to the characters in the completion code that do not match the target code meet the preset position conditions.
[0065] In some specific embodiments, unmatched characters refer to characters whose character positions in the completion code are the same as the character positions of the second character in the target code, but whose contents are different. For example: "print" in the completion code and "peint" in the target code, where the character positions of "r" in "print" in the completion code and the character positions of "e" in "peint" in the target code are the same, but the meanings they express are different. Another example: "(" in the completion code and "9" in the target code, where the character positions of the two are the same, but the meanings they express are different.
[0066] In some specific embodiments, the above step S102 includes steps S1021 and S1022:
[0067] Step S1021, determining a first character from the completion code, and determining a second character from the target code.
[0068] Specifically, the character position of the first character in the completion code is the same as the character position of the second character in the target code, but the contents are different. In other words, the first character and the second character are unmatched characters.
[0069] Step S1022, determining whether the first position of the key value corresponding to the first character on the keyboard and the second position of the key value corresponding to the second character on the keyboard meet the preset position condition.
[0070] Specifically, the above-mentioned preset position conditions include but are not limited to: the first position is the same as or adjacent to the second position.
[0071] The above step S1022 is described by taking an example:
[0072] Assuming that the first character is the "r" in the completion code "print" and the second character is the "e" in the target code "peint", according to the layout of the key values in the keyboard, it can be determined that the key value of the first character "r" and the key value of the second character "e" are adjacent to each other on the keyboard. Therefore, the positions of the key value corresponding to the first character "r" and the key value corresponding to the second character "e" on the keyboard meet the preset position conditions.
[0073] Assume that the first character is the opening parenthesis '(' in the completion code "(int i = 0; i < n; i++)", and the second character is the digit '9' in the target code "9int i = 0; i < n; i++)". According to the layout of each key value on the keyboard, it can be determined that the key values of the first character '(' and the second character '9' are in the same position on the keyboard. Therefore, the positions of the key values corresponding to the first character '(' and the second character '9' on the keyboard satisfy the preset position condition.
[0074] Step S103, if the key value of the unmatched character satisfies the preset position condition on the keyboard, then use the target code as the code to be corrected.
[0075] Specifically, when the key values of the unmatched characters satisfy preset position conditions such as adjacent or the same on the keyboard. For example, the key values of the above first character '(' and the second character '9' are in the same position on the keyboard. Another example is that the key values of the above first character 'r' and the second character 'e' are adjacent on the keyboard. It can be determined that the error that occurs during the user's code writing is a typing error. Therefore, use the target code input by the user as the code to be corrected.
[0076] Step S104, use the first character to correct the code to be corrected, and obtain the corrected target code.
[0077] In some specific embodiments, the first character can be used to replace the second character in the code to be corrected to generate the corrected target code. For example, use the first character 'r' to replace the second character 'e' in the code to be corrected "peint" to obtain the corrected target code "print". Another example is to use the first character '(' to replace the second character '9' in the code to be corrected "9int i = 0; i < n; i++)" to obtain the corrected target code "(int i = 0; i < n; i++)".
[0078] In some specific embodiments, the method further includes steps a1 - a2:
[0079] Step a1, after obtaining the corrected target code, send a correction cancellation prompt message to the user terminal;
[0080] Step a2, if the correction cancellation instruction sent from the user terminal is received, then use the second character to replace the first character in the corrected target code to obtain the target code.
[0081] In the above steps a1 - a2, when it is recognized that there is an input error in the user's code writing, the incorrect input character is automatically changed to the correct one, and a prompt is popped up (such as Figure 2 ). If the user clicks the "Undo" button, the modified characters will be changed back to the original input; if the user does not choose "Undo" and continues to write, the automatically modified content will become part of the written content and be saved in the document. In other words, the user does not need to roll back the modification, and the system automatically fixes the typing error.
[0082] In some specific embodiments, the present invention also provides a model training method for a code completion model, including steps b1 to b3:
[0083] Step b1, obtaining multiple source codes.
[0084] Specifically, the multiple source codes obtained are not specifically limited here, and the corresponding source codes can be selected according to actual needs. For example: the multiple source codes obtained can come from different technical fields or application scenarios, respectively, so that the code completion model finally trained has universality, that is: the code completion model can perform code completion operations on source codes to be completed in different technical fields or application scenarios. For another example: the multiple source codes obtained can belong to the same technical field or application scenario, so that the code completion model finally trained has domain specificity, that is: the code completion model can better understand and predict code patterns and structures in a specific technical field, and improve the accuracy of code completion.
[0085] Step b2: for any one of the multiple source codes, perform word segmentation processing on the source code to generate a character sequence corresponding to the source code, and obtain multiple character sequences corresponding to the multiple source codes one by one.
[0086] Specifically, the specific implementation means of the word segmentation process is not specifically limited here, and can achieve the purpose of dividing the source code into a sequence including multiple characters.
[0087] Step b3: training the initial model according to the multiple character sequences to obtain the code completion model.
[0088] In some specific embodiments, step b3 includes steps b31 to b34:
[0089] Step b31, for any character sequence among the multiple character sequences, randomly delete part of the character sequence in the character sequence to obtain a target character sequence.
[0090] In some specific embodiments, each character sequence includes a plurality of characters, and the characters include at least one of the following: a keyword, an identifier, a constant, a string literal, and a special symbol.
[0091] Step b32, determining the target position of the deleted character sequence in the target character sequence.
[0092] Step b33: Determine a first character sequence and a second character sequence from the target character sequence according to the target position.
[0093] Specifically, the first character sequence represents a character sequence of a preceding part of a target position of the target character sequence, and the second character sequence represents a character sequence of a succeeding part of the target position of the target character sequence.
[0094] In some specific embodiments, the above step b33 includes steps b331 and b332:
[0095] Step b331, taking the character sequence corresponding to the preset start symbol located at the front part of the target position in the target character sequence as the first character sequence.
[0096] Specifically, the preset start symbol may be understood as the start symbol that is closest to the target position and located before the target position, and the first character sequence may be understood as the character sequence between the preset start symbol and the target position.
[0097] Step b332: taking the character sequence corresponding to the preset separator located at the post-order part of the target position in the target character sequence as the second character sequence.
[0098] Specifically, the preset separator can be understood to be selected according to actual needs, for example, the Nth separator located after the target position is selected, and the second character sequence can be understood to be the character sequence between the preset separator and the target position.
[0099] Step b34, training the initial model to predict the deleted character sequence based on the first character sequence and the second character sequence.
[0100] Specifically, the initial model can select a large language model suitable for sequence-to-sequence tasks, such as a Transformer-based model, such as GPT (Generative Pre-trained Transformer), BERT (Bidirectional Encoder Representations from Transformers), etc.
[0101] In some specific embodiments, during the model training process, a validation set can be used to evaluate the performance of the model using appropriate evaluation indicators, such as BLEU score, ROUGE score, or a custom evaluation indicator. The model can also be fine-tuned based on the evaluation results, which may include adjusting the network structure, optimizing the training process, or using more data for training.
[0102] In some specific embodiments, after the above step b34, the method further includes steps c1 to c3:
[0103] Step c1, inputting a first character sequence and a second character sequence corresponding to any target character sequence into the initial model to obtain a completed character sequence output by the initial model.
[0104] Step c2: if the completion character sequence is the same as the deleted character sequence in any one of the target character sequences, the initial model is determined as the code completion model.
[0105] Step c3: if the complement character sequence is different from the deleted character sequence in any one of the target character sequences, optimizing the initial model according to a plurality of character sequences corresponding one-to-one to the plurality of source codes.
[0106] The disclosed embodiment can effectively evaluate the code completion effect of the model by comparing the completed character sequence output by the initial model with the deleted character sequence in any one of the target character sequences to ensure the output accuracy of the completed code; and, under the condition that the completed character sequence output by the model is different from the deleted character sequence in any one of the target character sequences, the model parameters can be adjusted through an optimization process so that the model outputs a completed code that meets the expected requirements.
[0107] Corresponding to the implementation of the above code writing and error correction method, the embodiment of the present disclosure also provides a code writing and error correction device for executing the above Figure 1 to Figure 2 The code writing error correction method described in any of the illustrated embodiments. Figure 3 As shown, the code writing error correction device includes:
[0108] A code comparison module, for comparing the completed code output by the code completion model with the target code input in real time in response to a code input operation;
[0109] a conditional judgment module, configured to detect whether a key value corresponding to a character in the completion code that does not match the character in the target code satisfies a preset position condition if the completion code is different from the target code, wherein the character that does not match the character in the completion code is a character whose character position in the completion code is the same as the character position of the second character in the target code but whose content is different;
[0110] A module for determining a code to be corrected, configured to use the target code as the code to be corrected if the position of the key value corresponding to the unmatched character on the keyboard satisfies the preset position condition;
[0111] The code error correction module is used to use the first character to perform error correction processing on the code to be corrected to obtain a target code after error correction.
[0112] Optionally, the conditional judgment module is also used to: determine a first character from the completion code, and determine a second character from the target code, the character position of the first character in the completion code is the same as the character position of the second character in the target code, but the contents are different; determine whether the key value corresponding to the first character at a first position on the keyboard and the key value corresponding to the second character at a second position on the keyboard meet the preset position condition.
[0113] Optionally, the preset position condition includes: the first position is the same as or adjacent to the second position.
[0114] Optionally, the code error correction module is further used to: use the first character to replace the second character in the code to be corrected, and generate the corrected target code.
[0115] Optionally, the device also includes: an error correction revocation module, which is used to send an error correction revocation prompt message to the user terminal after obtaining the corrected target code; if an error correction revocation instruction is received from the user terminal, the second character is used to replace the first character in the corrected target code to obtain the target code.
[0116] Optionally, the device further comprises:
[0117] A code acquisition module is used to acquire multiple source codes;
[0118] A word segmentation processing module is used to perform word segmentation processing on any one of the multiple source codes, generate a character sequence corresponding to the source code, and obtain multiple character sequences corresponding to the multiple source codes one by one;
[0119] The model training module is used to train the initial model according to the multiple character sequences to obtain the code completion model.
[0120] Optionally, the model training module is also used to: for any one character sequence among the multiple character sequences, randomly delete part of the character sequence in the character sequence to obtain a target character sequence; determine the target position of the deleted character sequence in the target character sequence; according to the target position, determine a first character sequence and a second character sequence from the target character sequence; the first character sequence represents the character sequence of the preceding part of the target position of the target character sequence, and the second character sequence represents the character sequence of the following part of the target position of the target character sequence; train the initial model to predict the deleted character sequence based on the first character sequence and the second character sequence.
[0121] Optionally, the device further comprises:
[0122] A model testing module is used to input a first character sequence and a second character sequence corresponding to any target character sequence into the initial model to obtain a completed character sequence output by the initial model; if the completed character sequence is the same as a deleted character sequence in any target character sequence, the initial model is determined as the code completion model; if the completed character sequence is different from the deleted character sequence in any target character sequence, the initial model is optimized according to a plurality of character sequences corresponding one-to-one to the plurality of source codes.
[0123] The code writing and error correction device provided by the above-mentioned embodiment of the present disclosure and the code writing and error correction method provided by the embodiment of the present disclosure are based on the same inventive concept and have the same beneficial effects as the methods adopted, run or implemented by the application programs stored therein.
[0124] The present disclosure also provides a computer device to execute the above-mentioned code writing and error correction method. Figure 4 , which shows a schematic diagram of a computer device provided by some embodiments of the present disclosure. Figure 4 As shown, the computer device 4 includes: a processor 400, a memory 401, a bus 402 and a communication interface 403, wherein the processor 400, the communication interface 403 and the memory 401 are connected via the bus 402; the memory 401 stores a computer program that can be run on the processor 400, and the processor 400 executes the aforementioned Figure 1 to Figure 2 A code writing error correction method is provided in any of the illustrated implementation modes.
[0125] The memory 401 may include a high-speed random access memory (RAM), and may also include a non-volatile memory, such as at least one disk memory. The communication connection between the system network element and at least one other network element is realized through at least one communication interface 403 (which may be wired or wireless), and the Internet, wide area network, local area network, metropolitan area network, etc. may be used.
[0126] The bus 402 may be an ISA bus, a PCI bus, or an EISA bus. The bus may be divided into an address bus, a data bus, a control bus, etc. The memory 401 is used to store programs. After receiving the execution instruction, the processor 400 executes the program. Figure 1 to Figure 2The code writing error correction method disclosed in any of the illustrated embodiments may be applied to the processor 400 or implemented by the processor 400 .
[0127] The processor 400 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit in the processor 400 or the instruction in the form of software. The above processor 400 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The disclosed methods, steps and logic block diagrams in the embodiments of the present disclosure can be implemented or executed. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in conjunction with the embodiments of the present disclosure can be directly embodied as a hardware decoding processor to be executed, or a combination of hardware and software modules in the decoding processor can be executed. The software module can be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 401, and the processor 400 reads the information in the memory 401 and completes the steps of the above method in combination with its hardware.
[0128] The computer device provided by the embodiment of the present disclosure and the code writing and error correction method provided by the embodiment of the present disclosure are based on the same inventive concept and have the same beneficial effects as the methods adopted, run or implemented by them.
[0129] The present disclosure also provides a computer-readable storage medium corresponding to the code writing and error correction method provided in the above embodiment. Figure 5 The computer-readable storage medium shown is a CD 30 on which a computer program (ie, a program product) is stored. When the computer program is run by a processor, the code writing and error correction method provided in any of the aforementioned embodiments will be executed.
[0130] It should be noted that examples of the computer-readable storage medium may also include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other optical or magnetic storage media, which are not listed here one by one.
[0131] The computer-readable storage medium provided by the above-mentioned embodiments of the present disclosure and the code writing and error correction method provided by the embodiments of the present disclosure are based on the same inventive concept and have the same beneficial effects as the methods adopted, run or implemented by the application programs stored therein.
[0132] It should be noted that:
[0133] In the description provided herein, a large number of specific details are described. However, it is understood that the embodiments of the present disclosure can be practiced without these specific details. In some instances, well-known structures and technologies are not shown in detail so as not to obscure the understanding of this description.
[0134] Similarly, it should be understood that in order to streamline the present disclosure and aid in understanding one or more of the various inventive aspects, in the above description of the exemplary embodiments of the present disclosure, the various features of the present disclosure are sometimes grouped together into a single embodiment, figure, or description thereof. However, this disclosed method should not be interpreted as reflecting that the claimed disclosure requires more features than those explicitly recited in each claim. More specifically, as reflected in the claims below, the inventive aspects lie in less than all the features of the individual embodiments disclosed above. Therefore, the claims that follow the specific embodiment are hereby expressly incorporated into the specific embodiment, with each claim itself serving as a separate embodiment of the present disclosure.
[0135] In addition, those skilled in the art will appreciate that, although some embodiments described herein include certain features included in other embodiments but not other features, the combination of features of different embodiments is meant to be within the scope of this disclosure and form different embodiments. For example, in the claims below, any one of the claimed embodiments may be used in any combination.
[0136] The above is only a preferred specific implementation of the present disclosure, but the protection scope of the present disclosure is not limited thereto. Any changes or substitutions that can be easily thought of by any technician familiar with the technical field within the technical scope disclosed in the present disclosure should be included in the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure should be based on the protection scope of the claims.
Claims
1. A method for correcting errors in code writing, characterized in that: The method comprises: In response to a code input operation, comparing the completed code output by the code completion model with the target code input in real time; If the completion code is different from the target code, detecting whether the key value corresponding to the character in the completion code that does not match the character in the target code satisfies a preset position condition, wherein the character that does not match the character in the completion code is the same as the character position of the second character in the target code, but has different contents; If the position of the key value corresponding to the unmatched character on the keyboard meets the preset position condition, the target code is used as the code to be corrected; The first character is used to perform error correction processing on the code to be corrected to obtain a target code after error correction.
2. The method according to claim 1, characterized in that The detecting whether the key value corresponding to the character in the completion code that does not match the character in the target code satisfies a preset position condition includes: Determine a first character from the complement code and determine a second character from the target code, wherein the character position of the first character in the complement code is the same as the character position of the second character in the target code, but the content is different; Determine whether a first position on the keyboard of the key value corresponding to the first character and a second position on the keyboard of the key value corresponding to the second character meet the preset position condition.
3. The method according to claim 2, characterized in that The preset position condition includes: the first position is the same as or adjacent to the second position.
4. The method according to claim 1 or 2, characterized in that: Using the first character to perform error correction processing on the code to be corrected to obtain a target code after error correction, comprising: The first character is used to replace the second character in the code to be corrected, so as to generate the corrected target code.
5. The method according to claim 1 or 2, characterized in that: The method further comprises: After obtaining the error-corrected target code, sending an error correction cancellation prompt message to the user terminal; If an error correction cancellation instruction sent by the user terminal is received, the first character in the error-corrected target code is replaced with the second character to obtain the target code.
6. The method according to claim 1 or 2, characterized in that: The method further comprises: Get multiple source codes; For any one of the multiple source codes, perform word segmentation processing on the source code to generate a character sequence corresponding to the source code, thereby obtaining multiple character sequences corresponding to the multiple source codes one by one; The initial model is trained according to the multiple character sequences to obtain the code completion model.
7. The method according to claim 6, characterized in that Training the initial model according to the multiple character sequences to obtain the code completion model includes: For any character sequence among the multiple character sequences, randomly delete part of the character sequence in the character sequence to obtain a target character sequence; Determine the target position of the deleted character sequence in the target character sequence; According to the target position, a first character sequence and a second character sequence are determined from the target character sequence; the first character sequence represents a character sequence of a preceding portion of the target position of the target character sequence, and the second character sequence represents a character sequence of a succeeding portion of the target position of the target character sequence; The initial model is trained to predict the deleted character sequence based on the first character sequence and the second character sequence.
8. The method according to claim 7, characterized in that After training the initial model to predict the deleted character sequence based on the first character sequence and the second character sequence, the method further includes: Inputting a first character sequence and a second character sequence corresponding to any target character sequence into the initial model to obtain a complementary character sequence output by the initial model; If the completion character sequence is the same as the deleted character sequence in any one of the target character sequences, the initial model is determined as the code completion model.
9. The method according to claim 8, characterized in that The method further comprises: If the complement character sequence is different from the deleted character sequence in any one of the target character sequences, the initial model is optimized according to a plurality of character sequences corresponding one-to-one to the plurality of source codes.
10. A code writing error correction device, characterized in that: The device comprises: A code comparison module, for comparing the completed code output by the code completion model with the target code input in real time in response to a code input operation; a conditional judgment module, configured to detect whether a key value corresponding to a character in the completion code that does not match the character in the target code satisfies a preset position condition if the completion code is different from the target code, wherein the character that does not match the character in the completion code is a character whose character position in the completion code is the same as the character position of the second character in the target code but whose content is different; A module for determining a code to be corrected, configured to use the target code as the code to be corrected if the position of the key value corresponding to the unmatched character on the keyboard satisfies the preset position condition; The code error correction module is used to use the first character to perform error correction processing on the code to be corrected to obtain a target code after error correction.
Citation Information
Patent Citations
Input error correction method and device for Chinese phonetic alphabet and electronic equipment
CN109597500A
Input error correction method and device
CN110488990A
Code completion method and device, equipment and storage medium
CN117744638A
Character input error correction
US20190138113A1
