Entity identification method, apparatus and device, and storage medium
By generating instructions corresponding to entity types and utilizing the text sequence probability prediction of a large language model, the problems of low efficiency and accuracy in entity recognition are solved, achieving efficient and accurate entity recognition.
Patent Information
- Application Number
- CN202510558741.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-28
- Publication Date
- 2025-09-23
AI Technical Summary
Existing technologies have problems with entity recognition, such as low efficiency and low accuracy, especially when there are many and inexhaustible entity types, and entities of different types are easily confused, which affects the accuracy and comprehensiveness of recognition.
An entity recognition method based on a large language model is adopted. By generating instructions corresponding to different entity types, the language understanding and generation capabilities are used to perform entity recognition. Through probabilistic prediction of text sequences and instruction screening, suitable instructions are identified to improve recognition accuracy.
It simplifies the entity recognition process, improves recognition efficiency and accuracy, avoids performance degradation and false recall caused by too many entity types, and ensures the stability and comprehensiveness of recognition.
Smart Images

Figure CN120688501A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of natural language processing technology, and in particular to an entity recognition method, apparatus, device and storage medium. Background Art
[0002] Named Entity Recognition (NER) is a critical task in natural language processing. Its core is to identify entities with specific meanings from text, such as names of people, places, and organizations. This is used for intelligent customer service, financial services, machine translation, information extraction, and other businesses.
[0003] In some business scenarios, there are numerous and inexhaustible entities, and entities of different entity types are easily confused. How to accurately and comprehensively identify entities of a specified entity type from natural language text has become a hot research direction. Summary of the Invention
[0004] The purpose of the embodiments of the present application is to provide an entity recognition method, apparatus, device and storage medium for improving the efficiency of entity recognition and solving the problems of poor recognition accuracy and comprehensiveness caused by the non-exhaustive enumeration of entities and the easy confusion between entities of different entity types.
[0005] In order to achieve the above objectives, the embodiments of the present application adopt the following technical solutions: In a first aspect, an embodiment of the present application provides an entity recognition method, comprising: Based on the description text of the first entity type, generate a plurality of first instructions corresponding to the first entity type; Sampling the first text to obtain a text sequence, and predicting the probability of words in the text sequence under each first instruction using a first model; Determining a second instruction applicable to the first text from the plurality of first instructions based on a probability of a word in the text sequence under each first instruction; Based on the second instruction and the first model, a first entity belonging to the first entity type in the first text is identified.
[0006] In a second aspect, an embodiment of the present application provides an entity recognition device, comprising: A generating module, configured to generate a plurality of first instructions corresponding to a first entity type based on a description text of the first entity type; A prediction module, configured to sample the first text to obtain a text sequence, and predict the probability of words in the text sequence under each first instruction using a first model; a determination module, configured to determine, from the plurality of first instructions, a second instruction applicable to the first text based on a probability of a word in the text sequence under each first instruction; An identification module is used to identify a first entity belonging to the first entity type in the first text based on the second instruction and the first model.
[0007] In a third aspect, an embodiment of the present application provides an electronic device, including: processor; a memory for storing instructions executable by the processor; The processor is configured to execute the instructions to implement the entity recognition method provided in the first aspect.
[0008] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, which, when instructions in the storage medium are executed by a processor of an electronic device, enables the electronic device to perform the entity recognition method provided in the first aspect.
[0009] In a fifth aspect, an embodiment of the present application provides a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program, and the computer program is operable to enable a computer to execute some or all of the steps in the entity recognition method provided in the first aspect.
[0010] At least one of the above technical solutions adopted in the embodiments of the present application can achieve the following beneficial effects: By utilizing the language understanding and generation capabilities of the first model, instructions are used to guide the first model to perform named entity recognition on the first text, and the instructions correspond to the entity types, so that different entity types correspond to different instructions. On the one hand, it helps the first model to distinguish entities of different entity types, effectively solving the problem that entities of different entity types are easily confused and affect the recognition accuracy, and avoids the performance degradation problem caused by too long instructions when there are many entity types, and avoids entities from being recalled incorrectly; on the other hand, this method does not require a large amount of data labeling and model training. Even if a new entity type is added, it is only necessary to generate corresponding instructions for the newly added entity type to realize the recognition of entities belonging to this entity type, thereby greatly simplifying the entity recognition process and improving recognition efficiency. Moreover, this method does not require enumeration of entities belonging to each entity type, thereby effectively solving the problem that entities are not exhaustive and affect the comprehensiveness of recognition.
[0011] On this basis, for instructions corresponding to the same entity type, the first text is sampled to obtain a text sequence, and the probabilities of words in the text sequence under different instructions are predicted by the first model. These conditional probabilities reflect the fluctuation of the probability when the first model predicts words based on different instructions, and thus reflect the stability of the prediction effect of the first model based on different instructions; further, based on the probability of words in the text sequence under each instruction, the second instruction applicable to the first text is determined from these instructions, and based on the second instruction and the first model, the first entity belonging to the first entity type in the first text is identified, which can ensure the stability of the first model's entity recognition of the first text, thereby improving the recognition accuracy. BRIEF DESCRIPTION OF THE DRAWINGS
[0012] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings: Figure 1 A schematic diagram of an implementation environment provided for one embodiment of the present application; Figure 2 A flowchart of an entity recognition method provided in accordance with an embodiment of the present application; Figure 3 A flowchart of an entity recognition method provided in another embodiment of the present application; Figure 4 A schematic structural diagram of an entity recognition device provided in one embodiment of the present application; Figure 5 A schematic structural diagram of an electronic device provided in accordance with an embodiment of the present application. DETAILED DESCRIPTION
[0013] To make the purpose, technical solutions, and advantages of this application more clear, the technical solutions of this application will be clearly and completely described below in conjunction with the specific embodiments of this application and the corresponding drawings. Obviously, the embodiments described are only part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0014] The terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequential order. It should be understood that the terms used in this way can be interchangeable under appropriate circumstances, and this is merely a way of distinguishing the objects of the same attributes when describing them in the embodiments of the present application. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, so that the process, method, system, product or equipment comprising a series of units need not be limited to those units, but may include other units that are not clearly listed or inherent to these processes, methods, products or equipment.
[0015] Currently, texts labeled with entities and their entity types are usually used as training data, and models are trained in a supervised manner, and then the trained models are used to identify entities contained in given texts.
[0016] However, this approach has significant limitations. It relies heavily on large amounts of high-quality training data, making data collection and labeling time-consuming and labor-intensive. Furthermore, the addition of new entity types necessitates re-labeling and model training, impacting recognition efficiency. Furthermore, in some business scenarios, entities are numerous and non-exhaustive, making it easy for entities of different types to be confused. In these cases, even after training, the model struggles to achieve the desired accuracy and comprehensiveness in entity recognition, impacting the effectiveness of subsequent entity recognition-based applications.
[0017] In order to improve recognition efficiency and solve the problem that entities are not exhaustive and entities of different entity types are easily confused, which affects recognition accuracy and comprehensiveness, the embodiment of the present application proposes an entity recognition method that generates different instructions for different entity types, uses the language understanding and generation capabilities of a large language model to understand these instructions, and then recognizes entities of different entity types from a given text. This method does not require a large amount of data annotation and model training work, and even if a new entity type is added, it is only necessary to generate corresponding instructions for the newly added entity type to realize the recognition of entities belonging to this entity type, thereby greatly simplifying the entity recognition process and improving recognition efficiency. Secondly, this method does not require enumeration of entities belonging to each entity type, thereby effectively solving the problem that entities are not exhaustive and affect recognition comprehensiveness. In addition, different entity types correspond to different instructions, which not only helps the large language model to distinguish entities of different entity types, effectively solving the problem that entities of different entity types are easily confused and affect recognition accuracy, but also avoids the performance degradation problem caused by too long instructions when there are many entity types, and avoids entities being recalled incorrectly. As a result, the recognition accuracy and comprehensiveness can be greatly improved.
[0018] It should be understood that the entity recognition method proposed in the embodiments of the present application can be executed by an electronic device. As an example, it can be executed by software in the electronic device. The electronic devices mentioned here can include terminal devices, such as smartphones, tablets, laptops, desktop computers, intelligent voice interaction devices, smart home appliances, smart watches, vehicle terminals, aircraft, etc.; or the electronic device can also include a server, such as an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing cloud computing services.
[0019] Before introducing the entity recognition method provided by the embodiment of the present application in detail, a brief introduction to the implementation environment involved in the embodiment of the present application is given. Figure 1 , is a schematic diagram of an implementation environment provided by an embodiment of the present application, the implementation environment includes a terminal 10, or the implementation environment includes a terminal 10 and a text processing platform 20. The terminal 10 is connected to the text processing platform 20 via a wireless network or a wired network.
[0020] The terminal 10 may be a terminal device, such as at least one of a smartphone, a tablet computer, a laptop computer, a desktop computer, an intelligent voice interaction device, a smart home appliance, a smart watch, a vehicle-mounted terminal, and an aircraft. The terminal 10 may have installed and run an application program that supports text processing, such as a system application or a word processing application.
[0021] For example, the terminal 10 can generate different instructions for different entity types. For each entity type, based on the probability of the words in the text to be recognized under different instructions, the terminal 10 determines the optimal instruction for the text. Based on the large language model (LLM) and the optimal instruction, the terminal 10 can identify entities belonging to the entity type from the text. The terminal 10 can complete this task independently or provide data services for it through the text processing platform 20. This embodiment of the present application is not limited to this.
[0022] The text processing platform 20 comprises at least one of a single server, multiple servers, a cloud computing platform, and a virtualization center. The text processing platform 20 provides backend services for applications that support text processing. Optionally, the text processing platform 20 performs primary processing, while the terminal 10 performs secondary processing. Alternatively, the text processing platform 20 performs secondary processing, while the terminal 10 performs primary processing. Alternatively, either the text processing platform 20 or the terminal 10 can operate independently.
[0023] For example, the terminal 10 may generate different instructions for different entity types, and for each entity type, determine the best instruction for the text based on the probability of the words in the text to be recognized under different instructions. The terminal 10 then sends the best instruction and the text to be recognized to the text processing platform 20. The text processing platform 20 is deployed with an LLM. By inputting the received best instruction and text into the LLM for entity recognition, the entity belonging to the entity type in the text can be obtained.
[0024] Based on the implementation environment introduced above, the entity recognition method provided in the embodiment of the present application is described in detail with reference to the accompanying drawings.
[0025] Please refer to Figure 2 , is a flow chart of an entity recognition method provided in one embodiment of the present application, the method comprising the following steps: S202: Generate a plurality of first instructions corresponding to the first entity type based on the description text of the first entity type.
[0026] The first entity type refers to the entity type to be identified. There are multiple first instructions corresponding to the first entity type, and each first instruction is used to identify an entity belonging to the first entity type from a given text.
[0027] In one implementation, the above S202 includes the following steps: obtaining multiple description texts of the entity recognition task and multiple description texts of the first entity type; splicing different description texts of the entity recognition task and different description texts of the first entity type to obtain multiple first instructions.
[0028] Each description of an entity recognition task introduces the task, providing background and concisely describing the desired entity recognition task. For example, the desired domain(s) of entity recognition tasks, the types of first entities, and the desired output format are described. For example, if the entity recognition task is to identify the entity "loan principal" from a given text, the description of the entity recognition task might be, "Your task objective is to identify named entities of type 'loan principal' from the input financial text, accurately identify these 'loan principals', and output the entity type and entity content in JSON format."
[0029] The description text of the first entity type may include, but is not limited to, at least one of the following texts: a definition of the first entity type, notes, etc. For example, if the first entity type is "loan principal", the definition of the first entity type is as follows: "1. Loan principal refers to the initial amount a borrower borrows from a lending institution, excluding interest and other fees, and is usually expressed in currency units, such as '100,000 yuan'.
[0030] 2. Only mark the clearly mentioned loan principal amount, excluding other financial data such as interest, total repayment amount, etc.
[0031] 3. The currency unit can be the Chinese "yuan", the English "USD", or other common currency symbols.
[0032] 4. The number format supports Arabic numerals and Chinese numerals, such as "100,000 yuan" and "one hundred thousand yuan". The precautions for the first entity type are as follows: "1. If the loan principal amount appears together with other financial data, only mark the loan principal part.
[0033] 2. If the amount mentioned in the text uses a non-standard currency unit, try to mark it as it is without converting it yourself.
[0034] 3. If the loan principal amount is unclear or ambiguous, "empty" can be output." By splicing a description text of the entity recognition task and a description text of the first entity type according to a preset instruction template, a first instruction corresponding to the first entity type is obtained. Among them, an instruction template is as follows: {You are a data analysis expert in the financial field. Please carefully read and understand the following requirements and complete the named entity recognition task for the input text.
[0035] ## Task Introduction {Description text of the entity recognition task} ## Entity Definition {Definition of the first entity type} ## Precautions {Precautions for the first entity type} } In the application, the description text of the first entity type and the description text of the entity recognition task can be pre-designed manually.
[0036] The first instruction obtained through the above implementation method can help the first model more accurately understand the task requirements and the definition of the first entity type, thereby improving the recognition accuracy.
[0037] In another implementation method, the above S202 includes the following steps: S2021, generate a third instruction based on the description text of the first entity type.
[0038] Specifically, splice the description text of the first entity type and the description text of the entity recognition task to obtain the third instruction.
[0039] S2022: Rewrite the third instruction based on the first model to obtain multiple first instructions.
[0040] The first model refers to a model used for named entity recognition. The first model can adopt various large language models, which are not limited in the embodiments of the present application.
[0041] The third instruction and the fourth instruction for instructing rewriting are spliced and input into the first model. The first model rewrites and polishes the third instruction according to the fourth instruction to obtain multiple first instructions.
[0042] In the above implementation, although the third instruction generated based on the description text of the first entity type helps the first model understand the first type of entity, in some business scenarios, due to the background differences of such scenarios, the third instruction is not necessarily the most optimal instruction for the first model to understand. For example, named entity recognition in financial scenarios requires understanding financial background common sense. Due to differences in financial background, the third instruction generated by different description texts is not equal to the optimal instruction for the first model to understand. To this end, rewriting the third instruction with the help of the first model can ensure that the resulting first instruction is easy for the first model to understand, thereby eliminating the impact of background differences on recognition accuracy.
[0043] The above describes some implementations of S202. Of course, it should be understood that S202 can also be implemented in other ways, which are not limited in this embodiment of the present application.
[0044] S204: Sampling the first text to obtain a text sequence.
[0045] The first text refers to the text to be recognized. The sampling of the first text may be random sampling, that is, starting from different positions of the first text, continuous subsequences of different lengths are randomly selected, and each selected subsequence is regarded as a text sequence.
[0046] There can be multiple text sequences, and the length of each text sequence can be different. The length of a text sequence refers to the number of words contained in the text sequence. For example, if there are N text sequences and the length of the jth text sequence is n, that is, the jth text sequence includes n words, then the jth text sequence can be expressed as .in, Represents the tth word in the text sequence.
[0047] For example, if we randomly sample the first text "XX Enterprise applied for a loan of RMB 5 million from XX Bank in January 2023, with a loan term of 3 years and a principal of RMB 5 million, and an equal installment repayment method of principal and interest, with a monthly repayment amount of approximately RMB 150,000", we can obtain the following four text sequences: Text sequence 1: The loan principal is 5 million yuan Text sequence 2: Equal principal and interest repayment Text sequence 3: Monthly repayment amount is approximately 150,000 yuan Text sequence 4: XX Company applied for a loan of RMB 5 million from XX Bank in January 2023 S206 , predicting the probability of words in the text sequence under each first instruction using the first model.
[0048] For each first instruction, the probability of a word in the text sequence under the first instruction represents the probability of generating the word based on the first instruction and the word before the word in the text sequence. For example, the tth word The probability under the first instruction represents the tth word according to the first instruction and the first t-1 words The probability of generation.
[0049] In one implementation, when a text sequence contains n (n is a positive integer) words, the probability of the t-th (1≤t≤n) word in the text sequence under each first instruction is determined as follows: for each first instruction, using a first model, based on the first instruction and the previous t-1 words, predict the conditional probability distribution of the next word of the t-1-th word; based on the conditional probability distribution, determine the probability that the next word is the t-th word; and determine the probability as the probability of the t-th word under the first instruction.
[0050] Specifically, the large language model has the ability to understand and generate language. It uses the input instructions and existing words as context to predict the probability of each word in the vocabulary being the next word. These probabilities constitute the conditional probability distribution of the next word, that is, , represents the conditional probability of the next word, represents the first t-1 words, represents the parameters of the large language model, represents an activation function, Represents a large language model, represents the instruction to input the first model; then, the word with the highest probability in the vocabulary is selected as the next word, i.e. , represents the maximum probability in the conditional probability distribution, Represents the vocabulary; repeat the above process until the complete text is generated.
[0051] For example, suppose there is a text generation task where the goal is to generate a sentence about the weather. The vocabulary V contains the following words: [“today”, “weather”, “sunny”, “raining”, “very”, “,”, “suitable for going out”, “.”] Initially, the large language model predicts the first word based on the given instruction "generate a description about the weather". The conditional probability distribution of the first word may include 、 、 The large language model selects the word with the highest probability as the first word, and repeatedly predicts the next word based on the instruction and the current words until a complete text is generated or the generated text reaches a predetermined length.
[0052] In the embodiment of the present application, the text sequence shown above For example, for each first instruction, the first model uses its own language understanding and generation capabilities to make n-step predictions based on the understanding of the first instruction. At the t-th step prediction, based on the previous t-1 words, it predicts the probability of each word in the vocabulary being the next word. These probabilities constitute the conditional probability distribution of the next word, which is recorded as ; Then, the tth word The probability of the next word is determined to be the tth word The probability under this first instruction.
[0053] In this way, the probability of each word in the text sequence under each first instruction can be accurately predicted, providing reliable data support for the subsequent determination of the second instruction applicable to the first text.
[0054] S208 : Determine a second instruction applicable to the first text from the plurality of first instructions based on the probability of the words in the text sequence under each first instruction.
[0055] For each first instruction, the probability of a word in the text sequence under that first instruction reflects the fluctuation in the probability of the first model predicting the word based on that first instruction. The smaller this fluctuation, the more stable the first model's prediction based on that first instruction, and the more suitable that first instruction is for the first text. Therefore, based on the probability of a word in the text sequence under each first instruction, a second instruction suitable for the first text can be accurately selected.
[0056] In one implementation, the above S208 includes the following steps: S2081: For each first instruction, determine a first mean corresponding to the text sequence based on the probability of each word in the text sequence under the first instruction and the number of words in the text sequence.
[0057] The first mean reflects the average level of probability of words in the text sequence under the first instruction. The first mean can be expressed as ,in, represents the probability of the i-th word in the text sequence under the first instruction, Indicates the number of words in a text sequence.
[0058] In an application, there may be multiple text sequences. In this case, each text sequence has a corresponding first mean. Specifically, for each text sequence, the first mean corresponding to the text sequence is determined based on the probability of each word in the text sequence under the first instruction and the number of words in the text sequence.
[0059] S2082: For each first instruction, determine the score of the first instruction based on the probability of each word under the first instruction and the first mean.
[0060] As an example, based on the probability of each word under the first instruction and the first mean, the first standard deviation corresponding to the text sequence is determined; based on the first standard deviation, the score of the first instruction is determined.
[0061] Specifically, the first standard deviation can be expressed as ,in, represents the first mean, represents the probability of the i-th word under the first instruction, Indicates the number of words in a text sequence.
[0062] After determining the first standard deviation, the first standard deviation can be negated to obtain the score of the first instruction. The first standard deviation reflects the degree of deviation of the probability of a word in the text sequence under the first instruction from the conditional probability mean (i.e., the first mean). That is, the smaller the first standard deviation, the smaller the degree of deviation, which means that the probability fluctuations when the first model predicts words based on the first instruction are greater, indicating that the first model's prediction effect based on the first instruction is more stable, the first instruction is more applicable to the first text, and thus the first instruction has a higher score. In this way, it can ensure that the selected second instruction is more applicable to the first text, thereby improving the accuracy of entity recognition.
[0063] In the case where there are multiple text sequences, a second mean is determined based on the first standard deviation and the number of text sequences; and a negative value of the second mean is determined as the score of the first instruction.
[0064] Specifically, the score of the first instruction can be expressed as ,in, Represents the number of text sequences, represents the first mean, represents the probability of the i-th word under the first instruction, Indicates the number of words in a text sequence.
[0065] It is understandable that, when there are multiple text sequences, the second mean reflects the average level of prediction stability of the first instruction across all text sequences. The smaller the second mean, the better the average level of prediction stability of the first instruction across all text sequences, and thus the higher the score of the first instruction. This ensures that the selected second instruction is more suitable for the first text, thereby improving the accuracy of entity recognition.
[0066] S2083: Determine the first instruction whose score is greater than or equal to the score threshold as the second instruction applicable to the first text.
[0067] Specifically, if there is one first instruction with a score greater than or equal to the score threshold, then the first instruction can be determined as the second instruction applicable to the first text; if there are multiple first instructions with a score greater than or equal to the score threshold, then the first instruction with the highest score can be determined as the second instruction applicable to the first text.
[0068] In another implementation, the above S208 includes the following step: for each first instruction, determining the average of the probabilities of the words in the text sequence under the first instruction as the score of the first instruction.
[0069] The above describes some implementations of the above S208. Of course, it should be understood that the above S208 can also be implemented in other ways, which are not limited in the present embodiment.
[0070] S210: Based on the second instruction and the first model, identify a first entity belonging to a first entity type in the first text.
[0071] In one implementation, the second instruction and the first text are input into the first model, and the first model uses its own language understanding and processing capabilities to identify the first entity belonging to the first entity type from the first text.
[0072] In another implementation, the above S210 includes the following steps: S2101: Determine, from the second text corresponding to the first entity type, a third text that is similar to the first text.
[0073] The second text contains a second entity belonging to the first entity type. In the application, human experts can try to annotate a small amount of text for the first entity type. This text is the second text containing the second entity. The second text and the second entity it contains can serve as examples for in-context learning (ICL) in the first model, guiding the first model to better learn, understand, and abstract the definition of the first entity type, thereby further improving the first model's entity recognition performance.
[0074] For example, if the first entity type is "loan principal", the second text corresponding to the first entity type and the second entities it contains are as follows: Second text: The customer applied for a loan of 100,000 yuan, with a total repayment amount of 120,000 yuan The second entity contained in the second text: {100,000 yuan, loan principal} In the application, the second text and the second entity it contains can be stored in association, recorded as ,in, Represents the second text, Represents the second entity in the second text.
[0075] In the case where there are multiple second texts, in order to facilitate the first model to better understand and filter different second texts and the second entities contained therein, the second texts can be embedded through the embedding model to obtain the representation vector of the second text; further, the second text, the representation vector of the second text and the second entity in the second text are associated and stored, which is recorded as ,in, Represents the second text, represents the representation vector of the second text, Represents the second entity in the second text.
[0076] The embedding model may adopt various models with embedding functions in the art, such as bge-base-zh-v1.5, etc., which is not limited in the embodiments of the present application.
[0077] In S2101 above, the first text is embedded using an embedding model to obtain a representation vector for the first text. Then, similarities, such as cosine similarity, are calculated between the representation vector of the first text and the representation vectors of each second text. Furthermore, the k second texts with the highest similarity are determined as the third text. Here, k is an integer greater than 1. The value of k can be set based on actual needs. For example, to better balance the number of second texts and recognition accuracy, the value of k can be 3.
[0078] S2102: Combine the third text and the second entity in the third text to obtain a first context.
[0079] Specifically, for each third text, the third text is combined with the second entity contained therein to obtain a first context.
[0080] S2103: Identify, through the first model, a first entity belonging to the first entity type in the first text based on the second instruction and the first context.
[0081] As an example, the second instruction and the first context are input into the first model, and the first model uses its language understanding ability to learn and understand the task requirements of the entity recognition task and the definition of the first entity type from the second instruction, and refers to the example provided by the first context to perform named entity recognition on the first text to obtain the first entity belonging to the first entity type.
[0082] As another example, when there are multiple first contexts, the multiple first contexts are spliced in different orders to obtain multiple context combinations; for each context combination, entity recognition is performed on the first text based on the second instruction and the context combination through the first model to obtain a third entity corresponding to the context combination; for each context combination, the number of occurrences of the third entity corresponding to the context combination in the above multiple context combinations is determined; the third entity whose number of occurrences is greater than the number threshold is determined as the first entity belonging to the first entity type in the first text.
[0083] The number threshold can be set according to actual needs and is not limited in the present embodiment. For example, if the number of context combinations is 6, the number threshold can be set to 6 / 2=3.
[0084] For example, the number of first contexts is 3, recorded as 、 、 By concatenating these first contexts in different orders, we can obtain the following six context combinations:
[0085] Assume that the third entity corresponding to each of the above context combinations is as follows:
[0086] In the above-mentioned third entity, if the number of occurrences of entity 1 in all context combinations and the number of occurrences of entity 2 in all context combinations are greater than the number threshold, entity 1 and entity 2 are determined as the first entity belonging to the first entity type in the first text.
[0087] By providing the first context and the second instruction to the first model, the first model can better understand the specific requirements of the entity recognition task and make inferences based on the entity recognition examples provided by the first context. In particular, when processing ambiguous or complex first texts, the model can make more reasonable judgments, thereby improving the accuracy of entity recognition. It can also ensure that the first model follows the same output format as the entity recognition example, ensuring the consistency of the output format of the first model. In addition, it is also taken into account that in some business scenarios, for the sake of data security, the first model usually adopts a model with a smaller parameter scale. Such models are highly sensitive to input instructions. Even if the same first context is input, different results may be obtained when the order of the first context is different. To this end, by splicing the first context in different orders and providing it to the first model for recognition, and determining the third entity that appears more times in the recognition result as the first entity, the prediction bias caused by the different order of the first context can be eliminated, further improving the recognition accuracy.
[0088] The above describes some implementations of the above S210. Of course, it should be understood that the above S210 can also be implemented in other ways, which are not limited in the present embodiment.
[0089] It is worth noting that there may be multiple first entity types. In this case, the above steps S202 to S210 may be performed for each first entity type, thereby identifying the first entity belonging to each first entity type from the first text.
[0090] The entity recognition method provided in the embodiment of the present application utilizes the language understanding and generation capabilities of the first model, and adopts instructions to guide the first model to perform named entity recognition on the first text, and the instructions correspond to the entity type, so that different entity types correspond to different instructions. On the one hand, it helps the first model to distinguish entities of different entity types, effectively solving the problem that entities of different entity types are easily confused and affect the recognition accuracy, and avoids the performance degradation problem caused by too long instructions when there are many entity types, and avoids entities from being recalled incorrectly; on the other hand, this method does not require a large amount of data labeling and model training. Even if a new entity type is added, it is only necessary to generate corresponding instructions for the newly added entity type to realize the recognition of entities belonging to this entity type, thereby greatly simplifying the entity recognition process and improving recognition efficiency. Moreover, this method does not require enumeration of entities belonging to each entity type, thereby effectively solving the problem that entities are not exhaustive and affect the comprehensiveness of recognition.
[0091] On this basis, for instructions corresponding to the same entity type, the first text is sampled to obtain a text sequence, and the probabilities of words in the text sequence under different instructions are predicted by the first model. These conditional probabilities reflect the fluctuation of the probability when the first model predicts words based on different instructions, and thus reflect the stability of the prediction effect of the first model based on different instructions; further, based on the probability of words in the text sequence under each instruction, the second instruction applicable to the first text is determined from these instructions, and based on the second instruction and the first model, the first entity belonging to the first entity type in the first text is identified, which can ensure the stability of the first model's entity recognition of the first text, thereby improving the recognition accuracy.
[0092] In order to facilitate the understanding of the above entity recognition method, the following Figure 3 , the entity recognition process is explained with a specific embodiment.
[0093] like Figure 3 As shown, multiple entity types that need to be identified are pre-configured. These entity types are traversed, and each time an entity type is traversed, the entity type is determined to be a first entity type. A third instruction is generated based on the definition of the first entity type, and the third instruction is rewritten using the first model to obtain multiple first instructions corresponding to the first entity type.
[0094] Then, the first text is sampled to obtain a text sequence, and the probability of the words in the text sequence under each first instruction is predicted by the first model, and based on the probability of the words in the text sequence under each first instruction, a second instruction suitable for the first text is determined from multiple first instructions.
[0095] Furthermore, a third text similar to the first text is determined from the second text corresponding to the first entity type, and the third text and the second entity in the third text are combined to obtain a first context; when there are multiple first contexts, the multiple first contexts are combined in different orders to obtain multiple context combinations, and for each context combination, entity recognition is performed on the first text based on the second instruction and the context combination through the first model to obtain a third entity corresponding to the context combination.
[0096] Finally, the number of occurrences of the third entity corresponding to each context combination in all context combinations is determined, and the third entity whose number of occurrences is greater than a threshold is determined as the first entity of the first entity type in the first text.
[0097] The foregoing description of this specification describes specific embodiments. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims can be performed in an order different from that described in the embodiments and still achieve the desired results. Furthermore, the processes depicted in the accompanying drawings do not necessarily require the specific order shown or the sequential order to achieve the desired results. In certain embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0098] Based on the same inventive concept, the present application also provides an entity recognition device. Figure 4 , is a structural diagram of an entity recognition device 400 provided in an embodiment of the present application, wherein the device 400 includes: a generation module 410, a prediction module 420, a determination module 430 and an identification module 440.
[0099] The generating module 410 is configured to generate a plurality of first instructions corresponding to the first entity type based on a description text of the first entity type.
[0100] The prediction module 420 is configured to sample the first text to obtain a text sequence, and predict the probability of words in the text sequence under each first instruction using a first model.
[0101] The determination module 430 is configured to determine a second instruction applicable to the first text from the plurality of first instructions based on the probability of a word in the text sequence under each first instruction.
[0102] The recognition module 440 is configured to recognize a first entity belonging to the first entity type in the first text based on the second instruction and the first model.
[0103] In another embodiment, the text sequence includes n words, where n is a positive integer; the probability of the t-th word in the text sequence under each first instruction is determined as follows, 1≤t≤n: The prediction module is used to: For each first instruction, predicting, by the first model, a conditional probability distribution of the next word following the t-1th word based on the first instruction and the first t-1th words; Determining, based on the conditional probability distribution, a probability that the next word is the t-th word; The probability is determined as the probability of the tth word under the first instruction.
[0104] In another implementation, the determining module is configured to: For each first instruction, determining a first mean corresponding to the text sequence based on a probability of each word in the text sequence under the first instruction and the number of words in the text sequence; and, determining a score for the first instruction based on the probability of each word under the first instruction and the first mean; A first instruction having a score greater than or equal to a score threshold is determined as a second instruction applicable to the first text.
[0105] In another embodiment, when determining the score of the first instruction based on the probability of each word under the first instruction and the first mean, the determination module performs the following steps: Determining a first standard deviation corresponding to the text sequence based on the probability of each word under the first instruction and the first mean; A score for the first instruction is determined based on the first standard deviation.
[0106] In another implementation, the number of the text sequences is multiple; When determining the score of the first instruction based on the first standard deviation, the determination module performs the following steps: determining a second mean based on the first standard deviation and the number of the text sequences; A negative value of the second mean is determined as the score of the first instruction.
[0107] In another embodiment, the identification module is configured to: Determining, from a second text corresponding to the first entity type, a third text similar to the first text, wherein the second text contains a second entity belonging to the first entity type; combining the third text and the second entity in the third text to obtain a first context; A first entity belonging to the first entity type in the first text is identified through the first model based on the second instruction and the first context.
[0108] In another implementation, the number of the first contexts is multiple; When the recognition module recognizes a first entity belonging to the first entity type in the first text based on the second instruction and the first context by using the first model, the recognition module performs the following steps: splicing the multiple first contexts in different orders to obtain multiple context combinations; For each context combination, performing entity recognition on the first text based on the second instruction and the context combination using the first model to obtain a third entity corresponding to the context combination; For each context combination, determining the number of occurrences of the third entity corresponding to the context combination in the multiple context combinations; A third entity whose occurrence number is greater than a threshold number is determined as a first entity belonging to the first entity type in the first text.
[0109] In another embodiment, the generating module is configured to: generating a third instruction based on the description text of the first entity type; The third instruction is rewritten based on the first model to obtain multiple first instructions.
[0110] Obviously, the entity recognition device provided in the embodiment of the present application can be used as Figure 2 The execution body of the entity recognition method shown, for example Figure 2 In the entity recognition method shown in FIG, step S202 can be performed by Figure 4 The generating module 410 in the entity recognition device shown in FIG. 1 is executed, and steps S204 and S206 can be performed by Figure 4 The prediction module 420 in the entity recognition device shown in FIG. 1 is executed, and step S208 can be performed by Figure 4 The determination module 430 in the entity recognition device shown in FIG. 1 is executed, and step S210 can be performed by Figure 4 The identification module 440 in the entity identification device shown is executed.
[0111] According to another embodiment of the present application, Figure 4 The various modules in the entity recognition device shown can be individually or completely combined into one or several other modules to form a whole, or one (or more) of the modules can be further divided into multiple functionally smaller modules to form a whole, which can achieve the same operation without affecting the realization of the technical effects of the embodiments of the present application. The above-mentioned units are divided based on logical functions. In actual applications, the functions of one module can also be implemented by multiple modules, or the functions of multiple modules can be implemented by one module. In the embodiments of the present application, the entity recognition device may also include other modules. In actual applications, these modules can also be implemented with the assistance of other modules, and can be implemented by the collaboration of multiple modules.
[0112] According to another embodiment of the present application, the system can be executed on a general computing device such as a computer including processing elements such as a CPU, RAM, ROM and storage elements. Figure 2 A computer program (including program code) for each step involved in the corresponding method shown in FIG. Figure 4 The entity recognition device shown in the figure and the entity recognition method according to the embodiment of the present application are implemented. The computer program can be recorded on a computer-readable storage medium, for example, and transferred to an electronic device through the computer-readable storage medium and run therein.
[0113] Figure 5 This is a schematic diagram of the structure of an electronic device provided by an embodiment of the present application. Figure 5 At the hardware level, the electronic device includes a processor and, optionally, an internal bus, a network interface, and memory. The memory may include internal memory, such as high-speed random-access memory (RAM), or non-volatile memory, such as at least one disk drive. Of course, the electronic device may also include other hardware required for its services.
[0114] The processor, network interface, and memory can be interconnected via an internal bus, which can be an ISA (Industry Standard Architecture) bus, a PCI (Peripheral Component Interconnect) bus, or an EISA (Extended Industry Standard Architecture) bus. The bus can be divided into an address bus, a data bus, a control bus, and the like. For ease of representation, Figure 5 Only one bidirectional arrow is used in the diagram, but this does not mean that there is only one bus or one type of bus.
[0115] The memory is used to store programs. Specifically, the program may include program code, which includes computer operating instructions. The memory may include internal memory and non-volatile memory, and provides instructions and data to the processor.
[0116] The processor reads the corresponding computer program from the non-volatile memory into the internal memory and then runs it, forming an entity recognition device at the logical level. The processor executes the program stored in the memory and is specifically used to perform the following operations: Based on the description text of the first entity type, generate a plurality of first instructions corresponding to the first entity type; Sampling the first text to obtain a text sequence, and predicting the probability of words in the text sequence under each first instruction using a first model; Determining a second instruction applicable to the first text from the plurality of first instructions based on a probability of a word in the text sequence under each first instruction; Based on the second instruction and the first model, a first entity belonging to the first entity type in the first text is identified.
[0117] The above application Figure 2The methods performed by the entity identification device disclosed in the illustrated embodiments can be applied to or implemented by a processor. The processor may be an integrated circuit chip with signal processing capabilities. During implementation, each step of the above method can be performed by hardware integrated logic circuits within the processor or by software instructions. The above processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. The methods, steps, and logic block diagrams disclosed in the embodiments of this application can be implemented or executed. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the methods disclosed in the embodiments of this application can be directly implemented and executed by a hardware decoding processor, or by a combination of hardware and software modules within the decoding processor. The software module can be located in a storage medium well-known in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, etc. The storage medium is located in the memory, and the processor reads the information in the memory and, in conjunction with its hardware, completes the steps of the above method.
[0118] The electronic device may also perform Figure 2 Method, and realize entity recognition device in Figure 2 、 Figure 3 The functions of the illustrated embodiment will not be described in detail in the embodiments of the present application.
[0119] Of course, in addition to software implementation, the electronic device of this application does not exclude other implementation methods, such as logic devices or a combination of software and hardware, etc. That is to say, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.
[0120] The embodiment of the present application also provides a computer-readable storage medium, which stores one or more programs, wherein the one or more programs include instructions, which, when executed by an electronic device including multiple application programs, can enable the electronic device to execute Figure 2 The method of the embodiment shown is specifically used to perform the following operations: Based on the description text of the first entity type, generate a plurality of first instructions corresponding to the first entity type; Sampling the first text to obtain a text sequence, and predicting the probability of words in the text sequence under each first instruction using a first model; Determining a second instruction applicable to the first text from the plurality of first instructions based on a probability of a word in the text sequence under each first instruction; Based on the second instruction and the first model, a first entity belonging to the first entity type in the first text is identified.
[0121] An embodiment of the present application also provides a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program, and the computer program is operable to cause a computer to execute some or all of the steps in the entity recognition method provided in the embodiment of the present application.
[0122] In short, the above description is only a preferred embodiment of the present application and is not intended to limit the scope of protection of the present application. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present application shall be included in the scope of protection of the present application.
[0123] The systems, devices, modules, or units described in the above embodiments may be implemented by computer chips or entities, or by products having certain functions. A typical implementation device is a computer. Specifically, the computer may be, for example, a personal computer, a laptop computer, a cellular phone, a camera phone, a smartphone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.
[0124] Computer-readable media includes permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. The information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include transitory computer-readable media (transitory media), such as modulated data signals and carrier waves.
[0125] It should also be noted that the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, commodity, or apparatus that includes a series of elements includes not only those elements but also other elements not explicitly listed, or includes elements inherent to such process, method, commodity, or apparatus. In the absence of further limitations, an element defined by the phrase "comprises a ..." does not exclude the presence of other identical elements in the process, method, commodity, or apparatus that includes the element.
[0126] The various embodiments in this specification are described in a progressive manner. Similar parts between the various embodiments can be referred to in conjunction with each other. Each embodiment focuses on the differences between the other embodiments. In particular, the system embodiments are generally similar to the method embodiments, so the description is relatively simple. For relevant parts, refer to the description of the method embodiments.
Claims
1. A method for entity recognition, characterized in that: include: Based on the description text of the first entity type, generate a plurality of first instructions corresponding to the first entity type; Sampling the first text to obtain a text sequence, and predicting the probability of words in the text sequence under each first instruction using a first model; Determining a second instruction applicable to the first text from the plurality of first instructions based on a probability of a word in the text sequence under each first instruction; Based on the second instruction and the first model, a first entity belonging to the first entity type in the first text is identified.
2. The method according to claim 1, characterized in that The text sequence includes n words, where n is a positive integer. The probability of the t-th word in the text sequence under each first instruction is determined as follows, 1≤t≤n: For each first instruction, predicting, by the first model, a conditional probability distribution of the next word following the t-1th word based on the first instruction and the first t-1th words; Determining, based on the conditional probability distribution, a probability that the next word is the t-th word; The probability is determined as the probability of the t-th word under the first instruction.
3. The method according to claim 1, characterized in that The determining, from the plurality of first instructions, a second instruction applicable to the first text based on the probability of a word in the text sequence under each first instruction, comprises: For each first instruction, determining a first mean corresponding to the text sequence based on a probability of each word in the text sequence under the first instruction and the number of words in the text sequence; and, determining a score for the first instruction based on the probability of each word under the first instruction and the first mean; A first instruction having a score greater than or equal to a score threshold is determined as a second instruction applicable to the first text.
4. The method according to claim 3, characterized in that The determining the score of the first instruction based on the probability of each word under the first instruction and the first mean value includes: Determining a first standard deviation corresponding to the text sequence based on the probability of each word under the first instruction and the first mean; A score for the first instruction is determined based on the first standard deviation.
5. The method according to claim 4, characterized in that There are multiple text sequences; and determining the score of the first instruction based on the first standard deviation includes: determining a second mean based on the first standard deviation and the number of the text sequences; A negative value of the second mean is determined as the score of the first instruction.
6. The method according to claim 1, characterized in that The step of identifying a first entity belonging to the first entity type in the first text based on the second instruction and the first model includes: Determining, from a second text corresponding to the first entity type, a third text similar to the first text, wherein the second text contains a second entity belonging to the first entity type; Combining the third text and the second entity in the third text to obtain a first context; A first entity belonging to the first entity type in the first text is identified through the first model based on the second instruction and the first context.
7. The method according to claim 6, characterized in that The number of the first contexts is multiple; The identifying, by the first model, a first entity belonging to the first entity type in the first text based on the second instruction and the first context includes: splicing the multiple first contexts in different orders to obtain multiple context combinations; For each context combination, performing entity recognition on the first text based on the second instruction and the context combination using the first model to obtain a third entity corresponding to the context combination; For each context combination, determining the number of occurrences of the third entity corresponding to the context combination in the multiple context combinations; A third entity whose occurrence number is greater than a threshold number is determined as a first entity belonging to the first entity type in the first text.
8. An entity recognition device, characterized in that: include: A generating module, configured to generate a plurality of first instructions corresponding to a first entity type based on a description text of the first entity type; A prediction module, configured to sample the first text to obtain a text sequence, and predict the probability of words in the text sequence under each first instruction using a first model; a determination module, configured to determine, from the plurality of first instructions, a second instruction applicable to the first text based on a probability of a word in the text sequence under each first instruction; An identification module is used to identify a first entity belonging to the first entity type in the first text based on the second instruction and the first model.
9. An electronic device, characterized in that: include: processor; a memory for storing instructions executable by the processor; The processor is configured to execute the instructions to implement the entity recognition method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that When the instructions in the storage medium are executed by a processor of an electronic device, the electronic device is enabled to perform the entity recognition method according to any one of claims 1 to 7.