Code conversion method, code conversion model training method and device

By generating semantic similarity between initial query statements and preset query statements, and utilizing the trained code conversion model, the target code is automatically analyzed and generated. This solves the problems of code migration failure and low efficiency in existing technologies, and achieves high accuracy and high efficiency in code conversion.

CN121832946APending Publication Date: 2026-04-10CHINA TELECOM CLOUD TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-11-28
Publication Date
2026-04-10

AI Technical Summary

Technical Problem

Existing technologies often fail due to incomplete data caused by code migration dependencies on mapping relationships. They also fail to accurately analyze the source code context and require manual assistance, resulting in low efficiency.

Method used

By generating an initial query statement, obtaining the semantic similarity of the preset query statement, and using the trained code conversion model, the system automatically analyzes and generates target code that is adapted to the target architecture.

Benefits of technology

It achieves high accuracy and efficiency in code conversion, avoids failures caused by incomplete mapping data, and requires no manual assistance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121832946A_ABST
    Figure CN121832946A_ABST
Patent Text Reader

Abstract

The invention discloses a code conversion method, a code conversion model training method and device, electronic equipment and a readable storage medium, and the code conversion method comprises the steps: generating an initial query statement according to a to-be-converted code and a target architecture; the target architecture is different from an architecture adaptive to the to-be-converted code; obtaining a plurality of preset query statements, and respectively obtaining semantic similarity between each preset query statement and the initial query statement; obtaining a target query statement from a plurality of preset query statements according to the semantic similarity; and inputting the initial query statement and the target query statement into the trained code conversion model to accurately obtain a target code which has the same semantics as the to-be-converted code and is matched with the target architecture, so that heterogeneous migration of the code is realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application belongs to the field of code processing technology, specifically relating to a code conversion method, a code conversion model training method, an apparatus, an electronic device, and a readable storage medium. Background Technology

[0002] Code migration is the process of converting code adapted to one runtime environment, development platform, or architecture into code adapted to another runtime environment, development platform, or architecture.

[0003] In related technologies, code that is compatible with one operating environment, development platform, or architecture is replaced with code that is compatible with another operating environment, development platform, or architecture by using code mapping relationships under different operating environments, development platforms, or architectures.

[0004] However, this method relies on the construction of mapping relationships, which may lead to code migration failure due to incomplete mapping data. Furthermore, this method cannot accurately analyze the context of the source code, resulting in low accuracy of code migration. The migration process also requires manual assistance, leading to low efficiency. Summary of the Invention

[0005] The purpose of this application is to provide a code conversion method, a code conversion model training method, an apparatus, an electronic device, and a readable storage medium, which can solve at least some of the above-mentioned technical problems in the related art.

[0006] In a first aspect, embodiments of this application provide a code conversion method, including: Based on the code to be converted and the target architecture, an initial query statement is generated; the target architecture is different from the architecture adapted to the code to be converted. Obtain multiple preset query statements, and obtain the semantic similarity between each preset query statement and the initial query statement respectively; Based on the semantic similarity, the target query statement is obtained from multiple preset query statements; The initial query statement and the target query statement are input into the trained code conversion model to obtain target code that has the same semantics as the code to be converted and is adapted to the target architecture.

[0007] Optionally, the preset query statement is in vector format; the semantic similarity between each preset query statement and the initial query statement is obtained, including: The initial query statement is vectorized to obtain a first vector; For each preset query statement, the semantic similarity between the preset query statement and the initial query statement is obtained based on the preset query statement and the first vector.

[0008] Optionally, the method further includes: Retrieve the query statement to be processed from the preset database; The query statement to be processed is vectorized to obtain a preset query statement in vector format; The method for vectorizing the query statement to be processed is the same as the method for vectorizing the initial query statement.

[0009] Secondly, embodiments of this application provide a code conversion model training method for training a code conversion model as described in the first aspect of the code conversion method, the code conversion model training method comprising: Acquire training data; there are multiple types of training data, and each type of training data is adapted to the architecture corresponding to the training data. Using the training data, the code conversion model is trained to obtain the trained code conversion model.

[0010] Optionally, the code conversion model is a pre-trained large language model; The step of using the training data to train the code conversion model to obtain the trained code conversion model includes: Using the training data, the pre-trained large language model is fine-tuned to obtain a trained code conversion model.

[0011] Optionally, the training data may include at least one of the following: assembly instructions, compiler options, compiler macros, and built-in functions.

[0012] Thirdly, embodiments of this application provide a code conversion apparatus, including: The first acquisition module is used to generate an initial query statement based on the code to be converted and the target architecture; The second acquisition module is used to acquire multiple preset query statements and acquire the semantic similarity between each preset query statement and the initial query statement respectively; The third acquisition module is used to acquire the target query statement from multiple preset query statements based on the semantic similarity. The fourth acquisition module is used to input the initial query statement and the target query statement into the trained code conversion model to obtain target code that has the same semantics as the code to be converted and is compatible with the target architecture.

[0013] Fourthly, embodiments of this application provide a code conversion model training apparatus, which is used to train a code conversion model in the code conversion method as described in any of the first aspects, the code conversion model training apparatus comprising: The fifth acquisition module is used to acquire training data; there are multiple types of training data, and each type of training data is adapted to the architecture corresponding to the training data. The sixth acquisition module is used to train the code conversion model using the training data to obtain the trained code conversion model.

[0014] Fifthly, embodiments of this application provide an electronic device, characterized in that the electronic device includes a processor, a memory, a communication interface, and a communication bus, wherein the processor, the memory, and the communication interface communicate with each other through the communication bus; the memory is used to store executable instructions, which cause the processor to perform the method as described in any one of the first or second aspects.

[0015] In a sixth aspect, embodiments of this application provide a readable storage medium that, when instructions in the readable storage medium are executed by a processor of an electronic device, enables the processor to perform the method as described in any one of the first or second aspects.

[0016] This embodiment generates an initial query statement based on the code to be converted and the target architecture. Based on the semantic similarity between the initial query statement and preset query statements, a target query statement is obtained from multiple preset query statements. Then, the target query statement and the initial query statement are input into a trained code conversion model. This yields target code that is semantically identical to the code to be converted and compatible with the target architecture. This embodiment uses a trained code conversion model for code conversion, which can accurately analyze the context of the code to be converted, resulting in high code conversion accuracy. It avoids code migration failures caused by incomplete mapping data. The entire process is automated based on the code conversion model, requiring no manual assistance, and is simple and efficient. Furthermore, this embodiment does not directly input the initial query statement into the trained code conversion model. Instead, it obtains the target query statement from multiple preset query statements based on their semantic similarity. Both the initial and target query statements are then input into the trained code conversion model. The target query statement forms a context related to the initial query statement. Inputting both the target and initial query statements into the code conversion model together further improves the accuracy of the target code output by the code conversion model. Attached Figure Description

[0017] Figure 1This is a flowchart illustrating the steps of a code conversion method provided in an embodiment of this application; Figure 2 This is a flowchart of another code conversion method provided in an embodiment of this application; Figure 3 This is a flowchart illustrating the steps of a code conversion model training method provided in an embodiment of this application; Figure 4 This is a flowchart illustrating a code conversion model training and inference method provided in an embodiment of this application; Figure 5 This is a flowchart illustrating the steps of a code conversion method provided in an embodiment of this application; Figure 6 This is a flowchart illustrating the steps of a method for acquiring training data according to an embodiment of this application; Figure 7 This is a flowchart illustrating the steps of a code conversion model training method provided in an embodiment of this application; Figure 8 This is a flowchart illustrating the steps of a vector database construction method provided in an embodiment of this application; Figure 9 This is a structural block diagram of a code conversion device provided in an embodiment of this application; Figure 10 This is a structural block diagram of a code conversion model training device provided in an embodiment of this application; Figure 11 This is a structural block diagram of an electronic device provided in an embodiment of this application. Detailed Implementation

[0018] The technical solutions of the embodiments of this application will be clearly described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application are within the scope of protection of this application.

[0019] The terms "first," "second," etc., used in the specification and claims of this application are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such use of data can be interchanged where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein, and the objects distinguished by "first," "second," etc., are generally of the same class and the number of objects is not limited; for example, a first object can be one or more. Furthermore, in the specification and claims, "and / or" indicates at least one of the connected objects, and the character " / " generally indicates that the preceding and following objects are in an "or" relationship.

[0020] Method Implementation Examples The code conversion method, code conversion model training method, apparatus, electronic device, and readable storage medium provided in this application will be described in detail below with reference to the accompanying drawings and through specific embodiments and application scenarios.

[0021] Some of the nouns or terms appearing in this application shall be interpreted as follows: Generative Pre-Trained Transformer (GPT) is a deep learning model for text generation that can be trained on data. It belongs to the generative pre-trained model category and is a transformer model that can be pre-trained using large-scale corpora.

[0022] Retrieval-augmented Generation (RAG) is a model that combines retrieval and large language model generation techniques. It can generate answers or content by referencing information from external knowledge bases, offering strong interpretability and customization capabilities. It is suitable for various natural language processing tasks such as question-answering systems, document generation, and intelligent assistants.

[0023] Low-Rank Adaptation (LoRA) and p-tuning are both model training techniques used to fine-tune large language models. Reference Figure 1 This embodiment provides a code conversion method, which may include the following steps: Step 101: Generate the initial query statement based on the code to be converted and the target architecture.

[0024] The target architecture is different from the architecture that the code to be converted is adapted to.

[0025] The initial query statement can reflect the query intent to convert the code to be transformed into target code that is compatible with the target architecture.

[0026] For example, the target architecture can be x86, Loongson, ARM, etc. The architecture that the code to be converted is adapted to can be different from the target architecture.

[0027] Step 102: Obtain multiple preset query statements, and obtain the semantic similarity between each preset query statement and the initial query statement.

[0028] For example, the vector similarity between each preset query statement and the initial query statement is obtained, and the vector similarity is determined as the semantic similarity between the two.

[0029] Step 103: Based on the semantic similarity, obtain the target query statement from the multiple preset query statements.

[0030] The semantic similarity between the target query and the initial query is greater than the semantic similarity between other preset query statements and the initial query.

[0031] For example, the semantic similarity is sorted in descending or ascending order, and the preset query statements corresponding to the k largest semantic similarity are determined as the target query statements.

[0032] Step 104: Input the initial query statement and the target query statement into the trained code conversion model to obtain target code that has the same semantics as the code to be converted and is compatible with the target architecture.

[0033] For example, the initial query statement and the target query statement constitute a text block. The text block is input into the trained code conversion model to obtain target code that has the same semantics as the code to be converted and is adapted to the target architecture.

[0034] This embodiment generates an initial query statement based on the code to be converted and the target architecture. Based on the semantic similarity between the initial query statement and preset query statements, a target query statement is obtained from multiple preset query statements. Then, the target query statement and the initial query statement are input into a trained code conversion model to obtain target code that is semantically identical to the code to be converted and adapted to the target architecture. This embodiment performs code conversion using a trained code conversion model, which can accurately analyze the context of the code to be converted, resulting in high code conversion accuracy. It avoids code migration failures caused by incomplete mapping data. The entire process is automatically implemented based on the code conversion model, requiring no manual assistance, and is simple and efficient. Furthermore, this embodiment does not directly input the initial query statement into the trained code conversion model. Instead, it obtains the target query statement from multiple preset query statements based on their semantic similarity. The target query statement forms a context related to the initial query statement. Inputting both the target query statement and the initial query statement into the code conversion model further improves the accuracy of the target code output by the model.

[0035] Figure 2 This is another code conversion method provided in this embodiment, see reference. Figure 2 The method may include the following steps: Step 201: Generate an initial query statement based on the code to be converted and the target architecture.

[0036] The target architecture is different from the architecture that the code to be converted is adapted to.

[0037] The method for this step has been explained in step 101 above, and will not be repeated here.

[0038] For example, the default query statement format is vector format. Furthermore, after step 201, the following steps are also included: Step 202: Vectorize the initial query statement to obtain the first vector.

[0039] For example, the initial query statement can be vectorized using embedding models such as word2vec and BERT to obtain the first vector.

[0040] Step 203: Obtain multiple preset query statements. For each preset query statement, obtain the semantic similarity between the preset query statement and the initial query statement based on the preset query statement and the first vector.

[0041] For example, a file containing the original query statement is extracted from a pre-defined knowledge base, the file is read and the text is segmented; then, the segmented text is converted into a pre-defined query statement in vector format using embedding models such as word2vec and BERT.

[0042] The preset query statement is in vector format. The vector similarity (e.g., cosine similarity) between the preset query statement and the first vector can be calculated, and the vector similarity is determined as the semantic similarity between the preset query statement and the initial query statement.

[0043] The initial query vector is vectorized to obtain the first vector. Based on the preset query statement and the first vector, the semantic similarity between the preset query statement and the initial query statement can be accurately obtained.

[0044] Step 204: Based on the semantic similarity, obtain the target query statement from the multiple preset query statements.

[0045] Among them, the vector similarity between the target query statement and the initial query statement is higher than that between other preset query statements and the initial query statement.

[0046] The method for this step has been explained in step 103 above, and will not be repeated here.

[0047] Step 205: Input the initial query statement and the target query statement into the trained code conversion model to obtain target code that has the same semantics as the code to be converted and is compatible with the target architecture.

[0048] The method for this step has been explained in step 104 above, and will not be repeated here.

[0049] For example, a vector knowledge base containing a large number of preset query statements can be constructed. During code conversion, the preset query statements are directly retrieved from the vector knowledge base, and the target query statement is obtained based on the vector similarity between the preset query statement and the initial query statement. Then, the initial query statement and the target query statement are input together into the trained code conversion model. Based on this, the training data used to train the code conversion model can be updated without fine-tuning the trained code conversion model. The training data used to train the code conversion model can be obtained from code dictionaries and compiler dictionaries.

[0050] For example, the method in this embodiment may also include the following steps: Step 206: Obtain the query statement to be processed from the preset database.

[0051] Step 207: Vectorize the query statement to be processed to obtain a preset query statement in vector format.

[0052] The method for vectorizing the query statement to be processed is the same as the method for vectorizing the initial query statement.

[0053] For example, both the query statement to be processed and the initial query statement are vectorized using embedding models such as word2vec and BERT.

[0054] In this embodiment, a query statement to be processed is obtained from a preset database; the query statement to be processed is vectorized to obtain a preset query statement in vector format. The method of vectorizing the query statement to be processed is the same as the method of vectorizing the initial query statement; therefore, when the initial query statement is vectorized to obtain a first vector, and the semantic similarity between the first vector and the preset query statement in vector format is calculated, the accuracy of the obtained semantic similarity is high, and it can accurately reflect the degree of semantic similarity between the two.

[0055] Reference Figure 3 This embodiment provides a method for training a code conversion model. This method is used to train a code conversion model as described in any of the code conversion methods in this application. The method of this embodiment may include the following steps: Step 301: Obtain training data.

[0056] There are multiple types of training data, and each type of training data is adapted to the architecture corresponding to the training data.

[0057] For example, training data may include at least one of the following: assembly instructions, compiler options, compiler macros, or built-in functions.

[0058] For example, an assembly dictionary library and a compiler dictionary library can be built. The original data in the dictionary library can be preprocessed to obtain preprocessed data. The preprocessed data can be cleaned, and then features can be extracted from the cleaned data. The extracted features can be labeled and encoded to obtain training data. The format of the training data conforms to the format requirements of the code conversion model.

[0059] For example, the compiler dictionary can contain the following training data: assembly characteristic instructions for architectures such as x86, Acorn RISC Machine (ARM), Microprocessor without interlocked piped stages (MIPS), Loongson, and Shenwei. For example, the compiler dictionary can include the following training data: compilation options, compiler macros, compiler-built-in functions, and attribute dictionaries for x86, ARM, Loongson, and Shenwei architectures; compilation options can include data types, generated code characteristics, target executor architecture, and processor hardware acceleration.

[0060] Step 302: Use the training data to train the code conversion model and obtain the trained code conversion model.

[0061] For example, the code translation model is a pre-trained large language model, such as the GPT model or the BERT model. A pre-defined fine-tuning framework is used to train the code translation model with training data, resulting in a trained code translation model. This enhances the trained code translation model's ability to translate heterogeneous code, enabling it to accurately perform heterogeneous code conversion; for example, it can accurately convert the code to be converted into target code adapted to the target architecture. Furthermore, the pre-defined fine-tuning framework and training data are used to fine-tune the code translation model, quickly obtaining a fully trained code translation model.

[0062] In this embodiment, multiple training data sets are acquired, each corresponding to a specific architecture. A code conversion model is trained based on these multiple training data sets. The resulting trained code conversion model can convert code across various architectures, improving the success rate and accuracy of converting code to be converted into target code adapted to the target architecture. The trained code conversion model obtained in this embodiment can perform code conversion accurately and efficiently, avoiding the potential problems of code conversion failure and low accuracy that can occur when using mapping relationships in related technologies.

[0063] For example, the code conversion model is a pre-trained large language model. Step 302 may include: using the training data to fine-tune the pre-trained large language model to obtain a trained code conversion model. For example, the pre-trained large language model may include a GPT model, a Bidirectional Encoder Representations from Transformers (BERT) model, etc.

[0064] For example, the code conversion model in this embodiment is the GPT model. Based on this embodiment, a GPT-based intelligent source code migration method can be implemented to solve the problems of low code conversion efficiency, low accuracy, and low intelligence caused by the need for manual assistance when migrating source code between different operating environments, architectures, or platforms in the fields of artificial intelligence and natural language processing.

[0065] In cloud-related industries (such as cloud-related industries related to the localization of domestic IT innovation), there is a need for application ecosystem compatibility of software source code. To solve this problem, it is necessary to migrate the software source code from one platform (such as a non-domestic IT innovation platform) to another platform (such as a heterogeneous domestic IT innovation platform).

[0066] Large Language Models (LLMs) have brought tremendous innovation to the field of machine learning and are an important technology in the field of artificial intelligence. LLMs can be applied to many areas such as question answering, translation, summarization, and content creation. Furthermore, LLMs possess advanced reasoning and logical thinking capabilities, making them suitable for code generation, code continuation, and code interpretation.

[0067] However, related technologies lack methods for migrating heterogeneous source code using large language models to transfer source code between different architectures. For example, there is a lack of methods to use large language models to convert code adapted to the x86 architecture, C / C++ language code, assembly code, etc., into code adapted to the ARM architecture.

[0068] Currently, there is a lack of methods for migrating heterogeneous source code based on large language models. Related technologies typically involve simple source code replacement using code-assisted porting software. This software works by replacing the source code based on the mapping relationships between different architectures. However, this method lacks precise and intelligent analysis of the source code, resulting in low accuracy in code conversion during the migration process. Furthermore, this method relies heavily on the implementation of the porting software itself, requiring significant manual analysis.

[0069] The method in this embodiment can be based on a large language model to realize an intelligent source code migration method, so as to at least solve the problems of low accuracy and low efficiency of code migration in related technologies.

[0070] The method of this embodiment will be further illustrated below.

[0071] In this embodiment, it is necessary to construct an assembly code dictionary library and a compiler dictionary library. For example, the compiler dictionary library can contain assembly characteristic instructions and other content for platforms such as x86, ARM, MIPS, Loongson, and Shenwei. The compiler dictionary library includes compilation options, compiler macros, compiler built-in functions, attribute dictionaries, and other content for platforms such as x86, ARM, Loongson, and Shenwei.

[0072] Furthermore, based on open-source large language models (such as GPT and BERT models), the constructed assembly code dictionary and compiler dictionary are used as data sources. First, the data in the data source is preprocessed through the document parsing subsystem. Then, the preprocessed data is converted into a format that can be processed by the large language model. Next, fine-tuning training of the large language model is carried out using fine-tuning frameworks such as Low-Rank Adaptation of Large Language Models (LoRA) and p-tuning to enhance the code conversion model's ability to perform heterogeneous code translation inference after training, thereby enabling the trained code conversion model to support heterogeneous code conversion.

[0073] The large language model, after fine-tuning and training, is the code conversion model trained in the aforementioned embodiments. It can be further optimized using retrieval-enhanced generation techniques. By combining retrieval and large language model generation techniques, and referencing information from external knowledge bases, answers or content can be generated. This allows for timely updates to the code dictionary and compiler dictionary without re-fine-tuning the training model, enabling the code conversion model to provide more accurate code conversion services.

[0074] Reference Figure 4 The code conversion model training method in this embodiment may include the following steps: Step S1: Obtain the dictionary dataset.

[0075] Specifically, the dictionary dataset includes a constructed assembly code dictionary library and a compiler dictionary library.

[0076] Furthermore, the document parsing subsystem parses the data in the dictionary to obtain a training dataset that meets the model's processing format requirements.

[0077] Step S2: Obtain training data based on the dictionary dataset, input the training data into the basic large language model, fine-tune the basic large language model to obtain the fine-tuned large language model; the fine-tuned large language model is the code conversion model trained in the aforementioned embodiment.

[0078] The basic large language model is a pre-trained large language model, such as the GPT model, the BERT model, etc.

[0079] Continue to refer to Figure 4 After obtaining the trained code conversion model, the method of using the trained code conversion model to perform code conversion may include the following steps: Step S3: Based on the code to be converted and the target architecture, obtain the initial query statement and input the initial query statement into the embedding vector model.

[0080] Step S4: The initial query statement is vectorized by embedding a vector model.

[0081] Step S5: Obtain the vectorized result of the question output by the embedded vector model.

[0082] The vectorization result of the question is the first vector in the aforementioned embodiment.

[0083] Step S6: Obtain the preset query statement from the vector knowledge base.

[0084] Step S7: Perform a similarity query on the first vector and the preset query statement to obtain the target query vector that matches the initial query vector.

[0085] For example, a method for performing a similarity query includes: calculating the semantic similarity between a first vector and a preset query statement in vector format, and using the semantic similarity to characterize the magnitude of the similarity between the two.

[0086] Step S8 yields a relevant text block containing the initial query vector and the target query vector.

[0087] Step S9: Generate a prompt based on the relevant text block.

[0088] For example, a text block containing the initial query vector and the target query vector can be inserted into a preset prompt to obtain the prompt.

[0089] Step S10: Input the prompt into the fine-tuned language model to obtain the answer corresponding to the query input.

[0090] The answer content is the target code in the aforementioned embodiments; the fine-tuned large language model is the code conversion model trained in the aforementioned embodiments.

[0091] Furthermore, refer to Figure 5 The method in this embodiment may include the following steps: Step F1: Construct a training dataset for training the code conversion model.

[0092] When obtaining the training dataset, the first step is to collect the raw training data. For example, the collected data may include the contents of the assembly dictionary and the compiler dictionary. The assembly dictionary contains assembly characteristic instructions for platforms such as x86, ARM, MIPS, Loongson, and Shenwei. The compiler dictionary contains compilation options, compiler macros, compiler-built-in functions, and attribute dictionaries for platforms such as x86, ARM, Loongson, and Shenwei; compilation options may include data types, generated code characteristics, target executor architecture, and processor hardware acceleration.

[0093] For example, raw training data can be collected from publicly available chip platform manuals, compiler and toolchain guides and manuals, and internal and external code porting documents.

[0094] After collecting the raw training data, the collected raw training data is converted into a format that the model can process.

[0095] For example, refer to Figure 6 The process from acquiring raw training data to processing it can include the following sub-steps: Sub-step F11: Obtain the original training data from the original corpus.

[0096] Sub-step F12 performs data preprocessing on the original training data.

[0097] Specifically, the original training data is preprocessed using a document parsing system. This includes Optical Character Recognition (OCR) processing, layout recognition, and document parsing.

[0098] The deep document parsing subsystem processes raw training data with diverse formats and a large amount of complex unstructured data to obtain preprocessed training data. Subsequent processing based on the preprocessed training data can improve the accuracy of text parsing.

[0099] Furthermore, refer to Figure 6 The document parsing subsystem can include three parts: a layout recognition module, an OCR processing module, and a document parser.

[0100] The layout recognition module includes the YOLOv algorithm, which can identify images, table structures, and the layout of images or table structures in a file.

[0101] The OCR processing module includes a fine-tuned Paddle OCR model, which can convert images and other formats into text formats.

[0102] The text parser can support the parsing of various types of files.

[0103] Sub-step F13 performs data deduplication and cleaning on the preprocessed data.

[0104] Sub-step F14 extracts features from the deduplication and cleaning data.

[0105] Sub-step F15 involves labeling the extracted features to obtain training data.

[0106] Step F2 involves fine-tuning the basic large language model using the training dataset to obtain the trained code conversion model.

[0107] Reference Figure 7 The method for this step may include the following sub-steps: Sub-step F21 inputs the training dataset into the base large language model and runs the base large language model.

[0108] Sub-step F22 fine-tunes the basic large language model.

[0109] Load its weights and run, taking the training dataset prepared in step F1 as input, and begin fine-tuning the model.

[0110] The model fine-tuning process typically involves multiple training epochs, during which the model's parameters are adjusted based on the training data.

[0111] For example, you would obtain a basic large language model (e.g., GPT model, BERT model), write code to load, train, validate, and save the fine-tuned model, and define steps such as training loops and selecting optimizers; then you would fine-tune the basic large language model using training data.

[0112] Sub-step F23: Determine whether the fine-tuning results of the basic large language model meet expectations; if yes, proceed to sub-step F24; otherwise, proceed to sub-step F25.

[0113] After fine-tuning, the performance of the fine-tuned large language model can be evaluated using a test set to determine whether the model performance has reached a preset performance threshold. Based on the judgment result, it can be determined whether the fine-tuning result meets expectations. For example, it can be determined whether the prediction accuracy of the large language model has reached a preset accuracy threshold.

[0114] Sub-step F24 saves the fine-tuned large language model after training.

[0115] Substep F25: Adjust the model parameters and return to substep F22.

[0116] After fine-tuning, the model needs to be evaluated and adjusted. The performance of the fine-tuned model is evaluated on the test set, and adjustments are made as needed until a large language model that meets expectations is obtained.

[0117] Step F3: Construct the vector database.

[0118] The vector database includes multiple preset query statements.

[0119] In this step, the fine-tuned large language model obtained in step F2 is updated in a timely manner by searching the vector knowledge base.

[0120] The vector knowledge base can be constructed using the following method: First, the knowledge base file that needs to be updated is loaded, read, and segmented. Then, the segmented text is vectorized (embedding).

[0121] For example, embedding models such as word2vec and BERT can be used to convert segmented text into numerical vectors.

[0122] After text vectorization, the resulting vector-formatted text is stored in a vector database.

[0123] For example, refer to Figure 8 The method for this step may include the following sub-steps: Sub-step F31 loads a file from the knowledge base file.

[0124] For example, the files retrieved from the knowledge base can be in Word, TXT, PDF, or other formats.

[0125] Sub-step F32 splits the loaded file.

[0126] Sub-step F33 inputs the segmented file into the embedded vector model to obtain a preset query statement in vector format.

[0127] In this embodiment, the text is segmented and vectorized to obtain a preset query statement in vector format.

[0128] Sub-step F34: Construct a vector database based on the preset query statement of the vector format.

[0129] Step F4: Based on the trained code conversion model and the constructed vector database, the code to be converted is converted into target code that is compatible with the target architecture.

[0130] For example, the code to be translated and the target architecture are converted into question vectors (i.e., the first vector corresponding to the initial query vector). Furthermore, the method for obtaining the vectorization of the question vectors is the same as the method for vectorizing data in the knowledge base file in the aforementioned embodiments.

[0131] In this embodiment, based on the first vector corresponding to the initial query statement and the preset query statements in text format in the vector knowledge base, the text similarity between the preset query statements in text format and the initial query vector is obtained, and the top k text similarities are selected, and the corresponding text vectors are determined as the top k target query statements most similar to the initial query vector.

[0132] Furthermore, the matched target query statement is added to the prompt along with the initial query statement that serves as the question. Thus, a question-related context is formed through the matched target query statement, and then both are input into the fine-tuned large language model.

[0133] Furthermore, by leveraging the translation reasoning capabilities of the finely tuned large language model, the translation code is converted into target code adapted to the target architecture, thereby achieving the conversion of heterogeneous code and outputting the answer.

[0134] Reference Figure 9 This embodiment also provides a code conversion device, the device 40 including: The first acquisition module 401 is used to generate an initial query statement based on the code to be converted and the target architecture; The second acquisition module 402 is used to acquire multiple preset query statements and acquire the semantic similarity between each preset query statement and the initial query statement respectively; The third acquisition module 403 is used to acquire the target query statement from multiple preset query statements based on the semantic similarity. The fourth acquisition module 404 is used to input the initial query statement and the target query statement into the trained code conversion model to obtain target code that has the same semantics as the code to be converted and is compatible with the target architecture.

[0135] Optionally, the preset query statement is in vector format; the second acquisition module 402 may include: The first acquisition submodule is used to perform vectorization processing on the initial query statement to obtain a first vector; The second acquisition submodule is used to acquire the semantic similarity between the preset query statement and the initial query statement for each preset query statement, based on the preset query statement and the first vector.

[0136] Optionally, device 40 also includes: The seventh module is used to retrieve query statements to be processed from a preset database; The eighth acquisition module is used to vectorize the query statement to be processed to obtain a preset query statement in vector format; wherein the vectorization processing method for the query statement to be processed is the same as the vectorization processing method for the initial query statement.

[0137] Based on this embodiment, the code conversion model can accurately analyze the context of the code to be converted, resulting in high code conversion accuracy. It avoids code migration failures caused by incomplete mapping data. The entire process is automated based on the code conversion model, requiring no manual assistance; the method is simple and highly efficient. Furthermore, this embodiment does not directly input the initial query statement into the trained code conversion model. Instead, it obtains the target query statement from multiple preset query statements based on the semantic similarity between the preset query statement and the initial query statement. The target query statement forms a context related to the initial query statement. Inputting both the target query statement and the initial query statement into the code conversion model further improves the accuracy of the target code output by the model.

[0138] Reference Figure 10 This embodiment also provides a code conversion model training device, which is used to train the code conversion model device 50 in the code conversion method described in any of the above embodiments, including: The fifth acquisition module 501 is used to acquire training data; there are multiple types of training data, and each type of training data is adapted to the architecture corresponding to the training data. The sixth acquisition module 502 is used to train the code conversion model using the training data to obtain the trained code conversion model.

[0139] Optionally, the code conversion model is a pre-trained large language model; the sixth acquisition module 502 may include: The third acquisition submodule is used to fine-tune the pre-trained large language model using the training data to obtain the trained code conversion model.

[0140] Optionally, the training data may include at least one of the following: assembly instructions, compiler options, compiler macros, and built-in functions.

[0141] In this embodiment, multiple training data sets are acquired, each corresponding to a specific architecture. A code conversion model is trained based on these multiple training data sets. The resulting trained code conversion model can convert code across various architectures, improving the success rate and accuracy of converting code to be converted into target code adapted to the target architecture. The trained code conversion model obtained in this embodiment can perform code conversion accurately and efficiently, avoiding the potential problems of code conversion failure and low accuracy that can occur when using mapping relationships in related technologies.

[0142] As the apparatus embodiment is basically similar to the method embodiment, it is described in a relatively simple manner. For relevant details, please refer to the description of the method embodiment.

[0143] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other.

[0144] Regarding the processor in the above embodiments, the specific manner in which each module performs operations has been described in detail in the embodiments related to the method, and will not be elaborated here.

[0145] Reference Figure 11 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. Figure 11 As shown, the electronic device includes: a processor, a memory, a communication interface, and a communication bus. The processor, memory, and communication interface communicate with each other through the communication bus. The memory is used to store executable instructions, which cause the processor to execute the code conversion method and the code conversion model training method of the aforementioned embodiments.

[0146] A processor can be a CPU, a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable devices, transistor logic devices, hardware components, or any combination thereof. A processor can also be a combination that implements computational functions, such as a combination of one or more microprocessors, or a combination of a DSP and a microprocessor.

[0147] A communication bus can include a pathway for transmitting information between memory and a communication interface. The communication bus can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. Communication buses can be categorized into address buses, data buses, control buses, etc. For ease of representation, Figure 11 The symbol is represented by only one line, but this does not mean that there is only one bus or one type of bus.

[0148] The memory can be read-only memory (ROM) or other types of static storage devices that can store static information and instructions, random access memory (RAM) or other types of dynamic storage devices that can store information and instructions, or electrically erasable programmable read-only memory (EEPROM), compact disc read-only memory (CD-ROM), magnetic tape, floppy disk, and optical data storage devices, etc.

[0149] This invention also provides a non-transitory computer-readable storage medium, which, when the instructions in the storage medium are executed by the processor of an electronic device (server or terminal), enables the processor to execute the code conversion method and the code conversion model training method shown in any embodiment of this application.

[0150] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other.

[0151] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, apparatus, or computer program products. Therefore, embodiments of the present invention can take the form of entirely hardware embodiments, entirely software embodiments, or embodiments combining software and hardware aspects. Furthermore, embodiments of the present invention can take the form of computer program products implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code. Embodiments of the present invention are described with reference to flowchart illustrations and / or block diagrams of methods, terminal devices (systems), and computer program products according to embodiments of the present invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing terminal device to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing terminal device, generate instructions for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0152] These computer program instructions may also be stored in a computer-readable storage medium capable of directing a computer or other programmable data processing terminal device to operate in a predictive manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0153] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal equipment, causing a series of operational steps to be performed on the computer or other programmable terminal equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable terminal equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0154] Although preferred embodiments of the present invention have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of the embodiments of the present invention.

[0155] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or terminal device that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or terminal device. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or terminal device that includes the element.

[0156] The foregoing has provided a detailed description of the code conversion method and the training method, apparatus, electronic device, and medium for the code conversion model provided by the present invention. Specific examples have been used to illustrate the principles and implementation methods of the present invention. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of the present invention. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of the present invention. Therefore, the content of this specification should not be construed as a limitation of the present invention.

Claims

1. A code conversion method, characterized in that, include: Generate an initial query statement based on the code to be converted and the target architecture; The target architecture is different from the architecture that the code to be converted is adapted to; Obtain multiple preset query statements, and obtain the semantic similarity between each preset query statement and the initial query statement respectively; Based on the semantic similarity, the target query statement is obtained from multiple preset query statements; The initial query statement and the target query statement are input into the trained code conversion model to obtain target code that has the same semantics as the code to be converted and is adapted to the target architecture.

2. The method according to claim 1, characterized in that, The preset query statement is in vector format; the semantic similarity between each preset query statement and the initial query statement is obtained, including: The initial query statement is vectorized to obtain a first vector; For each preset query statement, the semantic similarity between the preset query statement and the initial query statement is obtained based on the preset query statement and the first vector.

3. The method according to claim 2, characterized in that, The method further includes: Retrieve the query statement to be processed from the preset database; The query statement to be processed is vectorized to obtain a preset query statement in vector format; The method for vectorizing the query statement to be processed is the same as the method for vectorizing the initial query statement.

4. A method for training a code conversion model, characterized in that, A method for training a code conversion model in the code conversion method as described in any one of claims 1 to 3, the code conversion model training method comprising: Acquire training data; there are multiple types of training data, and each type of training data is adapted to the architecture corresponding to the training data. Using the training data, the code conversion model is trained to obtain the trained code conversion model.

5. The method according to claim 4, characterized in that, The code conversion model is a pre-trained large language model; The step of using the training data to train the code conversion model to obtain the trained code conversion model includes: Using the training data, the pre-trained large language model is fine-tuned to obtain a trained code conversion model.

6. The method according to claim 4, characterized in that, The training data includes at least one of the following: assembly instructions, compiler options, compiler macros, and built-in functions.

7. A code conversion device, characterized in that, include: The first acquisition module is used to generate an initial query statement based on the code to be converted and the target architecture; The second acquisition module is used to acquire multiple preset query statements and acquire the semantic similarity between each preset query statement and the initial query statement respectively; The third acquisition module is used to acquire the target query statement from multiple preset query statements based on the semantic similarity. The fourth acquisition module is used to input the initial query statement and the target query statement into the trained code conversion model to obtain target code that has the same semantics as the code to be converted and is compatible with the target architecture.

8. A code conversion model training device, characterized in that, The code conversion model training device is used to train the code conversion model in the code conversion method as described in any one of claims 1 to 3, and the code conversion model training device comprises: The fifth acquisition module is used to acquire training data; there are multiple types of training data, and each type of training data is adapted to the architecture corresponding to the training data. The sixth acquisition module is used to train the code conversion model using the training data to obtain the trained code conversion model.

9. An electronic device, characterized in that, The electronic device includes a processor, a memory, a communication interface, and a communication bus, wherein the processor, the memory, and the communication interface communicate with each other through the communication bus; The memory is used to store executable instructions that cause the processor to perform the method as described in any one of claims 1 to 6.

10. A readable storage medium, characterized in that, When the instructions in the readable storage medium are executed by the processor of the electronic device, the processor is enabled to perform the method as described in any one of claims 1 to 6.