# US 2025/0148317 A1 · Method and apparatus for generating prompt data based on knowledge graph

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 2025/0148317 A1
- Document ID: US20250148317A1
- Status: Published application
- Kind: A1
- Application number: 18/905,401
- Filed: 2024-10-03
- Published: 2025-05-08
- Earliest claimed: 2023-10-12
- Assignees: Alipay (Hangzhou) Information Technology Co., Ltd.
- Applicants: Alipay (Hangzhou) Information Technology Co., Ltd.
- Inventors: Deng ZHAO; Lei SHI; Bin HU; Jianshan HE
- Web page: https://patentgrep.com/patent/US20250148317A1

## CPC

- G06N 5/04: Inference or reasoning models
- G06N 5/02: Knowledge representation; Symbolic representation
- G06N 5/022: Knowledge engineering; Knowledge acquisition
- G06N 5/025: Extracting rules from data
- G06N 5/041: {Abduction}
- G06N: COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS

## Abstract

Embodiments of this specification provide a method and an apparatus for generating a prompt based on a knowledge graph. In the method, a reasoning rule and an instance subgraph from the knowledge graph that match each other can be obtained in a plurality of manners. A question and answer template is constructed based on the reasoning rule. The question and answer template includes a question template and an answer template, and the answer template includes a cause template and a result template. A target text can be generated based on a combination of the question and answer template and the instance subgraph. The target text includes a question text and an answer text, and the answer text includes a cause text and a result text. The target text is used as a prompt to adjust a language model.

## Claims

### Claim 1

A method for generating a prompt based on a knowledge graph, comprising:
obtaining a first reasoning rule and a matched first instance subgraph, wherein the first instance subgraph is from the knowledge graph, and the first reasoning rule comprises a reasoning condition and a reasoning result;
obtaining a first question and answer template constructed based on the first reasoning rule, wherein the first question and answer template comprises a question template and an answer template, the answer template comprises a cause template and a result template, the question template and the result template are obtained by performing text conversion on the reasoning result, and the cause template is obtained by performing text conversion on the reasoning condition; and
generating a target text based on the first question and answer template and the first instance subgraph, wherein the target text comprises a question text and an answer text, the answer text comprises a cause text and a result text, and the target text is used as a prompt to adjust a language model.

### Claim 2 (depends on 1)

The method according to claim 1, wherein the step of obtaining a first reasoning rule and a matched first instance subgraph comprises:
obtaining several reasoning rules of the knowledge graph, wherein the several reasoning rules comprise the first reasoning rule; and
determining several instance subgraphs that match the first reasoning rule from the knowledge graph, wherein the several instance subgraphs comprise the first instance subgraph.

### Claim 3 (depends on 1)

The method according to claim 1, wherein the step of obtaining a first reasoning rule and a matched first instance subgraph comprises:
reading a first instance subgraph in the knowledge graph;
obtaining several reasoning rules of the knowledge graph; and
matching the first instance subgraph with the several reasoning rules, to obtain a matched first reasoning rule comprised by the several reasoning rules.

### Claim 4 (depends on 3)

The method according to claim 3, wherein the step of reading a first instance subgraph in the knowledge graph comprises:
receiving a to-be-queried first question text; and
determining a first instance subgraph associated with the first question text from the knowledge graph.

### Claim 5 (depends on 1)

The method according to claim 1, wherein the question template is determined in the following manner:
converting a text corresponding to the reasoning result into a general question, and determining the question template based on a conversion result.

### Claim 6 (depends on 5)

The method according to claim 5, wherein a text corresponding to the first reasoning rule comprises several rule elements, and the several rule elements correspond to several instance elements in the first instance subgraph; and
the step of determining the question template based on a conversion result comprises:
converting a text that is in the conversion result and that corresponds to the several rule elements into several to-be-filled slots, to obtain the question template.

### Claim 7 (depends on 1)

The method according to claim 1, wherein the result template is determined in the following manner:
combining a preset word representing a meaning of “therefore” with a text corresponding to the reasoning result, and determining the result template based on a combination result.

### Claim 8 (depends on 1)

The method according to claim 1, wherein the cause template is determined in the following manner:
combining a preset word representing a meaning of “because” with a text corresponding to the reasoning condition, and determining the cause template based on a combination result.

### Claim 9 (depends on 1)

The method according to claim 1, wherein the result template further comprises a to-be-filled probability descriptor; and
the step of generating a target text comprises:
obtaining a first evaluation indicator of the first reasoning rule;
determining a probability descriptor corresponding to the first evaluation indicator from a preset correspondence between an evaluation indicator and a probability descriptor, filling the probability descriptor into the result template, and using a result template obtained after the filling as a prefilled result template; and
generating the target text based on the question template, the cause template, the prefilled result template, and the first instance subgraph.

### Claim 10 (depends on 1)

The method according to claim 1, wherein the step of generating a target text comprises:
obtaining a first evaluation indicator of the first reasoning rule;
determining a probability descriptor corresponding to the first evaluation indicator as a first probability descriptor from a preset correspondence between an evaluation indicator and a probability descriptor; and
generating the target text, so that the first probability descriptor is comprised at a predetermined location of the target text.

### Claim 11 (depends on 1)

The method according to claim 1, wherein the first question and answer template comprises several to-be-filled slots, and the several slots correspond to several rule elements in the first reasoning rule; and the step of generating a target text comprises:
determining several instance elements that are in the first instance subgraph and that correspondingly match the several rule elements, and filling the several instance elements into the several slots, to obtain the target text.

### Claim 12

(canceled)

### Claim 13

A non-transitory computer-readable storage medium, comprising instructions stored therein that, when executed by a processor of a computing device, cause the computing device to:
obtain a first reasoning rule and a matched first instance subgraph, wherein the first instance subgraph is from a knowledge graph, and the first reasoning rule comprises a reasoning condition and a reasoning result;
obtain a first question and answer template constructed based on the first reasoning rule, wherein the first question and answer template comprises a question template and an answer template, the answer template comprises a cause template and a result template, the question template and the result template are obtained by performing text conversion on the reasoning result, and the cause template is obtained by performing text conversion on the reasoning condition; and
generate a target text based on the first question and answer template and the first instance subgraph, wherein the target text comprises a question text and an answer text, the answer text comprises a cause text and a result text, and the target text is used as a prompt to adjust a language model.

### Claim 14

A computing device, comprising a memory and a processor, wherein the memory stores executable instructions that, in response to execution by the processor, cause the computing device to:
obtain a first reasoning rule and a matched first instance subgraph, wherein the first instance subgraph is from a knowledge graph, and the first reasoning rule comprises a reasoning condition and a reasoning result;
obtain a first question and answer template constructed based on the first reasoning rule, wherein the first question and answer template comprises a question template and an answer template, the answer template comprises a cause template and a result template, the question template and the result template are obtained by performing text conversion on the reasoning result, and the cause template is obtained by performing text conversion on the reasoning condition; and
generate a target text based on the first question and answer template and the first instance subgraph, wherein the target text comprises a question text and an answer text, the answer text comprises a cause text and a result text, and the target text is used as a prompt to adjust a language model.

### Claim 15 (depends on 14)

The computing device according to claim 14, wherein the computing device being caused to obtain a first reasoning rule and a matched first instance subgraph comprises being caused to:
obtain several reasoning rules of the knowledge graph, wherein the several reasoning rules comprise the first reasoning rule; and
determine several instance subgraphs that match the first reasoning rule from the knowledge graph, wherein the several instance subgraphs comprise the first instance subgraph.

### Claim 16 (depends on 14)

The computing device according to claim 14, wherein the computing device being caused to obtain a first reasoning rule and a matched first instance subgraph comprises being caused to:
read a first instance subgraph in the knowledge graph;
obtain several reasoning rules of the knowledge graph; and
match the first instance subgraph with the several reasoning rules, to obtain a matched first reasoning rule comprised by the several reasoning rules.

### Claim 17 (depends on 16)

The computing device according to claim 16, wherein the computing device being caused to read a first instance subgraph in the knowledge graph comprises being caused to:
receive a to-be-queried first question text; and
determine a first instance subgraph associated with the first question text from the knowledge graph.

### Claim 18 (depends on 14)

The computing device according to claim 14, wherein the computing device is further caused to:
convert a text corresponding to the reasoning result into a general question, and determine the question template based on a conversion result.

### Claim 19 (depends on 18)

The computing device according to claim 18, wherein a text corresponding to the first reasoning rule comprises several rule elements, and the several rule elements correspond to several instance elements in the first instance subgraph; and
the computing device being caused to determine the question template based on a conversion result comprises being caused to:
convert a text that is in the conversion result and that corresponds to the several rule elements into several to-be-filled slots, to obtain the question template.

### Claim 20 (depends on 14)

The computing device according to claim 14, wherein the computing device is further caused to:
combine a preset word representing a meaning of “therefore” with a text corresponding to the reasoning result, and determine the result template based on a combination result.

### Claim 21 (depends on 14)

The computing device according to claim 14, wherein the computing device is further caused to:
combine a preset word representing a meaning of “because” with a text corresponding to the reasoning condition, and determine the cause template based on a combination result.
