Question and answer pair automatic generation method and system for medical long text
By integrating text segmentation, structured processing, and multi-dimensional task identifiers, combined with keyword alignment and semantic similarity verification, the problems of semantic fragmentation and lack of diversity in medical question-answer pair generation are solved, achieving high-quality and diverse question-answer pair generation, and improving the performance and application effect of medical AI models.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-02-13
- Publication Date
- 2026-04-14
Smart Images

Figure CN121858718A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the technical field of combining natural language processing with medical artificial intelligence, and more specifically, to a method and system for automatically generating question-answer pairs for long medical texts. Background Technology
[0002] With the deep penetration and widespread application of large language models (LLM) in the field of natural language processing (NLP), the demand for high-quality, large-scale, and professional instruction data in the medical field is becoming increasingly urgent. Medical question-answer pairs, as the core form of instruction data, are key elements for optimizing the performance of medical AI models (such as medical question-answering systems, clinical decision support platforms, etc.), improving the accuracy of medical knowledge, logical coherence, and domain adaptability of the models [2]. In practical application scenarios such as medical diagnosis assistance, medical knowledge popularization, and clinical pathway planning, the performance of the model directly depends on the quality of the training question-answer pairs - complete and relevant question-answer pairs can help the model accurately capture core medical knowledge, while diverse instruction forms can improve the model's generalization ability to cope with complex scenarios. However, existing medical question-answer pair generation methods have significant technical bottlenecks in long text processing and instruction diversity generation, which seriously restrict the further development and application of medical AI models.
[0003] Firstly, there is insufficient capability in processing long texts, making it difficult to generate complete and relevant question-and-answer pairs. Core textual data in the medical field (such as medical research papers, multi-chapter clinical guidelines, and complex case reports) are typically characterized by their length, high information density, and complex knowledge structure. The length of a single medical paper or clinical guideline often far exceeds that of ordinary natural language text, and it contains a large amount of highly structured knowledge content such as professional terminology, pathological mechanisms, and treatment procedures. Existing instruction generation methods generally suffer from semantic fragmentation and topic drift when processing such long texts, resulting in question-and-answer pairs that fail to fully cover core knowledge and lack relevance. Traditional paragraph-level generation strategies (such as DoG-Instruct) rely solely on single paragraphs for question-and-answer pair generation, lacking an understanding of the overall document context. Key information such as core research conclusions and core treatment principles contained in the document summary are not fully utilized, causing the model to easily become limited to local paragraph information when generating questions and answers, failing to connect with the overall document theme. Consequently, the question-and-answer pairs deviate from core medical knowledge and fail to reflect the core points of the text. While reverse instruction generation methods (such as LongForm) attempt to infer instructions from long documents, they primarily capture explicit content and struggle to handle implicit logic such as argument chains and pathological mechanism derivations in academic texts. Furthermore, they lack support for complex cross-paragraph reasoning. For instance, when processing multi-chapter clinical guidelines, existing methods struggle to integrate scattered information from different chapters regarding diagnostic criteria, treatment plans, and prognostic assessments for the same disease to generate question-and-answer pairs that cover the entire disease management process. This results in highly fragmented content that fails to meet the stringent requirements of the medical field for complete and logically sound instruction generation. Moreover, existing methods often neglect semantic connections between paragraphs when processing long text segments. The fragmentation of information between adjacent paragraphs leads to a lack of coherence in the generated question-and-answer pairs, further reducing data quality and usability, and hindering the accurate knowledge learning and application capabilities of medical AI models.
[0004] Then there's the issue of insufficient diversity in instruction generation and limited generalization ability: Medical applications are highly complex and diverse, encompassing multiple dimensions such as disease diagnosis, treatment selection, medication guidance, prognosis management, and medical knowledge Q&A. Different scenarios have different requirements for instruction format, questioning angle, and task type. However, existing methods, whether manually generated or automatically generated by models, suffer from limited instruction format and coverage, making it difficult to meet the diverse application needs of the medical field. Manually generated (HG) instruction models rely on professional medical personnel or domain annotation experts manually designing templates and annotating data. For example, the instruction data used in OpenAI's InstructGPT model is constructed from prompts written by professional annotators, while the SuperNaturalInstructions dataset manually compiled instructions corresponding to 161 natural language processing tasks. These methods are limited by the annotators' knowledge background, thought patterns, and workload, resulting in a lack of diversity in the question-answer pairs generated in terms of question format and task type. They often focus on factual questions and answers, while failing to cover multiple task types such as causal reasoning (e.g., "Why is a certain drug effective for a specific disease?"), contextual judgment (e.g., "What disease's diagnostic criteria does a patient's clinical symptoms meet?"), and text summarization. Furthermore, the question sentence structure is monotonous, making it difficult to train models to handle diverse question scenarios. At the same time, the high cost and low efficiency of manual annotation result in a limited scale of generated instruction data, further restricting the diversity of instruction coverage. While automatic model generation methods (such as Self-Instruct) improve generation efficiency through a pipeline model of "seed instruction-generation-filtering-fine-tuning," enabling the performance of the GPT-3 model, they are prone to falling into fixed generation paradigms in long medical text processing, leading to high semantic repetition of generated instructions. Due to the lack of targeted design for multiple task types in the medical field, the question-answer pairs generated by the model often concentrate on a few common task types, failing to cover the multi-scenario and multi-dimensional knowledge needs of the medical field. Related experimental data shows that in medical question-and-answer pairs generated by existing automatic model generation methods, factual questions account for over 70%, while complex types of questions such as causal reasoning and situational judgments account for a very low percentage. Furthermore, the sentence structure is highly similar, and the self-BLEU index is high, indicating a severe lack of instruction diversity. This lack of instruction diversity limits the generalization ability of trained medical AI models. When faced with diverse question scenarios and task requirements in real-world applications, it is difficult to flexibly adjust the response logic and generate accurate, tailored responses, significantly impacting the model's practical application effectiveness.
[0005] Through extensive research and practice, the inventors of this application have discovered that existing methods lack effective technical means to address the two core problems mentioned above: Firstly, regarding the semantic fragmentation problem in long text processing, an effective mechanism for integrating global document information has not been established, failing to fully utilize the complementary information between the summary and the main text to improve the completeness and relevance of question-answer pairs. Secondly, regarding the insufficient diversity of instructions, there is a lack of systematic design for multiple task types in the medical field, and no training paradigm has been constructed to guide the model in generating diverse instructions. These technical bottlenecks overlap, making it difficult for existing medical question-answer pair generation methods to produce high-quality, diverse instruction data, severely restricting the performance improvement and application of medical AI models. Therefore, a technical solution that can effectively solve the problems of incomplete long text processing and insufficient diversity of instruction generation is urgently needed. Summary of the Invention
[0006] To address the shortcomings of existing technologies, such as insufficient long text processing capabilities and a lack of diverse instruction generation methods, this invention proposes an automatic question-and-answer pair generation method and system for medical long texts. This method can transform the latest medical knowledge into standardized QA pairs, helping large medical models to quickly internalize professional knowledge and meet the demand for high-quality QA data in multiple scenarios.
[0007] To achieve the above objectives, a first aspect of the present invention provides a method for automatically generating question-answer pairs for long medical texts, comprising: Collect medical text data; The collected data undergoes text splitting, structuring, and data cleaning. The text summary obtained after splitting is concatenated with the corresponding text fragments, and multi-dimensional task type identifiers are incorporated into the concatenated text. The fused text is then input into the instruction wrapper to generate an initial set of question-answer pairs. A dual filtering mechanism of keyword alignment and semantic similarity verification was adopted to select target question-answer pairs from the initial question-answer pair set to form a medical question-answer pair set, which was used as training data; The pre-defined base model is trained using training data. During the training process, LoRA low-rank adaptation technology is introduced to train only the low-rank matrix parameters of the model. The trained model is used to automatically generate question-answer pairs.
[0008] In one implementation, medical text data collection includes multi-domain long text subsets of existing datasets, medical research papers, clinical guidelines, and electronic medical records.
[0009] In one implementation, the collected data undergoes text splitting and structuring processing, including: For a structurally complete long text, a splitting method based on chapter titles and semantic boundaries is adopted to automatically extract the abstract part, and the main text is split into multiple segments according to the logical structure; For the dataset related to the abstract in the multi-domain long text subset of the existing dataset, for each dataset, the main text is split into multiple judgments according to the length, and the abstract of the current data is used as the abstract part.
[0010] In one implementation, the text abstract obtained after splitting is spliced with the corresponding main text segment, and a multi-dimensional task type identifier is incorporated, including: The text abstract obtained after splitting is spliced with the corresponding main text segment to form the input text :
[0011] Among them, represents the abstract part of the j-th document, is the main text segment of the j-th document; Use a large model to classify the task, and incorporate the obtained multi-dimensional task identifiers into the spliced text. Among them, the task types include fact extraction, causal reasoning, context judgment, text summarization, and comparative analysis.
[0012] In one implementation, the fused text is input into an instruction wrapper to generate an initial set of question-answer pairs, including: Input the fused text into the instruction wrapper, and set the maximum generation length during the generation process to limit the length of the answer; Perform format verification on the generated answer to generate an initial set of question-answer pairs.
[0013] In one implementation, a dual filtering mechanism of keyword alignment screening and semantic similarity verification is adopted to screen out target question-answer pairs from the initial set of question-answer pairs to form a medical question-answer pair set, including: For the fused text and the initial set of question-answer pairs, extract the core keywords respectively, calculate the Jaccard similarity between the keywords of the initial question-answer pairs and the text keywords, and screen out candidate data related to the theme according to the first similarity threshold; Use the Sentence-BERT model to perform semantic encoding on the answers and the original text in the question-answer pairs in the candidate data, calculate the cosine similarity between the two, and retain the question-answer pairs with qualified semantic similarity as the target question-answer pairs according to the second similarity threshold to form a medical question-answer pair set.
[0014] In one implementation, the calculation method of the Jaccard similarity between the keywords of the initial question-answer pairs and the text keywords is:
[0015] Let be the set of keywords in the source document corresponding to the i-th question-answer pair. Let i be the set of keywords for the i-th question-answer pair; The cosine similarity between the semantic encoding of the answer in the question-answer pair in the candidate data and the semantic encoding of the original text is calculated as follows:
[0016] in , For the i-th answer , For the answer in the i-th question-and-answer pair The sentence embedding vectors, generated by the Sentence-BERT model, are used to reflect... semantic features; It is the source document corresponding to the i-th question-answer pair. The sentence embedding vectors are generated by the Sentence-BERT model to reflect the semantic features of the source document.
[0017] Based on the same inventive concept, a second aspect of the present invention provides an automatic question-answer pair generation system for long medical texts, comprising: The data acquisition module is used to collect medical text data; The data splitting and cleaning module is used to perform text splitting, structuring, and data cleaning on the collected data. The initial question-answer pair generation module is used to concatenate the text summary obtained after splitting with the corresponding text fragments, and to incorporate multi-dimensional task type identifiers into the concatenated text. The fused text is then input into the instruction wrapper to generate the initial question-answer pair set. The dual filtering module is used to select target question-answer pairs from the initial question-answer pair set using a dual filtering mechanism of keyword alignment and semantic similarity verification, forming a medical question-answer pair set as training data; The model training module is used to train a preset base model using training data. During the training process, LoRA low-rank adaptation technology is introduced to train only the low-rank matrix parameters of the model. The question-answer pair automatic generation module is used to automatically generate question-answer pairs using a trained model.
[0018] Based on the same inventive concept, a third aspect of the present invention provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, provides the method for automatically generating question-answer pairs for long medical texts as described in the first aspect.
[0019] Based on the same inventive concept, a fourth aspect of the present invention provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the automatic question-answer pair generation method for medical long texts described in the first aspect.
[0020] Compared with the prior art, the advantages and beneficial technical effects of the present invention are as follows: This invention proposes an automatic question-answer pair generation method for long medical texts. The method involves text segmentation, structuring, and data cleaning of the collected data. The resulting text summary is concatenated with the corresponding text fragments, and a multi-dimensional task type identifier is incorporated into the concatenated text. This merged text is then input into an instruction wrapper to generate an initial question-answer pair set. A dual filtering mechanism of keyword alignment and semantic similarity verification is then used to select target question-answer pairs from the initial set, forming a medical question-answer pair set as training data. This training data is used to train a pre-defined basic model, incorporating LoRA low-rank adaptation technology to train only the model's low-rank matrix parameters. Finally, the trained model is used for automatic question-answer pair generation. Notably, in generating the initial question-answer pair set, the method innovatively concatenates the summary with the text fragments to form the training input. This leverages the global topic information contained in the summary to constrain the direction of local knowledge extraction from the text, addressing the lack of overall contextual control in traditional paragraph-level generation strategies. This fusion approach allows the model to focus on specific knowledge points within paragraphs while also connecting them to the core theme of the document when generating QA pairs. This ensures that the generated QA pairs fully cover the key information in the text, avoiding knowledge fragmentation and content incompleteness caused by relying on a single paragraph. Furthermore, by incorporating multi-dimensional task type identifiers into the concatenated text, the model receives clear and diverse training guidance. Compared to the traditional single instruction generation paradigm, this design allows the model to learn QA generation logic from different scenarios and perspectives during training, laying a solid foundation for subsequent output of diverse instructions, while avoiding the monotonous format problem caused by the inertia of manual annotation. Furthermore, a dual filtering mechanism of keyword alignment screening and semantic similarity verification is adopted to select target question-answer pairs from the initial question-answer pair set to form a medical question-answer pair set as training data. Through two rounds of progressive filtering, it is ensured that the QA pairs are highly consistent with the source text, which can effectively reduce the model illusion risk and ensure that the topic of each data is closely aligned with the source text. In the end, high-quality question-answer pairs can be output, which can help the medical large model to quickly internalize professional knowledge and meet the demand for high-quality QA data in multiple scenarios. Attached Figure Description
[0021] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the 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 based on these drawings without creative effort.
[0022] Figure 1 This is a flowchart of the method for automatically generating question-answer pairs for long medical texts in an embodiment of the present invention; Figure 2 This is a detailed flowchart of the question-answer pair generation in an embodiment of the present invention; Figure 3 This is a flowchart illustrating the dual filtering mechanism of keyword alignment screening and semantic similarity verification in an embodiment of the present invention. Figure 4 This is a schematic diagram showing the county-level distribution of multiple models trained in this embodiment of the invention in terms of semantic entropy; Figure 5 This is a schematic diagram comparing the differences in the generation results of different models in an embodiment of the present invention; Figure 6 This is a structural diagram of the question-answer pair automatic generation system for long medical texts in an embodiment of the present invention; Figure 7 This is a framework diagram of the question-answer pair automatic generation system for long medical texts in an embodiment of the present invention; Figure 8 This is a schematic diagram of API calls in an embodiment of the present invention. Detailed Implementation
[0023] Example 1 This embodiment provides a method for automatically generating question-answer pairs for long medical texts. Please refer to [link to relevant documentation]. Figure 1 ,include: S1: Collect medical text data.
[0024] Specifically, S1 is data acquisition.
[0025] The medical text data collected includes multi-domain long text subsets of existing datasets, medical research papers, clinical guidelines, and electronic medical records.
[0026] Existing medical instruction construction often faces problems including: low domain coverage (focusing only on short articles from a single department), low authority (mixed sources of online science popularization), and low diversity (single question-and-answer type). This leads to frequent illusions, numerous blind spots in departmental knowledge, and fragmented context in long texts during subsequent model fine-tuning. This invention proposes a "13 departments × dual authoritative sources" cross-collection strategy. Specifically, this strategy refers to the complementary fusion of two types of authoritative data sources, ensuring both the professionalism and comprehensiveness of medical domain knowledge, while also enhancing the model's core capabilities through cross-domain long text task generalization. The specific implementation is as follows: (1) Medical-related subset of LongBench dataset: A subset of long texts from multiple domains in the LongBench dataset (including government reports, news summaries, meeting minutes, etc.) is selected as the basis for generalization training. The core value of this dataset lies in providing a large number of structured long text samples with abstracts and main text. The model can learn the general rules in this cross-domain data, such as "how to locate key information in the main text based on the abstract, how to mine the semantic relationship between the abstract and the main text, and how to generate compliant question-answer pairs around the related content", and form the ability to generalize to abstract-text fusion question-answer generation tasks. This generalization ability can be transferred to the medical field to help the model quickly grasp the relationship logic between the abstract (core conclusion) and the main text (experimental data, treatment basis) in medical papers, solve the problem of context breakage and inaccurate extraction of key information in long medical texts, and fit the core design concept of abstract-text fusion in this invention.
[0027] (2) Medical Guidelines: Nearly 10,000 core journal articles from 13 core medical departments serve as the source of professional knowledge support. Core journal articles ensure the authority and professionalism of medical knowledge, which can fill the professional gaps in online popular science data, comprehensively cover the knowledge of disease diagnosis and treatment, pathological mechanisms and other sub-fields in various departments, solve the problem of departmental knowledge blind spots in the model, and provide a solid domain knowledge foundation for instruction generation in medical scenarios;
[0028] S2: Perform text splitting and structuring processing on the collected data, as well as data cleaning.
[0029] Figure 2 This is a detailed flowchart of question-answer pair generation in an embodiment of the present invention. Specifically, S2 is data preprocessing.
[0030] S2 performs text splitting and structuring processing on the collected data, including: S2.1: For long texts with complete structure, a splitting method based on chapter titles and semantic boundaries is adopted to automatically extract the summary part and split the main text into multiple segments according to the logical structure; S2.2: For the datasets related to the summary in the multi-domain long text subset of the existing dataset, for each dataset, split the main text into multiple judgments according to the length, and take the summary of the current data as the summary part.
[0031] Specifically, when an entire paper is directly input into a large model, it is often forcibly truncated due to exceeding the context length limit, discarding crucial information such as experimental data and conclusions at the end, resulting in a lack of core evidence for the subsequently generated questions. Furthermore, medical papers typically cover multiple topics, including background, methods, results, and discussion; mixed input can easily cause the model to experience topic drift when sampling across chapters. This implementation uses a maximum length of 10,000 tokens for the abstract-body text segment to ensure that the body text contains usable information, with an overlap of no more than 1,000 tokens. This makes the topic boundaries explicit, significantly reducing the risk of truncation and misalignment.
[0032] (1) For long texts with complete structures, such as medical research papers and clinical guidelines, a splitting method based on chapter titles and semantic boundaries is used to automatically extract the abstract. The main text is then divided into multiple segments according to its logical structure. Ensure that each text segment revolves around a single topic, with a length of no more than 10K tokens, and that the overlapping area of adjacent segments does not exceed 1K tokens; (2) For the summary-related datasets in the Longbench dataset, for each dataset, the text fragments are split according to length into... The current data summary is used directly as... .
[0033] In addition, S2 includes data cleaning and standardization. This involves removing invalid information: eliminating formatting marks, redundant spaces, special characters, and other invalid content from the text to ensure readability. S3: Concatenate the split text summary with the corresponding text fragment, and incorporate multi-dimensional task type identifiers into the concatenated text. Input the fused text into the instruction wrapper to generate the initial question-answer pair set.
[0034] Specifically, S3 is the initial medical question-and-answer pair generation.
[0035] The resulting text summaries are concatenated with the corresponding text fragments, and multi-dimensional task type identifiers are incorporated into the concatenated text, including: S3.1: Concatenate the split text summary with the corresponding text fragments to form the input text. :
[0036] in, This represents the summary portion of the j-th document. This is a text segment from the j-th document; S3.2: Use a large model to classify tasks and incorporate the obtained multi-dimensional task identifiers into the concatenated text. The task types include fact extraction, causal reasoning, situational judgment, text summarization and comparative analysis.
[0037] Specifically, a simple prompt like "Please summarize the above and generate question-and-answer pairs" can easily lead to homogenized outputs, and the model performs poorly in complex medical scenarios requiring causality, comparison, and reasoning. This implementation explicitly injects stylistic identifiers into the prompts: five types of tasks including fact extraction, causal reasoning, contextual judgment, text summarization, and comparative analysis. This allows the same guideline / article excerpt to generate multi-faceted questions and answers such as "What is it?", "Why?", "Which is better?", and "How to do it?". Combined with the background knowledge provided in the abstract, the questions closely align with clinical concerns, and the answers cover the chain of evidence, significantly expanding the semantic and structural diversity of the training data.
[0038] In its implementation, this invention categorizes all tasks using a large model. Task types are defined as five core categories: fact extraction, causal reasoning, contextual judgment, text summarization, and comparative analysis. Each category contains multiple specific sub-types, ensuring that the generated question-and-answer pairs exhibit rich task diversity.
[0039] Fusion text input: For each original document collected in step S1 (denoted as the j-th document, where j is a positive integer, corresponding to the set of original documents) (where n is the total number of original documents), extract the summary portion (denoted as...) from the index in the original document. (i.e., the summary of the j-th document) and the split and cleaned text fragments (denoted as...). (i.e., the main text segment of the j-th document), which is then concatenated in the manner described above to form the model input text.
[0040] Specifically, the system collects various types of medical texts, including medical papers, clinical guidelines, and electronic medical records. After splitting the texts according to preset rules, the abstracts are precisely spliced with the corresponding text segments to achieve the fusion of global thematic information and local detailed information, thus avoiding semantic fragmentation. At the same time, multi-dimensional task type identifiers such as fact extraction, causal reasoning, context judgment, and text summarization are incorporated into the spliced text to provide training basis for the model to generate diverse QA pairs.
[0041] The fused text is input into the instruction wrapper to generate an initial set of question-answer pairs, including: The merged text is input into the instruction wrapper, and the maximum generation length is set during the generation process to limit the length of the answer. The generated answers are formatted and validated to generate an initial set of question-and-answer pairs.
[0042] In practice, this step involves batch generation and preliminary quality control: using batch processing, the merged input text is input into the instruction wrapper in batches to generate an initial set of question-answer pairs. During the generation process, a maximum length limit was set to prevent answers from being too long or too short. Simultaneously, the generated question-and-answer pairs underwent preliminary format verification to ensure a clear correspondence between instructions and answers, and to prevent formatting errors. Through this step, approximately 60,000 initial question-and-answer pairs were generated, covering professional knowledge from 13 medical departments and 5 core task types.
[0043] S4: A dual filtering mechanism of keyword alignment and semantic similarity verification is used to select target question-answer pairs from the initial question-answer pair set to form a medical question-answer pair set, which is used as training data.
[0044] Specifically, S4 is a dual filtering process.
[0045] Please see Figure 3 S4 includes: S4.1: Extract core keywords from the fused text and the initial question-answer pair set, calculate the Jaccard similarity between the keywords of the initial question-answer pair and the keywords of the text, and filter out topic-related candidate data based on the first similarity threshold. S4.2: The Sentence-BERT model is used to semantically encode the answers in the question-answer pairs in the candidate data with the original text, calculate the cosine similarity between the two, and retain the question-answer pairs that meet the semantic similarity threshold as the target question-answer pairs according to the second similarity threshold, thus forming a medical question-answer pair set.
[0046] Specifically, if filtering is skipped, the model is prone to mistaking marginal sentences for facts, creating illusions such as "pseudo-dosage" or "pseudo-therapeutic effects." When the topic shifts severely, the question-answer pairs lose alignment with the original text sections, resulting in a misalignment where "the question is in the method section, and the answer is in the discussion section." In this implementation, the first and second similarity thresholds can be set as needed, for example, to 0.4 and 0.6 respectively. The first-stage keyword Jaccard ≥ 0.4 filtering removes pseudo-samples with low overlap with the original text's topic; the second-stage Sentence-BERT cosine ≥ 0.6 filtering further eliminates illusions where the answer does not match the semantics of the abstract and main text. Through this double screening, the question-answer pairs are traceable, significantly reducing the illusion rate and ensuring logical consistency across paragraphs.
[0047] S4.1 For the concatenated text and the generated initial QA pairs, the Top 10 core keywords are extracted respectively. The Jaccard similarity between the QA pair keywords and the text keywords is calculated. A similarity threshold of 0.4 is set to filter out candidate data with high topic relevance and to initially filter out samples that deviate from the topic, so as to ensure that the QA pairs are aligned with the topic of the source text.
[0048] S4.2 employs semantic encoding to calculate cosine similarity, retaining high-quality training data that meets the criteria. The Sentence-BERT model is used to semantically encode the QA pair answers and the original text (summary + main text fragments) in the candidate data, calculating their cosine similarity. A similarity threshold of 0.6 is set, retaining samples that meet the semantic similarity criteria. This effectively reduces the risk of model-generated illusions and ensures the factual accuracy of the QA pairs.
[0049] Specifically, S4.1: Keyword alignment filtering implementation: (1) Keyword extraction: Call the keyword extraction interface of the ChatGPT-4 model to extract keywords from the initial question-answer pair set. Each question and answer pair (i is a positive integer, corresponding to the index of the initial question-answer pair set, and m is the total number of initial question-answer pairs), and the source document corresponding to the question-answer pair (i.e., the summary of the j-th document). With the main text The keyword extraction process involves combining elements (where j represents the index of the original document, i.e., the j-th document). A semantic weight-based keyword ranking algorithm is used. This algorithm analyzes the semantic logic of the text, assigning higher weights to words representing the core theme and key information. After sorting by weight in descending order, the top 10 keywords are extracted from each text, forming separate keyword sets. and The specific formula is as follows:
[0050]
[0051] For the keyword combination of the source document corresponding to the i-th question-answer pair, by and The top 10 keywords extracted together are used to reflect the core theme of the source document; For the i-th question-answer pair The set of keywords, by instructions With the answer The top 10 keywords extracted together are used to reflect the core semantics of the question-answer pair; This is a keyword extraction function, responsible for parsing the input text and outputting candidate keywords; This is a Top-N filtering function used to filter the top 10 high-weight keywords, reflecting the core relevance and conciseness of the keyword set. (2) Jaccard similarity calculation: Write a dedicated similarity calculation program, according to the formula
[0052] Calculate the keyword similarity for each question-answer pair.
[0053] (1) Threshold filtering and intermediate set generation: Set the first similarity threshold Question-answer pairs with a Jaccard similarity greater than 0.4 were selected to obtain an intermediate set. .
[0054] S4.2: Text Attribution Validation Implementation: (1) Semantic embedding encoding: Deploy the Sentence-BERT model and encode the intermediate set respectively. Each question and answer in the text corresponds to an answer. and corresponding source document Encode it.
[0055] (2) Cosine similarity calculation: Calculated using a vector computing library. and The cosine similarity, where It is the answer in the i-th question-and-answer pair. The sentence embedding vectors, generated by the Sentence-BERT model, reflect... semantic features; For the source document corresponding to the i-th question-answer pair The sentence embedding vectors are generated by the Sentence-BERT model and reflect the semantic features of the source document; the cosine similarity ranges from [-1, 1], and the closer the value is to 1, the higher the semantic consistency between the two.
[0056] (2) Threshold filtering and final set generation: Set the cosine similarity threshold Question-answer pairs with a similarity of ≥0.6 are retained, resulting in a high-quality set of medical question-answer pairs. A total of approximately 40,000 entries were processed. This step primarily eliminated samples whose answers deviated significantly from the semantics of the source documents and contained misleading content.
[0057]
[0058] .
[0059] S5: Train the preset base model using training data. During the training process, LoRA low-rank adaptation technology is introduced to train only the low-rank matrix parameters of the model.
[0060] Specifically, S5 refers to model training, which includes: S5.1: Employing LoRA technology, only low-rank matrix parameters are trained, reducing costs and improving efficiency. Mainstream basic models such as ChatGLM3-6B, Qwen1.5-8B, and DeepSeek-RL-8B are selected, and LoRA low-rank adaptation technology is introduced to train only the low-rank matrix parameters of the model, eliminating the need for full fine-tuning and significantly reducing computational resource consumption during training.
[0061] S5.2: Use 40,000 data points to complete 6 rounds of training, and perform dynamic monitoring and parameter tuning.
[0062] S5.3: Save the low-rank matrix parameters and combine them with the basic model parameters to form a dedicated model focused on medical QA generation. This model has small parameter increments, making it easy to deploy and reuse.
[0063] In the specific implementation process, the LoRA model is used for fine-tuning, and its specific implementation is as follows: Experimental environment setup: (1) Hardware environment: A single server is used, configured with an NVIDIA RTX 4090 GPU (24GB video memory).
[0064] (2) Software environment: The operating system used is Ubuntu 22.04 LTS; the deep learning framework used is PyTorch2.0, which supports automatic mixed precision training and improves training efficiency; LoRA is implemented using the PEFT library (Parameter-Efficient Fine-Tuning), which provides convenient LoRA parameter configuration and training interface; other dependent libraries include Transformers (model loading and inference), Sentence-BERT (semantic encoding), NumPy (numerical computation), Pandas (data processing), etc.
[0065] Basic model loading and configuration: (1) Model loading: Download the pre-trained model weights of ChatGLM3-6B, Qwen1.5-8B and DeepSeek-RL-8B from Hugging Face Hub. Set appropriate precision (such as FP16) during loading to balance model performance and memory usage.
[0066] (2) LoRA parameter configuration: Adjust the LoRA related parameters for different base models: set the rank to 8-64 (adaptively select according to the model size), set the value of α to 16-32 to ensure that the low-rank matrix can effectively capture medical domain knowledge; activate the LoRA layer as the attention layer of the Transformer encoder layer and decoder layer of the model; set the dropout probability to 0.1 to prevent overfitting.
[0067] S6: Use the trained model to automatically generate question-answer pairs.
[0068] Specifically, S6 refers to system deployment and applications. Please see [link / reference]. Figure 8 This diagram illustrates API calls in an embodiment of the present invention. The system provides a dedicated API interface that supports uploading and custom splitting of various types of unstructured medical text. Combined with multi-round parameter randomization and ambiguity checking mechanisms, it efficiently generates and outputs high-quality QA pairs, meeting the needs of knowledge internalization and multi-scenario data in large medical models. Specifically, it includes the following sub-steps: Text reception and segmentation: It receives various types of unstructured medical texts, supports user-defined segmentation rules and methods, and decomposes the original text into fragments that are suitable for model input, laying the foundation for accurate QA generation.
[0069] Model invocation, QA generation, and quality verification: The split text fragments are input into the trained dedicated medical model to initially generate QA pairs without redundancy; at the same time, the hallucination filtering mechanism is activated, and the base model is invoked 10 times for the same question. Each time, parameters such as temperature and topk are randomly adjusted to improve the diversity of responses. The results of the 10 invocations are then input into the large model for analysis to verify whether there are any ambiguities or mutually exclusive contents. Low-quality QA pairs are filtered out, and high-quality results that are accurate and consistent are retained.
[0070] QA Pair Organization and Output: High-quality QA pairs selected from the screening process are standardized and organized in sequence. The output format is adapted to various application scenarios such as medical large-scale model training and medical knowledge services, realizing the efficient transformation of the latest medical knowledge into standardized QA pairs.
[0071] The specific implementation of the model's deployment and application is as follows: Step S6.1: System Deployment Architecture: The system of this invention adopts a client-server (C / S) architecture. The server deploys the finely tuned medical model, data processing module, filtering module and other core components, which are responsible for receiving text input from the client, generating question-answer pairs and returning results. The client can directly call the service through the API structure, supporting users to upload multiple types of medical text.
[0072] The method for selecting high-quality question-answer pairs involves performing ten repeated question-answer operations with different random parameters for the same text input in the system-level code implementation. Subsequently, an external large model is used to perform semantic consistency judgment on the above ten sets of question-answer results through the API interface to identify whether there is significant semantic ambiguity. If significant ambiguity is detected, the question-answer pair is determined to be invalid and is removed.
[0073] Continuous training: At regular intervals, we can filter out high-quality question-answer pairs from the multiple text inputs and outputs collected from users, and use these pairs as training data for the next round of model training. This allows for better adaptation to the current domain and task, and gradual optimization of the model's performance.
[0074] The preference alignment method includes: filtering out unqualified question-answer pairs from the logs, specifically those with obvious semantic ambiguity in multiple calls; for example, for a certain question, if at least seven model outputs show the same semantic consistency, while the outputs of other models are inconsistent with the others, then the aforementioned seven highly consistent responses are considered as a group, and semantic similarity is used to determine whether they constitute a valid answer; if the group of responses has a high semantic similarity to the original question, then they are considered to maintain a high degree of consistency with the original text from the perspective of most models, and can be identified as high-quality positive samples; among the remaining low-consistency responses, the one with the lowest semantic similarity is selected as a negative sample; thus, a dataset that can be used for DPO (Direct Preference Optimization) training is constructed; after periodically extracting the above data, it is used to perform the model preference alignment process.
[0075] Step S6.2: Application Scenarios Expansion: The high-quality medical question-and-answer pairs generated by this invention can be widely applied to multiple scenarios: (1) Medical AI model training: As instruction fine-tuning data, it is used to train medical question-and-answer systems, clinical decision support models, medical knowledge question-and-answer robots, etc., to improve the professional performance of the models; Please see Figure 4 and Figure 5 , Figure 4 The distribution of semantic entropy across counties is shown for multiple models trained using this method. Higher semantic entropy indicates greater diversity in the corresponding question-answer pairs. The models marked with the 'LoRA' suffix are the versions trained in this paper.
[0076] Figure 5 The study then highlighted the differences in the diversity of question-and-answer pairs generated by different models by comparing the noun and verb pairings in the generated question-and-answer pairs.
[0077] (2) Development of medical education resources: used to build medical question banks and teaching case banks to provide materials for the learning and assessment of medical students and medical staff; (3) Clinical decision support: Provides medical staff with a quick knowledge search service to help them obtain the latest diagnosis and treatment knowledge in a timely manner and assist in clinical decision-making; Example 2 Based on the same inventive concept, this embodiment discloses an automatic question-answer pair generation system for long medical texts. Please refer to [link to relevant documentation]. Figure 6 ,include: Data acquisition module 101 is used to acquire medical text data; The data splitting and cleaning module 102 is used to perform text splitting, structuring processing, and data cleaning on the collected data; The initial question-answer pair generation module 103 is used to concatenate the text summary obtained after splitting with the corresponding text fragment, and to incorporate multi-dimensional task type identifiers into the concatenated text. The fused text is then input into the instruction wrapper to generate the initial question-answer pair set. The dual filtering module 104 is used to filter out target question-answer pairs from the initial question-answer pair set using a dual filtering mechanism of keyword alignment filtering and semantic similarity verification, forming a medical question-answer pair set as training data; The model training module 105 is used to train a preset base model using training data. During the training process, LoRA low-rank adaptation technology is introduced to train only the low-rank matrix parameters of the model. The question-answer pair automatic generation module 106 is used to automatically generate question-answer pairs using a trained model.
[0078] Specifically, this invention addresses a core pain point in current medical question-answering pair (QA pair) generation systems: the difficulty in generating logically complete, topic-aligned, and diverse QA pairs when processing medical text fragments, failing to meet the urgent need for high-quality training data in the medical field. This invention aims to construct a high-quality medical QA pair generation system based on a dual alignment instruction wrapper. Through the core idea of "summary completion of paragraph information + topic alignment training," the model acquires the ability to generate diverse, topic-consistent, and logically rigorous QA pairs from the complementary information of summaries and paragraphs.
[0079] In its implementation, this invention systematically addresses key issues in traditional medical QA pair generation through a three-layer architecture: data preparation, model training, and application generation. These issues include inconsistent data quality, high model fine-tuning costs, and semantically fragmented or monotonous generated results. The data preparation layer uses a summary-text fusion and dual filtering mechanism to select high-quality training data, laying a solid foundation for model training. The model training layer employs LoRA low-rank adaptation fine-tuning technology, completing six rounds of precise training based on 40,000 high-quality medical QA data points, enabling the model to deeply master the extraction of core knowledge from medical texts and the generation of logical QA pairs. The application generation layer supports users uploading various types of unstructured medical texts, such as medical papers, clinical guidelines, and electronic medical records, and allows for custom splitting rules. The trained dedicated model quickly outputs semantically aligned, diverse, and high-quality QA pairs. Ultimately, this provides efficient and intelligent QA generation capabilities for multiple scenarios, including medical research, clinical assistance, and model training, meeting the urgent need for high-quality QA data in the medical field.
[0080] To achieve the above objectives, this invention designs a high-quality medical question-and-answer pair generation system based on a dual alignment instruction wrapper. Please see below. Figure 7 The system is divided into the following three levels: Data Preparation Layer: The core function is to use an innovative mechanism of "summary-text fusion + dual filtering" to screen high-purity, highly aligned training data, providing a high-quality data foundation for subsequent model training and ensuring the quality of QA generation from the source. We use public datasets (specifically designed for summarizing tasks, constructing question-answer pairs from summaries and paragraphs) and self-built datasets (guideline literature from 13 departments). The summary-text fusion concatenates the summary of medical texts with corresponding text segments, using the core thematic information contained in the summary to constrain the knowledge extraction direction of the text segments, preventing the generated content from deviating from the core of the text. Dual filtering uses two rounds of screening—keyword alignment and semantic similarity verification—to accurately eliminate low-quality data that is off-topic or factually distorted, ensuring the reliability of the training data.
[0081] Model Training Layer: Utilizing LoRA low-rank adaptation fine-tuning technology, accurate training is performed on high-quality medical QA data. The focus is on improving the model's professional adaptability to the medical field and its ability to generate logical QA queries, achieving low-cost, high-efficiency model optimization. By training only the low-rank matrix parameters, the resource consumption associated with full-parameter fine-tuning is avoided, ensuring training effectiveness while lowering the deployment threshold.
[0082] Application Generation Layer: This layer supports user uploads of various types of unstructured medical text, and a trained dedicated model quickly outputs high-quality QA pairs. A filtering mechanism is added at this stage to select high-quality QA pairs for the generated QA. Leveraging the possibility of hallucinatory responses from the Big Prophet model, a method is proposed to call the same question 10 times on the base model, randomly modifying the parameters of each call (e.g., changing temperature and topk index) to alter the diversity of the model's responses. Finally, the results of the 10 calls are fed into the Big Prophet model for analysis to check for ambiguity or mutual exclusion. If ambiguity or mutual exclusion exists, it indicates that the current question-answer pair is not of high quality.
[0083] Ultimately, this invention provides an efficient medical question-and-answer pair generation capability, which can transform the latest medical knowledge into a standardized QA pair system, helping large medical models to quickly internalize professional knowledge and meet the demand for high-quality QA data in multiple scenarios.
[0084] In summary, the system provided by this invention integrates core technologies such as medical document summarization and text fragments, multi-level semantic alignment filtering, and low-rank adaptation (LoRA) model fine-tuning. Targeting the characteristics of long texts in the medical field (such as medical research papers, clinical guidelines, electronic medical records, and medical policy documents), it achieves automated generation of high-quality, highly diverse, and semantically consistent medical question-answer pairs in zero-shot scenarios. The generated question-answer pairs can be widely applied to scenarios such as instruction fine-tuning of large medical language models, training of intelligent medical question-answering systems, and development of medical education resources. This effectively improves the domain adaptation capability, accuracy of medical knowledge, and practical application performance of medical AI models, providing key technical support for the intelligent upgrading of the healthcare field.
[0085] Since the system in Embodiment 2 of this invention is the same system used in the automatic question-and-answer pair generation method for long medical texts in Embodiment 1, those skilled in the art can understand the specific structure and variations of this system based on the method described in Embodiment 1 of this invention, and therefore will not be repeated here. All systems used in the method of Embodiment 1 of this invention fall within the scope of protection of this invention.
[0086] Example 3 Based on the same inventive concept, the present invention also provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the method for automatically generating question-answer pairs for long medical texts according to Embodiment 1.
[0087] Since the computer-readable storage medium described in Embodiment 3 of this invention is the same computer-readable storage medium used in implementing the automatic question-answer pair generation method for long medical texts in Embodiment 1 of this invention, those skilled in the art can understand the specific structure and variations of this computer-readable storage medium based on the method described in Embodiment 1 of this invention, and therefore will not be repeated here. All computer-readable storage media used in the method of Embodiment 1 of this invention fall within the scope of protection of this invention.
[0088] Example 4 Based on the same inventive concept, the present invention also provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the method described in Embodiment 1.
[0089] Since the computer device described in Embodiment 4 of this invention is the same computer device used to implement the automatic question-answer pair generation method for long medical texts in Embodiment 1 of this invention, those skilled in the art can understand the specific structure and variations of this computer device based on the method described in Embodiment 1 of this invention, and therefore will not be repeated here. All computer devices used in the method of Embodiment 1 of this invention fall within the scope of protection of this invention.
[0090] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0091] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0092] Although preferred embodiments of the invention have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including both the preferred embodiments and all changes and modifications falling within the scope of the invention. Clearly, those skilled in the art can make various modifications and variations to the embodiments of the invention without departing from the spirit and scope of the invention. Thus, if these modifications and variations of the embodiments of the invention fall within the scope of the claims of the invention and their equivalents, the invention also intends to include these modifications and variations.
Claims
1. A method for automatically generating question-answer pairs for long medical texts, characterized in that, include: Collect medical text data; The collected data undergoes text splitting, structuring, and data cleaning. The text summary obtained after splitting is concatenated with the corresponding text fragments, and multi-dimensional task type identifiers are incorporated into the concatenated text. The fused text is then input into the instruction wrapper to generate an initial set of question-answer pairs. A dual filtering mechanism of keyword alignment and semantic similarity verification was adopted to select target question-answer pairs from the initial question-answer pair set to form a medical question-answer pair set, which was used as training data; The pre-defined base model is trained using training data. During the training process, LoRA low-rank adaptation technology is introduced to train only the low-rank matrix parameters of the model. The trained model is used to automatically generate question-answer pairs.
2. The method for automatically generating question-answer pairs for long medical texts as described in claim 1, characterized in that, The medical text data collected includes multi-domain long text subsets of existing datasets, medical research papers, clinical guidelines, and electronic medical records.
3. The method for automatically generating question-answer pairs for long medical texts as described in claim 1, characterized in that, The collected data undergoes text splitting and structuring processing, including: For long texts with complete structure, a splitting method based on chapter titles and semantic boundaries is adopted to automatically extract the summary and split the main text into multiple segments according to the logical structure. For the datasets related to the summary in the multi-domain long text subset of the existing dataset, for each dataset, the main text is split into multiple judgments according to length, and the summary of the current data is used as the summary part.
4. The method for automatically generating question-answer pairs for long medical texts as described in claim 1, characterized in that, The resulting text summary is concatenated with the corresponding text fragment, and multi-dimensional task type identifiers are incorporated, including: The resulting text summary is then concatenated with the corresponding text fragments to form the input text. : in, This represents the summary portion of the j-th document. This is a text segment from the j-th document; The large model is used to classify tasks, and the resulting multi-dimensional task identifiers are incorporated into the concatenated text. The task types include fact extraction, causal reasoning, situational judgment, text summarization and comparative analysis.
5. The method for automatically generating question-answer pairs for long medical texts as described in claim 1, characterized in that, The merged text is input into the instruction wrapper to generate an initial set of question-answer pairs, including: The merged text is input into the instruction wrapper, and the maximum generation length is set during the generation process to limit the length of the answer. The generated answers are formatted and validated to generate an initial set of question-and-answer pairs.
6. The method for automatically generating question-answer pairs for long medical texts as described in claim 4, characterized in that, A dual filtering mechanism of keyword alignment and semantic similarity verification is used to select target question-answer pairs from the initial question-answer pair set to form a medical question-answer pair set, including: For the fused text and the initial question-answer pair set, core keywords are extracted respectively. The Jaccard similarity between the keywords of the initial question-answer pair and the keywords of the text is calculated. Candidate data related to the topic are selected based on the first similarity threshold. The Sentence-BERT model is used to semantically encode the answers in the question-answer pairs in the candidate data with the original text, calculate the cosine similarity between the two, and retain the question-answer pairs that meet the semantic similarity threshold as the target question-answer pairs, thus forming a medical question-answer pair set.
7. The method for automatically generating question-answer pairs for long medical texts as described in claim 6, characterized in that, The Jaccard similarity between the keywords of the initial question-and-answer pair and the keywords in the text is calculated as follows: Let be the set of keywords in the source document corresponding to the i-th question-answer pair. Let i be the set of keywords for the i-th question-answer pair; The cosine similarity between the semantic encoding of the answer in the question-answer pair in the candidate data and the semantic encoding of the original text is calculated as follows: in , For the i-th answer , For the answer in the i-th question-and-answer pair The sentence embedding vectors, generated by the Sentence-BERT model, are used to reflect... semantic features; It is the source document corresponding to the i-th question-answer pair. The sentence embedding vectors are generated by the Sentence-BERT model to reflect the semantic features of the source document.
8. A question-answer pair automatic generation system for long medical texts, characterized in that, include: The data acquisition module is used to collect medical text data; The data splitting and cleaning module is used to perform text splitting, structuring, and data cleaning on the collected data. The initial question-answer pair generation module is used to concatenate the text summary obtained after splitting with the corresponding text fragments, and to incorporate multi-dimensional task type identifiers into the concatenated text. The fused text is then input into the instruction wrapper to generate the initial question-answer pair set. The dual filtering module is used to select target question-answer pairs from the initial question-answer pair set using a dual filtering mechanism of keyword alignment and semantic similarity verification, forming a medical question-answer pair set as training data; The model training module is used to train a preset base model using training data. During the training process, LoRA low-rank adaptation technology is introduced to train only the low-rank matrix parameters of the model. The question-answer pair automatic generation module is used to automatically generate question-answer pairs using a trained model.
9. A computer-readable storage medium, characterized in that, It stores a computer program that, when executed by a processor, implements the method for automatically generating question-answer pairs for long medical texts as described in any one of claims 1 to 7.
10. A computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the method for automatically generating question-answer pairs for long medical texts as described in any one of claims 1 to 7.