Multi-language code generation method based on sentence-level language code conversion model
Through a multilingual code generation method based on the sentence-level code switching model, machine translation and code large model technology are used to solve the problem of inaccurate codes in multilingual code generation and achieve higher code consistency and accuracy.
Patent Information
- Application Number
- CN202410588587.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-13
- Publication Date
- 2024-08-23
AI Technical Summary
Existing multi-language code generation technology has the problem of code inaccuracy in code generation, mainly because code switching destroys the grammatical structure of the code and data replacement destroys the instruction intention, and the problem of polysemy has not been effectively solved.
Adopt a multilingual code generation method based on the sentence-level code-switching model, introduce code information and contextual information through machine translation and code large model technology, and use sentence-level segmentation and beam search to improve code consistency and accuracy .
It significantly improves the accuracy of multi-language code generation, solves the problems of word polysemy and code irrelevance in code switching, and improves the context consistency and code consistency of generated code.
Smart Images

Figure CN118535149A
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of data augmentation, and particularly relates to a multi - language code generation method based on a sentence - level code - switching model. Background Art
[0002] The multi - language code generation task is to generate corresponding correct code given an instruction describing the code function, where the instruction describing the code can be in multiple languages. Code - switching is a common data augmentation method in multiple languages. It aligns the hidden layer representations between languages during the fine - tuning stage by randomly replacing words in a sentence with their corresponding words in other languages. For example, the word "你" in "你吃了吗" is replaced with "you", and after conversion, it becomes "you吃了吗". However, this method has limitations when applied to code generation. On the one hand, replacing keywords in the code will destroy the syntax structure of the code itself. For example, replacing "while" with "然而", " <messege>"Replace it with <information>; on the other hand, the instructions describing the code function may contain the data that needs to be operated on, and replacing this data may destroy the original intention of the instructions. For example, "delete the key-value pair with the key value of 'one'" is replaced with "delete the key-value pair with the key value of 'one'". In addition, there is also the problem of polysemy in code-switching itself. To solve these problems, it is necessary to combine the code information and the context information, while the existing methods do not consider this information, resulting in the problem that the generated code by the existing multi-language code generation technology is inaccurate." Summary of the Invention
[0003] The object of the present invention is to solve the problem that the generated code by the existing multi-language code generation technology is inaccurate. The present invention proposes a multi-language code generation method based on a sentence-level code-switching model."
[0004] A multi-language code generation method based on a sentence-level code-switching model, characterized by comprising the following steps:"
[0005] I. Build a multi-language code generation model; obtain a trained multi-language code generation model."
[0006] II. Input the multi-language task instructions into the trained multi-language code generation model; obtain the task code."
[0007] The multi-language task instructions are task instructions described in P languages; P is a positive integer, and the P languages are natural languages. The natural languages include: English, Chinese, French, German, etc.; the multi-language code generation model is, for example, GitHub Copilot, OpenAI Codex, etc."
[0008] In the above step I of building a multi-language code generation model; obtain a trained multi-language code generation model; the specific process is as follows:"
[0009] Step 1. Obtain a training set."
[0010] Step 2. Build a multi-language code generation model; fine-tune the multi-language code generation model according to the training set to obtain a trained multi-language code generation model."
[0011] In the above step 1 of obtaining a training set; the specific process is as follows:"
[0012] Step 1-1. Build a sentence-level code-switching model and a source language data set."
[0013] Step 1-2. Input each piece of data in the source language data set into the sentence-level code-switching model to obtain the new data corresponding to each piece of data."
[0014] For each data in the source language data set, one of the X target languages to be aligned is randomly selected as the target language, where X is a positive integer;
[0015] Step 13: Use all new data as training sets.
[0016] In the step 1, the selected data is fed into the sentence-level code switching model to obtain new data; the specific process is:
[0017] S1: Input the source language sentence S to be converted into the machine translation, and translate the source language sentence S into the target language sentence T.
[0018] S2: Segment the source language sentence S at the sentence level to obtain the source language sentence set SEG(S);
[0019] Segment the target language sentence T at the sentence level to obtain the target language sentence set SEG(T);
[0020] S3: Use the sentence alignment algorithm to align the source language sentence set SEG(S) and the target language sentence set SEG(T) obtained in S2 to obtain the aligned list {(S 1:i ,T 1:p ),..,(S j:m ,T q:n )}; ensure that the semantics of the aligned clauses between the source language and the target language are consistent.
[0021] S4: Use beam search to minimize the perplexity level (PPL) of the code model, and reorganize the sentences of the source language and the target language to obtain the final sentence.
[0022] The beneficial effects of the present invention are:
[0023] The present invention proposes a multi-language code generation method based on a sentence-level code conversion model. Aiming at the technical problems of polysemy and irrelevant codes in the original code conversion technology, the method uses machine translation and large code model technology to effectively introduce code information and context information into the model, enhances the context consistency and code consistency of code conversion sentences, and the generated new data can significantly improve the multi-language code generation capability of the model. The key of the present invention is to use sentence-level segmentation instead of word-level segmentation to solve the polysemy of a word, and use the PPL combination sentence of the large code model to introduce code information, which solves the problems of polysemy and irrelevant codes in the original code conversion technology. Thereby improving the accuracy of the generated code in the multi-language code generation technology. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] Figure 1 It is a flow chart of the sentence alignment algorithm of the present invention;
[0025] Figure 2 It is a flow chart of the sentence-level code switching model of the present invention. DETAILED DESCRIPTION
[0026] Specific implementation method 1: A multi-language code generation method based on a sentence-level code switching model, comprising:
[0027] 1. Build a multi-language code generation model; obtain a trained multi-language code generation model;
[0028] 2. Input the multi-language task instructions into the trained multi-language code generation model to obtain the task code;
[0029] The multi-language task instruction is a task instruction described in P languages; P is a positive integer, and the P languages are natural speech. The natural languages include: English, Chinese, French, German, etc.; the multi-language code generation model is such as GitHub Copilot, OpenAI Codex, etc.;
[0030] Specific implementation method 2: The difference between this implementation method and specific implementation method 1 is that in the first implementation method, a multi-language code generation model is constructed; a trained multi-language code generation model is obtained; the specific process is:
[0031] Step 1: Get the training set;
[0032] Step 2: Build a multi-language code generation model; fine-tune the multi-language code generation model according to the training set to obtain a trained multi-language code generation model;
[0033] The present invention proposes a multi-language code generation method based on a sentence-level code conversion model. Aiming at the technical problems of polysemy and irrelevance of codes in the original code conversion technology, the method uses machine translation and large code model technology to effectively introduce code information and context information into the model, enhance the context consistency and code consistency of code conversion sentences, and the generated new data can significantly improve the multi-language code generation capability of the model. The key of the present invention is to use sentence-level segmentation instead of word-level segmentation to solve the polysemy of a word, and use the PPL combination sentence of the large code model to introduce code information, which solves the problem of polysemy and irrelevance of codes in the original code conversion technology. Thereby improving the accuracy of the generated code of the multi-language code generation technology. The other steps and parameters are the same as those in the first specific implementation mode.
[0034] Specific implementation method three: The difference between this implementation method and specific implementation method one is that the training set is obtained in step one; the specific process is:
[0035] Step 1: Build a sentence-level code-switching model and source language dataset.
[0036] Each piece of data in the source language data set can be represented by a tuple (instruction, output code).
[0037] Step 1 and 2: Send each piece of data in the source language data set into the sentence-level code conversion model to obtain new data corresponding to each piece of data;
[0038] For each data in the source language data set, one of the X target languages to be aligned is randomly selected as the target language, where X is a positive integer;
[0039] Step 13: All new data are used as training sets, and the other steps and parameters are the same as those in the specific implementation methods 1 to 2.
[0040] Specific implementation mode 4: This implementation mode is different from specific implementation modes 1 to 4 in that in step 1 and 2, a piece of data in the source language data set is fed into the sentence-level code conversion model, and the specific process of obtaining the new data corresponding to the piece of data is as follows:
[0041] S1: Take the data as the source language sentence S to be converted, input the source language sentence S to be converted into the machine translation model, and translate the source language sentence S into the target language sentence T.
[0042] S2: Segment the source language sentence S at the sentence level to obtain the source language sentence set SEG(S);
[0043] Segment the target language sentence T at the sentence level to obtain the target language sentence set SEG(T);
[0044] S3: Use the sentence alignment algorithm to align the source language sentence set SEG(S) and the target language sentence set SEG(T) obtained in S2 t times to obtain the optimal aligned list A; ensure that the semantics of the aligned sentences between the source language and the target language are consistent.
[0045] S4: Use beam search to minimize the perplexity PPL of the code model, reorganize the sentences of the source language and the target language, and obtain the final sentence F. The final sentence F is used as the new data corresponding to the data to ensure that the semantics of the aligned sentences between the source language and the target language are consistent. The other steps and parameters are the same as those of the specific implementation methods one to three.
[0046] Specific implementation mode five: The difference between this implementation mode and specific implementation modes one to four is that the machine translation model in S1 is gpt3.5-turbo, and the other steps and parameters are the same as those in specific implementation modes one to four.
[0047] Specific implementation example 6: This implementation example is different from specific implementation examples 1 to 5 in that, in S2, the source language sentence S is segmented at the sentence level to obtain a source language sentence set SEG(S);
[0048] The target language sentence T is segmented at the sentence level to obtain the target language sentence set SEG(T); the specific process is as follows:
[0049] Use regular expressions to split the source language sentence S into a set of clauses, and obtain the source language sentence set SEG(S);
[0050] SEG(S)={S1,..,S m }
[0051] In the formula, S m It represents the mth clause after the source language sentence S is segmented at the clause level; m is a positive integer
[0052] The regular expression is a text processing tool used to search, replace, check or operate a string that meets a specific pattern; suppose we have an English text "Hello! My name is A. How are you today? I'm here to help. Let's solve your problems together. Do you need assistance with anything else?"
[0053] When dividing sentences, we can use punctuation and whitespace to determine the end of each sentence. For the above paragraph, we usually use periods (.), question marks (?), and exclamation marks (!) to divide it, and get sentences 1. "Hello!" 2. "My name is A." 3. "How are you today?" 4. "I'm here to help." 5. "Let's solve your problems together." 6. "Do you need assistance with anything else?", and combine sentences 1 to 5 into a sentence set.
[0054] Use regular expressions to split the target language sentence T into a set of clauses, and obtain the target language clause set SEG(T);
[0055] SEG(T)={T1,..,T n }
[0056] Where, T n It represents the nth sentence after the target language sentence T is segmented at the sentence level, where n is a positive integer; the other steps and parameters are the same as those in the specific implementation modes one to five.
[0057] Specific implementation method 7: The difference between this implementation method and specific implementation methods 1 to 6 is that, in S3, a sentence alignment algorithm is used to align the source language sentence set SEG(S) and the target language sentence set SEG(T) obtained in S2 t times to obtain an optimally aligned list A;
[0058]
[0059] in, refers to the i-th best alignment in the list of alignments A; Represents the source language sentence set from the i-th sentence to the s-th sentence i The clauses are put together in sequence to form a sentence. represents the sentence composed of the sequence of clauses from the i-th clause to the i-th clause of the target language clause set, s i The value range is from i to m, t i The value range of is from i to n, i∈[1,z];
[0060] For example, the source language clause set SEG(S) has three clauses: S1: "you" S2: "eaten" S3: "did you"? 1:1, The table is "you", element S 1:2, It means "you eat", element S 1:3, It's "Have you eaten it, element S 2:2, It means "eaten", element S 2:3, That is "Have you eaten?", and the target language sentence set is processed in the same way.
[0061] The i-th alignment is performed in S3 to obtain the i-th alignment The specific process is:
[0062] S3.1: Initialize alignment C;
[0063] S3.2: Construct source language candidate alignment C1 and target language candidate alignment C2 based on alignment C,
[0064] S3.3: Compute the cosine similarity L between the elements in alignment C C ;
[0065] Compute the cosine similarity between elements in the source language candidate alignment C1
[0066] Compute the cosine similarity between elements in the target language candidate alignment C2
[0067] S3.4: Determine the cosine similarity L C , and The size of
[0068] like When the value is the largest, update the source language candidate alignment C1 to the new alignment C and return to S3.3;
[0069] like When the value is the largest, update the target language candidate alignment C2 to the new alignment C and return to S3.3;
[0070] If L C When the maximum value is reached, alignment C is used as the optimal alignment. The i-th alignment is completed; the other steps and parameters are the same as those in the specific implementation modes 1 to 6.
[0071] Specific implementation eight: This implementation differs from specific implementations one to seven in that the specific process of initializing the alignment C in S3.1 is as follows:
[0072] S3.1.1: Take the sentence consisting of the i-th clause to the i-th clause of the source language clause set SEG(S) as element S i:i, ;
[0073] For example, the source language clause set SEG(S) has three clauses: S1: "you" S2: "eaten" S3: "did you"? 1:1, The table is "you", element S 2:2, It is "eaten", and the same is true for the target language sentence set processing;
[0074] S3.1.2: Take the sentence consisting of the i-th clause to the i-th clause of the target language clause set SEG(T) as element T i:i
[0075] S3.1.3: Initialize alignment C = (S i:,i , T i:i );
[0076] Assume that the alignment C in S3.2 is C=(S i:p ,T i:q ), the source language candidate alignment C1 and the target language candidate alignment C2 are constructed according to the alignment C. The specific process is:
[0077] Align elements S in C i:,p Sequentially add the next clause of the source language clause set SEG(S) to obtain the source language S i:,p+1 ; According to the source language S i:,p+1 Construct source language candidate alignment C1 = (S i:,p+1 ,T i:q );
[0078] For example, the source language sentence set SEG(S) has three clauses: S1: "you" S2: "eat" S3: "did you"? Then the element S of alignment C is 1:2, That is, "you ate", and the next clause of the source language clause set SEG(S) is added sequentially to get the element S 1:3, That is, "Have you eaten?", and the same is true for the target language sentence set.
[0079] Align elements T in C to i:q Sequentially add the next clause of the target language clause set SEG(T) to obtain the target language T i:q+1 , according to the target language T i:q+1 Construct the target language candidate alignment C2 = (S i:p ,T i:q+1 ) The other steps and parameters are the same as those in Specific Implementation Methods 1 to 7.
[0080] Specific implementation method 9: This implementation method is different from specific implementation methods 1 to 8 in that it is assumed that the alignment C in S3.3 is equal to (S i:p ,T i:q ); Source language candidate alignment C1 = (S i:,p+1 ,T i:q ); target language candidate alignment C2 = (S i:p ,T i:q+1 ), calculate the cosine similarity L between the elements in alignment C C ;
[0081] Compute the cosine similarity between elements in the source language candidate alignment C1
[0082] Compute the cosine similarity between elements in the target language candidate alignment C2 The specific process is:
[0083] S3.3.1: Align the elements S in C i:p and T i:q Input the LaBSE model and get the vector representation LaBSE (S i:p ),LaBSE(T i:q ),
[0084] Align the source language candidate to the elements in C1 S i:p+1 and T i:q Input the LaBSE model, and the resulting vector represents LaBSE (S i:p+1 ),LaBSE(T i:q ),
[0085] Align the target language candidates to the elements S in C2 i:p and T i:q+1 Input the LaBSE model, and the resulting vector represents LaBSE (S i:p ),LaBSE(T i:q+1 ),
[0086] S3.3.2: Compute the element S aligned to C i:p and T i:q The cosine similarity L C , expressed as:
[0087] L C = cosine_similarity(LaBSE(S i:p ),LaBSE(T i:q ))
[0088] Where, cosine_similarity() represents the cosine similarity function;
[0089] Calculate the element S in the source language candidate alignment C1 i:p+1 and T i:q The cosine similarity of The formula is:
[0090]
[0091] Calculate the element S in the target language candidate alignment C2 i:p and T i:q+1 The cosine similarity of The formula is:
[0092] The other steps and parameters are the same as those in Specific Embodiments 1 to 8.
[0093] Specific implementation method 10: The difference between this implementation method and specific implementation methods 1 to 9 is that beam search is used in S4 to minimize the perplexity PPL, and the source language and target language sentences are recombined to obtain the final sentence F. The specific process is as follows:
[0094] S4.1: Set the parameter k of the search to be infinite, and use beam search to reorganize the sentences of the source language and the target language to obtain H combined sentences; H is a positive integer;
[0095] The method of using beam search to recombine the sentences of the source language and the target language is to use beam search to splice the aligned elements in order to obtain all the ways of combining sentences; one way of recombination the sentences of the source language and the target language is: concatanate(a1, a2.., a t )elementa i Represented as the i-th alignment A i Elements of the source language sentence and target language sentences Choose one;
[0096] S4.2: Calculate the perplexity PPL of the H combined sentences;
[0097] Perplexity PPL is an indicator used to evaluate the performance of a language model. It measures the prediction ability of a language model for a given set of text sequences and is a well-known process.
[0098] S4.2: Select the combined sentence with the lowest perplexity PPL as the final sentence F; the specific process is:
[0099]
[0100] a i ∈A i ,i=1,2...,t
[0101] Among them A i refers to the ith alignment in the alignment list A, and F is the final sentence, starting from the ith alignment A i Elements of the source language sentence and target language sentences Select one of them to be represented as element a i ; concatanate() means to concatenate elements in sequence. Indicates selecting the combined sentence with the smallest perplexity PPL. The other steps and parameters are the same as those in the first to ninth embodiments.
[0102] The above only describes the preferred embodiments of the present invention. It should be understood that the present invention is not limited to the above specific implementation methods. Although the present invention has been disclosed as above in the preferred embodiments, it is not used to limit the present invention. Any technician familiar with the profession can make some changes or modify the technical contents disclosed above into equivalent embodiments with equivalent changes without departing from the scope of the technical solution of the present invention. However, any simple modification, equivalent replacement and improvement made to the above embodiments without departing from the content of the technical solution of the present invention, based on the technical essence of the present invention, within the spirit and principles of the present invention, still fall within the protection scope of the technical solution of the present invention.< / messege>
Claims
1. A multilingual code generation method based on sentence-level code switching model, It is characterized in that The following steps are involved:
1. Build a multi-language code generation model; obtain a trained multi-language code generation model; 2. Input the multi-language task instructions into the trained multi-language code generation model to obtain the task code; The multilingual task instruction is a task instruction described in P languages; P is a positive integer, and the P languages are natural speech.
2. A multilingual code generation method based on a sentence-level code switching model according to claim 1, It is characterized in that In the first step, a multi-language code generation model is constructed; and a trained multi-language code generation model is obtained; the specific process is: Step 1: Get the training set; Step 2: Build a multi-language code generation model; train the multi-language code generation model according to the training set to obtain a trained multi-language code generation model.
3. The multilingual code generation method based on the sentence-level code switching model according to claim 2, It is characterized in that In the step 1, a training set is obtained; the specific process is as follows: Step 1: Build a sentence-level code-switching model and source language dataset. Step 1 and 2: Send each piece of data in the source language data set into the sentence-level code conversion model to obtain new data corresponding to each piece of data; Step 13: Use all new data as training sets.
4. The multilingual code generation method based on the sentence-level code switching model according to claim 3, It is characterized in that In the steps 1 and 2, a piece of data in the source language data set is fed into the sentence-level code conversion model to obtain the new data corresponding to the piece of data as follows: S1: Take a piece of data in the source language dataset as the source language sentence S to be converted, input the source language sentence S to be converted into the machine translation model, and translate the source language sentence S into the target language sentence T. S2: Segment the source language sentence S at the sentence level to obtain the source language sentence set SEG(S); Segment the target language sentence T at the sentence level to obtain the target language sentence set SEG(T); S3: Use the sentence alignment algorithm to align the source language sentence set SEG(S) and the target language sentence set SEG(T) obtained in S2 t times to obtain the optimally aligned list A; S4: Use beam search to minimize the perplexity PPL, reorganize the sentences of the source language and the target language, and obtain the final sentence F, and use the final sentence F as the new data corresponding to the data.
5. The multilingual code generation method based on the sentence-level code switching model according to claim 4, It is characterized in that The machine translation model in S1 is gpt3.5-turbo.
6. The multilingual code generation method based on the sentence-level code switching model according to claim 5, It is characterized in that In S2, the source language sentence S is segmented at the sentence level to obtain a source language sentence set SEG(S); The target language sentence T is segmented at the sentence level to obtain the target language sentence set SEG(T); the specific process is as follows: Use regular expressions to split the source language sentence S into a set of clauses, and obtain the source language sentence set SEG(S); MON(S)={S 1 ,..,S m } In the formula, S m It represents the mth clause after the source language sentence S is segmented at the clause level; m is a positive integer Use regular expressions to split the target language sentence T into a set of clauses, and obtain the target language clause set SEG(T); SEG(T)={T 1 ,..,T n } Where, T n It represents the nth clause after the target language sentence T is segmented at the clause level, where n is a positive integer.
7. The multilingual code generation method based on the sentence-level code switching model according to claim 6, It is characterized in that In S3, a sentence alignment algorithm is used to align the source language sentence set SEG(S) and the target language sentence set SEG(T) obtained in S2 for t times to obtain an optimally aligned list A; in, refers to the i-th best alignment in the list of alignments A; Represents the source language sentence set from the i-th sentence to the s-th sentence i The clauses are put together in sequence to form a sentence. represents the sentence composed of the sequence of clauses from the i-th clause to the i-th clause of the target language clause set, s i The value range is from i to m, t i The value range of is from i to n, i∈[1,z]; The i-th alignment is performed in S3 to obtain the i-th alignment The specific process is: S3.1: Initialize alignment C; S3.2: Construct source language candidate alignment C based on alignment C 1 and the target language candidate alignment C 2 , S3.3: Compute the cosine similarity L between the elements in alignment C C ; Compute the source language candidate alignment C 1 The cosine similarity between the elements in Calculate the target language candidate alignment C 2 The cosine similarity between the elements in S3.4: Determine the cosine similarity L C , and The size of like When the maximum value is reached, align the source language candidates to C 1 Update to the new alignment C and return to S3.3; like When the maximum value is reached, align the target language candidates to C 2 Update to the new alignment C and return to S3.3; If L C When the maximum value is reached, alignment C is used as the optimal alignment. The i-th alignment ends;.
8. The multilingual code generation method based on the sentence-level code switching model according to claim 7, It is characterized in that The specific process of initializing alignment C in S3.1 is as follows: S3.1.1: Take the sentence consisting of the i-th clause to the i-th clause of the source language clause set SEG(S) as element S i:i, ; S3.1.2: Take the sentence consisting of the i-th clause to the i-th clause of the target language clause set SEG(T) as element T i:i S3.1.3: Initialize alignment C = (S i:,i , T i:i ); Assume that the alignment C in S3.2 is C=(S i:p ,T i:q ), construct source language candidate alignment C according to alignment C 1 and the target language candidate alignment C 2 , the specific process is: Align elements S in C i:,p Sequentially add the next clause of the source language clause set SEG(S) to obtain the source language S i:,p+1 ; According to the source language S i:,p+1 Construct source language candidate alignment C 1 =(S i:,p+1 ,T i:q ); Align elements T in C i:q Sequentially add the next clause of the target language clause set SEG(T) to obtain the target language T i:q+1 , according to the target language T i:q+1 Construct target language candidate alignment C 2 =(S i:p ,T i:q+1 ).
9. The multilingual code generation method based on the sentence-level code switching model according to claim 8, It is characterized in that Assume that the alignment C in S3.3 is C=(S i:p ,T i:q ); source language candidate alignment C 1 =(S i:,p+1 ,T i:q );Target language candidate alignment C 2 =(S i:p ,T i:q+1 ), calculate the cosine similarity L between the elements in alignment C C ; Compute the source language candidate alignment C 1 The cosine similarity between the elements in Calculate the target language candidate alignment C 2 The cosine similarity between the elements in The specific process is: S3.3.1: Align the elements S in C i:p and T i:q Input the LaBSE model and get the vector representation LaBSE (S i:p ),LaBSE(T i:q ), Align source language candidates to C 1 The elements of the elements in S i:p+1 and T i:q Input the LaBSE model, and the resulting vector represents LaBSE (S i:p+1 ),LaBSE(T i:q ), Align the target language candidates to C 2 The element S in i:p and T i:q+1 Input the LaBSE model, and the resulting vector represents LaBSE (S i:p ),LaBSE(T i:q+1 ), S3.3.2: Compute the element S aligned to C i:p and T i:q The cosine similarity L C , expressed as: L C =cosine_similarity(LaBSE(S i:p ),LaBSE(T i:q )) Where cosine_similarity() represents the cosine similarity function; Compute the source language candidate alignment C 1 The element S in i:p+1 and T i:q Cosine similarity of The formula is: Calculate the target language candidate alignment C 2 The element S in i:p and T i:q+1 Cosine similarity of The formula is:
10. The multi-language code generation method based on the sentence-level code switching model according to claim 9, It is characterized in that In S4, beam search is used to minimize the perplexity PPL, and the source language and target language sentences are recombined to obtain the final sentence F. The specific process is: S4.1: Set the parameter k of the search to be infinite, and use beam search to reorganize the sentences of the source language and the target language to obtain H combined sentences; H is a positive integer; S4.2: Calculate the perplexity PPL of the H combined sentences; S4.2: Select the combined sentence with the lowest perplexity PPL as the final sentence F; the specific process is: a i ∈A i ,i=1,2...,t Among them A i refers to the ith alignment in the alignment list A, and F is the final sentence, starting from the ith alignment A i Elements of the source language sentence and target language sentences Select one of them to be represented as element a i ; concatanate() means to concatenate elements in sequence. Indicates selecting the combined sentence with the smallest perplexity PPL.
