Complex instruction code generation method and system based on large model

By fine-tuning the large model and using pseudocode generation methods, the problem of smart home systems being unable to handle complex commands was solved. This enabled accurate understanding of user intentions and generation of executable code, improving the precision and automation level of smart home control.

CN122018868APending Publication Date: 2026-05-12BEIJING NANSHE TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
BEIJING NANSHE TECH CO LTD
Filing Date
2026-01-29
Publication Date
2026-05-12

AI Technical Summary

Technical Problem

Existing smart home systems cannot understand and process complex commands, such as those involving conditional judgments, time waits, and loops, which prevents users from issuing personalized commands and limits the functional boundaries and control flexibility of smart homes.

Method used

The large model is fine-tuned to convert user requirements into pseudocode. The optimal pseudocode is then selected through syntax checking and similarity calculation, and finally executable instruction code is generated, including query and set method functions. Similarity is calculated using TF-IDF and BGE models, and code generation is performed in combination with a syntax checker and a sandbox environment.

Benefits of technology

It enables accurate understanding and execution of complex instructions, improving the precision and automation of smart home appliance control in smart home scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122018868A_ABST
    Figure CN122018868A_ABST
Patent Text Reader

Abstract

The invention discloses a large-model-based complex instruction code generation method and system, and the method comprises the steps: firstly obtaining a demand input by a user for controlling an intelligent household electrical appliance, then converting the demand into a plurality of different pseudo codes through employing a fine-tuned large model, taking the capability of the intelligent household electrical appliance as a prompt word during the fine tuning of the large model, and carrying out the fine tuning of the large model. Predefining a control method according to the cue word; secondly, screening an optimal pseudo code from a plurality of different pseudo codes; and finally, an executable instruction code is generated according to the optimal pseudo code and is used for controlling the intelligent household electrical appliance. According to the method, complex user requirements can be accurately understood, and instruction codes are accurately generated.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of smart home control, and in particular to a method and system for generating complex instruction codes based on large models. Background Technology

[0002] Smart homes have entered a phase of rapid development, with various smart appliances, security devices, and environmental control devices interconnected, allowing users to intelligently control home devices. Current intent understanding models can only comprehend simple user commands, such as turning on the bedroom light, or simple multi-command commands, such as turning on the bedroom light and then turning off the living room curtains. However, they cannot understand or process complex commands involving conditional judgments, time-based waiting, and loops. This prevents users from issuing personalized commands based on their living scenarios, limiting the functional boundaries of smart homes and reducing the flexibility and convenience of intelligent control. Summary of the Invention

[0003] Purpose of the invention: The purpose of this invention is to provide a method and system for generating complex instruction code based on a large model, which can understand the user's complex intentions and convert them into executable code.

[0004] Technical solution: The present invention provides a method for generating complex instruction code based on a large model, comprising the following steps:

[0005] The need to obtain user input for controlling smart home appliances;

[0006] The requirements are converted into several different pseudocodes using the fine-tuned large model. In the fine-tuning of the large model, the capabilities of smart home appliances are used as prompt words, and control methods are predefined according to the prompt words.

[0007] Select the optimal pseudocode from several different pseudocodes;

[0008] Executable instruction code is generated based on the optimal pseudocode to control the smart home appliances.

[0009] Furthermore, the method for generating executable instruction code based on the optimal pseudocode includes: extracting the control methods from the optimal pseudocode, converting them into method functions in the instruction code, and obtaining executable instruction code.

[0010] Furthermore, the method functions in the instruction code include query methods and set methods.

[0011] Furthermore, the method for selecting the optimal pseudocode from several different pseudocodes includes: using a syntax checker to filter the pseudocode to obtain a first pseudocode; if the number of the first pseudocodes is 0, then reusing the fine-tuned large model to convert the requirement into several different pseudocodes; if the number of the first pseudocodes is 1, then the first pseudocode is the optimal pseudocode; otherwise, the optimal pseudocode is selected based on the similarity between the first pseudocode and the requirement.

[0012] Furthermore, the method for selecting the optimal pseudocode based on the similarity between the first pseudocode and the requirement includes:

[0013] The finely tuned large model is used to convert the first pseudocode into natural language, the similarity between the natural language and the requirement is calculated, and the first pseudocode with the highest similarity is selected as the optimal pseudocode.

[0014] Furthermore, the method for calculating the similarity between the natural language and the requirement includes:

[0015] The natural language and the requirement are segmented using the TF-IDF model to obtain the first feature vector and the second feature vector respectively. The cosine similarity token_sim between the first feature vector and the second feature vector is calculated.

[0016] The natural language and the requirement are embedded using the BGE model to obtain the third feature vector and the fourth feature vector respectively, and the cosine similarity between the third feature vector and the fourth feature vector is calculated as semantic_sim.

[0017] Calculate the similarity between the natural language and the requirement. ,in, , It's a hyperparameter.

[0018] The present invention discloses a complex instruction code generation system based on a large model, comprising:

[0019] The demand acquisition unit is used to acquire user input regarding their needs for controlling smart home appliances.

[0020] The pseudocode generation unit is used to convert the requirements into several different pseudocodes using a fine-tuned large model. In the fine-tuning of the large model, the capabilities of smart home appliances are used as prompt words, and a control method is predefined according to the prompt words.

[0021] An optimal pseudocode filtering unit is used to filter the optimal pseudocode from several different pseudocodes;

[0022] The instruction code generation unit is used to generate executable instruction code based on the optimal pseudocode, for controlling the smart home appliance.

[0023] The electronic device of the present invention includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the computer program is loaded onto the processor, it implements the complex instruction code generation method based on a large model.

[0024] The computer-readable storage medium of the present invention stores a computer program, which, when executed by a processor, implements the method for generating complex instruction code based on a large model.

[0025] The computer program product of the present invention includes a computer program that, when executed by a processor, implements the complex instruction code generation method based on a large model.

[0026] Beneficial effects: Compared with the prior art, the advantages of the present invention are: the present invention can understand the user's intent from complex instruction requirements, accurately generate pseudocode and further generate executable code, improve the accuracy of requirement intent recognition, and thus improve the precision and automation of smart home appliance control in smart home scenarios. Attached Figure Description

[0027] Figure 1 This is a flowchart of a complex instruction code generation method according to an embodiment of the present invention.

[0028] Figure 2 This is a flowchart of the similarity calculation method according to an embodiment of the present invention.

[0029] Figure 3 This is a flowchart of a method for generating instruction code based on optimal pseudocode according to an embodiment of the present invention. Detailed Implementation

[0030] The technical solution of the present invention will be further described below with reference to the accompanying drawings.

[0031] like Figure 1 As shown, the complex instruction code generation method includes the following steps.

[0032] Step 1: Obtain the user's input requirements for controlling smart home appliances.

[0033] Specifically, the user-input requirements are complex needs for controlling smart home appliances, including complex conditions involving conditional judgments, time waiting, and / or loops. For example, the requirement in this embodiment is: turn off the bedroom light if the child is asleep, and send me a message if the child is still awake by 9 pm.

[0034] Step 2: Using the fine-tuned large model, the requirements are converted into several different pseudocodes. In the fine-tuning of the large model, the capabilities of smart home appliances are used as prompt words, and control methods are predefined according to the prompt words.

[0035] Specifically, since the original large model is difficult to support the intent of the smart home (or smart home) vertical field, it needs to be fine-tuned. This embodiment uses the Qwen3-Coder-30B-A3B-Instruct model as the base and fine-tunes the large model using LoRa, allowing it to generate pseudocode according to user needs. Operable devices in the home (usually smart appliances) include various lights, air conditioners, curtains, fresh air systems, televisions, robot vacuums, sleep sensors, cameras, and smart doors, etc., with functions including opening, closing, adjusting, and querying.

[0036] A large model is fine-tuned using a training set consisting of no less than 50,000 training data points. The capabilities of each device are set in the prompt words of the training set, and a control method is predefined according to the prompt words. For example, some prompt words in this embodiment are shown in Table 1.

[0037] Table 1. Capability List and Control Method Instruction Format Examples

[0038]

[0039] The fine-tuned large model can generate pseudocode containing control methods according to requirements. For example, the pseudocode generated for the requirements in this embodiment is shown in Table 2.

[0040] Table 2 Pseudocode Examples

[0041]

[0042] Step 3: Select the optimal pseudocode from several different pseudocodes.

[0043] like Figure 2 As shown, in order to improve accuracy, a sorting and scoring mechanism is introduced to filter the generated pseudocode. The filtering method includes the following steps.

[0044] Step 3.1: Use the finely tuned large model to generate several pseudocodes through reasoning. In this embodiment, the temperature is set to 0.5, generating 3 different responses.

[0045] Step 3.2: Call the Python syntax checker to filter out answers with syntax errors, those that cannot run, and those that do not generate any predefined control methods. If all answers in step 3 are filtered out, the process is marked as failed, exits, and pseudocode is regenerated according to requirements. If only one answer remains after filtering, the pseudocode corresponding to that answer is the optimal pseudocode, and the process proceeds to step 4; otherwise, proceed to step 3.3.

[0046] Step 3.3: Call the fine-tuned large model again to convert the filtered n (n=2 or 3) pseudocodes into natural language.

[0047] Step 3.4: Use a similarity algorithm to score and calculate natural language (Natural Language) ) and original user needs ( The similarity score is calculated between the pseudocode and the pseudocode, and the pseudocode with the highest similarity score is selected as the optimal pseudocode. The method for calculating the similarity score is as follows:

[0048] (1) Perform Chinese word segmentation on the two text segments, and then use the TF-IDF model to obtain the feature vectors of the two text segments respectively. Use cosine similarity to calculate the similarity score token_sim of the two feature vectors. This can ensure that key data, such as location information and time information, are not lost.

[0049] (2) Embed the two natural language segments using the BGE model. Use the cosine similarity algorithm to calculate the similarity score of the two feature vectors, semantic_sim, which can ensure that the two text segments are similar in general meaning, such as if something is true and whether there is a loop.

[0050] (3) Perform score fusion: .in This is a hyperparameter; initially set it to 0.5, then adjust it based on actual conditions. The final similarity score will then be obtained. .

[0051] Step 4: Generate executable instruction code based on the optimal pseudocode to control the smart home appliances.

[0052] Specifically, such as Figure 3 The diagram illustrates a method for generating executable instruction code based on the optimal pseudocode. In this embodiment, the Python instruction code is generated, and the generation process is as follows:

[0053] Step 4.1: Extract the control methods generated in the pseudocode using regular expressions. For example:

[0054] Query(device='sleep sensor', action='query', position='child's bedroom', parameter='asleep');

[0055] Turn off (device='light', action='turn off', position='bedroom').

[0056] Step 4.2, Method Name Replacement: Methods are divided into two main categories: get and set. These are used to call different interfaces. The parameters are still the content within the parentheses of the control method, completing the method name and parameter settings. For example, the two control methods in Step 4.1 are replaced as follows:

[0057] get(device='sleep sensor', action='query', position='child's bedroom', parameter='asleep');

[0058] set(device='light', action='off', position='bedroom').

[0059] Step 4.3 involves adding the `get` and `set` method definitions to Python to obtain executable Python code. The `get` and `set` methods defined in Python are general-purpose; for example, the `get` method definition is shown in Table 3.

[0060] Table 3 Example of get method definition

[0061]

[0062] Step 4.4: Execute the Python instruction code in the sandbox. This Python instruction code is used to control the smart home appliance.

[0063] Specifically, sandboxes have advantages such as isolation, restriction, and controllability, and can be used to test generated Python instruction code.

[0064] The present invention discloses a complex instruction code generation system based on a large model, comprising:

[0065] The demand acquisition unit is used to acquire user input regarding their needs for controlling smart home appliances.

[0066] The pseudocode generation unit is used to convert the requirements into several different pseudocodes using a fine-tuned large model. In the fine-tuning of the large model, the capabilities of smart home appliances are used as prompt words, and a control method is predefined according to the prompt words.

[0067] An optimal pseudocode filtering unit is used to filter the optimal pseudocode from several different pseudocodes;

[0068] The instruction code generation unit is used to generate executable instruction code based on the optimal pseudocode, for controlling the smart home appliance.

[0069] The electronic device of the present invention includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the computer program is loaded onto the processor, it implements the complex instruction code generation method based on a large model.

[0070] The computer-readable storage medium of the present invention stores a computer program, which, when executed by a processor, implements the method for generating complex instruction code based on a large model.

[0071] The computer program product of the present invention includes a computer program that, when executed by a processor, implements the complex instruction code generation method based on a large model.

[0072] The computer-readable storage medium may include RAM, ROM, EEPROM, CD-ROM or other optical disc storage devices, magnetic disk storage devices or other magnetic storage devices, flash memory, or any other media that can be used to store program code in the form of instructions or data structures and is accessible by a computer.

[0073] The processor is used to execute a computer program stored in memory to implement the various steps in the methods described in the above embodiments.

Claims

1. A method for generating complex instruction code based on a large model, characterized in that, Includes the following steps: The need to obtain user input for controlling smart home appliances; The requirements are converted into several different pseudocodes using the fine-tuned large model. In the fine-tuning of the large model, the capabilities of smart home appliances are used as prompt words, and control methods are predefined according to the prompt words. Select the optimal pseudocode from several different pseudocodes; Executable instruction code is generated based on the optimal pseudocode to control the smart home appliances.

2. The method for generating complex instruction code based on a large model according to claim 1, characterized in that, The method for generating executable instruction code based on the optimal pseudocode includes: extracting the control methods from the optimal pseudocode, converting them into method functions in the instruction code, and obtaining executable instruction code.

3. The method for generating complex instruction code based on a large model according to claim 2, characterized in that, The methods and functions in the instruction code include query methods and set methods.

4. The method for generating complex instruction code based on a large model according to claim 1, characterized in that, The method for selecting the optimal pseudocode from several different pseudocodes includes: using a syntax checker to filter the pseudocodes to obtain a first pseudocode; if the number of the first pseudocodes is 0, then reusing the fine-tuned large model to convert the requirement into several different pseudocodes; if the number of the first pseudocodes is 1, then the first pseudocode is the optimal pseudocode; otherwise, the optimal pseudocode is selected based on the similarity between the first pseudocode and the requirement.

5. The method for generating complex instruction code based on a large model according to claim 4, characterized in that, The method for selecting the optimal pseudocode based on the similarity between the first pseudocode and the requirement includes: The first pseudocode is converted into natural language using the finely tuned large model. The similarity between the natural language and the requirement is calculated, and the first pseudocode with the highest similarity is selected as the optimal pseudocode.

6. The method for generating complex instruction code based on a large model according to claim 5, characterized in that, The method for calculating the similarity between the natural language and the requirement includes: The natural language and the requirement are segmented using the TF-IDF model to obtain the first feature vector and the second feature vector respectively. The cosine similarity token_sim between the first feature vector and the second feature vector is calculated. The natural language and the requirement are embedded using the BGE model to obtain the third feature vector and the fourth feature vector respectively, and the cosine similarity between the third feature vector and the fourth feature vector is calculated as semantic_sim. Calculate the similarity between the natural language and the requirement. ,in, , It's a hyperparameter.

7. A complex instruction code generation system based on a large model, characterized in that, include: The demand acquisition unit is used to acquire user input regarding their needs for controlling smart home appliances. The pseudocode generation unit is used to convert the requirements into several different pseudocodes using a fine-tuned large model. In the fine-tuning of the large model, the capabilities of smart home appliances are used as prompt words, and a control method is predefined according to the prompt words. An optimal pseudocode filtering unit is used to filter the optimal pseudocode from several different pseudocodes; The instruction code generation unit is used to generate executable instruction code based on the optimal pseudocode, for controlling the smart home appliance.

8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the computer program is loaded into the processor, it implements the complex instruction code generation method based on a large model according to any one of claims 1-6.

9. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by the processor, it implements the method for generating complex instruction code based on a large model according to any one of claims 1-6.

10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by the processor, it implements the method for generating complex instruction code based on a large model according to any one of claims 1-6.