Method, apparatus, medium, and device for entity recognition of text

CN121072522BActive Publication Date: 2026-08-11BEIJING DONGCHEZU TECHNOLOGY CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-05-27
Publication Date
2026-08-11

AI Technical Summary

Technical Problem

原始的车史信息,存在数据来源多样、结构不统一、人工书写不规范、描述和耗材记录混杂等问题,致使车史信息解析(即,将原始文本变为结构化信息存储的过程)变得异常困难

Benefits of technology

[0016]根据第四方面,提供了一种计算机可读存储介质,其上存储有计算机程序,当上述计算机程序在计算机中执行时,令上述计算机执行第一方面或者第二方面中任一项上述的方法。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121072522B_ABST
    Figure CN121072522B_ABST
Patent Text Reader

Abstract

This disclosure provides a method, apparatus, medium, and device for entity recognition of text. One specific implementation of the method includes: acquiring a pre-trained entity recognition model for recognizing entities, wherein the training data used in the training process of the entity recognition model is based on a language model; obtaining entity pairs corresponding to the text to be recognized based on the entity recognition model; and converting the entity pairs corresponding to the text to be recognized into standard representation entity pairs.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of information processing technology, and in particular to a method, apparatus, medium, and device for entity recognition of text. Background Technology

[0002] Currently, information comes from diverse sources, but raw information often suffers from inconsistent structure and non-standard manual writing. Take vehicle history records as an example: these records document a vehicle's maintenance and repair history, essentially its "archive." Raw vehicle history information suffers from diverse data sources, inconsistent structure, non-standard manual writing, and a mixture of descriptions and consumable records, making the parsing of vehicle history information (i.e., the process of transforming raw text into structured information storage) extremely difficult. Therefore, how to automate the parsing of information is a problem that urgently needs to be solved. Summary of the Invention

[0003] The embodiments of this disclosure describe a method and apparatus for entity recognition in text. The entity recognition process uses an entity recognition model. The training data used in the training process of the entity recognition model is obtained based on a language model. The language model provides efficient and high-quality training data support for the information extraction training of the entity recognition model, so that the trained entity recognition model can be used to extract entity pairs in text, thereby realizing the extraction of relationships between entities and completing the automated parsing of text.

[0004] According to a first aspect, a method for entity recognition of text is provided, comprising: acquiring a pre-trained entity recognition model for recognizing entities, wherein the training data used in the training process of the entity recognition model is obtained based on a language model; obtaining entity pairs corresponding to the text to be recognized based on the entity recognition model; and converting the entity pairs corresponding to the text to be recognized into standard representation entity pairs.

[0005] In one embodiment, the entity recognition model is trained through the following steps: generating sample entity pairs for the sample text based on sample text, preset prompts, and a language model; determining the position information of each entity in the sample entity pair within the sample text to obtain sample entity pair information, wherein the sample entity pair information includes a first entity and a second entity, as well as the position information of the first entity and the second entity within the sample text; constructing training data for training the entity recognition model based on the sample text and its corresponding sample entity pair information, wherein the training data includes the sample text and its corresponding sample entity pair information; and training the entity recognition model based on the training data.

[0006] In one embodiment, training the entity recognition model based on the training data includes: inputting sample text and part-of-speech tagging information from the training data into the entity recognition model to obtain predicted entity pairs; determining the difference loss between the predicted entity pairs corresponding to the sample text and the sample entity pairs; and adjusting the parameters of the entity recognition model with the goal of minimizing the difference loss. Therefore, part-of-speech tagging information can be incorporated into the prediction process of the entity recognition model, thereby making the entity recognition model more accurate.

[0007] In one embodiment, generating sample entity pairs for the sample text based on the sample text, a preset prompt, and a language model includes: inputting the sample text and a preset first prompt into the language model to generate sample entity pairs for the sample text, wherein the first prompt is used to instruct the language model to extract entity pairs from the sample text. Thus, sample entity pairs can be generated based on the sample text, the first prompt, and the language model.

[0008] In one embodiment, generating sample entity pairs for the sample text based on the sample text, a preset prompt, and a language model includes: recognizing the sample text using a current entity recognition model to obtain preliminary entity recognition results, wherein the preliminary entity recognition results include entity pairs; calculating the similarity between the sample text and target text in a preset target dataset, wherein the target data in the target dataset includes target text and target entity pairs corresponding to the target text; selecting at least one target data from the target dataset as a learning example based on the similarity; and inputting the sample text, the preliminary entity recognition results, the learning example, and a preset second prompt into the language model to generate sample entity pairs, wherein the second prompt is used to prompt the language model to generate sample entity pairs based on the sample text and the preliminary entity recognition results. Therefore, the language model can be used to correct and optimize the results recognized by the current entity recognition model, thereby making the generated sample entity pairs more accurate.

[0009] In one embodiment, calculating the similarity between the sample text and the target text in a preset target dataset includes: calculating a first similarity between the sample text and the target text based on the longest common prefix; calculating a second similarity between the sample text and the target text based on their vectors; and calculating the overall similarity between the sample text and the target text based on the first and second similarities. Therefore, a comprehensive similarity can be calculated by combining the two similarities, resulting in a more accurate similarity calculation.

[0010] In one embodiment, the entity recognition model is a Word-Pair NER model, which is used to identify a first entity, a second entity, and entity pairs consisting of the first entity and the second entity. Therefore, the Word-Pair NER model can be used as a model for entity recognition and dual-entity relation extraction.

[0011] In one embodiment, the above-mentioned conversion of the entity pair corresponding to the text to be identified into a standard representation entity pair includes: inputting the entity pair into a pre-trained text matching model to obtain the standard entity representation corresponding to the entity in the entity pair, wherein the text matching model is used to match the entity with the standard entity representation of a preset standard entity representation library; and mapping the entity pair into a standard representation entity pair according to the standard entity representation corresponding to the entity in the entity pair.

[0012] In one embodiment, the text matching model described above uses positive and negative samples during training, wherein positive samples include synonym pairs and positive sample identifiers, and negative samples include non-synonym pairs and negative sample identifiers.

[0013] In one embodiment, the positive and negative samples are generated as follows: A first word, a preset list of first words, and a preset third prompt are input into a language model to generate multiple second words that are synonyms of the first word. The third prompt is used to prompt the language model to generate multiple second words that are synonyms of the first word based on the first word and the first word list. Positive samples are generated based on the first word, the multiple second words, and a preset thesaurus. Negative samples are generated based on the first word, the multiple second words, and the preset list of second words, wherein the list of second words includes words that are not synonyms of the first word.

[0014] According to a second aspect, an entity recognition device for text is provided, comprising: an acquisition unit configured to acquire a pre-trained entity recognition model for recognizing entities, wherein the training data used in the training process of the entity recognition model is obtained based on a language model; a recognition unit configured to obtain entity pairs corresponding to the text to be recognized based on the entity recognition model; and a conversion unit configured to convert the entity pairs corresponding to the text to be recognized into standard representation entity pairs.

[0015] According to a third aspect, a computer program product is provided, comprising a computer program that, when executed by a processor, implements the method described in either the first or second aspect.

[0016] According to a fourth aspect, a computer-readable storage medium is provided, on which a computer program is stored, which, when executed in a computer, causes the computer to perform the method described in either the first or second aspect.

[0017] According to a fifth aspect, an electronic device is provided, including a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, it implements the method described in either the first or second aspect.

[0018] According to the entity recognition method and apparatus for text provided in this disclosure, firstly, a pre-trained entity recognition model for recognizing entities can be obtained. The training data used in the training process of this entity recognition model is based on a language model. Then, entity pairs corresponding to the text to be recognized can be obtained based on the entity recognition model. Finally, the entity pairs corresponding to the text to be recognized can be converted into standard representation entity pairs. Since the language model provides efficient and high-quality training data support for the information extraction training of the entity recognition model, the trained entity recognition model can be used to extract entity pairs from the text, thereby realizing the extraction of relationships between entities and completing the automated parsing of text. Attached Figure Description

[0019] Figure 1 A schematic diagram is shown illustrating one application scenario in which embodiments of this disclosure can be applied;

[0020] Figure 2 A flowchart illustrating a method for training an entity recognition model based on a language model according to one embodiment is shown.

[0021] Figure 3 An example diagram shows an example of inputting sample text and a first prompt into a language model and outputting sample entity pairs;

[0022] Figure 4 This diagram illustrates an example of inputting sample text, preliminary entity recognition results, learning examples, and a second prompt into a language model to output sample entity pairs.

[0023] Figure 5 This diagram illustrates an example of how the Word-Pair NER model processes text.

[0024] Figure 6 A schematic diagram illustrating an example of incorporating part-of-speech tagging information into the input layer is shown.

[0025] Figure 7 An entity recognition method for text is illustrated according to one embodiment;

[0026] Figure 8 A schematic diagram illustrating an example of synonym mining based on a language model is shown;

[0027] Figure 9 A schematic block diagram of an apparatus for training an entity recognition model based on a language model according to one embodiment is shown;

[0028] Figure 10 A schematic block diagram of an entity recognition device for text according to one embodiment is shown;

[0029] Figure 11 A schematic diagram of the structure of an electronic device suitable for implementing embodiments of this application is shown. Detailed Implementation

[0030] It is understood that before using the technical solutions disclosed in the various embodiments of this disclosure, users should be informed of the types, scope of use, and usage scenarios of the personal information involved in this disclosure in an appropriate manner in accordance with relevant laws and regulations, and user authorization should be obtained.

[0031] For example, upon receiving a user's active request, a prompt message is sent to the user to explicitly inform them that the requested operation will require the acquisition and use of the user's personal information. This allows the user to independently choose whether to provide personal information to the software or hardware, such as the electronic device, application, server, or storage medium performing the operations of this disclosed technical solution, based on the prompt message.

[0032] As an optional but non-limiting implementation, in response to a user's active request, sending a prompt message to the user can be done via a pop-up window, where the prompt message can be presented in text format. Furthermore, the pop-up window can also include a selection control allowing the user to choose "agree" or "disagree" to provide personal information to the electronic device.

[0033] It is understood that the above notification and user authorization process are merely illustrative and do not constitute a limitation on the implementation of this disclosure. Other methods that comply with relevant laws and regulations may also be applied to the implementation of this disclosure.

[0034] The technical solutions provided in this disclosure will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the relevant invention and not intended to limit the invention. Furthermore, it should be noted that, for ease of description, only the parts relevant to the invention are shown in the accompanying drawings. It should be noted that, unless otherwise specified, the embodiments and features described in these embodiments can be combined with each other.

[0035] As mentioned above, how to achieve automated information parsing is a problem that urgently needs to be solved. To this end, embodiments of this disclosure provide an entity recognition method for text. This method uses a pre-trained entity recognition model in the entity recognition process. The training data used in the training of this entity recognition model is based on a language model. The language model can provide efficient and high-quality data support for the training of information extraction of the entity recognition model, so that the trained entity recognition model can be used to extract entity pairs in the text, thereby realizing the extraction of relationships between entities and completing the automated parsing of text.

[0036] Figure 1 A schematic diagram illustrating an application scenario to which embodiments of this disclosure can be applied. Figure 1 In the application scenario shown, electronic device 10 can first generate training data for training entity recognition model 101 and train entity recognition model 101. Then, electronic device 20 can obtain entity recognition model 101 from electronic device 10 and use entity recognition model 101 to extract entity pairs from the text to be recognized, which represent the relationship between entities.

[0037] Specifically, the process by which electronic device 10 generates training data and trains entity recognition model 101 may include the following steps 1)-4):

[0038] Step 1) The staff who want to train the entity recognition model 101 can pre-design prompts. The electronic device 10 can call the language model interface to generate sample entity pairs for the sample text based on the sample text, prompts and language model. Here, the language model can be a generative language model.

[0039] Step 2) Determine the position information of each entity in the sample entity pair in the sample text to obtain the sample entity pair information. The sample entity pair information may include the first entity and the second entity, as well as the position information of the first entity and the second entity in the sample text.

[0040] Step 3) Based on the sample text and its corresponding sample entity pair information, construct training data for training entity recognition model 101. Each training data may include sample text and sample entity pair information corresponding to the sample text.

[0041] Step 4): Based on the training data, train the entity recognition model 101. Thus, the electronic device 101 completes the training of the entity recognition model 101.

[0042] Subsequently, electronic device 20 can acquire the trained entity recognition model 101 from electronic device 10, and input the text to be recognized into the entity recognition model to obtain entity pairs corresponding to the text. Each entity pair can include two entities, and only two entities with a certain relationship will be extracted by entity recognition model 101 as entity pairs. Therefore, the entity pairs extracted by entity recognition model 101 reflect the relationship between entities. Afterwards, the entity pairs extracted from the text to be recognized can be converted into standard entity pairs. That is, each entity in the entity pair is converted into a unified standard entity representation.

[0043] See also Figure 2 , Figure 2 A flowchart illustrating a method for training an entity recognition model based on a language model, according to one embodiment, is shown. This method can be executed by any device, apparatus, platform, or cluster of devices with computing and processing capabilities. Figure 2 As shown, the method for training an entity recognition model based on a language model may include the following steps 201-204, specifically:

[0044] Step 201: Generate sample entity pairs for the sample text based on the sample text, the preset prompts, and the language model.

[0045] In this embodiment, if the entity recognition model to be trained is used to extract entity relations from text in a target domain, then the sample text can be text from the target domain. For example, suppose we want to train an entity recognition model to extract entity relations from vehicle history information, then the sample text can be vehicle history information. Here, vehicle history information can refer to the historical records of vehicles. In this example, the language model can be a machine learning model capable of generating corresponding output text based on the text content input by the user. To improve the quality of the text generated by the language model, prompt engineering can also be used to guide the language model to generate high-quality, accurate, and targeted output text. Prompt engineering can guide the language model to produce better results that meet expectations by constructing more specialized input text. For example, prompts can be constructed to guide the language model to generate targeted output text. As an example, the prompt can be a pre-defined text. Thus, based on the sample text, the pre-constructed prompt, and the language model, sample entity pairs for the sample text can be generated.

[0046] In some implementations, step 201 above may specifically include the following: inputting the sample text and a preset first prompt into the language model to generate sample entity pairs for the sample text.

[0047] In this implementation, the aforementioned first prompt can be used to instruct the language model to extract entity pairs from the sample text. For example, suppose we want to train an entity recognition model to extract entity relationships from vehicle history information, and the sample text is vehicle history information. Then, the first prompt can be used to instruct the language model to extract entity pairs from the vehicle history information. As an example, the first prompt can specify the format, requirements, etc., of the entity pairs output by the language model.

[0048] like Figure 3 As shown, Figure 3 An example diagram is shown, illustrating an instance of inputting sample text and a first prompt into a language model to output sample entity pairs.

[0049] exist Figure 3 In the example shown, the sample text is a piece of vehicle history information, which reads: "Text: Left rear fender paint; right side bodywork; rear bumper disassembly and assembly; right front door trim replacement; right front door painting; right front door automatic bodywork; right rear door trim replacement; left rear fender metal plate; right side paint; right rear door metal plate; left rear taillight replacement; rear bumper paint; body low paint; paint polishing; right rear door paint."

[0050] The first prompt can be a piece of text, such as: "You will receive an unstructured text describing car repair and maintenance. Your task is relation extraction and entity recognition. The returned format should be entity pairs of 'Automotive Part: Operation or Defect'. Requirements: 1. Prioritize quality, conciseness, and interpretability. Return the most concise JSON array, where each element is in the format 'Automotive Part Name: Repair Operation or Defect Condition'. Both 'Automotive Part Name' and 'Repair Operation or Defect Condition' must appear in the original text. 2. The returned array should only list the repair inspection items from the original text. If no repair inspection items exist, return an empty array []. Entity pairs that do not exist in the original text must never be returned." This is understandable. Figure 3 The content of the first prompt in the system is merely illustrative and not a limitation on its content. In practice, various prompts can be set as needed.

[0051] Next, the vehicle history information and the first prompt can be concatenated and sent to the language model. The language model will then output JSON-type entity pairs, specifically including the following entity pairs: "Right front door: paint; Right front door: automatic bodywork; Right front door trim: replacement; Right rear door: metal panel; Right rear door: paint; Right rear door trim: replacement; Right side panel: paint; Right side panel: bodywork; Rear pole: disassembly and assembly; Rear bumper: paint; Left rear taillight: replacement; Left rear fender: paint; Paint: polishing; Body low: paint, etc." As can be seen from the entity pairs listed above, the entity pairs output by the language model are formed by "inspection items" and "defect items or operation items." In this example, "inspection items" are the names of automotive parts, including the right front door, right front door, right rear door trim, right side panel, etc. "Defect items" can be defects in the inspection items, such as dents, bends, etc. "Operation items" can be operations performed on the inspection items, such as painting, bodywork, polishing, etc.

[0052] Depend on Figure 3 As shown in the example, by concatenating the sample text and the first prompt and directly inputting them into the language model, sample entity pairs of the sample text can be generated.

[0053] In some other implementations, step 201 above may further include the following steps S1-S4, specifically:

[0054] Step S1: Use the current entity recognition model to recognize the sample text and obtain preliminary entity recognition results.

[0055] In practice, entity recognition models can be various neural network models, which typically require multiple rounds of training to complete. Here, the current entity recognition model can refer to an entity recognition model that has undergone several rounds of training but is not yet fully trained, and whose accuracy needs improvement. In this example, the current entity recognition model can be used to recognize sample text and obtain preliminary entity recognition results, which may include multiple entity pairs.

[0056] Step S2: Calculate the similarity between the sample text and the target text in the preset target dataset.

[0057] Here, the target dataset mentioned above can be a few-shot dataset, and the target data in the target dataset can include target text and the corresponding target entity pairs. The target data can be accurate results after manual verification. Then, various methods can be used to calculate the similarity between the sample text and the target text in the target dataset. For example, cosine similarity, Jaccard similarity, etc.

[0058] As an example, the similarity between the sample text and each target text can also be calculated using the following steps a)-c):

[0059] Step a) Calculate the first similarity between the sample text and the target text based on the longest common prefix.

[0060] Specifically, the first similarity sim LCP for,

[0061]

[0062] Here, s1 and s2 can represent two texts, LCP(s1, s2) can represent the length of the longest common substring of the two texts, and n1 = len(s1) and n2 = len(s2) can represent the minimum length of the two texts respectively.

[0063] Step b) Calculate the second similarity between the sample text and the target text based on their vectors.

[0064] For example, after vectorizing the two texts using SentenceTransformer, the cosine similarity can be calculated to obtain the second similarity score, sim. ST .

[0065] Step c), calculate the similarity between the sample text and the target text based on the first similarity and the second similarity.

[0066] For example, the similarity score (sim) can be calculated using the following formula. combined Specifically:

[0067] sim combined =α×sim LCP +(1-α)×sim ST ;

[0068] Here, α can represent the weighting parameter. This implementation combines two similarity metrics to calculate a comprehensive similarity score, resulting in a more accurate similarity calculation.

[0069] Step S3: Based on similarity, select at least one target data point from the target dataset as a learning example. For example, target data corresponding to target texts with a similarity higher than a preset threshold to the sample text can be selected as learning examples.

[0070] Step S4: Input the sample text, preliminary entity recognition results, learning examples, and preset second prompts into the language model to generate sample entity pairs.

[0071] In this implementation, the second prompt can be used to prompt the language model to generate sample entity pairs based on the sample text and preliminary entity recognition results. Here, the learning examples can guide the language model to learn how to process input information by providing a series of examples with the expected output.

[0072] like Figure 4 As shown, Figure 4 This diagram illustrates an example of inputting sample text, preliminary entity recognition results, learning examples, and a second prompt into a language model to output sample entity pairs. In this example, the entity recognition model extracts entity pairs from vehicle history information. The sample text is vehicle history information: "Replace right front door trim; Right front door repainting". After inputting this vehicle history information into the current entity recognition model, the model outputs preliminary entity recognition results, which may include multiple entity pairs such as "Right front door trim: Replace; Right front door: Repainting; Front door: Repainting; Right front door: Replace". Then, the similarity between the sample text and target text in a preset target dataset is calculated, and at least one target data point is selected from the target dataset as a learning example based on the similarity. In this example, for the sample text "text: Replace right front door trim; Right front door repainting", the resulting learning examples may include "text1 = Replace upper right front door trim, result1 = Right front door trim: Replace", and "text2 = Right front door repainted once, result2 = Right front door: Repainting".

[0073] In this example, the second prompt could be: "You will receive an unstructured text describing a car repair or maintenance procedure, along with the entity pairs I extracted from this sentence. Your task is to correct my relation extraction and entity recognition results. The returned format should be entity pairs of 'Automotive Parts: Operation or Defect'. You should first try to extract all automotive parts entities, then extract all operations or defects, and then correctly assemble them into entity pairs and return them to me. Requirements: 1. Prioritize quality, conciseness, and interpretability. Return the most concise JSON array, with each element in the format 'Automotive Part Name: Repair Operation or Defect Status'. Both 'Automotive Part Name' and 'Repair Operation or Defect Status' must appear in the original text. 2. The returned array should only list the repair inspection items in the original text. If no repair inspection items exist, please return an empty array []. Entity pairs that do not exist in the original text must never be returned."

[0074] Next, the sample text, preliminary entity recognition results, learning examples, and second prompts are input into the language model, which then outputs sample entity pairs. In this example, the sample entity pairs are "Right front door trim: Replace" and "Right front door: Paint".

[0075] Depend on Figure 4As the example shown illustrates, a language model can be used to correct and optimize the results identified by the current entity recognition model, thereby making the generated sample entity pairs more accurate.

[0076] Step 202: Determine the position information of each entity in the sample entity pair in the sample text to obtain the sample entity pair information.

[0077] In this embodiment, the positional information of each entity in the sample entity pair within the sample text can be obtained through various methods. For example, a recursive search can be used to obtain the positional information of each entity in the sample entity pair within the sample text. Another example is the use of depth-first search (DFS) to obtain the positional information of each entity in the sample entity pair within the sample text. Thus, sample entity pair information is obtained, which may include a first entity and a second entity, as well as the positional information of the first entity and the second entity within the sample text.

[0078] Step 203: Based on the sample text and its corresponding sample entity pair information, construct training data for training the entity recognition model.

[0079] In this embodiment, the training data can be composed of sample text and its corresponding sample entity pairs. That is, each training data may include sample text and its corresponding sample entity pairs. It is understood that the entity recognition model in this embodiment can be various forms of neural network models, such as convolutional neural networks, recurrent neural networks, long short-term memory networks, etc.

[0080] As an example, an entity recognition model can also be a Word-Pair NER model, which can be used to identify a first entity, a second entity, and entity pairs consisting of the first and second entities. Figure 5 As shown, Figure 5 This diagram illustrates an example of text processing using the Word-Pair NER model. Figure 5 In the example shown, the Word-Pair NER model can include an Encoder Layer, a Convolution Layer, and a Co-Predictor Layer. The Co-Predictor Layer can include a Biaffine Predictor and an MLP Predictor (Multilayer Perceptron). This is understandable. Figure 5The Word-Pair NER model shown is a well-known existing model, and the contents of each part are shown in the figure, which will not be described in detail here.

[0081] Step 204: Train the entity recognition model based on the training data.

[0082] In this embodiment, an entity recognition model can be trained based on the training data constructed in step 203. For example, sample text from the training data can be input into the model to be trained, and the model can extract entity pair information from the sample text to obtain predicted entity pair information. As an example, the predicted entity pair information may include the predicted entity pairs and the position information of each entity in the predicted entity pair in the sample text. Then, the difference loss between the predicted entity pair information and the sample entity pair information in the training data is calculated, and the model parameters of the model to be trained are adjusted with the goal of minimizing this difference loss. Finally, the trained entity recognition model is obtained.

[0083] Research has revealed that entities within entity pairs exhibit distinct part-of-speech (POS) features. For instance, in vehicle history information, entity pairs consist of "detection items" and "defect items or operation items," where detection items are nouns, defect items are adjectives or adverbs of state, operation items are verbs, and terms like "left," "right," "front," and "back" are locative words. Therefore, adding POS embedding information to the input layer of an entity recognition model can effectively improve its recognition accuracy.

[0084] For example, such as Figure 6 As shown, Figure 6 This diagram illustrates an example of incorporating part-of-speech tagging (POS) embedding information into the input layer. Figure 6 In the example shown, the sample text is "repair the left rear door; replace the front bumper". The input layer can include word embedding information for each token, paragraph embedding information for each token, position embedding information for each token, and part-of-speech (POS) embedding information. In the POS embedding information, different symbols represent different POS categories. For example, 'm' can represent a numeral, 'f' can represent a locative word, 'n' can represent a noun, 'v' can represent a verb, 'x' can represent a non-morpheme, and so on. In addition, the input layer also includes two special markers: [CLS] and [SEP]. [CLS] is an abbreviation for "classification," which in text classification tasks typically represents the beginning of a sentence or document. [SEP] is an abbreviation for "separator," which typically represents the end of a sentence or document and can be used to separate different sentences.

[0085] Based on this, in some implementations, step 204 can be specifically performed as follows: First, the sample text and its part-of-speech tagging information from the training data are input into the entity recognition model to obtain predicted entity pairs. Then, the difference loss between the predicted entity pairs corresponding to the sample text and the sample entity pairs is determined, and the model parameters of the entity recognition model are adjusted with the goal of minimizing this difference loss. Through this implementation, part-of-speech tagging information can be added during the prediction process of the entity recognition model, thereby making the entity recognition model more accurate.

[0086] The above describes the training process of the entity recognition model. The resulting entity recognition model can extract information from the input text and output entity pairs. These entity pairs can effectively reflect the relationships between entities. Thus, the entity recognition model can be used to extract relationships from text, enabling automated text parsing.

[0087] Next, please continue to see Figure 7 , Figure 7 An entity recognition method for text is illustrated according to one embodiment. This method can be performed by any device, apparatus, platform, or cluster of devices with computing and processing capabilities.

[0088] like Figure 7 As shown, the entity recognition method for text may include the following steps 701-703, specifically:

[0089] Step 701: Obtain the pre-trained entity recognition model for recognizing entities.

[0090] In this embodiment, it is possible to obtain Figure 2 The entity recognition model trained by the described method can extract information from the received text and output entity pairs in the text.

[0091] Step 702: Based on the text to be identified and the entity recognition model, obtain the entity pairs corresponding to the text to be identified.

[0092] In this embodiment, the text to be recognized can be input into the entity recognition model, and the entity recognition model can output the entity pairs corresponding to the text to be recognized.

[0093] Step 703: Convert the entity pairs corresponding to the text to be recognized into standard representation entity pairs.

[0094] In practice, the same item or operation may correspond to multiple descriptions. For example, taking vehicle history information as an example, a rear bumper may also be called a rear bumper, rear baffle, or the rear bumper, etc. Therefore, to standardize the descriptions, the entity pairs corresponding to the text to be recognized can be converted into standard description entity pairs. Specifically, this means converting each entity in an entity pair into a standard description entity. For example, a mapping table between standard and non-standard description entities can be pre-defined. By querying this table, each non-standard description entity can be converted into a standard description entity.

[0095] In some implementations, step 703 above may also include steps (1) and (2), specifically:

[0096] Step (1) inputs the entity pairs corresponding to the text to be identified into the pre-trained text matching model to obtain the standard entity representations corresponding to the entities in the entity pairs.

[0097] In this example, the text matching model can be used to match entities with standard entity representations in a pre-defined standard entity representation library. Specifically, the text matching model can identify whether two entities with different representations are synonyms; if they are synonyms, they can be converted to each other. For instance, the text matching model can match entity X with standard entity representations in the standard entity representation library, determining that entity X and standard entity representation X1 are synonyms, thus confirming that entity X and standard entity representation X1 can be converted to each other.

[0098] Here, the text matching model described above uses positive and negative samples during training. Positive samples can include synonym pairs and positive sample identifiers, while negative samples can include non-synonymous pairs and negative sample identifiers. As an example, positive and negative samples can be manually set samples.

[0099] Optionally, positive and negative samples can be generated through the following steps A)-C), specifically:

[0100] Step A) involves inputting the first word, a preset first word vocabulary, and a preset third prompt into the language model to generate multiple second words that are synonyms of the first word. Here, the third prompt can be used to prompt the language model to generate multiple second words that are synonyms of the first word based on the first word and the first word vocabulary.

[0101] Step B) Generate positive samples based on the first word, multiple second words, and a preset thesaurus.

[0102] Step C) Based on the first word, multiple second words, and a preset list of second words, generate negative samples. Here, the list of second words includes words that are not synonyms of the first word.

[0103] like Figure 8 As shown, Figure 8 This diagram illustrates an example of synonym mining based on a language model. Figure 8 In the example shown, taking vehicle parts as an example, the first word input to the language model can include ["front bumper", "left front door", "driver's side airbag", "accelerator pedal", "catalytic converter", "car battery"], etc. The first word list can be a list of names containing multiple vehicle parts, not shown in the figure. As an example, the third prompt can be a pre-defined text. In this example, the third prompt could be: "You are a very knowledgeable vehicle parts repairman who needs to complete a synonym expansion task. I will give you a list of vehicle parts names; please return a JSON-type thesaurus dictionary. The list of vehicle parts names is as follows:"

[0104] Based on the first word, the list of first words, and the third prompt, the language model can output multiple second words that are synonyms of each first word. In this example, the output is {"front bumper": ["front mudguard", "front bumper cover", "front bumper plate"], "left front door": ["driver's side door", "driver's side door", "driver's door"], "driver's side airbag": ["driver's seat airbag", "driver's side airbag", "driver's airbag"], "accelerator pedal": ["accelerator pedal", "accelerator plate", "accelerator pedal"], "three-way catalytic converter": ["catalytic converter", "car purifier", "exhaust gas processor"], "car battery": ["vehicle battery", "car battery", "car battery"]}. From the above output, it can be seen that the multiple second words synonymous with the first word "front bumper" include "front mudguard", "front bumper cover", and "front bumper plate".

[0105] Then, positive samples can be generated based on the first word, multiple second words, and a pre-defined thesaurus. For example, assuming the thesaurus includes front bumper, front fender, front bumper plate, front bumper, etc., a positive sample (Positive Pair) can be generated: [CLS]front bumper [SEP]front bumper plate [SEP], score = 1, where score = 1 indicates a positive sample identifier.

[0106] Then, negative samples can be generated based on the first word, multiple second words, and a preset list of second words. Here, the list of second words can include words that are not synonyms of the first word. In this example, the list of second words can be a parts vocabulary, which can include the names of multiple parts. In this example, the parts list can include front bumper, front fuse, front fender, front steering gear, front tire, etc. Through calculation, parts with high similarity to the first word can be selected from the parts vocabulary to form negative samples. For example, a negative sample (NegativePair) can be formed: [CLS]front bumper [SEP]front fuse [SEP], score = -1, where score = -1 represents the negative sample identifier.

[0107] After obtaining positive and negative samples, the text matching model can be trained using the following loss function:

[0108]

[0109] Where N can represent the number of samples; w i and w j It can represent entities in the sample; E(w) i ) and E(w j ) can represent w i and w j The word embeddings represent the similarity between them as follows:

[0110]

[0111] If w i With w j If they are synonym pairs, then the tag is y. ij =1;

[0112] If w i With w j If the words are not synonyms but have a high degree of similarity, then the label is y. ij =-1.

[0113] Step (2): Based on the standard entity representations of the entities in the entity pairs corresponding to the text to be identified, map the entity pairs to standard representation entity pairs.

[0114] In retrospect, in the above embodiments of this disclosure, entity pairs in the text to be identified were extracted through an entity recognition model, thereby realizing the extraction of relationships between entities and completing the automated parsing of the text.

[0115] According to another embodiment, an apparatus for training an entity recognition model based on a language model is provided. The above-described apparatus for training an entity recognition model based on a language model can be deployed on any device, equipment, platform, device cluster, etc., with computing and processing capabilities.

[0116] Figure 9 A schematic block diagram of an apparatus for training an entity recognition model based on a language model according to one embodiment is shown. Figure 9 The device shown is used to perform Figure 2 The method shown. (As illustrated) Figure 9 As shown, the apparatus 900 for training an entity recognition model based on a language model includes: a generation unit 901 configured to generate sample entity pairs for the sample text based on sample text, preset prompts, and a language model; a determination unit 902 configured to determine the position information of each entity in the sample entity pair in the sample text to obtain sample entity pair information, wherein the sample entity pair information includes a first entity and a second entity, and the position information of the first entity and the second entity in the sample text; a construction unit 903 configured to construct training data for training the entity recognition model based on the sample text and its corresponding sample entity pair information, wherein the training data includes the sample text and its corresponding sample entity pair information; and a training unit 904 configured to train the entity recognition model based on the training data.

[0117] In some optional implementations of this embodiment, the training unit 904 is further configured to: input the sample text and part-of-speech tagging information of the sample text in the above training data into the above entity recognition model to obtain predicted entity pair information; determine the difference loss between the predicted entity pair information corresponding to the sample text and the sample entity pair information; and adjust the parameters of the above entity recognition model with the goal of minimizing the difference loss.

[0118] In some optional implementations of this embodiment, the generation unit 901 is further configured to: input the sample text and a preset first prompt into the language model to generate sample entity pairs for the sample text, wherein the first prompt is used to prompt the language model to extract entity pairs from the sample text.

[0119] In some optional implementations of this embodiment, the generation unit 901 is further configured to: use the current entity recognition model to recognize the sample text to obtain preliminary entity recognition results, wherein the preliminary entity recognition results include entity pairs; calculate the similarity between the sample text and the target text of the target data in the preset target dataset, wherein the target data in the target dataset includes the target text and the target entity pairs corresponding to the target text; select at least one target data from the target dataset as a learning example based on the similarity; input the sample text, the preliminary entity recognition results, the learning example, and the preset second prompt into the language model to generate sample entity pairs, wherein the second prompt is used to prompt the language model to generate sample entity pairs based on the sample text and the preliminary entity recognition results.

[0120] In some optional implementations of this embodiment, the calculation of the similarity between the sample text and the target text in the preset target dataset includes: calculating a first similarity between the sample text and the target text based on the longest common prefix; calculating a second similarity between the sample text and the target text based on the vectors of the sample text and the target text; and calculating the similarity between the sample text and the target text based on the first and second similarities.

[0121] In some optional implementations of this embodiment, the entity recognition model is a Word-Pair NER model, which is used to identify a first entity, a second entity, and an entity pair consisting of the first entity and the second entity.

[0122] According to another embodiment, an entity recognition device for text is provided. The aforementioned entity recognition device for text can be deployed in any device, equipment, platform, device cluster, etc., with computing and processing capabilities.

[0123] Figure 10 A schematic block diagram of an entity recognition device for text according to one embodiment is shown. Figure 10 The device shown is used to perform Figure 7 The method shown. (As illustrated) Figure 10 As shown, the entity recognition device 1000 for text includes: an acquisition unit 1001 configured to acquire a pre-trained entity recognition model for recognizing entities, wherein the training data used in the training process of the entity recognition model is based on a language model; a recognition unit 1002 configured to obtain entity pairs corresponding to the text to be recognized based on the entity recognition model; and a conversion unit 1003 configured to convert the entity pairs corresponding to the text to be recognized into standard representation entity pairs.

[0124] In some optional implementations of this embodiment, the conversion unit 1003 is further configured to: input the above entity pair into a pre-trained text matching model to obtain the standard entity representation corresponding to the entity in the above entity pair, wherein the above text matching model is used to match the entity with the standard entity representation of the preset standard entity representation library; and map the above entity pair to a standard representation entity pair according to the standard entity representation corresponding to the entity in the above entity pair.

[0125] In some optional implementations of this embodiment, the text matching model uses positive and negative samples during training. Positive samples include synonym pairs and positive sample identifiers, while negative samples include non-synonym pairs and negative sample identifiers.

[0126] In some optional implementations of this embodiment, the positive and negative samples are generated as follows: A first word, a preset list of first words, and a preset third prompt are input into a language model to generate multiple second words synonymous with the first word. The third prompt is used to prompt the language model to generate multiple second words synonymous with the first word based on the first word and the first word list. Positive samples are generated based on the first word, the multiple second words, and a preset thesaurus. Negative samples are generated based on the first word, the multiple second words, and a preset list of second words, wherein the list of second words includes words that are not synonyms of the first word.

[0127] The above-described apparatus embodiments correspond to the method embodiments, and detailed descriptions can be found in the description of the method embodiments section, which will not be repeated here. The apparatus embodiments are derived based on the corresponding method embodiments and have the same technical effects as the corresponding method embodiments; detailed descriptions can be found in the corresponding method embodiments.

[0128] According to another embodiment, a computer-readable storage medium is also provided, on which a computer program is stored, which, when executed in a computer, causes the computer to perform... Figure 2 or Figure 7 The method described.

[0129] According to another embodiment, an electronic device is also provided, including a memory and a processor, characterized in that the memory stores executable code, and when the processor executes the executable code, it implements... Figure 2 or Figure 7 The method described.

[0130] The foregoing description describes specific embodiments of this disclosure; other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims may be performed in a different order than those shown in the embodiments, and the desired result may still be achieved. Furthermore, the processes depicted in the drawings do not necessarily need to follow the specific or sequential order shown to achieve the desired result. In some embodiments, multitasking and parallel processing are possible or may be advantageous.

[0131] The following is for reference. Figure 11 It shows a schematic diagram of the structure of an electronic device 1100 suitable for implementing the embodiments of this application. Figure 11 The electronic device shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of this application.

[0132] like Figure 11 As shown, electronic device 1100 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 1101, which can perform various appropriate actions and processes according to a program stored in read-only memory (ROM) 1102 or a program loaded from storage device 1108 into random access memory (RAM) 1103. RAM 1103 also stores various programs and data required for the operation of electronic device 1100. Processing device 1101, ROM 1102, and RAM 1103 are interconnected via bus 1104. Input / output (I / O) interface 1105 is also connected to bus 1104.

[0133] Typically, the following devices can be connected to I / O interface 1105: input devices 1106 including, for example, touchscreens, touchpads, keyboards, mice, etc.; output devices 1107 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 1108 including, for example, magnetic tapes, hard disks, etc.; and communication devices 1109. Communication device 1109 allows electronic device 1100 to communicate wirelessly or wiredly with other devices to exchange data. Although Figure 11 An electronic device 1100 with various devices is shown; however, it should be understood that it is not required to implement or possess all of the devices shown. More or fewer devices may be implemented or possessed alternatively. Figure 11 Each box shown can represent a device or multiple devices as needed.

[0134] Specifically, according to embodiments of this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication device 1109, or installed from storage device 1108, or installed from ROM 1102. When the computer program is executed by processing device 1101, it performs the functions defined in the methods of embodiments of this application.

[0135] This disclosure also provides a computer-readable storage medium having a computer program stored thereon, which, when executed in a computer, causes the computer to perform the methods provided in this disclosure.

[0136] It should be noted that the computer-readable medium described in the embodiments of this disclosure can be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In the embodiments of this disclosure, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In the embodiments of this disclosure, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium may be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wires, optical fibers, RF (Radio Frequency), etc., or any suitable combination thereof.

[0137] The aforementioned computer-readable medium may be included in the aforementioned electronic device; or it may exist independently and not assembled into the electronic device. The aforementioned computer-readable medium carries one or more programs that, when executed by the electronic device, cause the electronic device to: acquire a pre-trained entity recognition model for recognizing entities, wherein the training data used in the training process of the entity recognition model is based on a language model; obtain entity pairs corresponding to the text to be recognized based on the entity recognition model; and convert the entity pairs corresponding to the text to be recognized into standard representation entity pairs.

[0138] Computer program code for performing the operations of embodiments of this disclosure can be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, and C++, and conventional procedural programming languages ​​such as the "C" language or similar programming languages. The program code can be executed entirely on a user's computer, partially on a user's computer, as a standalone software package, partially on a user's computer and partially on a remote computer, or entirely on a remote computer or electronic device. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0139] The various embodiments in this disclosure are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the embodiments for storage media and computing devices are basically similar to the method embodiments, so they are described more simply; relevant parts can be referred to the descriptions of the method embodiments.

[0140] Those skilled in the art will recognize that the functions described in the embodiments of the present invention in one or more of the above examples can be implemented using hardware, software, firmware, or any combination thereof. When implemented in software, these functions can be stored in a computer-readable medium or transmitted as one or more instructions or code on a computer-readable medium.

[0141] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above descriptions are merely specific embodiments of the present invention and are not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, or improvements made based on the technical solutions of the present invention should be included within the scope of protection of the present invention.

Claims

1. A method for entity recognition in text, comprising: Obtain a pre-trained entity recognition model for recognizing entities, wherein the entity recognition model is trained through the following steps: Based on sample text, preset prompts, and a language model, sample entity pairs are generated for the sample text; the positional information of each entity in the sample entity pair in the sample text is determined to obtain sample entity pair information, wherein the sample entity pair information includes a first entity and a second entity, as well as the positional information of the first entity and the second entity in the sample text; based on the sample text and its corresponding sample entity pair information, training data for training an entity recognition model is constructed, wherein the training data includes the sample text and its corresponding sample entity pair information; based on the training data, the entity recognition model is trained. The step of generating sample entity pairs for the sample text based on the sample text, a preset prompt, and a language model includes: recognizing the sample text using the current entity recognition model to obtain preliminary entity recognition results, wherein the preliminary entity recognition results include entity pairs; calculating the similarity between the sample text and target text in a preset target dataset, wherein the target data in the target dataset includes target text and target entity pairs corresponding to the target text; selecting at least one target data from the target dataset as a learning example based on the similarity; and inputting the sample text, the preliminary entity recognition results, the learning example, and a preset second prompt into the language model to generate sample entity pairs, wherein the second prompt is used to prompt the language model to generate sample entity pairs based on the sample text and the preliminary entity recognition results. The step of calculating the similarity between the sample text and the target text in the preset target dataset includes: calculating a first similarity between the sample text and the target text based on the longest common prefix; calculating a second similarity between the sample text and the target text based on their vectors; and calculating the overall similarity between the sample text and the target text based on the first and second similarities. Based on the text to be identified and the entity recognition model, the entity pairs corresponding to the text to be identified are obtained; The entity pairs corresponding to the text to be identified are converted into standard representation entity pairs.

2. The method according to claim 1, wherein, The step of training the entity recognition model based on the training data includes: The sample text and part-of-speech tagging information of the sample text in the training data are input into the entity recognition model to obtain predicted entity pair information; The difference loss between the predicted entity pair information corresponding to the sample text and the sample entity pair information is determined, and the parameters of the entity recognition model are adjusted with the goal of minimizing the difference loss.

3. The method according to claim 1, wherein, The process of generating sample entity pairs for the sample text based on the sample text, preset prompts, and a language model includes: The sample text and a preset first prompt are input into the language model to generate sample entity pairs for the sample text, wherein the first prompt is used to prompt the language model to extract entity pairs from the sample text.

4. The method according to claim 1, wherein, The entity recognition model is a Word-Pair NER model, which is used to identify a first entity, a second entity, and an entity pair consisting of the first entity and the second entity.

5. The method according to claim 1, wherein, The step of converting the entity pairs corresponding to the text to be identified into standard representation entity pairs includes: The entity pair is input into a pre-trained text matching model to obtain the standard entity representation corresponding to the entity in the entity pair. The text matching model is used to match the entity with the standard entity representation of the preset standard entity representation library. Based on the standard entity representations corresponding to the entities in the entity pair, the entity pair is mapped to a standard representation entity pair.

6. The method according to claim 5, wherein, The text matching model uses positive and negative samples during training. Positive samples include synonym pairs and positive sample identifiers, while negative samples include non-synonym pairs and negative sample identifiers.

7. The method according to claim 6, wherein, The positive and negative samples were generated in the following way: Input the first word, a preset list of first words, and a preset third prompt into the language model to generate multiple second words that are synonyms with the first word. The third prompt is used to prompt the language model to generate multiple second words that are synonyms with the first word based on the first word and the first word list. Based on the first word, the multiple second words, and a preset thesaurus, positive samples are generated; Based on the first word, the plurality of second words, and a preset list of second words, negative samples are generated, wherein the list of second words includes words that are not synonyms of the first word.

8. An entity recognition device for text, comprising: The acquisition unit is configured to acquire a pre-trained entity recognition model for recognizing entities, wherein the entity recognition model is trained through the following steps: Based on sample text, preset prompts, and a language model, sample entity pairs are generated for the sample text; the positional information of each entity in the sample entity pair in the sample text is determined to obtain sample entity pair information, wherein the sample entity pair information includes a first entity and a second entity, as well as the positional information of the first entity and the second entity in the sample text; based on the sample text and its corresponding sample entity pair information, training data for training an entity recognition model is constructed, wherein the training data includes the sample text and its corresponding sample entity pair information; based on the training data, the entity recognition model is trained. The step of generating sample entity pairs for the sample text based on the sample text, a preset prompt, and a language model includes: recognizing the sample text using the current entity recognition model to obtain preliminary entity recognition results, wherein the preliminary entity recognition results include entity pairs; calculating the similarity between the sample text and target text in a preset target dataset, wherein the target data in the target dataset includes target text and target entity pairs corresponding to the target text; selecting at least one target data from the target dataset as a learning example based on the similarity; and inputting the sample text, the preliminary entity recognition results, the learning example, and a preset second prompt into the language model to generate sample entity pairs, wherein the second prompt is used to prompt the language model to generate sample entity pairs based on the sample text and the preliminary entity recognition results. The step of calculating the similarity between the sample text and the target text in the preset target dataset includes: calculating a first similarity between the sample text and the target text based on the longest common prefix; calculating a second similarity between the sample text and the target text based on their vectors; and calculating the overall similarity between the sample text and the target text based on the first and second similarities. The recognition unit is configured to obtain entity pairs corresponding to the text to be recognized based on the text to be recognized and the entity recognition model. The conversion unit is configured to convert the entity pairs corresponding to the text to be recognized into standard representation entity pairs.

9. A computer-readable storage medium having a computer program stored thereon, which, when executed in a computer, causes the computer to perform the method of any one of claims 1-7.

10. An electronic device comprising a memory and a processor, wherein the memory stores executable code, and the processor, when executing the executable code, implements the method of any one of claims 1-7.

Citation Information

Patent Citations

  • Model training method and device, information processing method and device, electronic equipment and medium

    CN114417974A

  • OA system entity object identification and standardization method

    CN116227490A