A question and answer data generation method and system, a computer device and a storage medium
By constructing a predefined entity relationship system and knowledge graph, and combining meta-path templates with a large language model, the problems of information fragmentation and inefficiency in existing question-and-answer data generation are solved, realizing the automated generation of high-quality, comprehensive question-and-answer data, which is suitable for intelligent question-and-answer systems in the cultural field.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- 山东齐鲁壹点传媒有限公司
- Filing Date
- 2026-02-26
- Publication Date
- 2026-06-05
Smart Images

Figure CN122152985A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of natural language processing technology, specifically to a question-and-answer data generation method, system, computer device, and storage medium. Background Technology
[0002] Currently, question-and-answer data generation largely relies on simple templates or direct generation from unstructured text, failing to integrate structured knowledge graphs and hierarchical entity relationships for knowledge fusion. This results in fragmented and inaccurate question-and-answer pairs. Furthermore, these methods typically lack structured knowledge guidance based on meta-paths and do not utilize standardized prompt templates combined with large language models for automated generation. Consequently, question-and-answer data generation efficiency is low, quality is difficult to guarantee, and the data fails to meet the demands of professional fields for high-quality question-and-answer data.
[0003] Therefore, there is an urgent need for a method based on knowledge graphs and meta-path guidance that can efficiently generate high-quality question-answering data. Summary of the Invention
[0004] In view of this, the present invention provides a question-and-answer data generation method, system, computer device and storage medium to solve the problems of low question-and-answer quality, information fragmentation and low generation efficiency in the prior art.
[0005] In a first aspect, the present invention provides a question-and-answer data generation method, comprising: Based on a predefined entity relationship system, entities are identified from text data, and target relationships between entities are determined, thereby constructing a knowledge graph. The predefined entity relationship system preferably adopts a two-level classification structure, including several first-level relationship categories (such as person association, geographical association, object association, etc.), and each first-level relationship category is further subdivided into multiple second-level relationship subcategories.
[0006] Specifically, the knowledge graph construction process includes the following steps: First, named entity recognition is performed on the text to extract the entity set. During the recognition process, a hybrid model combining a pre-trained language model, a recurrent neural network (RNN), and a conditional random field (CRF) can be used. The RNN is a bidirectional long short-term memory (BiLSTM) network. Specifically, the process is as follows: a pre-trained language model (such as BERT, Bidirectional Encoder Representations from Transformers) is used to obtain the embedding vector representation of each character in the text; then, this character vector sequence is input into the BiLSTM network, and the forward and backward hidden states output by the BiLSTM network at each time step are fused. The fused vector is used as the context-related feature representation at that time step, thus obtaining the context representation of each character. Finally, the above features are input into the CRF model for decoding to predict the globally optimal entity label sequence, and entities are extracted accordingly. During the model training phase, a BIOES (Begin, Inside, Outside, End, Single) annotation system can be used to construct named entity recognition annotation data suitable for the cultural domain.
[0007] The specific process can be represented by the following formula.
[0008] ; ; P(y|x) is the probability of the target label sequence, and Z(x) is the normalization factor, which is the sum of the scores of all label sequences. and The transition weights and state weights are determined by multiplying the corresponding feature functions with their respective weights and then summing the results. The probability of the target sequence is then obtained, and the optimal label-state sequence is found using dynamic programming to achieve entity recognition.
[0009] Secondly, obtain the descriptive information of the entities. This can be achieved by crawling the entry descriptions of the corresponding entities from relevant encyclopedia knowledge bases (such as Baidu Encyclopedia), thereby constructing accompanying descriptive text for each entity.
[0010] Next, based on a predefined entity relationship system, the system determines whether a target relationship exists between any two entities in the entity set and, if so, the specific relationship category. This step is accomplished using a relationship classification model, fine-tuned from a pre-trained language model. Its input integrates descriptive information of a pair of entities, contextual vocabulary, and syntactic features. During model training, data augmentation techniques are introduced to expand the training samples, and the cross-entropy loss function is used for optimization. The model outputs relationship categories covering all categories in the predefined system, including a special "no-relationship" category.
[0011] Then, the language model is used to verify the target relationships between the identified entities, filtering out abnormal relationships with confidence levels below a preset threshold, thereby improving the accuracy and reliability of the knowledge graph.
[0012] Finally, by integrating entities, entity descriptions, and verified target relationships between entities, a structured knowledge graph is constructed.
[0013] Based on the knowledge graph, and according to a pre-defined domain-specific meta-path template, path sampling is performed starting from a specific initial entity to obtain multiple meta-paths associated with that initial entity and descriptive information of the nodes on each path. Path sampling is implemented using a weighted random walk algorithm, where the probability of walking to the next node is determined by the weight corresponding to the relationship type between the current node and the candidate node in a predefined entity relationship system. Starting from the same initial entity, multiple independent path walks are performed to obtain multiple different meta-paths. These multiple independent path walks use the same meta-path template and the same pre-defined weights, and each walk path is different from the others. The algorithm sets a path length threshold and performs redundancy removal processing on the sampled paths, retaining a pre-defined number (e.g., a maximum of 5) of core meta-paths for each initial entity.
[0014] Furthermore, based on the type of meta-path template, the corresponding prompt word template is obtained. The starting entity, its corresponding multiple meta-path information, the description information of each node, and the prompt word template are combined into a structured prompt text. This prompt text is input into a Large Language Model (LLM) fine-tuned with a cultural domain corpus. The model is instructed to perform information integration and semantic refinement to generate multiple candidate question-answer pairs with the starting entity as the topic. During the generation process, decoding strategies such as beam search can be used to improve the quality and diversity of the generated results.
[0015] Secondly, the present invention provides a question-and-answer data generation system, comprising: The knowledge graph construction module is used to identify entities from text data, obtain entity description information, determine target relationships between entities, and construct a knowledge graph based on entities, entity description information, and target relationships between entities. The meta-path sampling module is used to sample paths in the knowledge graph based on a preset meta-path template, starting from the initial entity, to obtain multiple meta-paths associated with the initial entity and description information of the nodes on each path. The prompt template acquisition module is used to obtain the corresponding prompt word template based on the type of the meta path template; The question-and-answer generation module is used to combine the starting entity, multiple meta-path information, node description information, and prompt word templates into prompt text, input the prompt text into the large language model, and generate multiple candidate question-and-answer pairs with the starting entity as the topic.
[0016] Thirdly, the present invention provides a computer device, comprising: a memory and a processor, the memory and the processor being communicatively connected to each other, the memory storing computer instructions, and the processor executing the computer instructions to perform the method described in the first aspect or any corresponding embodiment thereof.
[0017] Fourthly, the present invention provides a computer-readable storage medium storing computer instructions for causing a computer to perform the method described in the first aspect or any corresponding embodiment thereof.
[0018] Fifthly, the present invention provides a computer program product, including computer instructions for causing a computer to perform the method described in the first aspect or any corresponding embodiment thereof.
[0019] This invention utilizes a pre-defined meta-path template to sample paths within an entity-related knowledge system, starting from a primary entity. This allows for precise extraction of multiple associated paths and descriptive information for each node related to the primary entity. This approach effectively uncovers deep relationships between entities, integrates multi-path association knowledge, and overcomes the fragmented information inherent in existing question-and-answer data generation methods. It enables question-and-answer data to present comprehensive entity-related knowledge, enhancing its practical value. The automated process—from entity identification, relationship mining, and the construction of a structured entity association system to path sampling, prompt text combination, and question-and-answer generation—requires minimal manual intervention, replacing costly and inefficient manual annotation. This method can rapidly process massive amounts of text, significantly reducing the cost of generating high-quality question-and-answer data while improving data output efficiency, providing efficient and reliable data support for training large-scale models in the cultural domain. Attached Figure Description
[0020] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0021] Figure 1 This is a flowchart illustrating a question-and-answer data generation method according to an embodiment of the present invention; Figure 2 This is a schematic diagram of the meta-path sampling and question-answer generation process of a question-answer data generation method according to an embodiment of the present invention; Figure 3 This is a structural block diagram of a question-and-answer data generation system according to an embodiment of the present invention; Figure 4 This is a schematic diagram of the hardware structure of a computer device according to an embodiment of the present invention. Detailed Implementation
[0022] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0023] Currently, methods for generating high-quality question-and-answer data still face many key bottlenecks, making it difficult to meet the application needs of professional scenarios such as the cultural field. First, the traditional method of relying on manual annotation has significant limitations. The sources of textual data in the cultural field are wide-ranging (covering ancient books, archaeological reports, folk records, etc.), and the quantity and style are vast. Manual annotation not only requires annotators to have profound professional knowledge, but also faces extremely high time and manpower costs. At the same time, the accuracy and stability of the generated data are inconsistent due to the fluctuation of the annotator's professional level, making it difficult to cover massive amounts of text and resulting in a limited scope of knowledge coverage.
[0024] Secondly, rule-based or simple template-based generation methods lack the ability to deeply understand and integrate semantics. They can only match and output surface information and cannot capture the deep connections and logical chains between cultural entities. The resulting question-and-answer pairs often have semantic breaks and loose logic, making it difficult to meet the requirements of rigor and accuracy in professional scenarios.
[0025] Third, existing methods lack a systematic definition of entity relationships and a multi-source knowledge fusion mechanism for specific domains. Entity relationships in the cultural domain are complex and diverse (such as family and teacher-student relationships between people, and employment and association relationships between people and places). The lack of a unified relationship system leads to knowledge fragmentation, and effective information from multi-source data cannot be fully integrated. The generated question-and-answer content is difficult to present comprehensive knowledge related to entities.
[0026] Fourth, it failed to fully leverage the synergistic advantages of structured knowledge representation and the semantic generation capabilities of large models. It neither utilized the structured characteristics of knowledge graphs to sort out entity relationships nor used the semantic processing capabilities of large models to refine and integrate information, resulting in low efficiency in the conversion from massive amounts of text to high-quality question-answer pairs, and a large amount of effective cultural knowledge could not be efficiently mined and utilized.
[0027] Therefore, there is an urgent need for a question-and-answer data generation method adapted to the characteristics of the cultural field, which can automatically and cost-effectively mine effective information from massive amounts of text, and generate comprehensive, semantically coherent, professional and accurate question-and-answer data through systematic relationship definition and multi-source knowledge integration, so as to provide reliable data support for high-quality applications such as digital protection of cultural heritage, construction of intelligent question-and-answer systems, and popularization of professional knowledge.
[0028] According to an embodiment of the present invention, a question-and-answer data generation method embodiment is provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here. Example
[0029] This embodiment provides a question-and-answer data generation method, which takes "unstructured text related to historical figures in the cultural field" as the processing object. It elaborates on the complete execution process of the invention in detail, involving the definition of entity relationship system, knowledge graph construction, meta-path sampling and question-and-answer generation, covering core information such as figures, works, locations and cultural relics related to calligraphy from the Eastern Jin to the Tang Dynasty. Figure 1 This is a flowchart of a question-and-answer data generation method according to an embodiment of the present invention, such as... Figure 1 As shown, the process includes the following steps: Step S101: Predefine the entity relationship system.
[0030] Based on the characteristics of calligraphy-related scenarios in the cultural field, a two-level entity relationship system is constructed, clarifying the first-level relationship categories and their corresponding second-level relationship subcategories, as specifically defined below: First-level relationship categories: Person-related relationships, Material-related relationships, Geographical-related relationships Second-level relation subcategories: The relationships between people can be further subdivided as follows: mentor (master-disciple), family (parents-children, brothers-sisters), colleagues (colleagues-workers), and close friends (friends-acquaintances). Subdivided under material relationships: creation (author-work), collection (collector-collection), inheritance (inheritor-inherited works), and expertise (creator-skilled techniques). Further subdivided by geographical connections: Place of Origin (person - place of origin), Position (employer - institution), Activities (person - location of activities), Collections (collection - location of collection).
[0031] This system covers core entity association scenarios in the field of calligraphy, providing a unified and standardized classification standard for subsequent entity relationship mining, and avoiding the problem of knowledge fragmentation caused by chaotic relationship definitions.
[0032] Step S102: Constructing a knowledge graph Knowledge graph construction consists of four sub-steps: named entity recognition, entity description information acquisition, entity relationship classification, and knowledge graph integration. The specific execution process is as follows: Step S1021: Named Entity Recognition and Entity Set Acquisition Named entity recognition is performed using a BERT-BiLSTM-CRF hybrid model. The model training and execution details are as follows: Data preprocessing: Manual annotation was performed using the BIOES annotation system (the annotators were 3 researchers with backgrounds in calligraphy history). The annotated entity categories included: Person (PER), Work (WOR), Location (LOC), Artifact (ART), Institution (ORG), and Craft (SKL).
[0033] Model configuration: The pre-trained language model uses BERT-base-chinese. Unlabeled text is input into the trained hybrid model, and the execution process is as follows: The BERT model is used to encode each character in the text, generating a sequence of character vectors; The word vector sequence is input into the BiLSTM network to capture contextual features from both forward and backward directions. For example, in the text fragment “Wang Xizhi created the Preface to the Orchid Pavilion Collection”, the positive contextual features of “Wang” include information such as “Xi, Zhi, Creation, and Composition”, while the negative contextual features include empty (because “Wang” is the beginning of the sentence). After concatenation, the contextual representation is obtained. The contextual representation is input into the CRF model for decoding, and the globally optimal entity label sequence is found through a dynamic programming algorithm. The optimal label sequence is decoded, and consecutive word fragments labeled with the same entity category are extracted as entities, resulting in a set of entities, including people (such as Wang Xizhi, Lady Wei, Yan Zhenqing, etc.), works (such as "Preface to the Poems Composed at the Orchid Pavilion" and "Draft of a Eulogy for My Nephew"), places (such as Langya County, Kuaiji Mountain, Chang'an, etc.), cultural relics (such as the original copy of "Preface to the Poems Composed at the Orchid Pavilion" and the copy of "Draft of a Eulogy for My Nephew"), institutions (such as Hongwen Hall and Zhaowen Hall), and skills (such as running script, regular script, and cursive script).
[0034] Step S1022: Obtain entity description information We used web crawlers to scrape the entry descriptions of the corresponding entities from Baidu Baike. We then cleaned the scraped entry descriptions, removing redundant information such as advertising links and irrelevant comments, and retaining the core descriptive content (100-300 words).
[0035] The description information of the example entity is as follows: The physical figure "Wang Xizhi" was a renowned calligrapher of the Eastern Jin Dynasty. His courtesy name was Yishao, and his pen name was Danzhai. He was from Linyi, Langya (present-day Linyi, Shandong), later moving to Shanyin, Kuaiji (present-day Shaoxing, Zhejiang). In his later years, he lived in seclusion in Jinting, Shan County. He held various positions, including Secretary, General of Ningyuan, and Governor of Jiangzhou, eventually rising to the rank of General of the Right Army and Prefect of Kuaiji. He was known as "Wang Youjun" (Wang the Right Army). His calligraphy excelled in all styles—clerical, cursive, regular, and running script. He meticulously studied the structure and form of characters, diligently practicing and learning from various masters, mastering all styles and fusing them into a unified whole. He broke free from the Han and Wei styles, establishing his own unique style with far-reaching influence. He was revered as the "Sage of Calligraphy" by later generations. His representative works include the "Preface to the Poems Composed at the Orchid Pavilion" and the "Huang Ting Jing" (Yellow Court Classic).
[0036] The physical copy of the *Preface to the Poems Composed at the Orchid Pavilion* (also known as *Preface to the Orchid Pavilion Gathering*, *Preface to the Orchid Pavilion*, *Preface to the Poems Composed at the Riverside*, and *The Purification Ritual Postscript*) is a manuscript written by Wang Xizhi, a calligrapher of the Eastern Jin Dynasty, on the third day of the third month of the ninth year of the Yonghe era (353 AD). It was written during a purification ritual at the Orchid Pavilion in Shanyin (present-day Shaoxing, Zhejiang Province), where forty-one high-ranking military and political officials, including Xie An and Sun Chuo, composed poems. The text consists of 28 lines and 324 characters, exhibiting a graceful and flowing style throughout, with each character exquisitely crafted. The strokes are like a dance, and it is widely recognized by calligraphers throughout history as the unparalleled "Number One Running Script in the World," possessing extremely high artistic value and historical significance.
[0037] The Palace Museum, the physical building, is the imperial palace of the Ming and Qing dynasties, located at the center of Beijing's central axis and representing the pinnacle of ancient Chinese palace architecture. Established on October 10, 1925, the Palace Museum is a comprehensive museum housing a vast collection of ancient art treasures, encompassing painting, calligraphy, ceramics, bronzes, jade, and many other categories. Its calligraphy collection includes precious artifacts such as a copy of Wang Xizhi's "Preface to the Poems Composed at the Orchid Pavilion" and the original "Draft of a Eulogy for My Nephew" by Yan Zhenqing, making it a crucial institution for the study of ancient Chinese calligraphy.
[0038] Ultimately, complete descriptive information was constructed for each entity in the entity set, providing sufficient contextual support for subsequent relationship classification.
[0039] Step S1023: Entity Relationship Classification A pre-trained small model based on BERT fine-tuning is used as the relation discrimination model to determine the target relationship between entities. The model training and execution details are as follows: Training data preparation: From the entity set obtained by named entity recognition, 5000 pairs of entities were randomly selected as labeled samples. Two professional annotators labeled the relationships according to a predefined two-level entity relationship system. The labeling results included specific relationship categories or "no relationship". Finally, 4200 valid labeled samples were generated (1800 of which were "no relationship" samples). The data was then expanded by sample augmentation techniques: synonym replacement, word order adjustment, sentence splitting and recombination were performed on the entity description information of each sample to generate 3 augmented samples, resulting in 12600 training samples.
[0040] The loss function used is the cross-entropy loss function: ; Where y is the class distribution represented by one-hot encoding (0,0,1,0,...,0) indicating that the true label is the third class, and y is the probability of the model predicting the label (0.03,0.1,0.8,0.02,....,0.01).
[0041] Model training results: The test results on the validation set (1260 samples) are as follows: precision 90.5%, recall 89.8%, and F1 score 90.1%. The recognition accuracy of core relationship categories such as "creation", "apprentice", and "collection" all exceed 92%, and the recognition accuracy of the "no relationship" category is 93.2%, which can effectively filter irrelevant entity pairs.
[0042] Relation classification execution: This involves training a relation classification model on all possible entity pairs from the entity set as input. The model input features include: descriptive information of entity pairs, contextual vocabulary of entity pairs in the text data, part-of-speech tagging, dependency paths between entities, NER annotations, token sequences and proximity distances between words, and syntactic features (such as subject-verb-object structure). The model ultimately outputs the target relations between entities, forming "entity-relation-entity" triples. Some examples of triples are shown below: (Wang Xizhi studied under Lady Wei) (Wang Xizhi, author of "Preface to the Poems Composed at the Orchid Pavilion") (Preface to the Poems Composed at the Orchid Pavilion, collection of the Palace Museum) (Wang Xizhi, native of Langya Commandery) (Yan Zhenqing, author of "Draft of a Eulogy for My Nephew") (Draft of a Eulogy for My Nephew, collection of the National Palace Museum, Taipei) (Wang Xizhi was skilled in running script) (Lady Wei, specializing in calligraphy) (Yan Zhenqing, served as Prefect of Pingyuan) A total of 12,860 triplet data were generated.
[0043] Step S1024: Knowledge Graph Integration The 12,860 generated triplet data were validated using a pre-trained language model (i.e., the relation classification model fine-tuned by BERT mentioned above). 320 low-confidence triplets with a prediction probability of less than 0.7 were removed to ensure the accuracy of the graph relations.
[0044] The validated triple data was stored and integrated to construct a structured knowledge graph. First, the node types and attributes of the graph database were defined: node types correspond to entity categories (PER, WOR, LOC, etc.), and attributes include entity name, entity description, and label category. Then, relation types and attributes were defined: relation types correspond to 16 predefined specific relation categories, and attributes include relation weight (initially set to 1.0, which can be dynamically adjusted based on data popularity). Finally, 12,540 high-quality triple data were imported into the database. Through the database's graph structure optimization function, duplicate associations were automatically removed, and logical conflicts were repaired (if multiple contradictory relations exist for the same entity pair, the relation with the highest prediction probability is retained). The final knowledge graph contains 989 nodes and 12,540 relations, with an average degree of 25.3 between nodes, forming a structured knowledge network covering the core entity relationships in the calligraphy field.
[0045] Step S103: Meta-path sampling Based on the question-and-answer requirements of calligraphy scenarios in the cultural field, three domain-specific meta-path templates are pre-defined, as follows: Template 1: Person → Creation → Work → Collection → Institution (Focusing on the related knowledge of "Author-Work-Collection Location") Template 2: Person → Apprentice → Person → Strengths → Skills (Focusing on the related knowledge of "Person-Apprentice-Skills") Template 3: Person → Place of Origin → Location → Activity → Works (Focusing on the related knowledge of "Person - Place of Origin - Related Works") A weighted random walk algorithm is used for path sampling in the knowledge graph. The algorithm parameters are configured as follows: Path length threshold: 3-5 steps (to ensure semantic coherence of the path and avoid information redundancy); Relationship weights: Initial weights are set based on the importance of the relationship, with "Creation", "Mentorship", and "Collection" weighted at 1.5, "Place of Origin", "Position", and "Expertise" weighted at 1.2, and "Family", "Close Friend", and "Activities" weighted at 1.0. Number of samplings: Each starting entity is sampled 10 times to ensure coverage of different associated paths; Redundancy removal rule: The semantic similarity of paths is calculated using cosine similarity. Paths with a similarity higher than 0.85 are considered redundant paths, and only the one with the most complete semantics is retained. Number of core meta-paths retained: Each starting entity can retain a maximum of 5 core meta-paths.
[0046] Taking the initial entity "Wang Xizhi" as an example, the sampling process and results are as follows: Starting with "Wang Xizhi", sampling was conducted according to Template 1: "Person → Creation → Works → Collection → Institution": Step 1: Starting with "Wang Xizhi", based on the "creation" relationship (weight 1.5), move to the nodes "Preface to the Poems Composed at the Orchid Pavilion" (probability 0.6), "Huang Ting Jing" (probability 0.3), and "Le Yi Lun" (probability 0.1), and choose "Preface to the Poems Composed at the Orchid Pavilion" with the highest probability; Step 2: Starting from the "Preface to the Poems Composed at the Orchid Pavilion", based on the "collection" relationship (weight 1.5), walk to the nodes Palace Museum (probability 0.8) and Shaoxing Museum (probability 0.2), and choose Palace Museum; Step 3: The path length has reached 3 steps (Wang Xizhi → Creation → Preface to the Poems Composed at the Orchid Pavilion → Collection → Palace Museum), meeting the threshold requirement, so the path is retained.
[0047] Starting with "Wang Xizhi", samples were taken according to Template 2: "Person → Teacher → Person → Strengths → Skills". Step 1: Starting with "Wang Xizhi", based on the "teacher-disciple" relationship (weight 1.5), move to the nodes Lady Wei (probability 0.9) and Wang Yi (probability 0.1), and choose Lady Wei; Step 2: Starting from Lady Wei, based on the "proficiency" relationship (weight 1.2), move to the nodes of calligraphy (probability 0.7) and clerical script (probability 0.3), and choose calligraphy; Step 3: The path length is 3 steps (Wang Xizhi → Apprentice → Lady Wei → Specializes in → Calligraphy), keep this path.
[0048] The repeated sampling process ultimately retained 5 core meta-paths for "Wang Xizhi", as follows: Path 1: Wang Xizhi → Creation → "Preface to the Poems Composed at the Orchid Pavilion" → Collection → Palace Museum Path 2: Wang Xizhi → Apprentice → Lady Wei → Specializes in → Calligraphy Path 3: Wang Xizhi → Place of Origin → Langya County → Activities → "Preface to the Poems Composed at the Orchid Pavilion" Path 4: Wang Xizhi → Creation → *Huang Ting Jing* → Transmission → Wang Xianzhi Path 5: Wang Xizhi → Close Friend → Xie An → Appointment → Eastern Jin Dynasty Court At the same time, the descriptive information of the nodes on each path is obtained. For example, the node description information of path 1 includes a brief introduction to Wang Xizhi, a brief introduction to the "Preface to the Poems Composed at the Orchid Pavilion", and a brief introduction to the Palace Museum, providing sufficient information support for subsequent question and answer generation.
[0049] Step S104: Question and Answer Data Generation Through a path cluster fusion mechanism, multiple core meta-paths and node description information of the starting entity are integrated to avoid information fragmentation caused by a single path and ensure the comprehensiveness of question-and-answer data. Question-and-answer data generation consists of two sub-steps: prompt text construction and large model generation. The specific execution process is as follows: Step S1041: Constructing the prompt text First, the corresponding prompt word template is matched based on the semantic type of the metapath. The preset prompt word template library is as follows: Template A (Creation-Collection Path): "Given the association information of entity [{Starting Entity}]: {Path Information}, {Node Description Information}. Please generate 3 professional and accurate question-and-answer pairs based on the creation and collection status of the works of [{Starting Entity}]. The questions should be clear, the answers concise, and contain core information." Template B (Mentor-Expertise Path): "Given the association information of entity [{Starting Entity}]: {Path Information}, {Node Description Information}. Please generate 3 professional and accurate question-and-answer pairs based on the mentorship relationship and expertise of [{Starting Entity}]. The questions should be targeted and the answers logically clear." Template C (Place of Origin - Activity Path): "Given the association information of entity [{Starting Entity}]: {Path Information}, {Node Description Information}. Please generate 3 professional and accurate question-and-answer pairs based on the place of origin and related activities of [{Starting Entity}], requiring complete information that incorporates historical context." Taking the five core meta-paths of the starting entity "Wang Xizhi" as an example, paths 1 and 4 belong to the creation-collection category and match template A; path 2 belongs to the apprenticeship-expertise category and matches template B; path 3 belongs to the place of origin-activity category and matches template C. The starting entity, meta-path information, and node description information are combined according to the template format to form the prompt text, as shown in the example below: "Known association information of the entity [Wang Xizhi]:" Path 1: Wang Xizhi → Creation → "Preface to the Poems Composed at the Orchid Pavilion" → Collection → Palace Museum; Path 2: Wang Xizhi → Apprentice to → Lady Wei → Specializes in → Calligraphy; Path 3: Wang Xizhi → Place of Origin → Langya County → Activities → "Preface to the Poems Composed at the Orchid Pavilion"; Path 4: Wang Xizhi → Creation → "Huang Ting Jing" → Inheritance → Wang Xianzhi; Path 5: Wang Xizhi → Close Friend → Xie An → Appointment → Eastern Jin Dynasty Court.
[0050] Node description information: Wang Xizhi: A famous calligrapher of the Eastern Jin Dynasty, courtesy name Yishao, sobriquet Danzhai, was a native of Linyi, Langya (present-day Linyi, Shandong), later moved to Shanyin, Kuaiji (present-day Shaoxing, Zhejiang). In his later years, he lived in seclusion in Jinting, Shan County. He was known as "Wang Youjun" and was praised by later generations as the "Sage of Calligraphy". His representative works include "Preface to the Poems Composed at the Orchid Pavilion" and "Huangting Jing". The Preface to the Poems Composed at the Orchid Pavilion: also known as the Preface to the Orchid Pavilion Gathering, is a manuscript written by Wang Xizhi on the third day of the third month of the ninth year of Yonghe (1493) at the Orchid Pavilion in Shanyin, Kuaiji, for the poems composed by the participants. It consists of 28 lines and 324 characters and is hailed as the "Number One Running Script in the World". The Palace Museum: the imperial palace of the Ming and Qing dynasties in China, houses a large collection of ancient art treasures, including a copy of the "Preface to the Poems Composed at the Orchid Pavilion". Lady Wei: A famous female calligrapher of the Eastern Jin Dynasty, skilled in calligraphy, and the calligraphy teacher of Wang Xizhi; Langya Commandery: Wang Xizhi's birthplace, located in the area of present-day Linyi, Shandong. The Huangting Jing: One of Wang Xizhi's representative works, it is a calligraphic work based on a classic Taoist text; Wang Xianzhi: Son of Wang Xizhi, also a famous calligrapher, who inherited Wang Xizhi's calligraphic skills; Xie An: A politician and military strategist of the Eastern Jin Dynasty, a close friend of Wang Xizhi, and served in the Eastern Jin court.
[0051] Based on the information above, please generate six professional and accurate question-and-answer pairs focusing on Wang Xizhi's artistic creations, teacher-student relationships, place of origin and activities, and close friendships. The questions should be clear and specific, the answers concise and complete, the meaning coherent, and they should meet the requirements of a professional calligraphy context. Step S1042: Large Model Generation The large language model was fine-tuned using a corpus of calligraphy-related texts in the cultural field. The fine-tuning data included: 1,000 professional Q&A pairs in the field of calligraphy, abstracts of 500 research papers on the history of calligraphy, and excerpts from 300 ancient books and documents related to calligraphy.
[0052] The constructed prompt text is input into the fine-tuned model, and a BeamSearch=3 decoding strategy is used to generate three candidate question-answer pairs. The optimal result is then selected based on semantic coherence, professional accuracy, and comprehensive information. Some of the generated results are shown below: Q: Which calligrapher did Wang Xizhi study under? A: Wang Xizhi studied calligraphy under Lady Wei, a famous female calligrapher of the Eastern Jin Dynasty. Lady Wei was skilled in calligraphy and had a profound influence on the improvement of Wang Xizhi's calligraphy skills.
[0053] Q: What is Wang Xizhi's masterpiece, the "Preface to the Poems Composed at the Orchid Pavilion," hailed as the "Number One Running Script in the World"? Where is it currently housed? A: Wang Xizhi's masterpiece, the "Preface to the Poems Composed at the Orchid Pavilion," is hailed as the "Number One Running Script in the World," and a copy of it is currently housed in the Palace Museum.
[0054] Q: Where was Wang Xizhi's birthplace? Where did he spend his time? A: Wang Xizhi's birthplace was Langya Commandery (present-day Linyi area, Shandong). He was active in Kuaiji Shanyin (present-day Shaoxing, Zhejiang), and in his later years he lived in seclusion in Jinting, Shan County.
[0055] Q: Besides the "Preface to the Poems Composed at the Orchid Pavilion," what other famous representative works does Wang Xizhi have? A: In addition to the "Preface to the Poems Composed at the Orchid Pavilion," Wang Xizhi's famous representative works also include the "Huang Ting Jing" and "Le Yi Lun," among others.
[0056] Q: To whom did Wang Xizhi pass on his calligraphy skills? A: Wang Xizhi mainly passed on his calligraphy skills to his son, Wang Xianzhi, who was also a famous calligrapher in the Eastern Jin Dynasty. He and Wang Xizhi are collectively known as the "Two Wangs".
[0057] Q: What position did Xie An, Wang Xizhi's close friend, hold? A: Xie An, Wang Xizhi's close friend, was a politician and military strategist during the Eastern Jin Dynasty. He served in the Eastern Jin court and played an important role in the Battle of Fei River.
[0058] This step generated 20 high-quality question-and-answer pairs for the starting entity "Wang Xizhi," covering multiple dimensions such as works, teachers, place of origin, inheritance, and close friends. The semantic coherence and professional accuracy of the question-and-answer pairs meet the application requirements of intelligent question-and-answer systems in the cultural field.
[0059] Step S105: Batch generation and quality verification Following steps S101-S104 above, question-and-answer data was generated for each of the 326 entities in the knowledge graph, ultimately producing 6520 question-and-answer pairs. Quality assessment was conducted using a combination of manual and automatic verification: 10% (652 pairs) of the question-and-answer pairs were manually verified and scored by two professionals based on three dimensions: semantic coherence, professional accuracy, and information completeness (out of 10), with an average score of 9.2. Automatic verification used indicators such as BLEU score, ROUGE-L score, and semantic similarity, comparing the data with the manually annotated high-quality question-and-answer data. The BLEU score was 0.85, the ROUGE-L score was 0.88, and the semantic similarity was 0.91, all higher than the industry average, indicating excellent quality of the generated question-and-answer data.
[0060] This embodiment achieves efficient transformation from massive amounts of unstructured cultural text to high-quality question-and-answer data by fully implementing the question-and-answer data generation method of the present invention. The generated question-and-answer data covers core knowledge in the field of calligraphy and can provide reliable data support for the training of large-scale models in the cultural field and the construction of intelligent question-and-answer systems. At the same time, it significantly reduces the cost of manual annotation (traditional manual annotation of 6520 question-and-answer pairs requires about 30 people / day, while this method only requires 2 people / day to complete data preprocessing and quality verification) and improves data output efficiency. Example
[0061] The difference between this embodiment and Embodiment 1 is that it focuses on unstructured texts of "ancient buildings in the cultural field" (including ancient building archives, repair records, historical documents, etc.). Example
[0062] The difference between this embodiment and Embodiment 1 is that it uses structured and semi-structured text data.
[0063] This embodiment also provides a question-and-answer data generation system. This device is used to implement the above embodiments and preferred embodiments, and details already described will not be repeated. As used below, the term "module" can be a combination of software and / or hardware that implements a predetermined function. Although the device described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.
[0064] This embodiment provides a question-and-answer data generation system, such as... Figure 3 As shown, it includes: The knowledge graph construction module is used to identify entities from text data, obtain entity description information, determine target relationships between entities, and construct a knowledge graph based on entities, entity description information, and target relationships between entities. The meta-path sampling module is used to sample paths in the knowledge graph based on a preset meta-path template, starting from the initial entity, to obtain multiple meta-paths associated with the initial entity and description information of the nodes on each path. The prompt template acquisition module is used to obtain the corresponding prompt word template based on the type of the meta path template; The question-and-answer generation module is used to combine the starting entity, multiple meta-path information, node description information, and prompt word templates into prompt text, input the prompt text into the large language model, and generate multiple candidate question-and-answer pairs with the starting entity as the topic.
[0065] Further functional descriptions of the above modules and units are the same as those in the corresponding embodiments described above, and will not be repeated here.
[0066] In this embodiment, a question-and-answer data generation system is presented in the form of functional units. Here, a unit refers to an ASIC (Application Specific Integrated Circuit) circuit, a processor and memory that execute one or more software or fixed programs, and / or other devices that can provide the above functions.
[0067] This invention also provides a computer device having the above-described features. Figure 4 This is a question-and-answer data generation system.
[0068] Please see Figure 4 , Figure 4 This is a schematic diagram of the structure of a computer device provided in an optional embodiment of the present invention, such as... Figure 4 As shown, the computer device includes one or more processors 10, memory 20, and interfaces for connecting the components, including high-speed interfaces and low-speed interfaces. The components communicate with each other via different buses and can be mounted on a common motherboard or otherwise installed as needed. The processors can process instructions executed within the computer device, including instructions stored in or on memory to display graphical information of a GUI on external input / output devices (such as display devices coupled to the interfaces). In some alternative implementations, multiple processors and / or multiple buses can be used with multiple memories and multiple memory modules, if desired. Similarly, multiple computer devices can be connected, each providing some of the necessary operations (e.g., as a server array, a group of blade servers, or a multiprocessor system). Figure 4 Take a processor 10 as an example.
[0069] Processor 10 may be a central processing unit, a network processor, or a combination thereof. Processor 10 may further include a hardware chip. The hardware chip may be an application-specific integrated circuit (ASIC), a programmable logic device (PLD), or a combination thereof. The programmable logic device may be a complex programmable logic device (CAMP), a field-programmable gate array (FPGA), a general-purpose array logic (GDA), or any combination thereof.
[0070] The memory 20 stores instructions executable by at least one processor 10 to cause the at least one processor 10 to perform the method shown in the above embodiments.
[0071] The memory 20 may include a program storage area and a data storage area. The program storage area may store the operating system and applications required for at least one function; the data storage area may store data created based on the use of the computer device. Furthermore, the memory 20 may include high-speed random access memory and may also include non-transitory memory, such as at least one disk storage device, flash memory device, or other non-transitory solid-state storage device. In some alternative embodiments, the memory 20 may optionally include memory remotely located relative to the processor 10, and these remote memories may be connected to the computer device via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.
[0072] The memory 20 may include volatile memory, such as random access memory; the memory may also include non-volatile memory, such as flash memory, hard disk or solid-state drive; the memory 20 may also include a combination of the above types of memory.
[0073] The computer device also includes a communication interface 30 for communicating with other devices or communication networks.
[0074] This invention also provides a computer-readable storage medium. The methods described above according to embodiments of the invention can be implemented in hardware or firmware, or implemented as computer code that can be recorded on a storage medium, or implemented as computer code downloaded via a network and originally stored on a remote storage medium or a non-transitory machine-readable storage medium and then stored on a local storage medium. Thus, the methods described herein can be processed by software stored on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. The storage medium can be a magnetic disk, optical disk, read-only memory, random access memory, flash memory, hard disk, or solid-state drive, etc.; further, the storage medium can also include combinations of the above types of memory. It is understood that computers, processors, microprocessor controllers, or programmable hardware include storage components capable of storing or receiving software or computer code, which, when accessed and executed by the computer, processor, or hardware, implements the methods shown in the above embodiments.
[0075] A portion of this application can be applied as a computer program product, such as computer program instructions, which, when executed by a computer, can invoke or provide the methods and / or technical solutions according to this application through the operation of the computer. Those skilled in the art will understand that the forms in which computer program instructions exist in a computer-readable medium include, but are not limited to, source files, executable files, installation package files, etc. Correspondingly, the ways in which computer program instructions are executed by a computer include, but are not limited to: the computer directly executing the instructions, or the computer compiling the instructions and then executing the corresponding compiled program, or the computer reading and executing the instructions, or the computer reading and installing the instructions and then executing the corresponding installed program. Here, the computer-readable medium can be any available computer-readable storage medium or communication medium accessible to a computer.
[0076] Although embodiments of the invention have been described in conjunction with the accompanying drawings, those skilled in the art can make various modifications and variations without departing from the spirit and scope of the invention, and such modifications and variations all fall within the scope defined by the appended claims.
Claims
1. A method for generating question-and-answer data, characterized in that, The method includes: Perform named entity recognition on the text to obtain an entity set; Obtain the description information of the entity; Based on a predefined entity relationship system, the target relationships between entities in the entity set are determined; Based on the entity, the description information, and the target relationship, the knowledge graph is constructed after the relationship is determined and verified by the language model. Based on the preset meta-path template, path sampling is performed in the knowledge graph starting from the starting entity to obtain multiple meta-paths associated with the starting entity and node description information on each path; Based on the type of the metapath template, obtain the corresponding prompt word template; The starting entity, the multiple meta-path information, the node description information, and the prompt word template are combined into prompt text; The prompt text is input into a large language model to generate multiple candidate question-answer pairs with the starting entity as the topic.
2. The question-and-answer data generation method according to claim 1, characterized in that, The process of performing named entity recognition on text to obtain an entity set includes: The character vector representation of each character in the text is obtained by using a pre-trained language model, resulting in a character vector sequence; The word vector sequence is input into a recurrent neural network to capture contextual features and obtain context-related feature representations for each word; The context-related features are input into the conditional random field model for decoding to determine the globally optimal entity label sequence; Based on the globally optimal entity tag sequence, consecutive word fragments with preset entity category tags are extracted as entities to form the entity set.
3. The question-and-answer data generation method according to claim 2, characterized in that, The process of obtaining the context-related feature representation of each character includes: fusing the positive hidden state and the negative hidden state output by the recurrent neural network at each time step, and using the fused vector as the context-related feature representation corresponding to that time step.
4. The question-and-answer data generation method according to claim 1, characterized in that, The path sampling in the knowledge graph, starting from the initial entity, includes: Based on the preset meta-path template, the path is traversed in the knowledge graph, starting from the initial entity; The transition probability to the next node is determined by the preset weight corresponding to the relationship type between the current node and the candidate node in the predefined entity relationship system; The path traversal process includes a path length threshold to ensure the semantic coherence of the metapath.
5. The question-and-answer data generation method according to claim 4, characterized in that, The path traversal in the knowledge graph includes: Starting from the same initial entity, multiple independent path walks are performed to obtain multiple different meta-paths; The multiple independent path walks use the same meta-path template and the same preset weights, but each walk path is different from the others.
6. The question-and-answer data generation method according to claim 5, characterized in that, The path sampling also includes: The multiple meta-paths obtained from the walk are deredundant to obtain the core meta-paths, and a preset number of core meta-paths are retained for each starting entity.
7. A question-and-answer data generation system, characterized in that, The system includes: The knowledge graph construction module is used to identify entities from text data, obtain the descriptive information of the entities, determine the target relationships between entities, and construct a knowledge graph based on the entities, entity descriptive information, and target relationships between entities. The meta-path sampling module is used to sample paths in the knowledge graph based on a preset meta-path template, starting from the starting entity, to obtain multiple meta-paths associated with the starting entity and description information of the nodes on each path. The prompt template acquisition module is used to acquire the corresponding prompt word template according to the type of the meta path template; The question-and-answer generation module is used to combine the starting entity, the multiple meta-path information, the node description information, and the prompt word template into prompt text, input the prompt text into the large language model, and generate multiple candidate question-and-answer pairs with the starting entity as the topic.
8. A computer device, characterized in that, include: A memory and a processor, the memory and the processor being communicatively connected to each other, the memory storing computer instructions, the processor executing the computer instructions to perform the method of any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions for causing a computer to perform the method of any one of claims 1 to 6.
10. A computer program product, characterized in that, Includes computer instructions for causing a computer to perform the method of any one of claims 1 to 6.