API relationship inference method and system based on large pre-training language model
The API relation reasoning method using a large pre-trained language model solves the problems of limited API relation mining scope and lack of reasoning ability in existing technologies, achieving comprehensive and accurate reasoning of API relations and improving the robustness of the method.
Patent Information
- Application Number
- CN202310697392.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-13
- Publication Date
- 2025-11-25
- Estimated Expiration
- 2043-06-13
Smart Images

Figure CN116776981B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of artificial intelligence, specifically to an API relational reasoning method and system based on a large-scale pre-trained language model. Background Technology
[0002] Application Programming Interfaces (APIs) are predefined functions. Through APIs, developers can call functions from other software applications, libraries, or services, enabling code reuse and simplifying the development process. APIs often involve complex relationships; one API may be related to multiple APIs, or one API may have multiple relationships with another. For example, `java.lang.StringBuffer` is related to `java.lang.String` and `java.lang.StringBuilder`. Furthermore, `java.lang.StringBuffer` and `java.lang.StringBuilder` also have multiple relationships. These API relationships typically exist in text form in API documentation, tutorials, and various developer forums. However, due to the unstructured nature of text, the rich API knowledge within it is not easily extracted. Moreover, the linguistic characteristics of text (syntactic complexity and semantic richness) further complicate the task of mining API relationships, making it difficult to accurately and comprehensively cover the diverse range of API relationships.
[0003] Currently, existing techniques for mining API relationships mainly rely on heuristic rules and deep learning methods. The former involves summarizing syntactic patterns from natural language text and then using these patterns to match API relationships within the text. The latter involves fine-tuning a natural language model (such as T5) using labeled data and then using the tuned model to extract API relationships. However, the main problem with existing technologies is:
[0004] 1) The range of API text collected from a single data source is limited and cannot adequately cover diverse API relationships. Furthermore, strict rule matching is susceptible to variations in text descriptions, and data annotation involves significant manual overhead. Therefore, extending existing methods to other data sources is challenging.
[0005] 2) Existing methods can only extract explicit API relationships from input text (default is a sentence), and cannot combine multiple sentences to infer API relationships, that is, they lack reasoning ability. Summary of the Invention
[0006] To address the shortcomings of the existing technologies, this invention provides an API relationship reasoning method and system based on a large pre-trained language model, which leverages the powerful context learning and reasoning capabilities of LLM to infer API relationships that are not explicitly expressed in text.
[0007] The technical solution adopted in this invention is:
[0008] Firstly, a method for API relation reasoning based on a large-scale pre-trained language model is provided, comprising the following steps:
[0009] S1, Start;
[0010] S2, extract the simple names of APIs from the text and infer their fully qualified names;
[0011] S3, determine whether the number of fully qualified API names is not less than 2. If the number of fully qualified API names is not less than 2, proceed to step S4; otherwise, proceed to step S1.
[0012] S4, combine all the fully qualified names of the APIs in pairs to construct API pairs;
[0013] S5, consult the LLM to obtain relevant knowledge blocks for a certain API pair;
[0014] S6, based on API-related knowledge blocks, uses crowd intelligence strategy reasoning to obtain the relationships between APIs;
[0015] S7, End.
[0016] Secondly, a method for API relation reasoning based on a large-scale pre-trained language model is provided. The steps for constructing API pairs include:
[0017] Extract the fully qualified name of the API from the existing API text data to obtain the fully qualified name of the API (API FQN).
[0018] To extract the API's fully qualified name from the API text data, we first extract the API's simple name.
[0019] By reasoning from the simple name of the API, we obtain the fully qualified name of the API, API FQN;
[0020] The API FQN does not exist in the text; it is derived through inference.
[0021] Combine all the fully qualified names of the APIs in pairs to obtain API pairs.
[0022] Thirdly, a method for API relation reasoning based on a large-scale pre-trained language model is provided, and the steps to obtain API-related knowledge blocks include:
[0023] Consult an LLM (Liver Management System) to obtain relevant knowledge about each API;
[0024] By combining the relevant knowledge of two APIs (which belong to an API pair), we obtain an API knowledge block.
[0025] Fourthly, a method for API relation reasoning based on a large-scale pre-trained language model is provided, characterized in that the steps for reasoning to obtain API relations include:
[0026] Combining API-related knowledge blocks, we use three different reasoning styles to reason about API relationships;
[0027] By aggregating the results of the three reasoning methods, the final API relationship is obtained.
[0028] Fifthly, an API relation reasoning system based on a large-scale pre-trained language model is provided, comprising: an API fully qualified name resolver module, an API knowledge extractor module, and an API relation decision-maker module; wherein the API knowledge extractor module is connected to the API fully qualified name resolver module and the API relation decision-maker module respectively.
[0029] The API Fully Qualified Name (API FQN) parsing module is used to obtain the fully qualified names (FQN) in the API text and combine them into API pairs. The fully qualified names (FQN) include fully qualified names (FQN) that are directly present in the text and fully qualified names (API FQN) that are inferred from the simple API names in the text.
[0030] The API knowledge extraction module is used to obtain relevant knowledge about the two APIs in an API pair and aggregate this knowledge to form an API knowledge block.
[0031] The API relationship decision module, based on API knowledge blocks, aggregates the results of three reasoning styles to obtain the final API relationship.
[0032] Sixthly, an API relation reasoning system based on a large-scale pre-trained language model is provided. The API fully qualified name (API FQN) parsing module includes: an API simple name extraction module, an API fully qualified name (API FQN) extraction module, an API fully qualified name (API FQN) reasoning module, and an API pair generation module.
[0033] The API Simple Name Extraction module is used to extract the simple name of the API from the API text.
[0034] The API Fully Qualified Name (API FQN) extraction module is used to extract the API's FQN from the API text.
[0035] The API Fully Qualified Name (API FQN) inference module infers the API Fully Qualified Name (API FQN) based on the extracted API Simple Name.
[0036] The API pair generation module is used to combine all fully qualified API names (API FQNs) in pairs to form API pairs.
[0037] Seventhly, an API relation reasoning system based on a large-scale pre-trained language model is provided. The API knowledge extraction module includes an API knowledge mining module and an API knowledge combination module.
[0038] The API knowledge mining module is used to extract API-related knowledge from LLM;
[0039] The API knowledge combination module is used to combine extracted API-related knowledge to form API knowledge blocks.
[0040] Eighthly, an API relation reasoning system based on a large-scale pre-trained language model is provided, wherein the API relation decision-maker module includes: API relation decision-1 module, API relation decision-2 module, API relation decision-3 module and API relation aggregation module;
[0041] The API Relationship Decision-1 module, based on API knowledge blocks, adopts an open-ended question-and-answer style to guide LLM reasoning on API relationships.
[0042] The API Relationship Decision-2 module, based on API knowledge blocks and employing a restricted judgment style, guides LLM reasoning on API relationships.
[0043] The API Relationship Decision-3 module, based on API knowledge blocks and employing a multiple-choice style, guides LLM reasoning for API relationships.
[0044] The API relationship aggregation module is used to aggregate results from three different styles to obtain the final API relationship.
[0045] A ninth aspect provides a computer device including a memory, a processor, and a computer program stored in the memory and running on the processor, wherein the processor executes the computer program to implement the API relational reasoning method based on a large pre-trained language model.
[0046] In a tenth aspect, a computer-readable storage medium is provided, the computer-readable storage medium storing a computer program that, when executed by a processor, implements the API relation reasoning method based on a large pre-trained language model.
[0047] The advantages of this invention over the prior art are:
[0048] This invention relates to an API relation reasoning method and system based on a large-scale pre-trained language model. By leveraging the massive knowledge stored in an LLM, it breaks through the limitations of the API text scope. With the powerful context learning and reasoning capabilities of an LLM, it can infer API relations that are not explicitly expressed in the text. Furthermore, its unique reasoning method is unaffected by the characteristics of the text language.
[0049] This invention presents an API relation reasoning method and system based on a large-scale pre-trained language model. Through a reasonable analysis flow design, it improves the robustness of the LLM response and can accurately and comprehensively reason about API relations. By using a swarm intelligence strategy, it aggregates API relation reasoning results of different styles to obtain the final API relations, thereby improving the robustness of the method. Attached Figure Description
[0050] Figure 1 This is a schematic diagram of the API relational reasoning method based on LLM in an example of the present invention;
[0051] Figure 2 This is a prompt design diagram of the API simple name extraction module in an example of the present invention;
[0052] Figure 3 This is a prompt design diagram of the API FQN inference module in an example of the present invention;
[0053] Figure 4 This is a prompt design diagram of the API knowledge mining and extraction module in an example of the present invention;
[0054] Figure 5 This is the prompt design diagram of the API relationship decision-1 module in this invention example;
[0055] Figure 6 This is the prompt design diagram of the API relationship decision-2 module in this invention example;
[0056] Figure 7 This is the prompt design diagram of the API relationship decision-3 module in this invention example;
[0057] Figure 8 This is an example diagram of an API relational reasoning system based on LLM in this invention. Detailed Implementation
[0058] The present invention will now be described in detail with reference to the accompanying drawings and embodiments:
[0059] It should be noted that the embodiments and figures in this application are based on one type of API relationship (functional similarity relationship). In fact, the present invention can deduce five types of API relationships (functional similarity, behavioral difference, efficiency comparison, functional substitution, logical constraint, etc.). Example 1:
[0060] like Figure 1 As shown, this invention provides an API relation reasoning method based on a large-scale pre-trained language model, the method comprising:
[0061] Retrieve all API FQNs from the API text.
[0062] The API FQNs are combined in pairs to obtain API pairs.
[0063] Extract relevant knowledge of APIFQN from large pre-trained language models to construct API knowledge blocks.
[0064] Based on API knowledge blocks, guide large pre-trained language models to infer API relationships.
[0065] Specifically, during the process of obtaining APIFQN, a prompt was used to prompt the LLM to perform this task, such as... Figure 2 As shown, the input is API text, and the output is the simple API name within the API text. The prompt consists of two main parts: a task description and five examples. The task description is "Extract the Non-FQNs of Java APIs in the natural language text." Each of the five examples consists of two parts: API text and the simple API name contained within the API text. Based on the prompt template, the LLM will mimic the behavior of the examples and output the simple API name contained within the given API text. Then, the FQN corresponding to the simple API name can be inferred, using a prompt such as... Figure 3 As shown in the prompt, by inputting the API text and a simple API name, the corresponding API FQN is obtained. Furthermore, the API text may directly contain the API FQN; we can use rule matching methods to directly extract these API FQNs.
[0066] Specifically, when the number of API FQNs is not less than 2, these FQNs are paired to form API pairs. Otherwise, the next text is entered.
[0067] Specifically, during the API knowledge extraction process, a Prompt was used to prompt the LLM to perform this task, such as... Figure 4As shown, the prompt consists of two main parts: a task description and five examples. The task description is "Answer the question about API knowledge," and each example consists of two parts: the API and the corresponding API knowledge. When given an API, the output is the corresponding API knowledge. We perform this operation in parallel to obtain the relevant knowledge for both APIs in the API pair. Then, we combine the knowledge of these two APIs to obtain the API knowledge block.
[0068] Specifically, during the inference of API relationships, three prompts were used to prompt the LLM to perform this task, as follows: Figure 5 , 6 As shown in Figure 7, the input is an API knowledge block and the API itself, and the output is the API relationship reasoning result. Among them, Figure 5 The prompt shown is in an open-ended question-and-answer style, with an example as follows; Figure 6 The prompt shown is a restricted judgment style; Figure 7 The diagram shows a multi-choice style, where three different prompt styles are executed in parallel to obtain inference results. Then, the three inference results are aggregated to obtain the final result.
[0069] In summary, this embodiment overcomes the limitation of API text scope by leveraging the vast API knowledge of LLM. Furthermore, the method's unique reasoning ability allows it to accurately and comprehensively infer API relationships regardless of the characteristics of the API text. Example 2:
[0070] This invention provides a system for reasoning API relationships, such as Figure 8 As shown, the API relation reasoning system includes: an API FQN parser module, an API knowledge extractor module, and an API relation decision-maker module.
[0071] Specifically, the API FQN parser module is used to obtain the FQNs in the API text and combine them into API pairs.
[0072] Specifically, the code structure extractor module is divided into several AI modules based on LLM inference and non-AI modules that follow clearly defined rules or logic. The AI modules include: an API simple name extraction module, configured to extract the API simple names from the text using LLM's context learning capabilities and use this information to guide the next AI module; and an API FQN inference module, configured to infer the FQNs of the API simple names using LLM's context learning capabilities. The non-AI modules include: an API FQN extraction module, configured to extract FQNs present in the text through character matching; and an API pair generation module, configured to combine all the API FQNs in pairs to form API pairs.
[0073] Specifically, the API knowledge extraction module is used to acquire relevant knowledge about the two APIs in an API pair and aggregate this knowledge to form an API knowledge block. The AI module includes an API knowledge mining module, configured to extract API-related knowledge using the context learning capabilities of LLM. The non-AI module includes an API knowledge combination module, configured to combine the extracted API-related knowledge using logical rules to form an API knowledge block.
[0074] Specifically, the API relationship determiner module, based on API knowledge blocks, aggregates the results of three reasoning styles to obtain the final API relationship. The AI module includes: API relationship decision-1 module, configured to guide LLM reasoning of API relationships using a restricted judgment style based on API knowledge blocks; API relationship decision-2 module, configured to guide LLM reasoning of API relationships using a restricted judgment style based on API knowledge blocks; and API relationship decision-3 module, configured to guide LLM reasoning of API relationships using a multiple-choice style based on API knowledge blocks. The non-AI module includes: an API relationship aggregation module, configured to aggregate the results of three different styles through logical rules to obtain the final API relationship.
[0075] This invention relates to an API relation reasoning method and system based on a large-scale pre-trained language model. By leveraging the massive knowledge stored in an LLM, it breaks through the limitations of the API text scope. With the powerful context learning and reasoning capabilities of an LLM, it can infer API relations that are not explicitly expressed in the text. Furthermore, its unique reasoning method is unaffected by the characteristics of the text language.
[0076] This invention presents an API relation reasoning method and system based on a large-scale pre-trained language model. Through a reasonable analysis flow design, it improves the robustness of the LLM response and can accurately and comprehensively reason about API relations. By using a swarm intelligence strategy, it aggregates API relation reasoning results of different styles to obtain the final API relations, thereby improving the robustness of the method.
[0077] The above description is merely a preferred embodiment of the present invention and does not constitute any limitation on the structure of the present invention. Any simple modifications, equivalent changes, and alterations made to the above embodiments based on the technical essence of the present invention shall fall within the scope of the technical solution of the present invention.
Claims
1. An API relation reasoning method based on a large-scale pre-trained language model, characterized in that, Includes the following steps: S1, Start; S2, extract the simple names of APIs from the text and infer their fully qualified names; S3, determine if the number of fully qualified API names is not less than 2. If the number of fully qualified API names is not less than 2, proceed to step S4; otherwise, enter the next text and proceed to step S1. S4, combine all the fully qualified names of the APIs in pairs to construct API pairs; S5, consult the LLM to obtain relevant knowledge blocks for a certain API pair; S6, based on API-related knowledge blocks, uses crowd intelligence strategy reasoning to obtain the relationships between APIs; S7, End; The steps to construct an API pair include: Extract the fully qualified name of the API from the existing API text data to obtain the fully qualified name of the API. To extract the API's fully qualified name from the API text data, we first extract the API's simple name. Infer the fully qualified API name from the simple API name; Combine all the fully qualified names of the APIs in pairs to obtain API pairs; The steps to obtain API-related knowledge blocks include: Consult an LLM (Liver Management System) to obtain relevant knowledge about each API; Combine the relevant knowledge of the two APIs to obtain an API knowledge block; The steps to derive API relationships through reasoning include: Combining API-related knowledge blocks, we use three different reasoning styles—open-ended question-and-answer style, restricted judgment style, and multiple-choice style—to reason about API relationships. By aggregating the results of the three reasoning methods, the final API relationship is obtained.
2. An API relational reasoning system based on a large-scale pre-trained language model, characterized in that, include: API Fully Qualified Name Resolution Module, API Knowledge Extraction Module, API Relationship Determination Module; The API knowledge extraction module is connected to the API fully qualified name resolution module and the API relationship decision module, respectively. The API fully qualified name parsing module is used to obtain fully qualified names in API text and combine them into API pairs. The fully qualified names include fully qualified names (FQN) that are directly present in the text and fully qualified names of APIs that are inferred from simple API names in the text. The API knowledge extraction module is used to obtain relevant knowledge about the two APIs in an API pair and aggregate this knowledge to form an API knowledge block. The API relationship decision module, based on API knowledge blocks, aggregates the results of three reasoning styles to obtain the final API relationship; The API fully qualified name resolution module includes: API simple name extraction module, API fully qualified name extraction module, API fully qualified name reasoning module, and API pair generation module; The API Simple Name Extraction module is used to extract the simple name of the API from the API text. The API Fully Qualified Name Extraction Module is used to extract the API's Fully Qualified Name (FQN) from the API text. The API fully qualified name reasoning module infers the API fully qualified name based on the extracted API simple name. The API pair generation module is used to combine all fully qualified API names in pairs to form API pairs; The API knowledge extraction module includes: an API knowledge mining module and an API knowledge combination module; The API knowledge mining module is used to extract API-related knowledge from LLM; The API knowledge combination module is used to combine extracted API-related knowledge to form API knowledge blocks; The API relationship determination module includes: API relationship decision-1 module, API relationship decision-2 module, API relationship decision-3 module, and API relationship aggregation module; The API Relationship Decision-1 module, based on API knowledge blocks, adopts an open-ended question-and-answer style to guide LLM reasoning on API relationships. The API Relationship Decision-2 module, based on API knowledge blocks and employing a restricted judgment style, guides LLM reasoning on API relationships. The API Relationship Decision-3 module, based on API knowledge blocks and employing a multiple-choice style, guides LLM reasoning for API relationships. The API relationship aggregation module is used to aggregate results from three different styles to obtain the final API relationship.
3. A computer device comprising a memory, a processor, and a computer program stored in the memory and running on the processor, characterized in that, When the processor executes the computer program, it implements the API relation reasoning method based on a large pre-trained language model as described in claim 1.
4. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by the processor, it implements the API relation reasoning method based on a large pre-trained language model as described in claim 1.
Citation Information
Patent Citations
Open entity relationship extraction method and device, equipment and storage medium
CN113011189A
Open entity relationship extraction method, apparatus and device, and storage medium
WO2022198868A1