A Prompt-based Named Entity Recognition Method, Device, and Terminal Device

By using a prompt-based method in named entity recognition, combining pre-trained models and synonyms collections, the problems of low recognition efficiency and poor generalization caused by insufficient data in vertical fields are solved, and more efficient and accurate named entity recognition is achieved.

CN115034223BActive Publication Date: 2025-06-13GUANGZHOU TANJI TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202210671093.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-06-14
Publication Date
2025-06-13
Estimated Expiration
2042-06-14

AI Technical Summary

Technical Problem

The existing named entity recognition technology is difficult to achieve good fine-tuning results when there is little data in the vertical field, resulting in low recognition efficiency and poor generalization, and the undefined entity type cannot be recognized.

Method used

Using a prompt-based named entity recognition method, by obtaining the sentence to be tested and combining the prompts in the preset prompt set, it is input into the pre-trained model to generate named entities, and mapped through the synonyms to improve the recognition accuracy.

Benefits of technology

It improves the efficiency and accuracy of naming entity recognition, reduces dependence on computing resources, enhances the model's recognition ability under a small amount of data, and improves the recognition ability of undefined entity types.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115034223B_ABST
    Figure CN115034223B_ABST
Patent Text Reader

Abstract

The present invention discloses a method, device and terminal device for named entity recognition based on prompts. By combining a sentence to be tested with a prompt in a prompt set, the sentence to be tested combined with the prompt is input into a pre-trained model for named entity recognition. Compared with the prior art of fine-tuning the pre-trained model through a large amount of computing resources and fine-tuning data, the present invention can tap the potential semantic ability of the pre-trained model through the design of prompts, so that the pre-trained model enhances the recognition effect under the action of the prompts, which is beneficial for the pre-trained model to perform named entity recognition based on a small amount of data, thereby improving the efficiency of named entity recognition.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of natural language processing, and in particular, to a prompt-based named entity recognition method, apparatus, and terminal device. Background Art

[0002] Named Entity Recognition (NER) is a basic task in the field of natural language processing. It is necessary to identify the entity type and its location of the text segment from the input text according to the predefined entity types. The pre-trained model is to pre-train a deep and complex model through a large amount of corpus data to enable it to obtain powerful text expression capabilities, and then apply it to downstream tasks. However, since the pre-trained model is usually very large, a large amount of computing resources and sufficient fine-tuning data are required to fine-tune it in order to achieve better results. The main steps of the current mainstream implementation method are: (1) fine-tuning the pre-trained language model using vertical domain corpus; (2) mapping the input text to a text expression in a continuous space through the fine-tuned language model; (3) performing recognition using a classification layer or a CRF layer according to the predefined entity types.

[0003] However, the existing named entity recognition technology usually has less data in the vertical domain, and even cannot obtain it, making it difficult to achieve good fine-tuning effects on large-scale pre-trained models, directly affecting the downstream recognition effects; and when fine-tuning or even re-training large-scale pre-trained models, a large amount of computing resources are required; the fine-tuned model only supports the recognition of predefined entity types and cannot recognize undefined entity types, with poor generalization. For example, a fine-tuned model that can recognize "person" and "location" cannot recognize "time". In summary, the existing named entity recognition technology has the problem of low recognition efficiency.

[0004] Therefore, there is an urgent need for a named entity recognition strategy to solve the problem of low named entity recognition efficiency in the existing technology. Summary of the Invention

[0005] Embodiments of the present invention provide a prompt-based named entity recognition method, apparatus, and terminal device to improve the efficiency of named entity recognition.

[0006] To solve the above problems, an embodiment of the present invention provides a prompt-based named entity recognition method, including:

[0007] Obtain a to-be-tested statement;

[0008] Obtain a prompt for the to-be-tested statement according to a preset prompt set;

[0009] The sentence to be tested and the prompt are input into a pre-trained model to obtain a generative named entity of the sentence to be tested.

[0010] As can be seen from the above, the present invention has the following beneficial effects:

[0011] The present invention provides a method for named entity recognition based on prompts. By combining a sentence to be tested with a prompt in a prompt set, the sentence to be tested combined with the prompt is input into a pre-trained model for named entity recognition. Compared with the prior art of fine-tuning the pre-trained model through a large amount of computing resources and fine-tuning data, the present invention can tap the potential semantic ability of the pre-trained model through the design of prompts, so that the pre-trained model enhances the recognition effect under the action of the prompts, which is beneficial for the pre-trained model to perform named entity recognition based on a small amount of data, thereby improving the efficiency of named entity recognition.

[0012] As an improvement of the above solution, after obtaining the generative named entity of the sentence to be tested, the method further includes:

[0013] Mapping the generative named entity through a preset synonym set to obtain a plurality of synonyms of the generative named entity;

[0014] According to the plurality of synonyms, the sentences to be tested are matched respectively to obtain the optimal named entity.

[0015] By implementing the improved solution of this embodiment, synonymous words are searched through a synonym set, which expands the search scope of named entities, and the obtained named entities are matched with the sentences to be tested, thereby improving the recognition accuracy of named entities.

[0016] As an improvement of the above solution, the method of matching the plurality of synonyms with the sentence to be tested to obtain the optimal named entity is as follows:

[0017] According to the plurality of synonyms, each sentence of the sentence to be tested is matched respectively to obtain similarity;

[0018] The optimal named entity is obtained according to the synonyms with the highest similarity.

[0019] The improved solution of this embodiment is implemented by matching synonyms with the sentence to be tested to perform similarity calculation, and the synonyms with high similarity obtained by calculation are used as the optimal named entity, thereby further improving the recognition accuracy of the named entity.

[0020] As an improvement of the above solution, the training method of the prompt set includes:

[0021] Obtain the entity type to be trained, input the entity type to be trained into the word vector model, and obtain the word vector of the entity type to be trained;

[0022] According to the word vector of the entity type to be trained, through cosine distance calculation, obtain a number of similar words of the entity type to be trained; wherein, the cosine distance between the word vector of the entity type to be trained and the word vectors of the number of similar words is less than a preset value;

[0023] Design a number of candidate prompts according to the entity type to be trained and the number of similar words;

[0024] Test the verification indexes of the number of candidate prompts respectively, and obtain the prompt set according to the candidate prompts whose verification indexes reach the preset value.

[0025] Implement the improved scheme of this embodiment. Obtain the word vector of the entity type to be trained through the word vector set, obtain the similar words of the entity type to be trained through cosine distance calculation, design candidate prompts according to the entity type to be trained and the similar words, and finally complete the training of all prompts in the prompt set by testing the verification indexes of the candidate prompts, thus laying a foundation for improving the efficiency of named entity recognition of the sentence to be tested.

[0026] As an improvement of the above scheme, the training method of the synonym set includes:

[0027] Obtain a naming dictionary; wherein, the naming dictionary is constructed from open-source data;

[0028] According to each original word in the naming dictionary, obtain the similar words of each original word through the word vector model;

[0029] Test the verification indexes of the similar words of each original word respectively, and use the similar words whose verification indexes reach the preset value as the synonymous words of each original word;

[0030] Summarize each original word and the corresponding synonymous words to obtain the synonym set.

[0031] Implement the improved scheme of this embodiment. By obtaining the similar words of each original word in the naming dictionary, establish the connection between each original word and the synonymous words of each original word, thus completing the training of the synonym set, which is beneficial to laying a foundation for improving the accuracy of named entity recognition of the sentence to be tested.

[0032] As an improvement of the above scheme, the training method of the word vector model includes:

[0033] Obtain a naming dictionary; wherein, the naming dictionary is constructed from open-source data;

[0034] According to all the words in the named dictionary, they are respectively input into the pre-trained model to obtain the high-dimensional vectors of each word;

[0035] According to the high-dimensional vectors of each word, the word vectors of each word are obtained.

[0036] Implementing the improvement scheme of this embodiment, by calculating the high-dimensional vectors of the words in the named dictionary, the word vectors of each word are obtained, laying a foundation for the training of the prompt set and the synonym set.

[0037] As an improvement of the above scheme, the step of inputting the to-be-detected statement and the prompt into the pre-trained model to obtain the generative named entity of the to-be-detected statement is specifically as follows:

[0038] The prompt includes several alternative prompts;

[0039] The to-be-detected statement is respectively combined with the several alternative prompts to obtain several spliced statements;

[0040] The several spliced statements are respectively input into the pre-trained model to obtain several candidate named entities;

[0041] Among the several candidate named entities, the coincidence degree is calculated, and the candidate named entity with the highest coincidence degree is output as the generative named entity.

[0042] Implementing the improvement scheme of this embodiment, through multiple prompts to jointly identify named entities, thus performing coincidence degree analysis on the named entities obtained according to multiple prompts, and finally determining the named entity with the highest coincidence degree, improving the accuracy and generalization of named entity recognition.

[0043] Correspondingly, an embodiment of the present invention further provides a prompt-based named entity recognition device, including: a data acquisition module, a prompt acquisition module, and a data generation module;

[0044] The data acquisition module is used to acquire the to-be-detected statement;

[0045] The prompt acquisition module is used to obtain the prompt of the to-be-detected statement according to the preset prompt set;

[0046] The data generation module is used to input the to-be-detected statement and the prompt into the pre-trained model to obtain the generative named entity of the to-be-detected statement.

[0047] As an improvement of the above scheme, after obtaining the generative named entity of the to-be-detected statement, it further includes: a data matching module;

[0048] The data matching module is used to map the generated named entity through a preset synonym set to obtain several synonymous words of the generated named entity;

[0049] According to the several synonymous words, respectively match them with the sentence to be tested to obtain the optimal named entity.

[0050] As an improvement to the above solution, the step of matching the several synonymous words with the sentence to be tested to obtain the optimal named entity is specifically:

[0051] According to the several synonymous words, respectively match them with each sentence of the sentence to be tested to obtain a similarity;

[0052] According to the synonymous word with the highest similarity, obtain the optimal named entity.

[0053] As an improvement to the above solution, the training method of the prompt set includes:

[0054] Obtain the entity type to be trained, input the entity type to be trained into the word vector model, and obtain the word vector of the entity type to be trained;

[0055] According to the word vector of the entity type to be trained, through cosine distance calculation, obtain several similar words of the entity type to be trained; wherein, the cosine distance between the word vector of the entity type to be trained and the word vectors of the several similar words is less than a preset value;

[0056] According to the entity type to be trained and the several similar words, design several candidate prompts;

[0057] Respectively test the verification indexes of the several candidate prompts, and obtain the prompt set according to the candidate prompts whose verification indexes reach the preset value.

[0058] As an improvement to the above solution, the training method of the synonym set includes:

[0059] Obtain a naming dictionary; wherein, the naming dictionary is constructed from open-source data;

[0060] According to each original word in the naming dictionary, through the word vector model, obtain the similar words of each original word;

[0061] Respectively test the verification indexes of the similar words of each original word, and use the similar words whose verification indexes reach the preset value as the synonymous words of each original word;

[0062] Summarize each original word and the corresponding synonymous words to obtain the synonym set.

[0063] As an improvement to the above solution, the training method of the word vector model includes:

[0064] Obtain a named entity dictionary; wherein, the named entity dictionary is constructed from open-source data;

[0065] Input all the words in the named entity dictionary into the pre-trained model respectively to obtain the high-dimensional vectors of each word;

[0066] Obtain the word vectors of each word according to the high-dimensional vectors of each word.

[0067] As an improvement to the above solution, inputting the sentence to be measured and the prompt into the pre-trained model to obtain the generative named entity of the sentence to be measured specifically includes:

[0068] The prompt includes several alternative prompts;

[0069] Combine the sentence to be measured with the several alternative prompts respectively to obtain several concatenated sentences;

[0070] Input the several concatenated sentences into the pre-trained model respectively to obtain several candidate named entities;

[0071] Calculate the coincidence degree among the several candidate named entities, and output the candidate named entity with the highest coincidence degree as the generative named entity.

[0072] Correspondingly, an embodiment of the present invention further provides a computer terminal device, including a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor. When the processor executes the computer program, it implements a prompt-based named entity recognition method as described in the present invention.

[0073] Correspondingly, an embodiment of the present invention further provides a computer-readable storage medium. The computer-readable storage medium includes a stored computer program. When the computer program runs, it controls the device where the computer-readable storage medium is located to execute a prompt-based named entity recognition method as described in the present invention. Description of the Drawings

[0074] Figure 1 is a flowchart of a prompt-based named entity recognition method provided by an embodiment of the present invention;

[0075] Figure 2 is a structural diagram of a prompt-based named entity recognition device provided by an embodiment of the present invention;

[0076] Figure 3 is a structural diagram of a terminal device provided by an embodiment of the present invention. Detailed implementation manners

[0077] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.

[0078] Embodiment 1

[0079] See Figure 1 , Figure 1 which is a schematic flowchart of a named entity recognition method based on prompts provided by an embodiment of the present invention. As Figure 1 shown, this embodiment includes steps 101 to 103, and the specific steps are as follows:

[0080] Step 101: Obtain the sentence to be tested.

[0081] In this embodiment, the sentence to be tested can be "Welcome to Guangzhou", "My name is Xiaoming", etc., and the user inputs the sentence to be tested into the method adopted in this embodiment.

[0082] Step 102: Obtain the prompt for the sentence to be tested according to the preset prompt set.

[0083] In this embodiment, to better illustrate the use of the Prompt Space (prompt set), please refer to the following example: When the sentence to be tested input to the pre-trained model is "Welcome to Guangzhou", the pre-trained generative model may recognize the named entity as "Thank you", resulting in an error in the recognition result; input "Welcome to Guangzhou" into the PromptSpace, and the generated Prompt (prompt) is "What are the place names among them". Since the pre-trained model has learned a large amount of corpus and can understand the meaning of the Prompt, the sentence to be tested and the Prompt are combined into "Welcome to Guangzhou, what are the place names among them", and at this time the named entity is recognized as "Guangzhou".

[0084] In this embodiment, the training method of the prompt set includes:

[0085] Obtain the entity type to be trained, input the entity type to be trained into the word vector model, and obtain the word vector of the entity type to be trained;

[0086] According to the word vector of the entity type to be trained, calculate through cosine distance to obtain several similar words of the entity type to be trained; wherein, the cosine distance between the word vector of the entity type to be trained and the word vectors of the several similar words is less than a preset value;

[0087] Design a number of candidate prompts according to the entity type to be trained and the number of similar words.

[0088] Test the verification metrics of the number of candidate prompts respectively, and obtain the prompt set according to the candidate prompts whose verification metrics reach the preset value.

[0089] In a specific embodiment, design a Prompt Space (prompt set), and design corresponding Prompts (prompts). For example, for "Guangzhou", since "Guangzhou" is a place name (entity type), the Prompt can be "What are the place names among them"; for "Xiaoming", since Xiaoming is a person name (entity type), the Prompt can be "What are the person names among them"; the specific design steps are as follows:

[0090] Determine an entity type; if the entity type is "place name", obtain the word vector of "place name" through a word vector model.

[0091] Calculate and obtain similar words of the entity type through a preset cosine distance (when the cosine distance between the word vector of the similar word and the word vector of the entity type is the preset value, it means a high similarity); for example, the similar words of "place name" are "location", "site", etc. (the setting value of the cosine distance is determined according to the user's test scenario).

[0092] Design the entity type and similar words into candidate prompts; for example, according to "place name", "location", "site", design candidate prompts such as "What are the locations", "What are the sites", "What places are there", etc.

[0093] Obtain the f1 value (verification metric) in the named entity recognition field of each candidate prompt through testing with a validation set, and select the candidate prompts with f1 values reaching the preset value as prompts for application.

[0094] In a specific embodiment, train the prompt set through a training set, a validation set, and a test set.

[0095] Step 103: Input the to-be-tested statement and the prompt into a pre-trained model to obtain the generative named entity of the to-be-tested statement.

[0096] In this embodiment, the inputting the to-be-tested statement and the prompt into a pre-trained model to obtain the generative named entity of the to-be-tested statement is specifically as follows:

[0097] The prompt includes a number of alternative prompts.

[0098] Combine the to-be-tested statement with each of the several alternative prompts respectively to obtain several concatenated statements;

[0099] Input each of the several concatenated statements into a pre-trained model to obtain several candidate named entities;

[0100] Calculate the coincidence degree among the several candidate named entities, and output the candidate named entity with the highest coincidence degree as the generated named entity.

[0101] In a specific embodiment, in order to enhance the effect of named entity recognition, an inference strategy of Prompt Ensemble is introduced to jointly determine a named entity by multiple different Prompts (prompts): multiple Prompts (such as "What are the place names among them", "What are the places among them", and "What are the locations among them") pre-trained according to the Prompt Space (prompt set) are respectively concatenated with the to-be-tested statement (such as "Welcome to Guangzhou What are the place names among them", "Welcome to Guangzhou What are the places among them", and "Welcome to Guangzhou What are the locations among them"), and input into the pre-trained model. The candidate named entities ("Guangzhou", "Guangzhou", and "Welcome") are obtained by output. Calculate the coincidence degree (the coincidence degree of "Guangzhou" is the highest among the three candidate named entities), and output the one with the highest coincidence degree as the named entity (output "Guangzhou").

[0102] In this embodiment, after obtaining the generated named entity of the to-be-tested statement, it further includes:

[0103] Map the generated named entity through a preset synonym set to obtain several synonymous words of the generated named entity;

[0104] Match each of the several synonymous words with the to-be-tested statement respectively to obtain the optimal named entity.

[0105] In this embodiment, the method for matching each of the several synonymous words with the to-be-tested statement to obtain the optimal named entity specifically is:

[0106] Match each of the several synonymous words with each statement of the to-be-tested statement respectively to obtain the similarity;

[0107] Obtain the optimal named entity according to the synonymous word with the highest similarity.

[0108] In this embodiment, the training method of the synonym set includes:

[0109] Obtain a naming dictionary; wherein, the naming dictionary is constructed from open-source data;

[0110] For each original word in the named dictionary, obtain similar words for each of the original words through a word vector model;

[0111] Test the verification metrics of the similar words of each of the original words respectively, and use the similar words whose verification metrics reach the preset value as the synonymous words for each of the original words;

[0112] Summarize each of the original words and the corresponding synonymous words to obtain the synonym set.

[0113] In a specific embodiment, to better illustrate the training method of the synonym set, the following example is given for illustration:

[0114] According to each word in the named dictionary, calculate the word vector of each word through Answer Space (a set of word vectors), and thus obtain similar words through the cosine distance between the word vectors; for example, the similar words of "Guangzhou" are: "Yangcheng", "Capital of Guangdong Province", and "Zhujiang New Town";

[0115] Obtain the f1 value (verification metric) in the named entity recognition field of each similar word through testing with the validation set, and screen out the similar words whose f1 value does not reach the preset value. After screening, the similar words of "Guangzhou" are: "Yangcheng" and "Capital of Guangdong Province".

[0116] In a specific embodiment, to better illustrate the application of the synonym combination, please refer to the following example:

[0117] When combining the sentence to be tested and the Prompt as "Welcome to Guangzhou, where are the place names", and inputting it into the pre-trained model, at this time, the named entity may be recognized as "Yangcheng", then obtain the similar words "Guangzhou" and "Capital of Guangdong Province" through Answer Space; since "Guangzhou" appears in the sentence to be tested "Welcome to Guangzhou", therefore, "Guangzhou" is the similar word with the highest similarity to the sentence to be tested "Welcome to Guangzhou", and the named entity is adjusted to "Guangzhou" through Answer Space.

[0118] In a specific embodiment, the training of the synonym set is carried out through a training set, a validation set, and a test set.

[0119] The training method of the word vector model includes:

[0120] Obtain the named dictionary; wherein, the named dictionary is constructed from open-source data;

[0121] According to all the words in the named dictionary, input them into the pre-trained model respectively to obtain the high-dimensional vectors of each word;

[0122] According to the high-dimensional vectors of each word, obtain the word vectors of each word.

[0123] In a specific embodiment, the pre-trained model adopts a generative model. Since the vertical fields of this embodiment are mostly Chinese scenes, the open source bart-base-chinese model is selected as the backbone network of the generative model;

[0124] In a specific embodiment, a word vector is a form of text expression. By mapping discrete text into a high-dimensional vector space, operations such as text similarity and text feature conversion can be performed in the high-dimensional vector space. For example, the word "company" can be mapped to a high-dimensional vector "12.25, 23.57, -52.11, ..."

[0125] In a specific embodiment, the training method of the word vector model is specifically: constructing a naming dictionary through open source data;

[0126] Map each word in the naming dictionary through the pre-trained model to obtain the hidden states (high-dimensional vector) of each word;

[0127] Take the mean of the hidden states of each word to obtain the word vector of each word. For example, "place" will be segmented into "place", and the model will only output one hidden state. For example, "artificial intelligence" will be segmented into "artificial" and "intelligence", and the model will output two hidden states, so the mean needs to be taken.

[0128] This embodiment generates a prompt for the sentence to be tested through a prompt set, combines the prompt and the sentence to be tested, and inputs them into a pre-trained model for named entity recognition. Through the combination of prompts, the potential semantic ability of the pre-trained model is fully explored, reducing the dependence of named entity recognition on data, which is conducive to improving the efficiency of named entity recognition. This embodiment also increases the search range of named entities through a synonym set, thereby improving the accuracy of named entities. This embodiment performs reasoning through multiple prompts, thereby improving the accuracy and generalization of named entity recognition of the sentence to be tested.

[0129] Embodiment 2

[0130] See also Figure 2 , Figure 2 2 is a schematic diagram of a structure of a prompt-based named entity recognition device provided by an embodiment of the present invention, comprising: a data acquisition module 201, a prompt acquisition module 202 and a data generation module 203;

[0131] The data acquisition module 201 is used to acquire the sentence to be tested;

[0132] The prompt obtaining module 202 is configured to obtain a prompt for the to-be-tested statement according to a preset prompt set;

[0133] The data generation module 203 is configured to input the to-be-tested statement and the prompt into a pre-trained model to obtain a generative named entity of the to-be-tested statement.

[0134] As an improvement to the above solution, after obtaining the generative named entity of the to-be-tested statement, it further includes: a data matching module 204;

[0135] The data matching module 204 is configured to map the generative named entity through a preset synonym set to obtain several synonymous words of the generative named entity;

[0136] Match each of the several synonymous words with the to-be-tested statement respectively to obtain an optimal named entity.

[0137] As an improvement to the above solution, the matching of the several synonymous words with the to-be-tested statement to obtain an optimal named entity is specifically:

[0138] Match each of the several synonymous words with each statement of the to-be-tested statement respectively to obtain a similarity;

[0139] Obtain the optimal named entity according to the synonymous word with the highest similarity.

[0140] As an improvement to the above solution, the training method of the prompt set includes:

[0141] Obtain a to-be-trained entity type, input the to-be-trained entity type into a word vector model to obtain a word vector of the to-be-trained entity type;

[0142] According to the word vector of the to-be-trained entity type, calculate through cosine distance to obtain several similar words of the to-be-trained entity type; wherein, the cosine distance between the word vector of the to-be-trained entity type and the word vectors of the several similar words is less than a preset value;

[0143] Design several candidate prompts according to the to-be-trained entity type and the several similar words;

[0144] Test the verification indexes of the several candidate prompts respectively, and obtain the prompt set according to the candidate prompts whose verification indexes reach the preset value.

[0145] As an improvement to the above solution, the training method of the synonym set includes:

[0146] Obtain a naming dictionary; wherein, the naming dictionary is constructed from open-source data;

[0147] For each original word in the named dictionary, obtain similar words for each of the original words through a word vector model;

[0148] Test the verification metrics of the similar words of each of the original words respectively, and use the similar words whose verification metrics reach the preset value as the synonymous words of each of the original words;

[0149] Summarize each of the original words and the corresponding synonymous words to obtain the synonym set.

[0150] As an improvement to the above solution, the training method of the word vector model includes:

[0151] Obtain a named dictionary; wherein, the named dictionary is constructed from open-source data;

[0152] Input all the words in the named dictionary into a pre-trained model respectively to obtain high-dimensional vectors for each word;

[0153] Obtain the word vectors for each word according to the high-dimensional vectors of each word.

[0154] As an improvement to the above solution, when inputting the to-be-tested statement and the prompt into the pre-trained model to obtain the generative named entity of the to-be-tested statement, specifically:

[0155] The prompt includes several alternative prompts;

[0156] Combine the to-be-tested statement with the several alternative prompts respectively to obtain several concatenated statements;

[0157] Input the several concatenated statements into the pre-trained model respectively to obtain several candidate named entities;

[0158] Calculate the coincidence degree among the several candidate named entities, and output the candidate named entity with the highest coincidence degree as the generative named entity.

[0159] In this embodiment, the to-be-tested statement is obtained through the data acquisition module and input into the prompt acquisition module to obtain the prompt. The data generation module combines the to-be-tested statement and the prompt to obtain the generative named entity. The efficiency of named entity recognition is improved by the combination of the prompts, and matching is performed through the data matching module, thereby improving the accuracy of the named entity; by using the prompts in this embodiment, the amount of data required for named entity recognition can be reduced, which is beneficial to reducing the dependence on hardware resources and the consumption of computing resources by the named entity.

[0160] Embodiment III

[0161] See Figure 3 ,Figure 3 It is a schematic structural diagram of a terminal device provided by an embodiment of the present invention.

[0162] A terminal device in this embodiment includes: a processor 301, a memory 302, and a computer program stored in the memory 302 and executable on the processor 301. When the processor 301 executes the computer program, it implements the steps of the above-mentioned various hint-based named entity recognition methods in the embodiment, such as Figure 1 All steps of the hint-based named entity recognition method shown. Alternatively, when the processor executes the computer program, it implements the functions of each module in the above-mentioned device embodiments, such as: Figure 2 All modules of the hint-based named entity recognition device shown.

[0163] In addition, an embodiment of the present invention also provides a computer-readable storage medium, which includes a stored computer program. When the computer program runs, it controls the device where the computer-readable storage medium is located to execute the hint-based named entity recognition method described in any of the above embodiments.

[0164] Those skilled in the art can understand that the schematic diagram is only an example of the terminal device, and does not constitute a limitation on the terminal device. It may include more or fewer components than shown, or combine some components, or different components. For example, the terminal device may also include input / output devices, network access devices, buses, etc.

[0165] The so-called processor 301 may be a central processing unit (CPU), or may also be other general-purpose processors, digital signal processors (DSPs), application specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor, or the processor may also be any conventional processor, etc. The processor 301 is the control center of the terminal device, and connects various parts of the entire terminal device through various interfaces and lines.

[0166] The memory 302 can be used to store the computer programs and / or modules. By running or executing the computer programs and / or modules stored in the memory, and by invoking the data stored in the memory 302, the processor 301 realizes various functions of the terminal device. The memory 302 may mainly include a program storage area and a data storage area. Among them, the program storage area may store an operating system, application programs required for at least one function (such as a sound playback function, an image playback function, etc.); the data storage area may store data created according to the use of the mobile phone (such as audio data, phone book, etc.). In addition, the memory may include a high-speed random access memory, and may also include a non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) card, a Flash Card, at least one magnetic disk storage device, a flash memory device, or other volatile solid-state storage devices.

[0167] Among them, if the modules / units integrated in the terminal device are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on such an understanding, to implement all or part of the processes in the above method embodiments of the present invention, it can also be completed by instructing relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium. When the computer program is executed by a processor, the steps of the above method embodiments can be realized. Among them, the computer program includes computer program code, and the computer program code can be in the form of source code, object code, an executable file, or some intermediate form, etc. The computer-readable medium may include: any entity or device capable of carrying the computer program code, a recording medium, a USB flash drive, a mobile hard disk, a magnetic disk, an optical disc, a computer memory, a read-only memory (ROM), a random access memory (RAM), an electrical carrier signal, a telecommunication signal, and a software distribution medium, etc.

[0168] It should be noted that the device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed to multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment. In addition, in the attached drawings of the device embodiments provided by the present invention, the connection relationships between the modules indicate that there is a communication connection between them, which can be specifically implemented as one or more communication buses or signal lines. Those of ordinary skill in the art can understand and implement it without creative efforts.

[0169] The above is the preferred implementation manner of the present invention. It should be pointed out that for those of ordinary skill in the art in the technical field, without departing from the principle of the present invention, several improvements and refinements can still be made, and these improvements and refinements are also regarded as the protection scope of the present invention.

Claims

1. A prompt-based named entity recognition method, characterized in that, it includes: Obtain the sentence to be tested; According to the preset set of prompt words, obtain the prompt words of the sentence to be tested; Input the sentence to be tested and the prompt words into a pre-trained model to obtain the generative named entity of the sentence to be tested; After obtaining the generative named entity of the sentence to be tested, it further includes: Map the generative named entity through a preset set of synonyms to obtain several synonymous words of the generative named entity; Match each of the several synonymous words with the sentence to be tested respectively to obtain the optimal named entity; Among them, the training method of the set of prompt words includes: obtaining the entity type to be trained, inputting the entity type to be trained into a word vector model to obtain the word vector of the entity type to be trained; according to the word vector of the entity type to be trained, through cosine distance calculation, obtain several similar words of the entity type to be trained; wherein, the cosine distance between the word vector of the entity type to be trained and the word vectors of the several similar words is less than a preset value; according to the entity type to be trained and the several similar words, design several candidate prompt words; respectively test the verification indexes of the several candidate prompt words, and obtain the set of prompt words according to the candidate prompt words whose verification indexes reach the preset value; the training method of the set of synonyms includes: obtaining a named entity dictionary; wherein, the named entity dictionary is constructed from open-source data; according to each original word in the named entity dictionary, through a word vector model, obtain the similar words of each original word; respectively test the verification indexes of the similar words of each original word, and use the similar words whose verification indexes reach the preset value as the synonymous words of each original word; summarize each original word and the corresponding synonymous words to obtain the set of synonyms.

2. The prompt-based named entity recognition method according to claim 1, characterized in that, The matching of the several synonymous words with the sentence to be tested to obtain the optimal named entity is specifically: Match each of the several synonymous words with each sentence of the sentence to be tested respectively to obtain the similarity; Obtain the optimal named entity according to the synonymous word with the highest similarity.

3. The prompt-based named entity recognition method according to claim 2, characterized in that, The training method of the word vector model includes: Obtain a named entity dictionary; wherein, the named entity dictionary is constructed from open-source data; Input all the words in the named entity dictionary into a pre-trained model respectively to obtain the high-dimensional vectors of each word; Obtain the word vectors of each word according to the high-dimensional vectors of each word.

4. The prompt-based named entity recognition method according to claim 1, characterized in that, The inputting of the sentence to be tested and the prompt words into a pre-trained model to obtain the generative named entity of the sentence to be tested is specifically: The prompt words include several candidate prompt words; Mutually combine the sentence to be tested with the several candidate prompt words respectively to obtain several spliced sentences; Input the several splicing statements into a pre-trained model respectively to obtain several candidate named entities; Calculate the coincidence degree among the several candidate named entities, and output the candidate named entity with the highest coincidence degree as the generated named entity.

5. A prompting-based named entity recognition device, characterized in that, it includes: a data acquisition module, a prompting phrase acquisition module, and a data generation module; The data acquisition module is used to acquire the statement to be tested; The prompting phrase acquisition module is used to obtain the prompting phrase of the statement to be tested according to a preset set of prompting phrases; The data generation module is used to input the statement to be tested and the prompting phrase into a pre-trained model to obtain the generated named entity of the statement to be tested; After obtaining the generated named entity of the statement to be tested, it further includes: Map the generated named entity through a preset set of synonyms to obtain several synonymous words of the generated named entity; Match each of the several synonymous words with the statement to be tested respectively to obtain the optimal named entity; Among them, the training method of the set of prompting phrases includes: obtaining the entity type to be trained, inputting the entity type to be trained into a word vector model to obtain the word vector of the entity type to be trained; calculating through cosine distance according to the word vector of the entity type to be trained to obtain several similar words of the entity type to be trained; wherein, the cosine distance between the word vector of the entity type to be trained and the word vectors of the several similar words is less than a preset value; designing several candidate prompting phrases according to the entity type to be trained and the several similar words; respectively testing the verification indexes of the several candidate prompting phrases, and obtaining the set of prompting phrases according to the candidate prompting phrases whose verification indexes reach the preset value; the training method of the set of synonyms includes: obtaining a naming dictionary; wherein, the naming dictionary is constructed from open-source data; obtaining the similar words of each original word in the naming dictionary through a word vector model; respectively testing the verification indexes of the similar words of each original word, and using the similar words whose verification indexes reach the preset value as the synonymous words of each original word; summarizing each original word and the corresponding synonymous words to obtain the set of synonyms.

6. A computer terminal device, characterized in that, it includes a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor. When the processor executes the computer program, it implements a prompting-based named entity recognition method according to any one of claims 1 to 4.

7. A computer-readable storage medium, characterized in that, the computer-readable storage medium includes a stored computer program, wherein when the computer program runs, it controls the device where the computer-readable storage medium is located to execute a prompting-based named entity recognition method according to any one of claims 1 to 4.

Citation Information

Patent Citations

  • Entity information processing method and device, electronic equipment and medium

    CN114254642A