Medical long text question answering method, device, electronic device and storage medium

By processing medical text data in a large language model, and using the grouping strategy of the RoPE encoding layer and attention layer, the problem of low efficiency in obtaining attention results in medical long text processing is solved, and the reasoning effect is improved.

CN118520882BActive Publication Date: 2024-11-01ATHENAEYES CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410978469.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-22
Publication Date
2024-11-01
Estimated Expiration
2044-07-22

AI Technical Summary

Technical Problem

In the long text processing in the medical field, large language models have low efficiency in obtaining attention results and lack of adaptive attention results, which affects the reasoning effect.

Method used

By obtaining medical text data, extracting question and answer data and performing splicing processing, long text question and answer data of target length are generated, and long text question and answer data of target length are encoded and calculated using RoPE encoding layer and attention layer to generate expansion coefficients and scaling factors, and embedding data of semantic units is enhanced. Group processing and input to the attention layer, perform full parameter training or Lora fine-tuning to obtain attention results.

Benefits of technology

The efficiency and reasoning effect of large language models in long text Q&A data are improved, and the ability to understand the relative position and relationship of semantic units is enhanced.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118520882B_ABST
    Figure CN118520882B_ABST
Patent Text Reader

Abstract

The present application discloses a medical long text question answering method, device, electronic device and storage medium, the method comprising: multiplying a first expansion coefficient by an original base frequency to obtain a target base frequency; multiplying a second expansion coefficient by an original scaling factor to obtain a target scaling factor; in a RoPE coding layer, encoding the first embedded data of a semantic unit based on the target base frequency and the target scaling factor to obtain the second embedded data of the semantic unit; dividing the second embedded data of multiple semantic units into multiple groups according to a preset grouping strategy; inputting the groups into the attention layer of a large language model, performing attention calculation on the current group, obtaining the calculation result corresponding to the group, merging the calculation results corresponding to the group, and obtaining the attention result output by the attention layer. The present application is conducive to improving the reasoning effect of a large language model on long text question answering data.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of Internet technology, and in particular to a method, device, electronic device and storage medium for answering long medical texts. Background Art

[0002] Large language models (LLMs) are usually trained on context data in a predefined window size. When the length of the context content exceeds the pre-training length, the performance of the large language model usually declines significantly.

[0003] However, in the medical field, data is usually in the form of long text, such as case reports, diagnosis and treatment plans, etc., and in practical applications, it is usually necessary to perform document summaries, question and answer, etc. The limited context length support of text makes large language models lack adaptive attention results in the medical field. Therefore, how to obtain the attention results of large language models is an urgent problem to be solved. Summary of the invention

[0004] The embodiments of the present application provide a medical long text question answering method, device, electronic device and storage medium to solve the technical problem of how to obtain the attention results of a large language model.

[0005] In a first aspect, an embodiment of the present application provides a medical long text question answering method, which is applied to an electronic device, wherein the electronic device stores a large language model, and the medical long text question answering method includes:

[0006] Acquire medical text data, extract question and answer data from the medical text data, and concatenate multiple question and answer data to obtain long text question and answer data with a target length;

[0007] Extracting semantic units from the long text question-answering data, inputting first embedding data of the semantic units into the RoPE coding layer of the large language model, and obtaining the original base frequency and the original scaling factor of the attention logarithm of the RoPE coding layer, wherein the first embedding data is embedding data carrying semantic information of the semantic unit;

[0008] Generate a first expansion coefficient according to the target length, the maximum length of the text processed by the large language model in the pre-training stage, and a preset first expansion coefficient generation model, and multiply the first expansion coefficient by the original basic frequency to obtain a target basic frequency;

[0009] Obtaining a position index of the semantic unit, generating a second expansion factor according to the position index, the maximum length, and a preset second expansion factor generation model, and multiplying the second expansion factor by the original scaling factor to obtain a target scaling factor;

[0010] In the RoPE coding layer, based on the target base frequency and the target scaling factor, the first embedded data of the semantic unit is encoded to obtain second embedded data of the semantic unit, where the second embedded data is embedded data carrying the semantic information and relative position information of the semantic unit;

[0011] According to a preset grouping strategy, the second embedded data of the plurality of semantic units are divided into a plurality of groups, wherein the grouping strategy is that the current group contains a preset number of the second embedded data of the semantic units in the previous or next group;

[0012] The group is input into the attention layer of the large language model, attention calculation is performed on the current group to obtain the calculation result corresponding to the group, and the calculation results corresponding to the group are merged to obtain the attention result output by the attention layer.

[0013] In a possible implementation manner of the first aspect, acquiring medical text data, extracting question and answer data from the medical text data, and concatenating a plurality of the question and answer data to obtain long text question and answer data having a text length of a target length includes:

[0014] Acquire the medical text data, extract each question sentence from the medical text data, and combine the question sentence and the answer information corresponding to the question sentence into a question-answer pair;

[0015] Multiple question-answer pairs are combined into question-answer data, and multiple question-answer data are concatenated to obtain the long text question-answer data whose text length is the target length.

[0016] In a possible implementation manner of the first aspect, dividing the second embedded data of the plurality of semantic units into a plurality of groups according to a preset grouping strategy includes:

[0017] Divide the context length of the long text question-answering data by the maximum length of the pre-trained large language model and round up to determine the number of groups;

[0018] The second embedded data of a plurality of the semantic units are divided into a plurality of the groups according to the grouping number and the grouping strategy.

[0019] In a possible implementation of the first aspect, after inputting the group into the attention layer of the large language model, performing attention calculation on the current group to obtain a calculation result corresponding to the group, and merging the calculation results corresponding to the group to obtain an attention result output by the attention layer, the medical long text question answering method includes:

[0020] Select full parameter training or Lora fine-tuning to train the large language model to obtain the trained large language model.

[0021] In a possible implementation manner of the first aspect, the first expansion coefficient generation model is:

[0022] ;

[0023] Wherein, x is the first expansion coefficient, is the target length, and c is the maximum length of the text processed by the large language model in the pre-training stage.

[0024] In a possible implementation manner of the first aspect, the second expansion coefficient generation model is:

[0025] ;

[0026] Among them, y is the second expansion coefficient, c is the maximum length of the text processed by the large language model in the pre-training stage, m is the position index of the semantic unit, and z is a preset constant.

[0027] In a possible implementation manner of the first aspect, the preset number includes one of 1 / 2 of the packet size, 1 / 3 of the packet size, 1 / 5 of the packet size, 1 / 6 of the packet size, or a combination thereof.

[0028] In a second aspect, an embodiment of the present application provides a medical long text question-answering device, which is applied to an electronic device, wherein the electronic device stores a large language model, including:

[0029] A first acquisition module is used to acquire medical text data, extract question and answer data from the medical text data, and concatenate multiple question and answer data to obtain long text question and answer data with a target length;

[0030] A second acquisition module is used to extract semantic units from the long text question-answering data, input first embedding data of the semantic units into the RoPE coding layer of the large language model, and obtain the original base frequency and the original scaling factor of the attention logarithm of the RoPE coding layer, wherein the first embedding data is embedding data carrying semantic information of the semantic unit;

[0031] A first generating module, configured to generate a model according to the target length, a maximum length of text processed by the large language model in a pre-training phase, and a preset first expansion coefficient, generate a first expansion coefficient, and multiply the first expansion coefficient by the original base frequency to obtain a target base frequency;

[0032] A second generation module is used to obtain a position index of the semantic unit, generate a second expansion factor according to the position index, the maximum length and a preset second expansion factor generation model, and multiply the second expansion factor by the original scaling factor to obtain a target scaling factor;

[0033] A coding module, configured to encode, in the RoPE coding layer, the first embedded data of the semantic unit based on the target base frequency and the target scaling factor to obtain second embedded data of the semantic unit, wherein the second embedded data is embedded data carrying the semantic information and relative position information of the semantic unit;

[0034] A grouping module, used for dividing the second embedded data of the plurality of semantic units into a plurality of groups according to a preset grouping strategy, wherein the grouping strategy is that the current group contains a preset number of the second embedded data of the semantic units in the previous or next group;

[0035] The output module is used to input the group into the attention layer of the large language model, perform attention calculation on the current group, obtain the calculation result corresponding to the group, merge the calculation results corresponding to the group, and obtain the attention result output by the attention layer.

[0036] In a third aspect, an embodiment of the present application provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the medical long text question and answer method in the first aspect when executing the computer program.

[0037] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the medical long text question and answer method in the above-mentioned first aspect is implemented.

[0038] In a fifth aspect, an embodiment of the present application provides a computer program product. When the computer program product is run on an electronic device, the electronic device executes the medical long text question and answer method described in the first aspect above.

[0039] The beneficial effects of the embodiments of the present application lie in two aspects. On the one hand, the grouping is input into the attention layer of the large language model, and attention calculation is performed on the current group to obtain the calculation result corresponding to the group, and the calculation results corresponding to the group are merged to obtain the attention result output by the attention layer. Therefore, the electronic device can obtain the attention result of the large language model, which is beneficial to improving the efficiency of obtaining the attention result. On the other hand, the attention result can help the large language model understand the relative positions and relationships of the different semantic units in the long text question and answer data, which is beneficial to improving the reasoning effect of the large language model on the long text question and answer data. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.

[0041] Figure 1 An application scenario diagram of the medical long text question answering method provided in an embodiment of the present application;

[0042] Figure 2 It is a flowchart of a medical long text question-answering method provided in an embodiment of the present application;

[0043] Figure 3 A flowchart for obtaining long text question and answer data provided in an embodiment of the present application;

[0044] Figure 4 A schematic block diagram of a medical long text question-answering device provided in an embodiment of the present application;

[0045] Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0046] In order to make the purpose, technical solutions and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not intended to limit the present application. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present application.

[0047] In the following description, specific details such as specific system structures, technologies, etc. are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application may also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present application.

[0048] It should be understood that when used in the present specification and the appended claims, the term "comprising" indicates the presence of described features, wholes, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or combinations thereof.

[0049] It should also be understood that the term “and / or” used in the specification and appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes these combinations.

[0050] As used in the specification and appended claims of this application, the term "if" can be interpreted as "when" or "uponce" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrase "if it is determined" or "if [described condition or event] is detected" can be interpreted as meaning "uponce it is determined" or "in response to determining" or "uponce [described condition or event] is detected" or "in response to detecting [described condition or event]", depending on the context.

[0051] In addition, in the description of the present application specification and the appended claims, the terms "first", "second", "third", etc. are only used to distinguish the descriptions and cannot be understood as indicating or implying relative importance.

[0052] References to "one embodiment" or "some embodiments" etc. described in the specification of this application mean that one or more embodiments of the present application include specific features, structures or characteristics described in conjunction with the embodiment. Therefore, the statements "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear in different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways.

[0053] In addition, the technical solutions between the various embodiments can be combined with each other, but they must be based on the fact that they can be implemented by ordinary technicians in this field. When the combination of technical solutions is contradictory or cannot be implemented, it should be deemed that such combination of technical solutions does not exist and is not within the scope of protection required by this application.

[0054] The flowcharts shown in the accompanying drawings are only examples and do not necessarily include all the contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps may also be decomposed, combined or partially merged, so the actual execution order may change according to actual conditions.

[0055] The medical long text question-and-answer method provided in the embodiments of the present application can be applied to electronic devices such as mobile phones, tablet computers, wearable devices, vehicle-mounted devices, augmented reality (AR) / virtual reality (VR) devices, laptop computers, ultra-mobile personal computers (UMPC), netbooks, personal digital assistants (PDA), etc. The embodiments of the present application do not impose any restrictions on the specific types of electronic devices.

[0056] For example, the electronic device may be a station (STAION, ST) in a WLAN, a cellular phone, a cordless phone, a Session Initiation Protocol (SIP) phone, a Wireless Local Loop (WLL) station, a Personal Digital Assistant (PDA) device, a handheld device with wireless communication function, a computing device or other processing device connected to a wireless modem, a vehicle-mounted device, a vehicle networking terminal, a computer, a laptop computer, a handheld communication device, a handheld computing device, a satellite wireless device, a wireless modem card, a TV set top box (STB), a customer premises equipment (CPE) and / or other devices for communicating on a wireless system and a next generation communication system, for example, a mobile terminal in a 5G network or a mobile terminal in a future evolved Public Land Mobile Network (PLMN) network, etc.

[0057] See also Figure 1 , Figure 1 The application scenario diagram of the medical long text question answering method provided in the embodiment of the present application is described in detail as follows:

[0058] See also Figure 1 , Figure 1 The application scenario diagram of the medical text question answering method provided in the embodiment of the present application is described in detail as follows:

[0059] The electronic device acquires medical text data, extracts question and answer data from the medical text data, and concatenates a plurality of the question and answer data to obtain long text question and answer data having a target length.

[0060] Among them, medical text data can come from one database or multiple databases.

[0061] For the sake of explanation, the medical text data comes from three databases as an example, which is described in detail as follows:

[0062] The three databases include database A, database B and database C. The electronic device is connected to database A, database B and database C respectively, and obtains medical text data from database A, database B and database C.

[0063] In an embodiment of the present application, the electronic device can be connected to different databases at the same time to obtain medical text data from different databases.

[0064] See also Figure 2 , Figure 2 It is a flow chart of the medical long text question answering method provided in an embodiment of the present application. The method can be applied to an electronic device that stores a large language model.

[0065] like Figure 2 As shown, the medical long text question answering method provided in the embodiment of the present application includes the following steps, which are described in detail as follows:

[0066] S201, obtaining medical text data, extracting question and answer data from the medical text data, and concatenating a plurality of the question and answer data to obtain long text question and answer data having a text length of a target length;

[0067] Among them, the long text question and answer data is the question and answer data of long text.

[0068] There are many types of long text question and answer data. For the sake of explanation, the long text question and answer data include the following types:

[0069] Drug development and clinical trial data: During the drug development process, researchers conduct a large number of clinical trials to evaluate the safety and effectiveness of drugs. These trials generate a large amount of text data, such as trial protocols, trial records, and result reports.

[0070] Medical education and training data: Medical schools, medical institutions, etc. often organize various medical education and training activities, such as lectures, seminars, online courses, etc. These activities will generate a large amount of teaching materials and learning data, many of which are in the form of long texts.

[0071] In the embodiments of the present application, long text question and answer data in the medical field is of great significance for promoting the progress of medical research.

[0072] S202, extracting a semantic unit from the long text question-answering data, inputting first embedding data of the semantic unit into the RoPE coding layer of the large language model, and obtaining an original base frequency and an original scaling factor of the attention logarithm of the RoPE coding layer, wherein the first embedding data is embedding data carrying semantic information of the semantic unit;

[0073] Among them, the RoPE (Rotary Position Embedding) encoding layer, which means rotational position encoding layer in Chinese, is a position encoding method used in the Transformer architecture.

[0074] S203, generating a first expansion coefficient according to the target length, the maximum length of the text processed by the large language model in the pre-training stage, and a preset first expansion coefficient generation model, and multiplying the first expansion coefficient by the original base frequency to obtain a target base frequency;

[0075] Wherein, the first expansion coefficient generation model is:

[0076] ;

[0077] Wherein, x is the first expansion coefficient, is the target length, and c is the maximum length of the text processed by the large language model in the pre-training stage.

[0078] Among them, when the target length is greater than the maximum length, the first expansion coefficient is greater than 1, and the first expansion coefficient is multiplied by the original basic frequency to obtain the target basic frequency. At this time, the target basic frequency will be greater than the original basic frequency, so the technical effect of amplifying the original basic frequency can be achieved.

[0079] S204, obtaining a position index of the semantic unit, generating a second expansion factor according to the position index, the maximum length and a preset second expansion factor generation model, and multiplying the second expansion factor by the original scaling factor to obtain a target scaling factor;

[0080] Wherein, the second expansion coefficient generation model is:

[0081] ;

[0082] Among them, y is the second expansion coefficient, c is the maximum length of the text processed by the large language model in the pre-training stage, m is the position index of the semantic unit, and z is a preset constant.

[0083] When the position index is greater than the maximum length, the second expansion factor will be greater than 1. The second expansion factor is multiplied by the original scaling factor to obtain the target scaling factor. At this time, the target scaling factor will be greater than the original scaling factor, thereby achieving the technical effect of amplifying the original scaling factor.

[0084] The value of z is set by the user or by the system default and is not restricted here.

[0085] For the sake of illustration, an example is given below:

[0086] For example, if z is 1, the second expansion coefficient generation model is:

[0087] ;

[0088] For example, if z is 2, the second expansion coefficient generation model is:

[0089] ;

[0090] In the embodiment of the present application, as the tasks of the large language model change, the preset constants can be readjusted to obtain the best performance.

[0091] S205, in the RoPE coding layer, encoding the first embedded data of the semantic unit based on the target base frequency and the target scaling factor to obtain second embedded data of the semantic unit, where the second embedded data is embedded data carrying the semantic information and relative position information of the semantic unit;

[0092] Exemplarily, in the RoPE coding layer, encoding the first embedded data of the semantic unit based on the target base frequency and the target scaling factor to obtain the second embedded data of the semantic unit includes:

[0093] In the RoPE coding layer, based on an extension mode of RoPE coding, the first embedded data of the semantic unit is encoded to obtain second embedded data of the semantic unit, wherein the extension mode of RoPE coding includes the target base frequency and the target scaling factor.

[0094] For ease of explanation, the extension method using RoPE encoding is as follows:

[0095] ;

[0096] Among them, m represents the position index of the Token, b is the original base frequency of RoPE, d is the dimension of the embedding vector, j is the ordinal number of the dimension, and t is the original scaling factor of the attention logarithm.

[0097] Wherein, x is the first expansion coefficient, and y is the second expansion coefficient.

[0098] in, This is the target fundamental frequency.

[0099] in, is the target scaling factor.

[0100] when When increasing, will also increase because and is a constant.

[0101] when When increasing, Will decrease.

[0102] Therefore, when When increasing, will approach 1, will approach .

[0103] Among them, the target base frequency amplifies the original base frequency, and the target scaling factor amplifies the original scaling factor. Therefore, the extended method of RoPE encoding can enhance the sensitivity and expression ability of the large language model to the relative position information of the semantic unit, as detailed as follows:

[0104] Enhanced position sensitivity: When the original base frequency increases, the difference between different position indices becomes more obvious in terms of rotation angle, which means that the model can more easily distinguish the relative position information of different semantic units.

[0105] Improve model expressiveness: When the target scaling factor increases, even a small position change may result in a large rotation angle change, which helps the model capture more subtle position dependencies.

[0106] Flexibility: The target base frequency and the target scaling factor are used to flexibly control the properties of RoPE encoding to adapt to different application scenarios. For example, when processing long sequences, the target base frequency and the target scaling factor help improve the modeling ability of large language models for long-range dependencies.

[0107] In an embodiment of the present application, the target base frequency and the target scaling factor can enhance the sensitivity and expressiveness of RoPE encoding in representing position information, enabling the large language model to better capture positional dependencies in sequence data and improve its performance in various application scenarios.

[0108] S206, dividing the second embedded data of the plurality of semantic units into a plurality of groups according to a preset grouping strategy, wherein the grouping strategy is that the current group contains a preset number of the second embedded data of the semantic units in the previous or next group;

[0109] The step of dividing the second embedded data of the plurality of semantic units into a plurality of groups according to a preset grouping strategy includes:

[0110] Divide the context length of the long text question-answering data by the maximum length of the pre-trained large language model and round up to determine the number of groups;

[0111] The second embedded data of a plurality of the semantic units are divided into a plurality of the groups according to the grouping number and the grouping strategy.

[0112] The preset number includes one of 1 / 2 of the group size, 1 / 3 of the group size, 1 / 5 of the group size, 1 / 6 of the group size, or a combination thereof.

[0113] For the sake of illustration, an example is given below:

[0114] For example, let N be the number of characters contained in each group. Now let's extend the text processing capability of the large language model to 10K. In order to save computing resources, the input long text question and answer data is first divided into several groups for intra-group calculations. The number of groups is calculated as follows: 10000 / 4096 = 2.441, which is rounded up to 3. Because the group must be an integer, rounding down will result in information loss.

[0115] In order to ensure the fluidity and connectivity of information after grouping, a preset number of the second embedded data of the semantic units are reserved at the beginning and end of adjacent groups, the preset number is N / 2, and the grouping is as follows:

[0116] .

[0117] in, A collection of groups.

[0118] in, Indicates that the 0th Token to the Nth Token are a group.

[0119] in, is the target length. For the last group.

[0120] in, The previous group of the last group.

[0121] For the sake of illustration, an example is given below:

[0122] For example, when N is 4096, in order to ensure information interaction between adjacent groups, the content of the first group is: the 1st semantic unit to the 4096th semantic unit.

[0123] The second grouping partially overlaps with the first grouping, and the second grouping is: the 2048th semantic unit to the 6144th semantic unit.

[0124] At this time, the semantic units from 2048 to 4096 exist in both the first group and the second group, and the subsequent groupings are also carried out in this way.

[0125] S207, input the grouping into the attention layer of the large language model, perform attention calculation on the current grouping to obtain the calculation result corresponding to the grouping, merge the calculation results corresponding to the grouping to obtain the attention result output by the attention layer.

[0126] Wherein, after inputting the group into the attention layer of the large language model, performing attention calculation on the current group to obtain the calculation result corresponding to the group, merging the calculation results corresponding to the group to obtain the attention result output by the attention layer, the medical long text question answering method includes:

[0127] Select full parameter training or Lora fine-tuning to train the large language model to obtain the trained large language model.

[0128] For the sake of illustration, an example is given below:

[0129] For example, the attention result is passed to the fully connected layer of the large language model, and the predicted answer output by the fully connected layer based on the attention result is obtained. According to the comparison result between the predicted answer and the preset answer of the question and answer data, the loss value of the loss function is calculated. When the loss value is greater than the preset value, the model parameters of the large language model are updated through full parameter training or Lora fine-tuning. Based on the question and answer data, the large language model after the model parameters are updated is trained until the loss value is less than the preset value, and then the training of the large language model is stopped to obtain the trained large language model.

[0130] Among them, the attention results can help the large language model understand the relative positions and relationships of the different semantic units in the long text question and answer data, which is conducive to improving the reliability and rationality of the predicted answers output by the fully connected layer based on the attention results, and further helps to improve the reasoning effect of the large language model on the long text question and answer data.

[0131] After the large language model is trained by selecting the full parameter training or Lora fine-tuning method to obtain the trained large language model, the medical long text question answering method includes:

[0132] Connecting to a medical question-answering system, and obtaining a medical conversation in the medical question-answering system;

[0133] In the medical conversation, a current question is obtained, a feature vector of the current question is extracted, the feature vector is input into the trained large language model, and a current answer output by the trained large language model based on the feature vector is obtained.

[0134] The beneficial effects of the embodiments of the present application lie in two aspects. On the one hand, the grouping is input into the attention layer of the large language model, and attention calculation is performed on the current group to obtain the calculation result corresponding to the group, and the calculation results corresponding to the group are merged to obtain the attention result output by the attention layer. Therefore, the electronic device can obtain the attention result of the large language model, which is beneficial to improving the efficiency of obtaining the attention result. On the other hand, the attention result can help the large language model understand the relative positions and relationships of the different semantic units in the long text question and answer data, which is beneficial to improving the reasoning effect of the large language model on the long text question and answer data.

[0135] See also Figure 3 , Figure 3 The flowchart for obtaining long text question and answer data provided in the embodiment of the present application is described in detail as follows:

[0136] S301, acquiring the medical text data, extracting each question sentence from the medical text data, and combining the question sentence and the answer information corresponding to the question sentence into a question-answer pair;

[0137] S302, composing a plurality of the question-answer pairs into question-answer data, and concatenating the plurality of the question-answer data to obtain the long text question-answer data whose text length is the target length.

[0138] For the sake of illustration, an example is given below:

[0139] For example, question-answering data A in the medical field: the number of question-answer pairs is 5,000;

[0140] Medical question-answering data B: The number of question-answer pairs is 3,000;

[0141] The question-answer data A and question-answer data B are concatenated to obtain long text question-answer data with a text length of the target length. The number of question-answer pairs in the long text question-answer data is 8,000.

[0142] The long text question-answering data in the medical field ensures that each question-answer pair maintains its original content and merges each question-answer pair into a larger long text question-answering data. In this way, the long text question-answering data will contain a variety of questions and answers from the medical field, forming a rich and diverse question-answering dataset.

[0143] In the embodiment of the present application, the long text question and answer data provides rich contextual information for the large language model, enabling the large language model to more accurately understand and infer the intention and logical relationship behind the question. By being exposed to a large number of question and answer pairs, the large language model can learn how to generate logical answers in different situations, thereby improving the accuracy and relevance of the large language model's answers.

[0144] Corresponding to the medical long text question answering method described in the above embodiment, please refer to Figure 4 , Figure 4 A schematic block diagram of a medical long text question-answering device provided in an embodiment of the present application, Figure 4 The medical long text question answering device 400 shown can be applied to Figure 1 The electronic device in the application scenario diagram shown below takes the electronic device as an example. Figure 4 The medical long text question and answer device 400 shown is described in detail. The medical long text question and answer device 400 may include a first acquisition module 401, a second acquisition module 402, a first generation module 403, a second generation module 404, an encoding module 405, a grouping module 406, and an output module 407.

[0145] The first acquisition module 401 is used to acquire medical text data, extract question and answer data from the medical text data, and concatenate multiple question and answer data to obtain long text question and answer data with a target length;

[0146] A second acquisition module 402 is used to extract semantic units from the long text question-answering data, input first embedding data of the semantic units into the RoPE coding layer of the large language model, and obtain the original base frequency and the original scaling factor of the attention logarithm of the RoPE coding layer, wherein the first embedding data is the embedding data carrying the semantic information of the semantic unit;

[0147] A first generating module 403 is configured to generate a model according to the target length, the maximum length of the text processed by the large language model in the pre-training stage, and a preset first expansion coefficient, generate a first expansion coefficient, and multiply the first expansion coefficient by the original basic frequency to obtain a target basic frequency;

[0148] A second generation module 404 is used to obtain a position index of the semantic unit, generate a second expansion factor according to the position index, the maximum length and a preset second expansion factor generation model, and multiply the second expansion factor by the original scaling factor to obtain a target scaling factor;

[0149] A coding module 405 is used to encode the first embedded data of the semantic unit in the RoPE coding layer based on the target base frequency and the target scaling factor to obtain second embedded data of the semantic unit, where the second embedded data is embedded data carrying the semantic information and relative position information of the semantic unit;

[0150] A grouping module 406, configured to group the second embedded data of the plurality of semantic units into a plurality of groups according to a preset grouping strategy, wherein the grouping strategy is that the current group contains a preset number of the second embedded data of the semantic units in the previous or next group;

[0151] The output module 407 is used to input the group into the attention layer of the large language model, perform attention calculation on the current group, obtain the calculation result corresponding to the group, merge the calculation results corresponding to the group, and obtain the attention result output by the attention layer.

[0152] It should be noted that the various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.

[0153] The beneficial effects of the embodiments of the present application lie in two aspects. On the one hand, the grouping is input into the attention layer of the large language model, and attention calculation is performed on the current group to obtain the calculation result corresponding to the group, and the calculation results corresponding to the group are merged to obtain the attention result output by the attention layer. Therefore, the electronic device can obtain the attention result of the large language model, which is beneficial to improving the efficiency of obtaining the attention result. On the other hand, the attention result can help the large language model understand the relative positions and relationships of the different semantic units in the long text question and answer data, which is beneficial to improving the reasoning effect of the large language model on the long text question and answer data.

[0154] See also Figure 5 , Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application.

[0155] like Figure 5 As shown, Figure 5 The electronic device 2 includes: at least one processor 20, a memory 21, and a computer program 22 stored in the memory 21 and executable on the at least one processor 20, and when the processor 20 executes the computer program 22, the steps in any of the above-mentioned method embodiments are implemented.

[0156] The electronic device 2 may include, but is not limited to, a processor 20 and a memory 21. Those skilled in the art will appreciate that Figure 5 It is only an example of the electronic device 2 and does not constitute a limitation on the electronic device 2. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, it may also include input and output devices, network access devices, etc.

[0157] The processor 20 is used to run the computer program 22 stored in the memory 21, and implement the following steps when executing the computer program 22:

[0158] Acquire medical text data, extract question and answer data from the medical text data, and concatenate multiple question and answer data to obtain long text question and answer data with a target length;

[0159] Extracting semantic units from the long text question-answering data, inputting first embedding data of the semantic units into the RoPE coding layer of the large language model, and obtaining the original base frequency and the original scaling factor of the attention logarithm of the RoPE coding layer, wherein the first embedding data is embedding data carrying semantic information of the semantic unit;

[0160] Generate a first expansion coefficient according to the target length, the maximum length of the text processed by the large language model in the pre-training stage, and a preset first expansion coefficient generation model, and multiply the first expansion coefficient by the original basic frequency to obtain a target basic frequency;

[0161] Obtaining a position index of the semantic unit, generating a second expansion factor according to the position index, the maximum length, and a preset second expansion factor generation model, and multiplying the second expansion factor by the original scaling factor to obtain a target scaling factor;

[0162] In the RoPE coding layer, based on the target basic frequency and the target scaling factor, the first embedded data of the semantic unit is encoded to obtain the second embedded data of the semantic unit, where the second embedded data is embedded data carrying the semantic information and relative position information of the semantic unit; according to a preset grouping strategy, the second embedded data of multiple semantic units are divided into multiple groups, and the grouping strategy is that the current group contains a preset number of the second embedded data of the semantic units in the previous or next group; the group is input into the attention layer of the large language model, and the attention calculation is performed on the current group to obtain the calculation result corresponding to the group, and the calculation results corresponding to the groups are merged to obtain the attention result output by the attention layer.

[0163] In some embodiments, the processor 20 is configured to implement:

[0164] Acquire the medical text data, extract each question sentence from the medical text data, and combine the question sentence and the answer information corresponding to the question sentence into a question-answer pair;

[0165] Multiple question-answer pairs are combined into question-answer data, and multiple question-answer data are concatenated to obtain the long text question-answer data whose text length is the target length.

[0166] In some embodiments, the processor 20 is configured to implement:

[0167] Divide the context length of the long text question-answering data by the maximum length of the pre-trained large language model and round up to determine the number of groups;

[0168] The second embedded data of a plurality of the semantic units are divided into a plurality of the groups according to the grouping number and the grouping strategy.

[0169] In some embodiments, the processor 20 is configured to implement:

[0170] Select full parameter training or Lora fine-tuning to train the large language model to obtain the trained large language model.

[0171] In some embodiments, the processor 20 is configured to implement:

[0172] The first expansion coefficient generation model is:

[0173] ;

[0174] Wherein, x is the first expansion coefficient, is the target length, and c is the maximum length of the text processed by the large language model in the pre-training stage.

[0175] In some embodiments, the processor 20 is configured to implement:

[0176] The second expansion coefficient generation model is:

[0177] ;

[0178] Among them, y is the second expansion coefficient, c is the maximum length of the text processed by the large language model in the pre-training stage, m is the position index of the semantic unit, and z is a preset constant.

[0179] In some embodiments, the processor 20 is configured to implement:

[0180] The preset number includes one of 1 / 2 of the group size, 1 / 3 of the group size, 1 / 5 of the group size, 1 / 6 of the group size, or a combination thereof.

[0181] The processor 20 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.

[0182] In some embodiments, the memory 21 may be an internal storage unit of the electronic device 2, such as a hard disk or memory of the electronic device 2. In other embodiments, the memory 21 may also be an external storage device of the electronic device 2, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the electronic device 2. Further, the memory 21 may also include both an internal storage unit and an external storage device of the electronic device 2. The memory 21 is used to store an operating system, an application program, a boot loader, data, and other programs, such as the program code of the computer program. The memory 21 may also be used to temporarily store data that has been output or is to be output.

[0183] It should be noted that the information interaction, execution process, etc. between the above-mentioned devices / units are based on the same concept as the method embodiment of the present application. Their specific functions and technical effects can be found in the method embodiment part and will not be repeated here.

[0184] An embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in the above-mentioned method embodiments can be implemented.

[0185] The computer-readable storage medium stores program codes, which can be called by a processor to execute the medical long text question-answering method described in the above method embodiment.

[0186] The computer-readable storage medium has a storage space for program codes.

[0187] The program code includes the code of any step in the medical long text question answering method described in the above method embodiment.

[0188] For example, the program code is called by the processor and can execute the following steps:

[0189] Acquire medical text data, extract question and answer data from the medical text data, and concatenate multiple question and answer data to obtain long text question and answer data with a target length;

[0190] Extracting semantic units from the long text question-answering data, inputting first embedding data of the semantic units into the RoPE coding layer of the large language model, and obtaining the original base frequency and the original scaling factor of the attention logarithm of the RoPE coding layer, wherein the first embedding data is embedding data carrying semantic information of the semantic unit;

[0191] Generate a first expansion coefficient according to the target length, the maximum length of the text processed by the large language model in the pre-training stage, and a preset first expansion coefficient generation model, and multiply the first expansion coefficient by the original basic frequency to obtain a target basic frequency;

[0192] Obtaining a position index of the semantic unit, generating a second expansion factor according to the position index, the maximum length, and a preset second expansion factor generation model, and multiplying the second expansion factor by the original scaling factor to obtain a target scaling factor;

[0193] In the RoPE coding layer, based on the target base frequency and the target scaling factor, the first embedded data of the semantic unit is encoded to obtain second embedded data of the semantic unit, where the second embedded data is embedded data carrying the semantic information and relative position information of the semantic unit;

[0194] According to a preset grouping strategy, the second embedded data of the plurality of semantic units are divided into a plurality of groups, wherein the grouping strategy is that the current group contains a preset number of the second embedded data of the semantic units in the previous or next group;

[0195] The group is input into the attention layer of the large language model, attention calculation is performed on the current group to obtain the calculation result corresponding to the group, and the calculation results corresponding to the group are merged to obtain the attention result output by the attention layer.

[0196] The specific implementation of the above operations can be found in the previous embodiments, which will not be described in detail here.

[0197] Among them, the computer-readable storage medium can also be an external storage device of the medical long-text question-and-answer device or electronic device, for example, a plug-in hard disk equipped on the medical long-text question-and-answer device or electronic device, a smart memory card (SmartMedia Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), a non-volatile computer-readable medium (non-transitory computer-readable storage medium), etc.

[0198] Since the computer program stored in the computer-readable storage medium can execute any one of the medical long-text question-and-answer methods provided in the embodiments of the present application, the computer-readable storage medium can achieve the beneficial effects that can be achieved by any one of the medical long-text question-and-answer methods provided in the embodiments of the present application. Please see the previous embodiments for details and will not be repeated here.

[0199] An embodiment of the present application provides a computer program product. When the computer program product is executed on an electronic device, the electronic device executes the above-mentioned medical long text question and answer method.

[0200] The computer program product is loaded into the electronic device and can execute the following steps:

[0201] Acquire medical text data, extract question and answer data from the medical text data, and concatenate multiple question and answer data to obtain long text question and answer data with a target length;

[0202] Extracting semantic units from the long text question-answering data, inputting first embedding data of the semantic units into the RoPE coding layer of the large language model, and obtaining the original base frequency and the original scaling factor of the attention logarithm of the RoPE coding layer, wherein the first embedding data is embedding data carrying semantic information of the semantic unit;

[0203] Generate a first expansion coefficient according to the target length, the maximum length of the text processed by the large language model in the pre-training stage, and a preset first expansion coefficient generation model, and multiply the first expansion coefficient by the original basic frequency to obtain a target basic frequency;

[0204] Obtaining a position index of the semantic unit, generating a second expansion factor according to the position index, the maximum length, and a preset second expansion factor generation model, and multiplying the second expansion factor by the original scaling factor to obtain a target scaling factor;

[0205] In the RoPE coding layer, based on the target base frequency and the target scaling factor, the first embedded data of the semantic unit is encoded to obtain second embedded data of the semantic unit, where the second embedded data is embedded data carrying the semantic information and relative position information of the semantic unit;

[0206] According to a preset grouping strategy, the second embedded data of the plurality of semantic units are divided into a plurality of groups, wherein the grouping strategy is that the current group contains a preset number of the second embedded data of the semantic units in the previous or next group;

[0207] The group is input into the attention layer of the large language model, attention calculation is performed on the current group to obtain the calculation result corresponding to the group, and the calculation results corresponding to the group are merged to obtain the attention result output by the attention layer.

[0208] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium.

[0209] The technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.

[0210] Based on such understanding, the present application implements all or part of the processes in the above-mentioned embodiment method, which can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a computer-readable storage medium. When the computer program is executed by the processor, the steps of each of the above-mentioned method embodiments can be implemented. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may at least include: any entity or device that can carry the computer program code to an electronic device, a recording medium, a computer memory, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), an electrical carrier signal, a telecommunication signal, and a software distribution medium. For example, a USB flash drive, a mobile hard disk, a disk or an optical disk.

[0211] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0212] The above are only preferred embodiments of the present application, and are not intended to limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.

Claims

1. A medical long text question answering method, It is characterized in that Applied to an electronic device, the electronic device stores a large language model, and the medical long text question answering method includes: Acquire medical text data, extract question and answer data from the medical text data, and concatenate multiple question and answer data to obtain long text question and answer data with a target length; Extracting semantic units from the long text question-answering data, inputting first embedding data of the semantic units into the RoPE coding layer of the large language model, and obtaining the original base frequency and the original scaling factor of the attention logarithm of the RoPE coding layer, wherein the first embedding data is embedding data carrying semantic information of the semantic unit; Generate a first expansion coefficient according to the target length, the maximum length of the text processed by the large language model in the pre-training stage, and a preset first expansion coefficient generation model, and multiply the first expansion coefficient by the original basic frequency to obtain a target basic frequency; Obtaining a position index of the semantic unit, generating a second expansion factor according to the position index, the maximum length, and a preset second expansion factor generation model, and multiplying the second expansion factor by the original scaling factor to obtain a target scaling factor; In the RoPE coding layer, based on the target base frequency and the target scaling factor, the first embedded data of the semantic unit is encoded to obtain second embedded data of the semantic unit, where the second embedded data is embedded data carrying the semantic information and relative position information of the semantic unit; According to a preset grouping strategy, the second embedded data of the plurality of semantic units are divided into a plurality of groups, wherein the grouping strategy is that the current group contains a preset number of the second embedded data of the semantic units in the previous or next group; The group is input into the attention layer of the large language model, attention calculation is performed on the current group to obtain the calculation result corresponding to the group, and the calculation results corresponding to the group are merged to obtain the attention result output by the attention layer.

2. The medical long text question answering method according to claim 1, It is characterized in that The step of acquiring medical text data, extracting question-answer data from the medical text data, and concatenating a plurality of the question-answer data to obtain long text question-answer data having a target length of text includes: Acquire the medical text data, extract each question sentence from the medical text data, and combine the question sentence and the answer information corresponding to the question sentence into a question-answer pair; Multiple question-answer pairs are combined into question-answer data, and multiple question-answer data are concatenated to obtain the long text question-answer data whose text length is the target length.

3. The medical long text question answering method according to claim 1, It is characterized in that The step of dividing the second embedded data of the plurality of semantic units into a plurality of groups according to a preset grouping strategy includes: Divide the context length of the long text question-answering data by the maximum length of the pre-trained large language model and round up to determine the number of groups; The second embedded data of a plurality of the semantic units are divided into a plurality of the groups according to the grouping number and the grouping strategy.

4. The medical long text question answering method according to claim 1, It is characterized in that After inputting the grouping into the attention layer of the large language model, performing attention calculation on the current grouping to obtain the calculation result corresponding to the grouping, merging the calculation results corresponding to the grouping to obtain the attention result output by the attention layer, the medical long text question answering method includes: Select full parameter training or Lora fine-tuning to train the large language model to obtain the trained large language model.

5. The medical long text question answering method according to claim 1, It is characterized in that The first expansion coefficient generation model is: ; Wherein, x is the first expansion coefficient, is the target length, and c is the maximum length of the text processed by the large language model in the pre-training stage.

6. The medical long text question answering method according to claim 1, It is characterized in that The second expansion coefficient generation model is: ; Among them, y is the second expansion coefficient, c is the maximum length of the text processed by the large language model in the pre-training stage, m is the position index of the semantic unit, and z is a preset constant.

7. The medical long text question answering method according to any one of claims 1 to 6, It is characterized in that The preset number includes one of 1 / 2 of the group size, 1 / 3 of the group size, 1 / 5 of the group size, 1 / 6 of the group size, or a combination thereof.

8. A medical long text question-answering device, It is characterized in that Applied to an electronic device, the electronic device stores a large language model, including: A first acquisition module is used to acquire medical text data, extract question and answer data from the medical text data, and concatenate multiple question and answer data to obtain long text question and answer data with a target length; A second acquisition module is used to extract semantic units from the long text question-answering data, input first embedding data of the semantic units into the RoPE coding layer of the large language model, and obtain the original base frequency and the original scaling factor of the attention logarithm of the RoPE coding layer, wherein the first embedding data is embedding data carrying semantic information of the semantic unit; A first generating module, configured to generate a model according to the target length, a maximum length of text processed by the large language model in a pre-training phase, and a preset first expansion coefficient, generate a first expansion coefficient, and multiply the first expansion coefficient by the original base frequency to obtain a target base frequency; A second generation module is used to obtain a position index of the semantic unit, generate a second expansion factor according to the position index, the maximum length and a preset second expansion factor generation model, and multiply the second expansion factor by the original scaling factor to obtain a target scaling factor; A coding module, configured to encode, in the RoPE coding layer, the first embedded data of the semantic unit based on the target base frequency and the target scaling factor to obtain second embedded data of the semantic unit, wherein the second embedded data is embedded data carrying the semantic information and relative position information of the semantic unit; A grouping module, used for dividing the second embedded data of the plurality of semantic units into a plurality of groups according to a preset grouping strategy, wherein the grouping strategy is that the current group contains a preset number of the second embedded data of the semantic units in the previous or next group; The output module is used to input the group into the attention layer of the large language model, perform attention calculation on the current group, obtain the calculation result corresponding to the group, merge the calculation results corresponding to the group, and obtain the attention result output by the attention layer.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, It is characterized in that When the processor executes the computer program, the medical long text question answering method according to any one of claims 1 to 7 is implemented.

10. A computer-readable storage medium storing a computer program. It is characterized in that When the computer program is executed by a processor, the medical long text question answering method according to any one of claims 1 to 7 is implemented.