Method, device, equipment and medium for automatically annotating medical texts with prompts based on large models
By constructing an automatic annotation method based on prompts based on a large model, the problems of low medical text annotation accuracy and difficulty in data acquisition are solved, and efficient and accurate medical text annotation is achieved, adapting to complex and changeable medical text data.
Patent Information
- Application Number
- CN202410896359.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-05
- Publication Date
- 2024-09-17
- Estimated Expiration
- 2044-07-05
AI Technical Summary
Existing medical text annotation methods rely on manual labeling or universal language models, which makes it difficult to make full use of specific knowledge and context in the medical field, resulting in low annotation accuracy and difficulty in obtaining annotation data.
An automatic annotation method based on large model prompt construction is adopted. By preprocessing medical text data, entity-undifferentiated category and differentiated category Prompt templates are constructed to capture general entities and entity relationship information in medical texts, and large model inference services are used for annotation.
Significantly reduce manual annotation time and costs, improve annotation efficiency and accuracy, adapt to medical text data in different fields and styles, reduce annotation error rates, and provide flexible and customizable solutions.
Smart Images

Figure CN118445419B
Abstract
Description
Background Art
[0002] In the medical field, a large amount of text data needs to be accurately labeled to extract valuable information, such as medical records, medical literature, and clinical trial reports. Traditional text annotation methods rely on manual labeling by experts, which is time-consuming and costly. Although there are some automated text annotation tools, they usually rely on rules or statistical models in specific fields and are difficult to adapt to complex and changeable medical texts.
[0003] In recent years, with the rapid development of pre-trained language models (such as the GPT series, BERT, T5, etc.), they have shown great potential in the field of natural language processing, especially in text annotation tasks. Using pre-trained general language models to predictively annotate medical texts often fails to fully utilize the specific knowledge and context in the medical field, resulting in low annotation accuracy.
[0004] As mentioned above, rule-based methods require manual writing of a large number of rules. For complex medical texts, rule writing is difficult and error-prone. Machine learning-based methods require a large amount of annotated data for model training. However, in the medical field, it is very difficult to obtain a large amount of annotated data. General language models fail to fully integrate medical expertise, affecting the quality of annotation. Summary of the invention
[0005] To solve the problems existing in the existing medical text annotation, the present invention provides a method, device, equipment and medium for automatically annotating medical texts based on a large model-based prompt.
[0006] In a first aspect, the technical solution of the present invention provides a method for automatically annotating medical texts with prompts based on a large model, comprising the following steps:
[0007] Preprocess the medical text data to generate sentence samples;
[0008] Construct entity-indistinguishable prompt templates based on sentence samples to capture common entity information in medical texts;
[0009] Based on the captured general entity information, preset entity types, build entity classification prompt templates, and capture entity type information in medical texts;
[0010] Based on the captured entity type information, the general entity relationship type is preset, and the entity relationship non-classified prompt template is constructed to capture the general entity relationship information in the medical text;
[0011] Based on the captured general information of entity relationships, the entity relationship types are preset, and an entity relationship category distinction prompt template is constructed to capture the entity relationship category information in medical texts.
[0012] As a further limitation of the technical solution of the present invention, the step of preprocessing the medical text data to generate sentence samples includes:
[0013] Screen data tables and data elements based on massive medical text data, and extract medical text data from data elements. Collect medical text data, including medical records, medical papers, drug instructions, etc.
[0014] As a further limitation of the technical solution of the present invention, the step of preprocessing the text data to generate sentence samples includes:
[0015] The extracted large text data is divided into sentences according to the preset feature symbols;
[0016] Detect outliers and handle missing values in the segmented sentences;
[0017] The sentences after missing processing are processed by similarity calculation to remove duplicates as a whole;
[0018] The sentences after deduplication are used to generate sentence samples; in the sentence samples, the similarity between sentences is zero.
[0019] As a further limitation of the technical solution of the present invention, the steps of constructing an entity non-classified prompt template based on sentence samples and capturing general entity information in medical texts include:
[0020] Based on the sentence sample, obtain each character combination in the sentence;
[0021] Construct entity-indistinguishable Prompt templates for each character;
[0022] Call the large model inference service, select the character combination belonging to the common entity, and build the first stage output result.
[0023] As a further limitation of the technical solution of the present invention, based on the captured general entity information, the entity type is preset, and an entity classification prompt template is constructed. The steps of capturing the entity type information in the medical text include:
[0024] Based on the output results of the first stage, preset entity categories;
[0025] Build entity classification prompt templates for each common entity, call the large model inference service, select character combinations belonging to the entity category, and build the second-stage output results, that is, the captured entity type information.
[0026] As a further limitation of the technical solution of the present invention, based on the captured entity type information, presetting the general entity relationship type, constructing the entity relationship non-classified prompt template, and capturing the general information of entity relationships in medical texts include:
[0027] Based on the output results of the second stage, preset entity relationships;
[0028] Construct a prompt template for entity relationships between entities of different categories without distinguishing categories, call the large model reasoning service, select the entity type combination belonging to the common relationship, and construct the output result of the third stage.
[0029] As a further limitation of the technical solution of the present invention, based on the captured general information of entity relationships, the entity relationship type is preset, and an entity relationship classification prompt template is constructed. The steps of capturing entity relationship classification information in medical texts include:
[0030] Based on the output results of the third stage, obtain the entity type combinations belonging to the general relationship in the sentence and preset the entity relationship type;
[0031] Construct a prompt template to distinguish the entity relationship categories between entity types, call the LLM reasoning service, select the entity type combinations belonging to the entity relationship type, and construct the final output result.
[0032] In a second aspect, the technical solution of the present invention also provides a device for automatically annotating medical texts based on a large model to construct a prompt, including a medical text data acquisition module, a text data preprocessing module, a general entity information acquisition module, an entity type information acquisition module, an entity relationship general information acquisition module and an entity relationship category information acquisition module;
[0033] A medical text data acquisition module is used to screen data tables and data elements based on massive medical text data, and extract medical text data from the data elements;
[0034] A text data preprocessing module is used to preprocess medical text data to generate sentence samples;
[0035] The general entity information acquisition module is used to build entity-indistinguishable category prompt templates based on sentence samples to capture general entity information in medical texts;
[0036] The entity type information acquisition module is used to preset entity types based on the captured general entity information, build entity classification prompt templates, and capture entity type information in medical texts;
[0037] The entity relationship general information acquisition module is used to preset the general entity relationship type based on the captured entity type information, build the entity relationship non-classified prompt template, and capture the general entity relationship information in the medical text;
[0038] The entity relationship category information acquisition module is used to preset entity relationship types based on the captured general entity relationship information, build an entity relationship category distinction prompt template, and capture entity relationship category information in medical texts.
[0039] As a further limitation of the technical solution of the present invention, the text data preprocessing module includes a sentence segmentation unit, an anomaly detection processing unit, a deduplication processing unit and a sentence sample generation unit;
[0040] The sentence segmentation unit is used to segment the extracted large paragraphs of text data into sentences according to preset feature symbols;
[0041] An anomaly detection processing unit, used for detecting anomalies and processing missing values in the segmented sentences;
[0042] A deduplication processing unit is used to perform overall deduplication processing on the sentences after the missing processing by similarity calculation;
[0043] The sentence sample generating unit is used to generate sentence samples from the sentences after deduplication processing; in the sentence samples, the similarity between sentences is zero.
[0044] As a further limitation of the technical solution of the present invention, the general entity information acquisition module is specifically used to obtain each character combination in a sentence based on a sentence sample; construct an entity non-classified Prompt template for each character; call the large model inference service, select the character combination belonging to the general entity, and construct the first stage output result.
[0045] As a further limitation of the technical solution of the present invention, the entity type information acquisition module is specifically used to preset the entity category based on the output result of the first stage; construct an entity classification prompt template for each general entity, call the large model reasoning service, select the character combination belonging to the entity category, and construct the output result of the second stage, that is, the captured entity type information.
[0046] As a further limitation of the technical solution of the present invention, the entity relationship general information acquisition module is specifically used to preset entity relationships based on the output results of the second stage; construct a prompt template without distinguishing categories between entity categories, call the large model reasoning service, select entity type combinations belonging to general relationships, and construct the output results of the third stage.
[0047] As a further limitation of the technical solution of the present invention, the entity relationship category information acquisition module is specifically used to obtain the combination of entity types belonging to the general relationship in the sentence based on the output result of the third stage, and preset the entity relationship type; construct a Prompt template for distinguishing the entity relationship categories between each entity type, call the LLM reasoning service, select the combination of entity types belonging to the entity relationship type, and construct the final output result.
[0048] In a third aspect, the technical solution of the present invention also provides an electronic device, comprising: at least one processor; and a memory communicatively connected to the at least one processor; the memory stores computer program instructions executable by the at least one processor, and the computer program instructions are executed by the at least one processor so that the at least one processor can execute the method for automatically annotating medical texts based on a large model to construct a prompt as described in the first aspect.
[0049] In a fourth aspect, the technical solution of the present invention also provides a non-transitory computer-readable storage medium, wherein the non-transitory computer-readable storage medium stores computer instructions, and the computer instructions enable the computer to execute the method for automatically annotating medical texts by constructing prompts based on a large model as described in the first aspect.
[0050] It can be seen from the above technical solutions that the present invention has the following advantages: by automating the prompt construction and annotation process, the time and cost of manual annotation can be significantly reduced, and the efficiency of medical text annotation can be improved.
[0051] The application of large models makes the annotation process more intelligent and can handle large-scale medical text data. The combined use of entity non-classification and class-distinguishing prompt templates can ensure the capture of general entity information and specific entity type information in medical texts, thereby improving the accuracy of annotation. The use of entity relationship non-classification and class-distinguishing prompt templates can more accurately capture the general information of entity relationships and specific relationship category information in medical texts. Since this method is built on a large model, it has strong generalization ability and can adapt to medical text data in different fields and styles. By presetting entity types and entity relationship types, flexible and customizable solutions can be provided for different medical text annotation tasks. The automated annotation process reduces the impact of human factors on the annotation results, thereby reducing the annotation error rate. The careful design and construction of the prompt template helps to more accurately extract key information in medical texts and further reduce the annotation error rate.
[0052] In addition, the invention has a reliable design principle, a simple structure and a very broad application prospect.
[0053] It can be seen that compared with the prior art, the present invention has outstanding substantive features and significant progress, and the beneficial effects of its implementation are also obvious. BRIEF DESCRIPTION OF THE DRAWINGS
[0054] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0055] Figure 1 is a schematic flow chart of a method according to an embodiment of the present invention.
[0056] Figure 2 is a schematic block diagram of an apparatus according to an embodiment of the present invention. DETAILED DESCRIPTION
[0057] In order to enable those skilled in the art to better understand the technical solutions in the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0058] like Figure 1 As shown, an embodiment of the present invention provides a method for automatically annotating medical texts with prompts based on a large model, comprising the following steps:
[0059] Step 1: Screen data tables and data elements based on massive medical text data, and extract medical text data from the data elements;
[0060] Step 2: Preprocess the medical text data to generate sentence samples;
[0061] Step 3: Build an entity-indistinguishable prompt template based on sentence samples to capture common entity information in medical texts;
[0062] Step 4: Based on the captured general entity information, preset entity types, build entity classification prompt templates, and capture entity type information in medical texts;
[0063] Step 5: Based on the captured entity type information, preset the general entity relationship type, build the entity relationship non-classified prompt template, and capture the general entity relationship information in the medical text;
[0064] Step 6: Based on the captured general information of entity relationships, preset entity relationship types, build an entity relationship classification prompt template, and capture entity relationship category information in medical texts.
[0065] In some embodiments, the step of preprocessing text data to generate sentence samples includes:
[0066] The extracted large paragraphs of text data are divided into sentences according to preset feature symbols, such as periods, line breaks, etc.; the cleaning function detects and processes outliers and missing values in sentences; the deduplication function deduplicates sentences as a whole; the desensitization function de-identifies, anonymizes or encrypts sensitive information to protect personal privacy and business secrets, and generates sentence samples; in the sentence samples, the similarity between sentences is zero.
[0067] In some embodiments, the step of constructing an entity-indistinguishable category prompt template based on sentence samples and capturing common entity information in medical texts includes:
[0068] Based on the sentence sample, obtain each character combination in the sentence;
[0069] Construct entity-indistinguishable Prompt templates for each character;
[0070] Call the large model inference service, select the character combination belonging to the common entity, and build the first stage output result.
[0071] Based on the sentence sample, such as "Body temperature: 36.5", obtain the character combinations in the sentence, build the 'Entity-free Prompt Template' for each character, call the LLM reasoning service, select the character combination belonging to the 'General Entity', and build the first stage output result:
[0072] First, there are 28 character combinations in the sentence 'body temperature: 36.5', namely ['body', 'body temperature', 'body temperature:', 'body temperature: 3', 'body temperature: 36', 'body temperature: 36.', 'body temperature: 36.5', 'temperature', 'temperature:', 'temperature: 3', 'temperature: 36', 'temperature: 36.', 'temperature: 36.5', ':', ':3', ':36', ':36.', ':36.5', '3', '36', '36.', '36.5', '6', '6.', '6.5', '.', '.5', '5'], each of which is regarded as a character segment. For example, the first character segment is 'body', and the entity of the character segment is constructed without distinguishing the category Prompt template. The character segment 'body' starts at '0' and ends at '1' in the text. The remaining 27 segments are constructed in the same way to construct the 'entity-indistinguishable category prompt template', and the template data is passed to the LLM reasoning service. The reasoning service is an inference service API interface that encapsulates the fine-tuned llama2-13b-base model and is deployed as a docker service. After the service is started, the fine-tuned model is loaded. When the API interface receives the template data request, the input prompts are tokenized to obtain token ids; the maximum length total_len of the current batch is calculated to create the input token tensor, and the maximum length cannot exceed the cache size; the generation starts from the position of the shortest prompt in the current batch; the input token tensor is passed into the transformer model, logits are calculated, and logits of shape (batch_size, hidden_size) are obtained (the output of the last layer of the transformer); softmax+top_p sampling is performed to obtain the current predicted token, and the current position is updated to prepare for predicting the next token; decoding is performed to obtain the generated text.
[0073] In the template data, the model's answer is limited to ['belongs to', 'does not belong to'], and the inference result is further post-processed. When the model answers 'belongs to', the character fragment in the template data is considered to be a 'general entity', and the following output is obtained: [
[0075] {
[0076] "text": "Body temperature: 36.5",
[0077] "entities": [
[0078] {
[0079] "entity": "body temperature",
[0080] "start_idx": 0,
[0081] "end_idx": 2,
[0082] "type": "Generic Entity",
[0083] "id": "0"
[0084] },
[0085] {
[0086] "entity": "36.5",
[0087] "start_idx": 3,
[0088] "end_idx": 6,
[0089] "type": "Generic Entity",
[0090] "id": "1"
[0091] } ]
[0093] } ]
[0095] In some embodiments, based on the captured general entity information, the entity type is preset, and an entity classification prompt template is constructed. The step of capturing entity type information in the medical text includes:
[0096] Based on the output results of the first stage, preset entity categories;
[0097] Build entity classification prompt templates for each common entity, call the large model inference service, select character combinations belonging to the entity category, and build the second-stage output results, that is, the captured entity type information.
[0098] Based on the output results of the first stage, some results of the preset entity categories are as follows:
[0099] {
[0100] "Diagnosis": "Diseases with clear lesions, pregnancy-related diagnoses, and descriptions of lesions with unknown etiology that are currently recognized by medicine: such as "Reye's syndrome" and "Ogilvie syndrome", etc. (mainly xxx syndrome). Diseases with clear lesions include diseases with clear clinical properties and pathological diagnoses, such as diabetes and small cell lung carcinoma."
[0101] "Pathogen": "An organism that causes a disease in a patient, such as bacteria, virus, fungus, or parasite."
[0102] "Medical devices": "Some medical auxiliary devices used in medical diagnosis and treatment."
[0103] "Observation item": "It mainly describes the characteristics of the described object (object or event) from a certain dimension, and also includes some medical quantitative assessment items of a certain function or pathology level."
[0104] "Abnormal cells": "Abnormal cells".
[0105] "Location and lesion locating words": "Indicates the division information of the structure inside the location. Such as lobe, segment, stump, wall, tube wall, muscle layer, cut end, cyst wall, center, tumor bed, inside, superficial muscle layer, etc."
[0106] "Observations": "Normal, good conclusive description".
[0107] "Examination items": "1. Examination methods, instrument examination items, major test items, etc. imposed on patients in order to discover, confirm diseases or symptoms, and find more information about diseases or symptoms; 2. Including test indicators, immunohistochemical indicators, genetic indicators and other test sub-items."
[0108] "Human secretions": "Mainly used to describe the visible secretions or excretions of the human body or the components of human tissue that have left the human body in gross organs or lesions."
[0109] "Treatment": "Except for surgical operations, various conventional medical treatments include chemotherapy, radiotherapy, targeted therapy, laser therapy, psychotherapy, general treatment (such as exercise, diet, rest), rehabilitation therapy, etc."
[0110] "Drugs": "Use the names of chemical drugs, including vaccines, biological tumor vaccines and other biological therapeutic agents, and contrast agents used in imaging examinations."
[0111] "Instructions for use": "Only the dosage, time, route and frequency of the drug should be marked separately."
[0112] "Care Level Classification": "Type or level of care".
[0113] "Modification": "Modification of certain attributes of the object being described, including: size, shape, color, etc."
[0114] "Rating items": "Currently there are only 'such and such scores' such as ECOG, KPS, PS, IPI, aaIPI, postnatal Apgar score, or other abbreviations that are definitely scores."
[0115] "Imaging manifestation": "1. The sonographic manifestation of a disease, the projection of a lesion on imaging; 2. The imaging characteristics of a lesion, an imaging manifestation of a lesion or part on imaging, used to determine the nature of the lesion."
[0116] "Symptoms": "(In addition to physical signs) abnormal sensations and states, abnormal clinical findings and examination findings manifested by the body due to the occurrence of disease."
[0117] "Drug Allergens": "Describe the patient's allergy history, medications associated with allergies".
[0118] "Anesthesia methods": "mainly general anesthesia, local anesthesia, local infiltration anesthesia, intravenous anesthesia, etc."
[0119] "Feature verbs": "Feature verbs with specific meanings and medical relationships connecting entities in medical text descriptions."
[0120] "Family Member": "Description of family members in the family history, used to avoid linking family members' disease or surgery information in the family history or reproductive history fields to the patient's information."
[0121] "Cell": "Used to mark normal cells and cells that are difficult to determine whether they are normal."
[0122] "Surgical operation": "Including invasive diagnostic and treatment operations such as surgery, procedures, puncture, biopsy, etc."
[0123] "Valued results": "Includes numerical results or yin and yang, grade description (+++), etc."
[0124] "Probability": "Used to express the likelihood of a certain diagnosis, symptom, toxicity, side effect, treatment, or other medical problem or procedure occurring."
[0125] "Tumor": "a tumor, mass, lump, nodule, growth, space-occupying mass, or mass whose nature is still unclear."
[0126] "chemotherapy regimen": "chemotherapy regimen name".
[0127] "Classification": "Indicates the type or grade of disease or diagnosis."
[0128] "Filter term": "Medical terms with no special meaning".
[0129] "Organizational Structure": "Mainly a description of the medical institution such as the hospital name, level, and departments."
[0130] "Moment": "represents a point in time, including: date, time node".
[0131] "Life events": "Events in life, mainly the triggering factors of symptoms or diseases and descriptions of traumatic events in past history."
[0132] "Material environment": "Mainly expresses general descriptions of radioactive substances, toxic substances, epidemic situations in epidemic areas, etc. in personal history."
[0133] Based on the output results of the first stage, the 'Entity Distinguishing Category Prompt Template' of the general entity is constructed. For example, the first 'general entity' content 'body temperature' has a starting position of 0 and an ending position of 2 in the text. Based on this information, the constructed 'Entity Distinguishing Category Prompt Template' is:
[0134] """Based on the definition of the entity category and the given text, complete the judgment specified in the question.
[0135] Definition of the 'diagnosis' entity category: "Diseases with clear lesions, pregnancy-related diagnoses, and descriptions of lesions with unknown etiology that are currently recognized by medicine: such as "Reye's syndrome" and "Ogilvie syndrome", etc. (mainly xxx syndrome). Diseases with clear lesions include diseases with clear clinical properties and pathological diagnoses, such as diabetes and small cell lung cancer";
[0136] Text: Temperature: 36.5;
[0137] Title: Determine whether the character segment 'body temperature' in the text belongs to the 'diagnosis' entity.
[0138] Note:
[0139] 1. The starting position of the character segment 'body temperature' in the text is '0' and the ending position is '2';
[0140] Answer 'yes' or 'no';
[0141] Answer: """ , the general entity needs to be constructed with the remaining 48 entity categories in the same way as the 'Entity Distinguishing Category Prompt Template', and the template data is passed to the LLM reasoning service in turn. The reasoning service is an inference service API interface that encapsulates the llama2-13b-base model that has been fine-tuned differently from the first stage, and is deployed as a docker service. After the service is started, the fine-tuned model is loaded. When the API interface receives the template data request, the input prompts are tokenized to obtain token ids; the maximum length total_len of the current batch is calculated to create the input token tensor, and the maximum length cannot exceed the cache size; the generation starts from the position of the shortest prompt in the current batch; the input token tensor is passed into the transformer model, logits are calculated, and logits of shape (batch_size, hidden_size) are obtained (the output of the last layer of the transformer); softmax+top_p sampling is performed to obtain the current predicted token, and the current position is updated to prepare for predicting the next token; decoding is performed to obtain the generated text.
[0142] In some embodiments, based on the captured entity type information, a general entity relationship type is preset, and an entity relationship non-classified prompt template is constructed. The steps of capturing general entity relationship information in medical texts include:
[0143] Based on the output results of the second stage, preset entity relationships;
[0144] Construct a prompt template for entity relationships between entities of different categories without distinguishing categories, call the large model reasoning service, select the entity type combination belonging to the common relationship, and construct the output result of the third stage.
[0145] Based on the output results of the second stage, a total of three entity types are obtained, the first entity content of the "observation item" type is "body temperature" and the second entity of the "vital sign" type. The "entity relationship non-classification prompt template" is constructed as follows:
[0146] """Please complete the judgment specified in the question based on the definition of the relationship and the given text.
[0147] Definition of 'universal relation' relation: a relation that satisfies a certain connection semantically and medically.
[0148] Text: Temperature: 36.5
[0149] Question: Determine whether the entity 'body temperature' in the text satisfies the 'general relationship' relationship with the entity 'body temperature'. The direction of the relationship is not considered.
[0150] Note:
[0151] 1. The type of entity 'body temperature' is 'observation item', the starting position in the text is '0' and the ending position is '2';
[0152] 2. The type of entity 'body temperature' is 'vital signs', the starting position in the text is '0' and the ending position is '2';
[0153] Answer 'satisfied' or 'not satisfied'.
[0154] Answer: """ , build an 'entity relationship non-classified prompt template', pass the template data to the LLM reasoning service, which encapsulates the Qwen1.5-14B model that has been fine-tuned differently from the first stage into an inference service API interface, and deploys it as a docker service. After the service is started, it loads the fine-tuned model. When the API interface receives the template data request, it tokenizes the input prompts to get token ids; calculates the maximum length total_len of the current batch to create the input token tensor, and the maximum length cannot exceed the cache size; starts generating from the position of the shortest prompt in the current batch as the starting position of the generation; passes the input token tensor into the transformer model, calculates logits, and gets logits of shape (batch_size, hidden_size) (the output of the last layer of the transformer); softmax+top_p sampling is performed to get the current predicted token, and the current position is updated to prepare for predicting the next token; decoding is performed to get the generated text.
[0155] In some embodiments, based on the captured general information of entity relationships, the entity relationship type is preset, and an entity relationship classification prompt template is constructed. The step of capturing entity relationship classification information in medical texts includes:
[0156] Based on the output results of the third stage, obtain the entity type combinations belonging to the general relationship in the sentence and preset the entity relationship type;
[0157] Construct a prompt template to distinguish the entity relationship categories between entity types, call the LLM reasoning service, select the entity type combinations belonging to the entity relationship type, and construct the final output result.
[0158] The preset entity relationship types include:
[0159] {
[0160] "Modification": "Usually indicates the subject's description of a certain property, state, characteristic or change of the object. This relationship helps us understand the specific connection between the subject and the object in more detail and provides more information about the events, states or characteristics in the text."
[0161] "Conclusion / Result": "Usually represents the final evaluation or summary of an observation, examination or treatment. This conclusion or result is drawn from medical treatment, examination, surgery or medical record description, and is used to describe the patient's illness, physical condition or treatment effect. It is a summary of key observations or actions in medical information, providing a comprehensive understanding of the patient's status. These conclusions or results can involve information on physiological conditions, disease diagnosis, treatment effects, pathological results, etc."
[0162] "Parallel": "refers to the relationship between two or more symptoms, diseases, medical characteristics, etc. described in the text existing or manifesting at the same time. These items are juxtaposed together, indicating that they appear or co-exist at a certain point in time or in a certain situation."
[0163] "Treatment": "refers to the measures taken or medical methods applied during the medical process to relieve, improve or cure the patient's symptoms, diseases or conditions. These treatments include medication, surgery, physical therapy, radiotherapy, chemotherapy, etc. In the triple, the subject of the 'treatment' relationship is usually a medical method, drug or treatment plan, and the predicate is the symptoms, disease or condition related to it."
[0164] "Causes": "Refers to a cause-and-effect relationship in which the first element is a causing event or condition, the second element is a resulting effect or impact, and the third element is the cause of the causing event or condition. Specifically, a "cause" relationship here means that one event, action, or condition causes or produces another event, symptom, or result."
[0165] "Accumulation / Metastasis / Invasion": "Describes the location of a tumor or lesion within the patient's body and the effects on surrounding tissue. Specifically, this relationship describes whether the tumor or lesion accumulates at the original location (accumulation), metastasizes to other sites, or invades surrounding tissue."
[0166] "Concurrent / accompanying": "It means that a patient has another symptom or disease on the basis of a certain symptom or disease, and there is a synchronous or mutual influence between the two. This relationship reflects the interaction between different systems of the patient's body and usually needs to be considered comprehensively in medicine to more fully understand the patient's health status."
[0167] "Location": "Describes the specific location or site of a physiological structure or condition mentioned in the text. It is usually an indication of a body region, organ, tissue, or lesion that helps to identify the specific location of the condition described."
[0168] "Subclass": "Defined as a more specific, detailed classification or subclass that describes a symptom, disease, or treatment in the medical field. Here, the first element in the triplet usually represents the specific manifestation or type of the symptom, disease, or treatment, the second element is "subclass", which represents a more specific classification of the manifestation or type, and the third element provides additional description or information about this relationship."
[0169] "Contains": "Indicates that one entity (usually the first element) contains or encompasses another entity (usually the third element). This relationship reflects an inclusive relationship between two entities, where the first entity includes or contains the third entity. This can represent various relationships in text in the medical field, such as drugs are contained in a specific treatment plan, chemotherapy regimens contain specific drugs, pathology examinations contain specific disease diagnoses, etc."
[0170] "Confirmed": "Refers to a medical judgment in the medical field, that is, a doctor or medical professional makes a clear and formal judgment or confirmation of the patient's condition through a series of examinations, tests or operations. In each triple, the first element represents the specific situation of the symptom or lesion, the second element is "confirmed", and the third element represents the confirmed disease or pathological state. This relationship reflects the doctor's clear understanding and medical diagnosis of the patient's condition."
[0171] Based on the output results of the third stage, a total of 1 set of 'general relations' is obtained. Based on the two types of entities in this set of relations, the 'Entity Relationship Classification Prompt Template' is constructed as follows:
[0172] Relationship definition:
[0173] [{
[0174] "modification": "usually indicates the subject's description of a certain property, state, characteristic or change of the object. This relationship helps us understand the specific connection between the subject and the object in more detail and provides more information about the events, states or characteristics in the text.",..."diagnosis": "refers to a medical judgment in the medical field, that is, a doctor or medical professional makes a clear and formal judgment or confirmation of the patient's condition through a series of examinations, tests or operations. In each triple, the first element represents the specific situation of the symptom or lesion, the second element is "diagnosis", and the third element represents the confirmed disease or pathological state. This relationship reflects the doctor's clear understanding and medical diagnosis of the patient's condition."
[0175] }]
[0176] Medical text: Temperature: 36.5.
[0177] Question: Determine which relationship the entity 'body temperature' and the entity '36.5' in the medical text above belong to. Output the relationship name directly without considering the direction of the relationship.
[0178] Note:
[0179] 1. The type of entity 'body temperature' is 'vital signs', the starting position in the text is '0' and the ending position is '2';
[0180] 2. The type of entity '36.5' is 'valued result', the starting position in the text is '3' and the ending position is '6';
[0181] Answer: """, build the 'Entity Relationship Classification Prompt Template', pass the template data to the LLM reasoning service, which is an inference service API interface that encapsulates the Qwen1.5-14B model that has been fine-tuned differently from the first stage, and deploys it as a docker service. After the service is started, the fine-tuned model is loaded. When the API interface receives the template data request, it tokenizes the input prompts to obtain token ids; calculates the maximum length total_len of the current batch to create the input token tensor, and the maximum length cannot exceed the cache size; starts generating from the position of the shortest prompt in the current batch as the starting position of the generation; passes the input token tensor into the transformer model, calculates logits, and obtains logits of shape (batch_size, hidden_size) (the output of the last layer of the transformer); softmax+top_p sampling is performed to obtain the current predicted token, and the current position is updated to prepare for predicting the next token; decodes to obtain the generated text. Format the reasoning results, repeat the above process for each group of 'general relations', and finally obtain the following output results: [
[0183] {
[0184] "text": "Body temperature: 36.5",
[0185] "entities": [
[0186] {
[0187] "entity": "body temperature",
[0188] "start_idx": 0,
[0189] "end_idx": 2,
[0190] "type": "Observation Item",
[0191] "id": "0"
[0192] },
[0193] {
[0194] "entity": "body temperature",
[0195] "start_idx": 0,
[0196] "end_idx": 2,
[0197] "type": "vital signs",
[0198] "id": "1"
[0199] },
[0200] {
[0201] "entity": "36.5",
[0202] "start_idx": 3,
[0203] "end_idx": 6,
[0204] "type": "Valued result",
[0205] "id": "0"
[0206] }
[0207] ],
[0208] "spo_list": [
[0209] {
[0210] "Combined": true,
[0211] "predicate": "modification",
[0212] "subject": "body temperature",
[0213] "subject_type": "Vital Signs",
[0214] "object": {
[0215] "@value": "36.5"
[0216] },
[0217] "object_type": {
[0218] "@value": "Value result"
[0219] },
[0220] "subject_start_idx": 0,
[0221] "subject_end_idx": 1,
[0222] "object_start_idx": 3,
[0223] "object_end_idx": 6
[0224] } ]
[0226] }
[0227] ].
[0228] In the embodiment of the present invention, for medical record text, large-scale high-quality medical record unstructured text data in the DWD data model library is selected to ensure the diversity and integrity of the data, covering more than one thousand fields such as one complaint, five histories, examinations, tests, diagnostic basis, differential diagnosis, and surgical procedures, covering the entire life cycle of patients; necessary pre-processing work such as cleaning, standardization, and feature extraction is performed on the data; the fine-tuning data set is checked to ensure that the label and the context correspond correctly, avoid containing noise or erroneous information, and ensure that there are enough examples in the fine-tuning data set involving situations that the model can answer and situations that cannot be answered, so as to avoid uneven data distribution; in terms of model selection, the llama2-13b-base model is selected for entity class annotation, and different data sets are constructed for distinguishing types and non-distinguishing types for fine-tuning; the Qwen1.5-14B model is selected for entity relationship class annotation, and different data sets are constructed for distinguishing types and non-distinguishing types for fine-tuning; data set sample: [{"instruction": "Please judge whether the character segment '###' in the text belongs to the 'general entity' class entity\n" according to the given following: *****\n","input": "","output": ""},{ ...}].
[0229] In terms of fine-tuning strategy, LoRA update is only applied to the selected linear layers, and the remaining layers remain fixed. During the training process, the product of the low-rank matrix is added to the original weight matrix bypass as a trainable parameter to simulate the change in the parameter. The effect of the original parameter matrix is gradually changed by learning the low-rank matrix instead of directly updating the original parameters. Specifically, assuming that the pre-trained weight is ${w_0\ \epsilon \ \mathbb{R}^{d*k}}$, the trainable parameters are ${\varDelta W\ =\BA}$, where ${B\ \epsilon \ \mathbb{R}^{d*r}}$, ${A\ \epsilon \ \mathbb{R}^{r*d}}$. During initialization, the matrix ${A}$ is initialized by a Gaussian function, and the matrix ${B}$ is initialized to zero, so that the bypass has no effect on the original model before training starts, that is, the parameter change is 0. For the input ${x}$ of this weight, the output is the formula ${h\ =\ W_0x+∆W\ x\ =W_0x+BAx}$. Fine-tuning training is performed on the target dataset. The gradient of the loss function with respect to the low-rank matrices W+ and W- is calculated through forward propagation and back propagation. The low-rank matrix is updated according to the gradient, and then it is combined with the original model parameters according to the LoRA formula to obtain the new parameter value, thereby improving the model performance without significantly increasing the number of model parameters.
[0230] Error detection mechanism: During the fine-tuning process, the model performance is periodically evaluated on an independent validation set, and key indicators such as accuracy, F1 score, etc. are monitored; according to the performance on the validation set, LoRA-related hyperparameters are adjusted, such as the rank of the low-rank matrix, learning rate, regularization strength, etc., to optimize the performance of the model; a strict output verification mechanism is established to ensure that the answers provided by the model are accurate; and an additional knowledge base is introduced for fact-checking.
[0231] like Figure 2 As shown, an embodiment of the present invention also provides a device for automatically annotating medical texts based on a large model to construct a prompt, including a medical text data acquisition module, a text data preprocessing module, a general entity information acquisition module, an entity type information acquisition module, an entity relationship general information acquisition module and an entity relationship category information acquisition module;
[0232] A medical text data acquisition module is used to screen data tables and data elements based on massive medical text data and extract medical text data from the data elements;
[0233] A text data preprocessing module is used to preprocess medical text data to generate sentence samples;
[0234] The general entity information acquisition module is used to build entity-indistinguishable category prompt templates based on sentence samples to capture general entity information in medical texts;
[0235] The entity type information acquisition module is used to preset entity types based on the captured general entity information, build entity classification prompt templates, and capture entity type information in medical texts;
[0236] The entity relationship general information acquisition module is used to preset the general entity relationship type based on the captured entity type information, build the entity relationship non-classified prompt template, and capture the general entity relationship information in the medical text;
[0237] The entity relationship category information acquisition module is used to preset entity relationship types based on the captured general entity relationship information, build an entity relationship category distinction prompt template, and capture entity relationship category information in medical texts.
[0238] As a further limitation of the technical solution of the present invention, the text data preprocessing module includes a sentence segmentation unit, an anomaly detection processing unit, a deduplication processing unit and a sentence sample generation unit;
[0239] The sentence segmentation unit is used to segment the extracted large paragraphs of text data into sentences according to preset feature symbols;
[0240] An anomaly detection processing unit, used for detecting anomalies and processing missing values in the segmented sentences;
[0241] A deduplication processing unit is used to perform overall deduplication processing on the sentences after the missing processing by similarity calculation;
[0242] The sentence sample generating unit is used to generate sentence samples from the sentences after deduplication processing; in the sentence samples, the similarity between sentences is zero.
[0243] In some embodiments, the general entity information acquisition module is specifically used to obtain each character combination in a sentence based on a sentence sample; construct an entity non-classified prompt template for each character; call a large model reasoning service, select a character combination belonging to a general entity, and construct a first-stage output result.
[0244] In some embodiments, the entity type information acquisition module is specifically used to preset the entity category based on the output results of the first stage; construct an entity classification prompt template for each general entity, call the large model reasoning service, select the character combination belonging to the entity category, and construct the output results of the second stage, that is, the captured entity type information.
[0245] In some embodiments, the entity relationship general information acquisition module is specifically used to preset entity relationships based on the output results of the second stage; construct a prompt template without distinguishing categories between entity categories, call the large model reasoning service, select entity type combinations belonging to general relationships, and construct the output results of the third stage.
[0246] In some embodiments, the entity relationship category information acquisition module is specifically used to obtain the combination of entity types belonging to the general relationship in the sentence based on the output result of the third stage, and preset the entity relationship type; construct a Prompt template for distinguishing the entity relationship categories between each entity type, call the LLM reasoning service, select the combination of entity types belonging to the entity relationship type, and construct the final output result.
[0247] The embodiment of the present invention also provides an electronic device, which includes: a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus. The communication bus can be used for information transmission between the electronic device and the sensor. The processor can call the logic instructions in the memory to execute the following method: Step 1: Screening data tables and data elements based on massive medical text data, and extracting medical text data from the data elements; Step 2: Preprocessing the medical text data to generate sentence samples; Step 3: Constructing an entity non-classified Prompt template based on the sentence samples to capture general entity information in the medical text; Step 4: Based on the captured general entity information, presetting the entity type, constructing the entity distinguishing category Prompt template, and capturing the entity type information in the medical text; Step 5: Based on the captured entity type information, presetting the general entity relationship type, constructing the entity relationship non-classified Prompt template, and capturing the general entity relationship information in the medical text; Step 6: Based on the captured general entity relationship information, presetting the entity relationship type, constructing the entity relationship distinguishing category Prompt template, and capturing the entity relationship category information in the medical text.
[0248] In addition, the logic instructions in the above-mentioned memory can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when sold or used as an independent product. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc., which can store program code.
[0249] An embodiment of the present invention provides a non-transitory computer-readable storage medium, which stores computer instructions, and the computer instructions enable a computer to execute the method provided by the above method embodiment, for example, including: Step 1: Filtering data tables and data elements based on massive medical text data, and extracting medical text data from the data elements; Step 2: Preprocessing the medical text data to generate sentence samples; Step 3: Constructing an entity non-classifying Prompt template based on the sentence samples to capture general entity information in the medical text; Step 4: Based on the captured general entity information, presetting the entity type, constructing an entity classifying Prompt template, and capturing the entity type information in the medical text; Step 5: Based on the captured entity type information, presetting the general entity relationship type, constructing an entity relationship non-classifying Prompt template, and capturing the general entity relationship information in the medical text; Step 6: Based on the captured general entity relationship information, presetting the entity relationship type, constructing an entity relationship classifying Prompt template, and capturing the entity relationship category information in the medical text.
[0250] It should be understood that the order of execution of the steps in the above embodiment does not necessarily mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present invention.
[0251] An embodiment of the present invention provides an embodiment of a device for automatically annotating medical texts with prompts based on a large model. The device and the methods for automatically annotating medical texts with prompts based on a large model in the above-mentioned embodiments belong to the same inventive concept. For details not fully described in the embodiment of the device for automatically annotating medical texts with prompts based on a large model, reference can be made to the embodiment of the method for automatically annotating medical texts with prompts based on a large model.
[0252] The device for automatically annotating medical texts with prompts based on a large model is a combination of the units and algorithm steps of each example described in the embodiments disclosed herein, and can be implemented with electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the above description. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.
[0253] Those skilled in the art will appreciate that various aspects of the method for automatically annotating medical texts with prompts based on a large model can be implemented as a system, method or program product. Therefore, various aspects of the present disclosure can be specifically implemented in the following forms, namely: a complete hardware implementation, a complete software implementation (including firmware, microcode, etc.), or an implementation combining hardware and software aspects, which can be collectively referred to as "circuit", "module" or "system" here.
[0254] Although the present invention has been described in detail with reference to the accompanying drawings and in combination with the preferred embodiments, the present invention is not limited thereto. Without departing from the spirit and essence of the present invention, a person of ordinary skill in the art may make various equivalent modifications or substitutions to the embodiments of the present invention, and these modifications or substitutions shall be within the scope of the present invention. Any person of ordinary skill in the art may easily think of changes or substitutions within the technical scope disclosed by the present invention, and these shall be within the scope of protection of the present invention.
Claims
1. A method for automatically annotating medical texts based on a large model to construct prompts, characterized in that: The steps include: Preprocess the medical text data to generate sentence samples; Construct entity-indistinguishable prompt templates based on sentence samples to capture common entity information in medical texts; Based on the captured general entity information, preset entity types, build entity classification prompt templates, and capture entity type information in medical texts; Based on the captured entity type information, the general entity relationship type is preset, and the entity relationship non-classified prompt template is constructed to capture the general entity relationship information in the medical text; Based on the captured general information of entity relationships, the entity relationship types are preset, and a prompt template for distinguishing entity relationship categories is constructed to capture entity relationship category information in medical texts; The steps of constructing entity-indistinguishable prompt template based on sentence samples and capturing common entity information in medical texts include: Based on the sentence sample, obtain each character combination in the sentence; Construct entity-indistinguishable Prompt templates for each character; Call the large model inference service, select character combinations belonging to common entities, and construct the first stage output results; Based on the captured general entity information, the entity type is preset, and an entity classification prompt template is constructed. The steps of capturing entity type information in medical texts include: Based on the output results of the first stage, preset entity categories; Build entity classification prompt templates for each common entity, call the large model inference service, select character combinations belonging to the entity category, and build the second-stage output results, that is, the captured entity type information.
2. The method for automatically annotating medical texts based on a large model-based prompt according to claim 1, characterized in that: The steps of preprocessing medical text data to generate sentence samples include: Filter data tables and data elements based on massive medical text data, and extract medical text data from data elements.
3. The method for automatically annotating medical texts based on a large model to construct prompts according to claim 2 is characterized in that: The steps of preprocessing text data to generate sentence samples include: The extracted large text data is divided into sentences according to the preset feature symbols; Detect outliers and handle missing values in the segmented sentences; The sentences after missing processing are processed by similarity calculation to remove duplicates as a whole; The sentences after deduplication are used to generate sentence samples; in the sentence samples, the similarity between sentences is zero.
4. The method for automatically annotating medical texts based on a large model-based prompt according to claim 3, characterized in that: Based on the captured entity type information, the general entity relationship type is preset, and the entity relationship non-classified prompt template is constructed. The steps of capturing the general information of entity relationships in medical texts include: Based on the output results of the second stage, preset entity relationships; Construct a prompt template for entity relationships between entities of different categories without distinguishing categories, call the large model reasoning service, select the entity type combination belonging to the common relationship, and construct the output result of the third stage.
5. The method for automatically annotating medical texts based on a large model-based prompt according to claim 4, characterized in that: Based on the captured general information of entity relationships, the entity relationship types are preset, and a prompt template for distinguishing entity relationship categories is constructed. The steps of capturing entity relationship category information in medical texts include: Based on the output results of the third stage, obtain the entity type combinations belonging to the general relationship in the sentence and preset the entity relationship type; Construct a prompt template to distinguish the entity relationship categories between entity types, call the LLM reasoning service, select the entity type combinations belonging to the entity relationship type, and construct the final output result.
6. A device for automatically annotating medical texts based on a large model and prompt, characterized in that: It includes a medical text data acquisition module, a text data preprocessing module, a general entity information acquisition module, an entity type information acquisition module, an entity relationship general information acquisition module and an entity relationship category information acquisition module; A medical text data acquisition module is used to screen data tables and data elements based on massive medical text data and extract medical text data from the data elements; A text data preprocessing module is used to preprocess medical text data to generate sentence samples; The general entity information acquisition module is used to build entity-indistinguishable category prompt templates based on sentence samples to capture general entity information in medical texts; The entity type information acquisition module is used to preset entity types based on the captured general entity information, build entity classification prompt templates, and capture entity type information in medical texts; The entity relationship general information acquisition module is used to preset the general entity relationship type based on the captured entity type information, build the entity relationship non-classified prompt template, and capture the general entity relationship information in the medical text; An entity relationship category information acquisition module is used to preset entity relationship types based on the captured entity relationship general information, build an entity relationship category distinguishing prompt template, and capture entity relationship category information in medical texts; The general entity information acquisition module is specifically used to obtain each character combination in a sentence based on a sentence sample; construct an entity-indistinguishable prompt template for each character; call the large model inference service, select the character combination belonging to the general entity, and construct the first-stage output result; The entity type information acquisition module is specifically used to preset entity categories based on the output results of the first stage; build entity classification prompt templates for each common entity, call the large model reasoning service, select character combinations belonging to the entity category, and build the output results of the second stage, that is, the captured entity type information.
7. An electronic device, characterized in that: The electronic device includes: at least one processor; and a memory communicatively connected to the at least one processor; the memory stores computer program instructions executable by the at least one processor, and the computer program instructions are executed by the at least one processor so that the at least one processor can execute the method for automatically annotating medical texts based on a large model-based prompt as described in any one of claims 1 to 5.
8. A non-transitory computer-readable storage medium, characterized in that: The non-transitory computer-readable storage medium stores computer instructions, and the computer instructions enable the computer to execute the method for automatically annotating medical texts based on a large model to construct a prompt as described in any one of claims 1 to 5.
