Entity recognition model training method, entity recognition method, device and equipment
By constructing an entity recognition instruction template including entity type annotation, explanation annotation, thought chain prompts and prediction fields, generating a training instruction set and adjusting model parameters, the problem of poor generalization ability of the existing model is solved and the recognition of the entity recognition model is improved. Accuracy and generalization ability.
Patent Information
- Application Number
- CN202410871875.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-01
- Publication Date
- 2024-10-18
AI Technical Summary
Existing large models have poor generalization capabilities in entity recognition tasks and need to be re-fine-tuned to adapt to different entity recognition tasks, resulting in limited model applications.
By constructing an optimized entity recognition instruction template, including entity type annotation field, entity type explanation annotation field, thought chain prompt field and prediction field, a training instruction set is generated, and the model parameters are adjusted according to the prediction results to improve the model's generalization ability and Recognition accuracy.
It improves the entity recognition model's ability to understand different entity types and dismantle entity recognition tasks, significantly improving recognition accuracy and generalization capabilities.
Smart Images

Figure CN118798197A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of model training technology, and in particular to a training method for an entity recognition model, an entity recognition method, a training device for an entity recognition model, an electronic device, and a computer-readable storage medium. Background Art
[0002] Entity recognition (NER) refers to identifying pre-defined entity types (such as names of people, organizations, places, etc.) in a text. Entity recognition is an important part of information extraction and a very important and basic problem in natural language processing.
[0003] In the prior art, entity recognition tasks can be implemented through various natural language processing models (e.g., large models). However, the existing large models have poor generalization capabilities when facing different entity recognition tasks. Therefore, for different entity recognition tasks, it may be necessary to re-fine-tune the training to improve the generalization ability of the model, so as to meet the diverse entity recognition task requirements. Summary of the invention
[0004] The present application provides an entity recognition model training method, an entity recognition method, an entity recognition model training device, an electronic device and a computer-readable storage medium. A training instruction set is constructed by optimizing an entity recognition instruction template, thereby improving the training effect of the entity recognition model and obtaining an entity recognition model with higher accuracy and generalization.
[0005] In a first aspect, the present application provides a training method for an entity recognition model, which includes: constructing a training instruction set based on a preset entity recognition instruction template, wherein the entity recognition instruction template includes at least an entity type annotation field, an entity type explanation annotation field, a thinking chain prompt field and a prediction field, and the training instruction set includes multiple training instructions, and the output order corresponding to the prediction fields of at least some of the training instructions is different; inputting the training instruction set into the entity recognition model to be trained to obtain an entity recognition prediction result; adjusting the model parameters of the entity recognition model to be trained according to the entity recognition prediction result to obtain a trained entity recognition model.
[0006] In a second aspect, the present application provides an entity recognition method, which includes: inputting text data to be recognized into an entity recognition model to obtain an entity recognition result corresponding to the text data to be recognized; wherein the entity recognition model is obtained using the above-mentioned entity recognition model training method.
[0007] In a third aspect, the present application provides a training device for an entity recognition model, which includes: a construction module, which is used to construct a training instruction set according to a preset entity recognition instruction template, wherein the entity recognition instruction template includes at least an entity type annotation field, an entity type explanation annotation field, a thinking chain prompt field and a prediction field, and the training instruction set includes multiple training instructions, and the output order corresponding to the prediction fields of at least some of the training instructions is different; a prediction module, which is used to input the training instruction set into the entity recognition model to be trained to obtain an entity recognition prediction result; an adjustment module, which is used to adjust the model parameters of the entity recognition model to be trained according to the entity recognition prediction result to obtain a trained entity recognition model.
[0008] In a fourth aspect, the present application provides an electronic device, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores one or more computer programs executable by the at least one processor, and one or more of the computer programs are executed by the at least one processor so that the at least one processor can execute the above-mentioned entity recognition model training method or entity recognition method.
[0009] In a fifth aspect, the present application provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor / processing core, implements the above-mentioned entity recognition model training method or entity recognition method.
[0010] The embodiment provided by the present application, first, constructs a training instruction set according to a preset entity recognition instruction template, wherein the entity recognition instruction template at least includes an entity type annotation field, an entity type explanation annotation field, a thinking chain prompt field and a prediction field, and the training instruction set includes multiple training instructions, and the output order corresponding to the prediction fields of at least some of the training instructions is different; secondly, inputs the training instruction set into the entity recognition model to be trained to obtain the entity recognition prediction result; finally, adjusts the model parameters of the entity recognition model to be trained according to the entity recognition prediction result to obtain a trained entity recognition model, on the one hand, by including the entity type annotation field and the entity type explanation annotation field in the entity recognition instruction template, the entity recognition model can be improved in terms of its understanding ability for different entity types when training the entity recognition model, on the other hand, by including the thinking chain prompt field and the prediction field in the entity recognition instruction template, and the output order corresponding to the prediction fields of at least some of the training instructions is different, when the entity recognition model is trained according to the training instruction set, not only the entity recognition ability of the model can be improved, but also the model's ability to decompose entity recognition tasks can be improved, effectively improving the recognition accuracy of the trained entity recognition model for different entity recognition tasks.
[0011] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present application, nor is it intended to limit the scope of the present application. Other features of the present application will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0012] The accompanying drawings are used to provide a further understanding of the present application and constitute a part of the specification. Together with the embodiments of the present application, they are used to explain the present application and do not constitute a limitation of the present application. The above and other features and advantages will become more apparent to those skilled in the art by describing detailed example embodiments with reference to the accompanying drawings. In the accompanying drawings:
[0013] Figure 1 A flowchart of a method for training an entity recognition model provided in an embodiment of the present application;
[0014] Figure 2 A schematic diagram of an entity recognition instruction template provided in an embodiment of the present application;
[0015] Figure 3 A flowchart of a method for training an entity recognition model provided in an embodiment of the present application;
[0016] Figure 4 A flowchart of an entity recognition method provided in an embodiment of the present application;
[0017] Figure 5 A block diagram of a training device for an entity recognition model provided in an embodiment of the present application;
[0018] Figure 6 A block diagram of an entity identification device provided in an embodiment of the present application;
[0019] Figure 7 A block diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0020] In order to enable those skilled in the art to better understand the technical solution of the present application, the exemplary embodiments of the present application are described below in conjunction with the accompanying drawings, including various details of the embodiments of the present application to facilitate understanding, which should be considered as merely exemplary. Therefore, those of ordinary skill in the art should recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the present application. Similarly, for the sake of clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0021] In the absence of conflict, the embodiments of the present application and the features therein may be combined with each other.
[0022] As used herein, the term "and / or" includes any and all combinations of one or more of the associated listed items.
[0023] The terms used herein are only used to describe specific embodiments and are not intended to limit the present application. As used herein, the singular forms "a" and "the" are also intended to include plural forms, unless the context clearly indicates otherwise. It will also be understood that when the terms "including" and / or "made of" are used in this specification, the presence of the features, wholes, steps, operations, elements and / or components is specified, but the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or groups thereof is not excluded. "Connected" or "connected" and similar words are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect.
[0024] Unless otherwise defined, all terms (including technical and scientific terms) used herein have the same meaning as commonly understood by those of ordinary skill in the art. It will also be understood that terms such as those defined in commonly used dictionaries should be interpreted as having a meaning consistent with their meaning in the context of the relevant art and this application, and will not be interpreted as having an idealized or overly formal meaning unless explicitly defined herein.
[0025] In the related art, when using entity recognition instructions to train an entity recognition model, the entity recognition instructions usually include system prompt information and user prompt information. Among them, the system prompt information is used to describe a general entity recognition task, and the user prompt information is used to describe a specific task scenario under the general entity recognition task. For example, the system prompt information may be "You are an expert in NER tasks and can accurately identify entities and entity types in the input content", and the user prompt information may be "Please extract the entity of the character type from the following content: Xiao Ming played badminton with his friends for an hour yesterday."
[0026] However, the entity recognition model trained based on the above entity recognition instructions has poor generalization ability when facing different entity recognition tasks. It cannot achieve a high entity recognition accuracy for different entity recognition tasks, which affects the application of the model in actual scenarios.
[0027] In view of this, the embodiments of the present application provide a training method for an entity recognition model, an entity recognition method, a training device for an entity recognition model, an electronic device and a computer-readable storage medium. A training instruction set is constructed through a preset entity recognition instruction template, so that the entity recognition model is trained based on the training instruction set. On the one hand, the entity recognition instruction template includes an entity type annotation field and an entity type explanation annotation field, so that when training the entity recognition model, the entity recognition model's ability to understand different entity types can be improved. On the other hand, the entity recognition instruction template includes a thinking chain prompt field and a prediction field, and the output order corresponding to the prediction fields of at least some of the training instructions is different. Therefore, when the entity recognition model is trained according to the training instruction set, not only the entity recognition ability of the model can be improved, but also the model's ability to decompose entity recognition tasks can be improved, effectively improving the recognition accuracy of the trained entity recognition model for different entity recognition tasks.
[0028] The training method or entity recognition method of the entity recognition model according to the embodiment of the present application can be performed by an electronic device such as a terminal device or a server, and the terminal device can be a user equipment (User Equipment, UE), a mobile device, a user terminal, a terminal, a cellular phone, a cordless phone, a personal digital assistant (Personal Digital Assistant, PDA), a handheld device, a computing device, a vehicle-mounted device, a wearable device, etc. The method can be implemented by a processor calling a computer-readable program instruction stored in a memory. The server can be an independent physical server, a server cluster composed of multiple servers, or a cloud server capable of cloud computing.
[0029] In a first aspect, an embodiment of the present application provides a method for training an entity recognition model.
[0030] Figure 1 A flowchart of a method for training an entity recognition model provided in an embodiment of the present application. Figure 1 , the method comprising:
[0031] Step S110: construct a training instruction set according to a preset entity recognition instruction template, wherein the entity recognition instruction template includes at least an entity type annotation field, an entity type explanation annotation field, a thought chain prompt field and a prediction field, and the training instruction set includes multiple training instructions, and the output order corresponding to the prediction fields of at least some of the training instructions is different.
[0032] The training instruction set includes multiple training instructions, and the entity recognition instruction template is a general instruction structure that the training instructions need to follow. By presetting the entity recognition instruction template, the training instruction set can be generated in a standardized and unified manner, and the entity recognition instruction template can be modified according to needs, thereby modifying the corresponding training instruction set in batches.
[0033] In some optional implementations, the entity recognition instruction template may include multiple fields, including at least an entity type annotation field, an entity type explanation annotation field, a thought chain prompt field, and a prediction field. Correspondingly, the training instruction generated based on the entity recognition instruction template also includes at least the corresponding entity type annotation field, entity type explanation annotation field, thought chain prompt field, and prediction field; in addition, the training instruction may also include an input data field, and the text data corresponding to the input data field is the data to be entity recognized.
[0034] Figure 2 A schematic diagram of an entity recognition instruction template provided in an embodiment of the present application. Figure 2 ,The entity recognition instruction template may include: an input data field, an entity type annotation field, an entity type explanation annotation field, a thinking chain prompt field and a prediction field.
[0035] Correspondingly, the training instructions generated according to the entity recognition instruction template also include: an input data field, an entity type annotation field, an entity type explanation annotation field, a thinking chain prompt field and a prediction field.
[0036] The field value corresponding to the input data field is the text data to be recognized as an entity. For example, the field value corresponding to the input data field may be: Xiao Ming plans to go to the park to fly a kite at 3 pm tomorrow.
[0037] Among them, the field value corresponding to the entity type annotation field is the entity type, which is the entity type to be extracted, which may include multiple types such as person entity, geographic location entity, organization entity, time entity, etc., and the embodiment of the present application does not limit this.
[0038] It should be noted that in the training instructions, the entity type annotation field is the real entity category of the entity to be identified in the input data, which can be determined by manual annotation, etc. For example, the field value corresponding to the entity type annotation field is: "person entity".
[0039] The field value corresponding to the entity type explanation annotation field is the explanation or description of the entity type, which is used to understand the entity type more accurately and deeply. In addition, by adding the entity type explanation field to the training instructions, the entity recognition model's ability to understand different entity types can be enhanced, and the differences and boundaries of different entity types can be clarified, thereby helping to improve the entity recognition model's entity recognition ability.
[0040] In some optional implementations, the entity type explanation annotation field may be used to explain the meaning of a certain entity type, and may also provide examples for describing entities corresponding to the entity type.
[0041] For example, if the entity type is a person entity, the corresponding entity type explanation annotation field can explain the connotation of the person entity. For example, the field value of the entity type explanation annotation field is: the person entity refers to the name of the person in the text to be identified. In addition, the entity type can also be illustrated with an example. For example, the field value of the entity type explanation annotation field is: in the text "Yesterday I met Xiao Ming", "Xiao Ming" is a person entity.
[0042] The thought chain hint field is used to indicate the execution logic used by the entity recognition model during the feedforward processing. For a certain training instruction, it may be necessary to extract entities of multiple entity types. Therefore, when the entity recognition model performs feedforward processing, the thought chain hint field can be used to guide the processing logic of the entity recognition model.
[0043] For example, if it is necessary to identify the person entity, geographic location entity, and organizational entity in the input text of the training instruction, then the thought chain prompt field of the training instruction may include:
[0044] Step 1: Please extract entities of the "person" class from the provided context;
[0045] Step 2: Extract entities of the "geographic location" class from the provided context;
[0046] Step 3: Please extract entities of class “Organization” from the provided context.
[0047] The input text is the field value corresponding to the input data field in the training instruction, and the context in the thought chain prompt field refers to the input text. Based on this, it is equivalent to splitting a complex entity recognition process into multiple simple tasks through the thought chain prompt field, so that the entity recognition model can perform entity recognition processing step by step according to the execution steps corresponding to the thought chain prompt field in the training instruction during the training phase, which helps to improve the training effect of the entity recognition model.
[0048] The prediction field is used to normalize the prediction results of the entity recognition model for the input text in the training instruction.
[0049] Exemplarily, the prediction field can be used to specify the output format of the prediction result, such as specifying that the output format is json (JavaScript Object Notation) format. The prediction field is also used to specify the output content of the prediction result, such as specifying that the output content includes entity type prediction information, task reasoning step information, etc. Correspondingly, the prediction field can include field information such as the output format field, the entity type prediction field, and the prediction reasoning step field, which is not limited in the embodiments of the present application.
[0050] It should be noted that when the prediction field is used to specify the output content of the prediction result, the prediction field is used to fill in the prediction results of the model. For example, the entity type prediction field is "person": [], "geographic location": [], "organization": [], so that after identifying the entity, the entity recognition prediction result is filled in the corresponding position.
[0051] In some optional implementations, the training instruction may include multiple prediction fields, and the robustness of the training may be improved by adjusting the output order of these prediction fields.
[0052] In some optional implementations, the prediction field may include multiple entity type prediction fields, and the output order of these entity type prediction fields in the training instruction may be set. The entity type prediction field is the prediction result of the entity type to be extracted.
[0053] For example, a training instruction set for extracting a person entity, a geographic location entity, and an organization entity from an input text may include training instruction A, training instruction B, and training instruction C.
[0054] Among them, the output order corresponding to the prediction fields in training instruction A is: "Person: [], Geographic location: [], Organization: []"; the output order corresponding to the prediction fields in training instruction B is: "Geographic location: [], Person: [], Organization: []"; the output order corresponding to the prediction fields in training instruction C is "Organization: [], Geographic location: [], Person: []".
[0055] It can be seen that in this training instruction set, the prediction field contents of training instruction A, training instruction B, and training instruction C are the same, but their respective output orders are different.
[0056] It should be noted that the order of entity type annotation fields in the entity recognition instruction template can be the same as the output order corresponding to the entity type prediction fields in the prediction field. Correspondingly, in the training instructions generated based on the entity recognition instruction template, the order of entity type annotation fields can also be the same as the output order corresponding to the entity type prediction fields in the prediction field.
[0057] For example, in a training instruction, the output order of the prediction fields is: "geographic location: [], person: [], organization: []", then the order of the entity type annotation fields is: geographic location, person, organization.
[0058] Similarly, since the entity type explanation annotation fields are used to explain the entity type, the order of the entity type explanation annotation fields can also be the same as the output order corresponding to the entity type prediction fields.
[0059] For example, in a training instruction, the output order of the prediction fields is: "Geographic location: [], Person: [], Organization: []", then the order of the entity type explanation annotation fields is:
[0060] Geographic location: the name of the geographic location in the text. For example, in the text "I took a walk in a certain park in City A", "City A" and "a certain park" are both geographic location entities.
[0061] Person: The name of a person in the text. For example, in the text "Yesterday I met Xiao Ming", "Xiao Ming" is a person entity.
[0062] Organization: The name of the organization in the text, such as a company, government agency, non-governmental organization, etc. For example, in the text "I work at Company A", "Company A" is an organizational entity.
[0063] By setting different output orders corresponding to prediction fields for some training instructions in the training instruction set, the robustness of the model in facing different entity recognition tasks can be improved when training the entity recognition model.
[0064] Step S120: input the training instruction set into the entity recognition model to be trained to obtain the entity recognition prediction result.
[0065] The entity recognition model to be trained may be a pre-trained general text processing model, such as a Bert (Bidirectional Encoder Representations from Transformer) model.
[0066] A training instruction set is constructed through a preset entity recognition instruction template, and then the training instruction set is input into the entity recognition model to be trained, so as to obtain the entity recognition prediction results of the entity recognition model for different training instructions in the training instruction set.
[0067] Among them, the entity recognition prediction result corresponds to the prediction field of the training instruction, that is, the entity recognition prediction result is the prediction content described in the prediction field that needs to be normalized and output.
[0068] In some optional implementations, the entity recognition prediction result includes an entity type prediction field and an entity type explanation prediction field. Accordingly, the prediction fields in the entity recognition instruction template and the training instruction also include an entity type prediction field and an entity type explanation prediction field.
[0069] The entity type explanation prediction field is the explanation information of the entity type prediction field. For example, for an entity in the input text in the training instruction, its corresponding entity type prediction field is a person entity, then the entity type explanation prediction field is the explanation information generated by the model for the person entity, for example, the person entity is the name of the person in the input text.
[0070] By generating not only an entity type prediction field but also an entity type explanation prediction field in the entity recognition prediction results, the model's ability to understand different entity types can be improved.
[0071] Step S130: adjusting the model parameters of the entity recognition model to be trained according to the entity recognition prediction result to obtain a trained entity recognition model.
[0072] Among them, in each round of model parameter updating process, the model parameters adjusted can be all model parameters or partial model parameters, and the embodiments of the present application do not limit this.
[0073] Specifically, when adjusting the model parameters of the entity recognition model to be trained according to the entity recognition prediction results, the overall model parameters of the model may be adjusted, or only the model parameters of some layers of the model may be adjusted, which is not limited in the embodiments of the present application.
[0074] Exemplarily, in a training mode using fine-tuning, only the model parameters of some layers of the model may be trained, and in a training mode using secondary training or pre-training, the overall model parameters of the model may be trained.
[0075] It should be noted that when adjusting the model parameters of the entity recognition model to be trained according to the entity recognition prediction results, a preset convergence condition for the model to complete the training can be set, so that the entity recognition model that meets the preset convergence condition is used as the trained entity recognition model.
[0076] In some optional implementations, the entity recognition prediction result includes an entity type prediction field and an entity type explanation prediction field; the model parameters of the entity recognition model to be trained are adjusted according to the entity recognition prediction result, including: for any training instruction, determining a first loss value according to the semantic similarity between the entity type prediction field and the entity type annotation field corresponding to the training instruction; determining a second loss value according to the semantic similarity between the entity type explanation prediction field and the entity type explanation annotation field corresponding to the training instruction; and adjusting the model parameters of the entity recognition model to be trained based on the first loss value and the second loss value.
[0077] Among them, the entity type prediction field is used to identify the model's predicted categories for different entities in the input text of the training instruction. For example, if it is predicted that a certain entity in the input text belongs to a person entity, the value of the entity type prediction field is determined to be a person entity.
[0078] Among them, the entity type explanation prediction field is the explanation information of different predicted entity categories output by the entity recognition model. For example, for the person entity category, the corresponding entity type explanation prediction field can be determined as: the person entity category includes the names of people in the input text.
[0079] Among them, the entity type annotation field is the label information that identifies the real categories of different entities in the input text of the training instruction. For example, the entity type annotation field for the input text "Xiao Ming plans to go to the park to fly a kite at 3 pm tomorrow" includes "person entity".
[0080] It should be noted that the semantic similarity between the entity type prediction field and the entity type annotation field is used to characterize the entity type prediction accuracy of the entity recognition model for the extracted entity, which can be determined in a variety of ways. For example, cross entropy loss, multi-label classification loss, cosine similarity loss, etc., which are not limited in the embodiments of the present application.
[0081] It should also be noted that the semantic similarity between the entity type explanation prediction field and the entity type explanation annotation field is used to characterize the entity recognition model's ability to understand the entity type, which can be obtained by any metric function. For example, the cosine similarity, Euclidean distance, Minkowski distance, etc. between the entity type explanation prediction field and the entity type explanation annotation field are calculated, and this embodiment of the application does not limit this.
[0082] Among them, when adjusting the model parameters of the entity recognition model to be trained according to the first loss value and the second loss value, the corresponding weighting coefficients can be determined according to the importance of the first loss value and the second loss value to the model training, so as to obtain the final training loss value according to the weighting coefficient to adjust the model parameters.
[0083] The model parameters of the trained entity recognition model are adjusted by using the first loss value of the entity type prediction field and the entity type annotation field corresponding to the training instruction and the second loss value of the entity type explanation prediction field and the entity type explanation annotation field corresponding to the training instruction, so that during the parameter optimization process, the model can not only improve the entity type prediction effect for the text to be recognized, but also improve the model's ability to understand different entity types.
[0084] According to an embodiment of the present application, a training instruction set is constructed through a preset entity recognition instruction template, so that the entity recognition model is trained based on the training instruction set. On the one hand, the entity recognition instruction template includes an entity type annotation field and an entity type explanation annotation field, so that when training the entity recognition model, the entity recognition model's ability to understand different entity types can be improved. On the other hand, the entity recognition instruction template includes a thinking chain prompt field and a prediction field, and the output order corresponding to the prediction fields of at least some training instructions is different. Therefore, when the entity recognition model is trained according to the training instruction set, not only the entity recognition ability of the model can be improved, but also the model's ability to interpret entity types and its ability to decompose tasks can be improved, effectively improving the recognition accuracy of the trained entity recognition model for different entity recognition tasks.
[0085] In some optional implementations, a training instruction set is constructed according to a preset entity recognition instruction template, including: constructing an initial training instruction set according to the entity recognition instruction template and preset material data, the initial training instruction set including multiple initial training instructions, and the output order of prediction fields of the multiple initial training instructions is the same; for the first initial training instruction in the initial training instruction set, adjusting the output order of the prediction field of the first initial training instruction based on a shuffling method to obtain multiple adjusted first initial training instructions corresponding to the first initial training instruction; obtaining a training instruction set based on the multiple adjusted first initial training instructions and the multiple second initial training instructions; wherein the first initial training instruction is part of the initial training instructions in the initial training instruction set, and the second initial training instruction is the initial training instruction in the initial training instruction set except the first initial training instruction.
[0086] The preset material data is text data containing preset entity types. The preset entity types are entity types that need to be recognized by the trained entity recognition model. After setting the entity recognition instruction template, the preset material data is processed according to the entity recognition instruction template to construct an initial training instruction set.
[0087] Specifically, the preset material data can be written into the corresponding position of the entity recognition instruction template as input text in the training instruction.
[0088] For example, in a certain entity recognition instruction template, it is specified that the entity types to be recognized are person entities, location entities, and organization entities, and the output order of the prediction fields is: "person": [], "location": [], "organization": [], therefore, after using the preset material data as the input data field in the entity recognition instruction template, the initial training instruction for entity recognition can be constructed. At this time, the output order of the prediction fields in the initial training instructions of the initial training instruction set is the same.
[0089] The shuffle method is a random data sorting method. The first initial training instruction is an initial training instruction in the initial training instruction set that needs to adjust the output order of the prediction field.
[0090] The output sequence of the prediction fields of the first initial training instructions is adjusted by shuffling, so that the output sequence of the prediction fields of different first initial training instructions is changed from the original sequence.
[0091] It should be noted that, when the prediction field contains multiple fields, you can select only some fields or all fields for order adjustment. And adjusting the output order of the prediction field means adjusting the internal order of each field selected for adjustment. By adjusting the output order of the prediction field, the internal order of the fields selected for adjustment can be changed, but the internal order of the adjusted fields can still maintain a corresponding relationship.
[0092] For example, for the entity type prediction field, the adjusted internal order is "person", "geographic location", "organization"; for the entity type explanation prediction field, the adjusted internal order is "explanation of person entity:", "explanation of geographic location entity:", "explanation of organization entity:", that is, the internal order after the order adjustment can still maintain the correspondence between them.
[0093] It should also be noted that since the order of entity type annotation fields, the order of entity type explanation annotation fields, and the order of reasoning step fields in the thinking chain prompt field in the entity recognition instruction template can correspond to the output order of the prediction fields, therefore, while adjusting the output order of the prediction fields of the first initial training instruction, the order of entity type annotation fields, the order of entity type explanation annotation fields, and the order of reasoning step fields in the thinking chain prompt field of the first initial training instruction can be adjusted to a corresponding order.
[0094] Exemplarily, before the execution order adjustment, the original first initial training instruction is:
[0095] Please follow the steps below to extract entities that match the following entity type definitions from the input text:
[0096] Step 1: Extract entities of the "person" class from the provided context;
[0097] Step 2: Extract entities of the "geolocation" class from the provided context;
[0098] Step 3: Extract entities of the "organization" class from the provided context;
[0099] Input text: Li Ming works in product sales at a company in City B;
[0100] Entity Type:
[0101] Person: used to identify names of people in text. For example, in the text "Yesterday I met Xiao Ming", "Xiao Ming" is a person entity.
[0102] Geographic location: used to identify geographic location names in text. For example, in the text "I took a walk in a certain park in City A", "City A" and "a certain park" are both location entities.
[0103] Organization: used to identify the organization name in the text, such as companies, government agencies, non-governmental organizations, etc. For example, in the text "I work at Company A", "Company A" is an organizational entity.
[0104] Please output in json format: {"Person":[],"Location":[],"Organization":[]}.
[0105] After the execution sequence is adjusted, the first initial training instruction for adjusting the sequence is:
[0106] Please follow the steps below to extract entities that match the following entity type definitions from the input text:
[0107] Step 1: Extract entities of the "geolocation" class from the provided context;
[0108] Step 2: Extract entities of the "organization" class from the provided context;
[0109] Step 3: Extract entities of the "person" class from the provided context;
[0110] Input text: Li Ming works in product sales at a company in City B;
[0111] Entity Type:
[0112] Geographic location: used to identify geographic location names in text. For example, in the text "I took a walk in a certain park in City A", "City A" and "a certain park" are both location entities.
[0113] Organization: used to identify the organization name in the text, such as companies, government agencies, non-governmental organizations, etc. For example, in the text "I work at Company A", "Company A" is an organizational entity.
[0114] Person: used to identify names of people in text. For example, in the text "Yesterday I met Xiao Ming", "Xiao Ming" is a person entity.
[0115] Please output in json format: {"geographic location":[],"organization":[],"person":[]}.
[0116] In an embodiment of the present application, the output order of the prediction fields of multiple first initial training instructions is adjusted based on a shuffling method, and a training instruction set is constructed based on the adjusted first initial training instructions and the original second initial training instructions, so that when the entity recognition model is trained based on the training instruction set, the robustness of the entity recognition model for different entity recognition tasks can be improved.
[0117] In some optional implementations, in order to improve the model's task decomposition capabilities for entity recognition tasks, the thinking chain prompt field includes multiple reasoning step fields, and the reasoning logic corresponding to the multiple reasoning step fields is used to execute the preset entity recognition task; the prediction field includes multiple prediction reasoning step fields, wherein the reasoning logic corresponding to the multiple prediction reasoning step fields is the execution logic of the entity recognition model to be trained when executing the preset entity recognition task.
[0118] Among them, each reasoning step field and each predicted reasoning step field are respectively used to describe a preset processing step and an actual processing step when the model performs entity recognition on the input text in the training instruction.
[0119] Among them, the preset entity recognition tasks are entity recognition tasks corresponding to different training instructions. According to the output order of the prediction fields of the entity recognition task and the order of the entity type annotation fields, the execution logic corresponding to each entity recognition task can be determined.
[0120] Correspondingly, the reasoning logic corresponding to the reasoning step field is the preset execution logic of the preset entity recognition task. The reasoning logic corresponding to the prediction reasoning step field is the actual execution logic of the model when executing the preset entity recognition task.
[0121] The similarity information between the reasoning step field of the thought chain prompt field and the predicted reasoning step field of the prediction field can show whether the model has learned the decomposition and processing capability of the entity recognition task during the training process of the entity recognition model.
[0122] For example, for a certain training instruction, the corresponding content of the thought chain prompt field and the prediction field are:
[0123] Please follow the inference steps below to extract entities from the provided context.
[0124] Step 1: Extract entities of class "geolocation" from the provided context.
[0125] Step 2: Extract entities of class "Organization" from the provided context.
[0126] Step 3: Extract entities of class "person" from the provided context.
[0127] Please output in json format: {"Thinking Chain CoT":"<Thinking Process>","result":{"Geographic Location":[],"Organization":[],"Person":[]}}"
[0128] After the training instruction is input into the model, the corresponding content of its prediction reasoning step field is:
[0129] "Chain of Thought CoT": extract entities according to the order of reasoning steps.
[0130] Step 1: Extract entities of the "geographic location" class from the provided context, including the ["City A"] entity.
[0131] Step 2: Extract the entity of "Organization" class from the provided context, including ["Company"] entity.
[0132] Step 3: Extract entities of the "person" class from the provided context, including the ["Xiao Ming"] entity.
[0133] According to the similarity between the predicted reasoning step field and the corresponding reasoning step field in the thought chain prompt field, the model's step-by-step processing learning effect on the entity recognition task can be demonstrated. By making the model output its actual predicted reasoning steps when processing the entity recognition task, the interpretability of the entity recognition model is also improved.
[0134] In an embodiment of the present application, by including multiple reasoning step fields in the thinking chain prompt field of the entity recognition instruction template, when training the entity recognition model based on each training instruction, the model can be guided to process the entity recognition task corresponding to the training instruction step by step according to the reasoning step information in the training instruction, thereby improving the task decomposition processing capability of the model when performing entity recognition tasks, and, by setting multiple prediction reasoning step fields in the prediction field, the execution logic of the model when processing the entity recognition task can be intuitively displayed, thereby improving the interpretability of the entity recognition model.
[0135] In some optional implementations, the entity recognition instruction template includes an entity type annotation field, an entity type explanation annotation field, and an entity explanation annotation field, and the entity recognition prediction result includes an entity type prediction field, an entity type explanation prediction field, and an entity explanation prediction field.
[0136] Accordingly, the model parameters of the entity recognition model to be trained are adjusted according to the entity recognition prediction results, including: for any training instruction, a first loss value is determined according to the semantic similarity between the entity type prediction field and the entity type annotation field corresponding to the training instruction; a second loss value is determined according to the semantic similarity between the entity type explanation prediction field and the entity type explanation annotation field corresponding to the training instruction; a third loss value is determined according to the semantic similarity between the entity explanation prediction field and the entity explanation annotation field corresponding to the training instruction; a fourth loss value is determined according to the degree of attribution between the entity explanation prediction field and the entity type annotation field corresponding to the training instruction, the degree of attribution being used to characterize the degree to which the entity corresponding to the entity explanation prediction field belongs to the entity type corresponding to the entity type annotation field; based on the first loss value, the second loss value, the third loss value and the fourth loss value, the model parameters of the entity recognition model to be trained are adjusted.
[0137] The entity explanation annotation field is the explanation information given in advance for the entity to be extracted in the input text in the training instruction. For example, for an entity "Xiao Ming" in the input text, the corresponding explanation information may be: "Xiao Ming" is a person's name.
[0138] The entity explanation prediction field is the predicted explanation information of the entity extracted by the entity recognition model from the input text in the training instruction. For example, the entity "Park A" extracted by the model from the input text has the corresponding entity prediction explanation information: "Park A" is a geographical location name.
[0139] It should be noted that the above-mentioned explanation information may also include other contents of the entity, such as the connotation of the entity, the attribute information of the entity, etc., which is not limited in the embodiment of the present application.
[0140] Among them, the semantic similarity between the entity type prediction field and the entity type annotation field corresponding to the training instruction is used to characterize the entity type prediction accuracy of the entity recognition model for the extracted entity, which can be obtained through any classification loss. For example, cross entropy loss, multi-label classification loss, cosine similarity loss, etc., which are not limited in the embodiments of the present application.
[0141] Among them, the semantic similarity between the entity type explanation prediction field and the entity type explanation annotation field corresponding to the training instruction is used to characterize the entity recognition model's ability to understand the entity type, which can be obtained by any metric function. For example, the cosine similarity, Euclidean distance, Ming's distance, etc. between the entity type explanation prediction field and the entity type explanation annotation field are calculated, and this embodiment of the application does not limit this.
[0142] After obtaining the semantic similarity between the entity type explanation prediction field and the entity type explanation annotation field, the semantic similarity can be further processed according to training needs to obtain a second loss value. For example, the value of the semantic similarity is adjusted to within a preset data range to ensure the training stability of the model.
[0143] Among them, the semantic similarity between the entity explanation prediction field and the entity explanation annotation field corresponding to the training instruction is used to characterize the entity recognition model's ability to understand the extracted entities. The higher the semantic similarity between the entity explanation prediction field and the corresponding entity explanation annotation field, the more correct the model's understanding of the entity's connotation is, and thus the model's accuracy in judging the type of the entity is also higher.
[0144] Similarly, the semantic similarity between the entity explanation prediction field and the entity explanation annotation field can also be obtained by any metric function. For example, the cosine similarity, Euclidean distance, Ming's distance, etc. between the entity explanation prediction field and the entity explanation annotation field are calculated, and the embodiments of the present application are not limited to this.
[0145] After obtaining the semantic similarity between the entity explanation prediction field and the entity explanation annotation field, the semantic similarity can also be further processed according to training needs to obtain a third loss value. For example, the value of the semantic similarity is adjusted to within a preset data range to ensure the training stability of the model.
[0146] Among them, the degree of belonging between the entity explanation prediction field corresponding to the training instruction and the entity type annotation field is used to characterize the degree to which the entity corresponding to the entity explanation prediction field belongs to the entity type corresponding to the entity type annotation field.
[0147] For example, for the entity explanation field of the entity "Xiao Ming": "Xiao Ming" is a person's name, and its corresponding entity type should be a person entity. Then the entity explanation field should have the highest degree of attribution to the entity type annotation field of the person entity.
[0148] It should be noted that the degree of belonging between the entity explanation prediction field and the entity type annotation field can be determined by clustering, for example, K-means clustering (K-means), density-based clustering (DBSCAN), etc.
[0149] By adopting a clustering approach to obtain the degree of attribution between the entity explanation prediction field and the entity type annotation field, it is possible to determine the probability that the entity explanation prediction field corresponds to the entity type based on the degree of attribution, and obtain the corresponding fourth loss value. In the process of optimizing the model parameters based on the loss value, the higher the probability that the entity explanation prediction field corresponds to its true entity type, that is, the greater the degree of attribution between the entity explanation prediction field and the entity type annotation field of the true entity type, thereby improving the accuracy of the model for entity explanation prediction and entity type prediction.
[0150] It should also be noted that, in actual application, the corresponding weight coefficients can be determined according to the importance of the first loss value, the second loss value, the third loss value, and the fourth loss value.
[0151] In some optional implementations, based on the first loss value, the second loss value, the third loss value and the fourth loss value, the model parameters of the entity recognition model to be trained are adjusted, including: performing weighted calculation according to a preset loss weight coefficient, the first loss value, the second loss value, the third loss value and the fourth loss value to obtain a weighted loss value; and adjusting the model parameters of the entity recognition model to be trained according to the weighted loss value.
[0152] Exemplarily, the first loss value and the second loss value are more important for model parameter optimization, while the third loss value and the fourth loss value are less important for model parameter optimization. Therefore, a higher weight coefficient is set for the first loss value and the second loss value, and a lower weight coefficient is set for the third loss value and the fourth loss value. By weighting each loss value and its corresponding weight coefficient, the final weight value is obtained, which facilitates the training of model parameters.
[0153] In an embodiment of the present application, a first loss value is determined by the semantic similarity between an entity type prediction field and an entity type annotation field, a second loss value is determined by the semantic similarity between an entity type explanation prediction field and an entity type explanation annotation field, and a third loss value is determined by the semantic similarity between an entity explanation prediction field and an entity explanation annotation field; a fourth loss value is determined by the degree of attribution between an entity explanation prediction field and an entity type annotation field, and an entity recognition model is jointly trained based on the above loss values, thereby improving the entity recognition accuracy of the trained entity recognition model and its ability to understand different entities and different entity types.
[0154] Figure 3 A flow chart of a method for training an entity recognition model provided in an embodiment of the present application. Figure 3 , the method comprising:
[0155] Step S310: construct a training instruction set according to a preset entity recognition instruction template, wherein the entity recognition instruction template includes at least an entity type annotation field, an entity type explanation annotation field, an entity explanation annotation field, a thinking chain prompt field and a prediction field, the prediction field includes an entity type prediction field, an entity type explanation prediction field and an entity explanation prediction field, the training instruction set includes multiple training instructions, and the output order corresponding to the prediction fields of at least some of the training instructions is different.
[0156] Step S320: input the training instruction set into the entity recognition model to be trained to obtain entity recognition prediction results, wherein the entity recognition prediction results include an entity type prediction field, an entity type explanation prediction field and an entity explanation prediction field.
[0157] Step S330: For any training instruction, determine a first loss value according to the semantic similarity between the entity type prediction field and the entity type annotation field corresponding to the training instruction.
[0158] Step S340: Determine a second loss value according to the semantic similarity between the entity type explanation prediction field and the entity type explanation annotation field corresponding to the training instruction.
[0159] Step S350: Determine a third loss value according to the semantic similarity between the entity explanation prediction field and the entity explanation annotation field corresponding to the training instruction.
[0160] Step S360: Determine a fourth loss value based on the degree of belonging between the entity explanation prediction field and the entity type annotation field corresponding to the training instruction, where the degree of belonging is used to characterize the degree to which the entity corresponding to the entity explanation prediction field belongs to the entity type corresponding to the entity type annotation field.
[0161] Step S370: Perform weighted calculation according to the preset loss weight coefficient, the first loss value, the second loss value, the third loss value and the fourth loss value to obtain a weighted loss value.
[0162] Step S380: According to the weighted loss value, adjust the model parameters of the entity recognition model to be trained to obtain a trained entity recognition model.
[0163] In an embodiment of the present application, the model parameters of the entity recognition model are jointly trained based on the semantic similarity between the entity type prediction field and the entity type annotation field, the semantic similarity between the entity type explanation prediction field and the entity type explanation annotation field, the semantic similarity between the entity explanation prediction field and the entity explanation annotation field, and the loss value corresponding to the degree of attribution between the entity explanation prediction field and the entity type annotation field, thereby improving the entity recognition accuracy of the trained entity recognition model, the ability to understand different entities and different entity types, and the ability to divide entity recognition tasks.
[0164] In a second aspect, an embodiment of the present application provides an entity recognition method.
[0165] Figure 4 A flowchart of an entity recognition method provided in an embodiment of the present application, referring to Figure 4 , the method comprising:
[0166] Step S400: inputting the text data to be recognized into the entity recognition model to obtain the entity recognition result corresponding to the text data to be recognized.
[0167] The entity recognition model is obtained by using the above-mentioned entity recognition model training method.
[0168] It should be noted that when using the entity recognition model to perform entity recognition on the text data to be recognized, you can only input the text data to the entity recognition model to obtain the model's entity recognition result for the text data to be recognized, or you can input the text data to be recognized and the preset reasoning steps for recognizing the text data into the entity recognition model together to guide the entity recognition model to extract entities according to the preset reasoning steps, and obtain the model's entity extraction result for the text data to be recognized.
[0169] Furthermore, when the model outputs the entity recognition result of the text data to be recognized, it can also output the model's predictive reasoning steps when performing entity recognition, the model's explanatory information for the recognized entity, the model's explanatory information for the entity type, etc., which is not limited in this embodiment of the present application.
[0170] In an embodiment of the present application, for a trained entity recognition model, by inputting the text data to be recognized into the model, the entity recognition result of the model for the text data to be recognized can be obtained, thereby realizing fast and accurate entity recognition of different text data to be recognized, and improving the generalization ability of the model under different entity recognition tasks.
[0171] It can be understood that the above-mentioned various method embodiments mentioned in this application can be combined with each other to form a combined embodiment without violating the principle logic. Due to space limitations, this application will not go into details. Those skilled in the art can understand that in the above-mentioned method of the specific implementation method, the specific execution order of each step should be determined by its function and possible internal logic.
[0172] In addition, the present application also provides a training device, an electronic device, and a computer-readable storage medium for an entity recognition model, all of which can be used to implement any training method for an entity recognition model provided in the present application. The corresponding technical solutions and descriptions are referred to in the corresponding records of the method part and will not be repeated here.
[0173] Figure 5 A block diagram of a training device for an entity recognition model provided in an embodiment of the present application.
[0174] Reference Figure 5 , the embodiment of the present application provides a training device for an entity recognition model, the training device 500 for the entity recognition model includes:
[0175] Construction module 501 is used to construct a training instruction set according to a preset entity recognition instruction template, wherein the entity recognition instruction template includes at least an entity type annotation field, an entity type explanation annotation field, a thinking chain prompt field and a prediction field, and the training instruction set includes multiple training instructions, and the output order corresponding to the prediction fields of at least some of the training instructions is different.
[0176] The prediction module 502 is used to input the training instruction set into the entity recognition model to be trained to obtain the entity recognition prediction result.
[0177] The adjustment module 503 is used to adjust the model parameters of the entity recognition model to be trained according to the entity recognition prediction result to obtain a trained entity recognition model.
[0178] In some optional implementations, the construction module 501 constructs a training instruction set according to a preset entity recognition instruction template, including: constructing an initial training instruction set according to the entity recognition instruction template and preset material data, the initial training instruction set including multiple initial training instructions, and the output order of the prediction fields of the multiple initial training instructions is the same; for the first initial training instruction in the initial training instruction set, adjusting the output order of the prediction field of the first initial training instruction based on a shuffling method to obtain multiple adjusted first initial training instructions corresponding to the first initial training instruction; obtaining a training instruction set based on the multiple adjusted first initial training instructions and the multiple second initial training instructions; wherein the first initial training instruction is part of the initial training instruction in the initial training instruction set, and the second initial training instruction is the initial training instruction in the initial training instruction set except the first initial training instruction.
[0179] In some optional implementations, the thought chain prompt field includes multiple reasoning step fields, and the reasoning logic corresponding to the multiple reasoning step fields is used to perform a preset entity recognition task; the prediction field includes multiple prediction reasoning step fields, wherein the reasoning logic corresponding to the multiple prediction reasoning step fields is the execution logic of the entity recognition model to be trained when performing the preset entity recognition task.
[0180] In some optional implementations, the entity recognition prediction result includes an entity type prediction field and an entity type explanation prediction field; the adjustment module 503 adjusts the model parameters of the entity recognition model to be trained according to the entity recognition prediction result, including: for any training instruction, determining a first loss value according to the semantic similarity between the entity type prediction field and the entity type annotation field corresponding to the training instruction; determining a second loss value according to the semantic similarity between the entity type explanation prediction field and the entity type explanation annotation field corresponding to the training instruction; and adjusting the model parameters of the entity recognition model to be trained based on the first loss value and the second loss value.
[0181] In some optional implementations, the entity recognition instruction template includes an entity type prediction field, an entity type explanation prediction field, an entity explanation prediction field and an entity explanation annotation field, and the entity recognition prediction result includes an entity type prediction field, an entity type explanation prediction field and an entity explanation prediction field; the adjustment module 503 adjusts the model parameters of the entity recognition model to be trained according to the entity recognition prediction result, including: for any training instruction, determining a first loss value according to the semantic similarity between the entity type prediction field and the entity type annotation field corresponding to the training instruction; determining a second loss value according to the semantic similarity between the entity type explanation prediction field and the entity type explanation annotation field corresponding to the training instruction; determining a third loss value according to the semantic similarity between the entity explanation prediction field and the entity explanation annotation field corresponding to the training instruction; determining a fourth loss value according to the degree of attribution between the entity explanation prediction field and the entity type annotation field corresponding to the training instruction, the degree of attribution being used to characterize the degree to which the entity corresponding to the entity explanation prediction field belongs to the entity type corresponding to the entity type annotation field; adjusting the model parameters of the entity recognition model to be trained based on the first loss value, the second loss value, the third loss value and the fourth loss value.
[0182] In some optional implementations, based on the first loss value, the second loss value, the third loss value and the fourth loss value, the model parameters of the entity recognition model to be trained are adjusted, including: performing weighted calculation according to a preset loss weight coefficient, the first loss value, the second loss value, the third loss value and the fourth loss value to obtain a weighted loss value; and adjusting the model parameters of the entity recognition model to be trained according to the weighted loss value.
[0183] Figure 6 A block diagram of an entity recognition device provided in an embodiment of the present application.
[0184] Reference Figure 6 , the embodiment of the present application provides an entity identification device, the entity identification device 600 includes:
[0185] The recognition module 601 is used to input the text data to be recognized into the entity recognition model to obtain the entity recognition result corresponding to the text data to be recognized.
[0186] The entity recognition model in the recognition module 601 is obtained by using the above-mentioned entity recognition model training method.
[0187] In an embodiment of the present application, by inputting the text data to be recognized into the entity recognition model of the recognition module, the entity recognition result of the model for the text data to be recognized can be obtained, thereby realizing fast and accurate entity recognition of different text data to be recognized, and improving the generalization ability of the model under different entity recognition tasks.
[0188] The training device of the entity recognition model or each module in the entity recognition device can be implemented in whole or in part by software, hardware, or a combination thereof. The modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory in the computer device in the form of software, so that the processor can call and execute the operations corresponding to the modules above.
[0189] Figure 7 A block diagram of an electronic device provided in an embodiment of the present application.
[0190] Reference Figure 7 An embodiment of the present application provides an electronic device, which includes: at least one processor 701; at least one memory 702, and one or more I / O interfaces 703, connected between the processor 701 and the memory 702; wherein the memory 702 stores one or more computer programs that can be executed by at least one processor 701, and the one or more computer programs are executed by at least one processor 701 so that the at least one processor 701 can execute the above-mentioned entity recognition model training method or entity recognition method.
[0191] Each module in the above electronic device can be implemented in whole or in part by software, hardware, or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module.
[0192] The present application also provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program implements the above-mentioned entity recognition model training method or entity recognition method when executed by a processor / processing core. The computer-readable storage medium may be a volatile or non-volatile computer-readable storage medium.
[0193] An embodiment of the present application also provides a computer program product, including a computer-readable code, or a non-volatile computer-readable storage medium carrying the computer-readable code. When the computer-readable code runs in a processor of an electronic device, the processor in the electronic device executes the above-mentioned entity recognition model training method or entity recognition method.
[0194] It will be appreciated by those skilled in the art that all or some of the steps, systems, and functional modules / units in the methods disclosed above may be implemented as software, firmware, hardware, and appropriate combinations thereof. In a hardware implementation, the division between the functional modules / units mentioned in the above description does not necessarily correspond to the division of physical components; for example, a physical component may have multiple functions, or a function or step may be performed by several physical components in cooperation. Some or all physical components may be implemented as software executed by a processor, such as a central processing unit, a digital signal processor, or a microprocessor, or may be implemented as hardware, or may be implemented as an integrated circuit, such as an application-specific integrated circuit. Such software may be distributed on a computer-readable storage medium, which may include a computer storage medium (or a non-transitory medium) and a communication medium (or a temporary medium).
[0195] As is known to those of ordinary skill in the art, the term computer storage media includes volatile and nonvolatile, removable and non-removable media implemented in any method or technology for storing information (such as computer-readable program instructions, data structures, program modules or other data). Computer storage media include, but are not limited to, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM), static random access memory (SRAM), flash memory or other memory technology, portable compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical disk storage, magnetic cassettes, magnetic tapes, magnetic disk storage or other magnetic storage devices, or any other medium that can be used to store desired information and can be accessed by a computer. In addition, it is known to those of ordinary skill in the art that communication media typically contain computer-readable program instructions, data structures, program modules or other data in a modulated data signal such as a carrier wave or other transmission mechanism, and may include any information delivery medium.
[0196] The computer-readable program instructions described herein can be downloaded from a computer-readable storage medium to each computing / processing device, or downloaded to an external computer or external storage device via a network, such as the Internet, a local area network, a wide area network, and / or a wireless network. The network can include copper transmission cables, optical fiber transmissions, wireless transmissions, routers, firewalls, switches, gateway computers, and / or edge servers. The network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards the computer-readable program instructions for storage in the computer-readable storage medium in each computing / processing device.
[0197] The computer program instructions for performing the operation of the present application can be assembler instructions, instruction set architecture (ISA) instructions, machine instructions, machine-related instructions, microcode, firmware instructions, state setting data, or source code or object code written in any combination of one or more programming languages, including object-oriented programming languages, such as Smalltalk, C++, etc., and conventional procedural programming languages, such as "C" language or similar programming languages. Computer-readable program instructions can be executed completely on a user's computer, partially on a user's computer, executed as an independent software package, partially on a user's computer, partially on a remote computer, or completely on a remote computer or server. In the case of a remote computer, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computer (for example, using an Internet service provider to connect through the Internet). In some embodiments, by using the state information of a computer-readable program instruction to personalize an electronic circuit, such as a programmable logic circuit, a field programmable gate array (FPGA) or a programmable logic array (PLA), the electronic circuit can execute a computer-readable program instruction, thereby realizing various aspects of the present application.
[0198] The computer program product described herein may be implemented in hardware, software, or a combination thereof. In one optional embodiment, the computer program product is embodied as a computer storage medium, and in another optional embodiment, the computer program product is embodied as a software product, such as a software development kit (SDK), etc.
[0199] Various aspects of the present application are described herein with reference to the flowcharts and / or block diagrams of the methods, devices (systems) and computer program products according to the embodiments of the present application. It should be understood that each box in the flowchart and / or block diagram and the combination of each box in the flowchart and / or block diagram can be implemented by computer-readable program instructions.
[0200] These computer-readable program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, thereby producing a machine, so that when these instructions are executed by the processor of the computer or other programmable data processing device, a device that implements the functions / actions specified in one or more boxes in the flowchart and / or block diagram is generated. These computer-readable program instructions can also be stored in a computer-readable storage medium, and these instructions cause the computer, programmable data processing device, and / or other equipment to work in a specific manner, so that the computer-readable medium storing the instructions includes a manufactured product, which includes instructions for implementing various aspects of the functions / actions specified in one or more boxes in the flowchart and / or block diagram.
[0201] Computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device so that a series of operating steps are performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby causing the instructions executed on the computer, other programmable data processing apparatus, or other device to implement the functions / actions specified in one or more boxes in the flowchart and / or block diagram.
[0202] The flow chart and block diagram in the accompanying drawings show the possible architecture, function and operation of the system, method and computer program product according to multiple embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a part of a module, program segment or instruction, and a part of the module, program segment or instruction includes one or more executable instructions for realizing the logical function of the specification. In some alternative implementations, the function marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two continuous square boxes can actually be executed substantially in parallel, and they can also be executed in the opposite order sometimes, depending on the function involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be realized by a dedicated hardware-based system that performs the function or action of the specification, or can be realized by a combination of special-purpose hardware and computer instructions.
[0203] Example embodiments have been disclosed herein, and although specific terms are employed, they are used and should be interpreted only in a general illustrative sense and not for limiting purposes. In some instances, it will be apparent to those skilled in the art that, unless otherwise expressly noted, features, characteristics, and / or elements described in conjunction with a particular embodiment may be used alone or in combination with features, characteristics, and / or elements described in conjunction with other embodiments. Therefore, those skilled in the art will appreciate that various changes in form and detail may be made without departing from the scope of the present application as set forth in the appended claims.
Claims
1. A training method for an entity recognition model, characterized in that: The method comprises: Constructing a training instruction set according to a preset entity recognition instruction template, wherein the entity recognition instruction template at least includes an entity type annotation field, an entity type explanation annotation field, a thought chain prompt field, and a prediction field, and the training instruction set includes a plurality of training instructions, and the output order corresponding to the prediction fields of at least some of the training instructions is different; Inputting the training instruction set into the entity recognition model to be trained to obtain an entity recognition prediction result; The model parameters of the entity recognition model to be trained are adjusted according to the entity recognition prediction result to obtain a trained entity recognition model.
2. The method according to claim 1, characterized in that The step of constructing a training instruction set according to a preset entity recognition instruction template includes: Constructing an initial training instruction set according to the entity recognition instruction template and the preset material data, wherein the initial training instruction set includes a plurality of initial training instructions, and the output order of the prediction fields of the plurality of initial training instructions is the same; For a first initial training instruction in the initial training instruction set, adjusting the output order of the prediction fields of the first initial training instruction based on a shuffling method to obtain a plurality of adjusted first initial training instructions corresponding to the first initial training instruction; Based on the plurality of adjusted first initial training instructions and the plurality of second initial training instructions, obtaining the training instruction set; The first initial training instruction is part of the initial training instructions in the initial training instruction set, and the second initial training instruction is the initial training instruction in the initial training instruction set except the first initial training instruction.
3. The method according to claim 1, characterized in that The thought chain prompt field includes a plurality of reasoning step fields, and the reasoning logic corresponding to the plurality of reasoning step fields is used to perform a preset entity recognition task; The prediction field includes multiple prediction reasoning step fields, wherein the reasoning logic corresponding to the multiple prediction reasoning step fields is the execution logic of the entity recognition model to be trained when performing the preset entity recognition task.
4. The method according to claim 1, characterized in that: The entity recognition prediction result includes an entity type prediction field and an entity type explanation prediction field; The adjusting the model parameters of the entity recognition model to be trained according to the entity recognition prediction result includes: For any training instruction, determining a first loss value according to the semantic similarity between the entity type prediction field and the entity type annotation field corresponding to the training instruction; Determining a second loss value according to the semantic similarity between the entity type explanation prediction field and the entity type explanation annotation field corresponding to the training instruction; Adjust model parameters of the entity recognition model to be trained based on the first loss value and the second loss value.
5. The method according to claim 1 or 4, characterized in that: The entity recognition instruction template includes an entity type annotation field, an entity type explanation annotation field, and an entity explanation annotation field, and the entity recognition prediction result includes an entity type prediction field, an entity type explanation prediction field, and an entity explanation prediction field; The adjusting the model parameters of the entity recognition model to be trained according to the entity recognition prediction result includes: For any training instruction, determining a first loss value according to the semantic similarity between the entity type prediction field and the entity type annotation field corresponding to the training instruction; Determining a second loss value according to the semantic similarity between the entity type explanation prediction field and the entity type explanation annotation field corresponding to the training instruction; Determining a third loss value according to the semantic similarity between the entity explanation prediction field corresponding to the training instruction and the entity explanation annotation field; Determine a fourth loss value according to the degree of belonging between the entity explanation prediction field corresponding to the training instruction and the entity type annotation field, wherein the degree of belonging is used to characterize the degree to which the entity corresponding to the entity explanation prediction field belongs to the entity type corresponding to the entity type annotation field; Based on the first loss value, the second loss value, the third loss value and the fourth loss value, the model parameters of the entity recognition model to be trained are adjusted.
6. The method according to claim 5, characterized in that The adjusting the model parameters of the entity recognition model to be trained based on the first loss value, the second loss value, the third loss value, and the fourth loss value includes: Performing weighted calculation according to a preset loss weight coefficient, the first loss value, the second loss value, the third loss value, and the fourth loss value to obtain a weighted loss value; According to the weighted loss value, the model parameters of the entity recognition model to be trained are adjusted.
7. An entity recognition method, characterized in that: The method comprises: Inputting the text data to be recognized into the entity recognition model to obtain the entity recognition result corresponding to the text data to be recognized; The entity recognition model is obtained by using the training method of the entity recognition model described in any one of claims 1 to 6.
8. A training device for an entity recognition model, the device comprising: A construction module, used to construct a training instruction set according to a preset entity recognition instruction template, wherein the entity recognition instruction template at least includes an entity type annotation field, an entity type explanation annotation field, a thought chain prompt field and a prediction field, and the training instruction set includes multiple training instructions, and the output order corresponding to the prediction fields of at least some of the training instructions is different; A prediction module, used for inputting the training instruction set into the entity recognition model to be trained to obtain an entity recognition prediction result; The adjustment module is used to adjust the model parameters of the entity recognition model to be trained according to the entity recognition prediction result to obtain a trained entity recognition model.
9. An electronic device, characterized in that: include: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores one or more computer programs that can be executed by the at least one processor, and one or more of the computer programs are executed by the at least one processor so that the at least one processor can execute the training method of the entity recognition model as described in any one of claims 1 to 6, or the entity recognition method as described in claim 7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When executed by a processor, the computer program implements the training method of the entity recognition model as described in any one of claims 1 to 6, or the entity recognition method as described in claim 7.
Citation Information
Cited By
Information generation model training method and information generation method
CN119249157A
Judicial text entity recognition method based on ternary instruction fine tuning and VCoT verification
CN120337927A
Judicial text entity recognition method based on ternary instruction fine tuning and VCoT verification
CN120337927B
