Target word determination method and device, electronic equipment, computer program product and computer readable storage medium
By constructing and analyzing the probability distribution of the text processing model, the prediction bias problem in the text processing model training phase was identified and solved, ensuring the accuracy of the model prediction.
Patent Information
- Application Number
- CN202410275154.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-11
- Publication Date
- 2025-09-16
AI Technical Summary
Existing text processing models suffer from prediction bias during the training phase and are unable to effectively identify words that cause prediction bias.
A text processing model is used to perform text prediction on multiple first text samples, obtain a first probability distribution of each sample, construct a second text sample including a target word, and combine the probability distributions of the first and second text samples to determine the deviation result of the target word and identify the word that causes the prediction deviation.
It achieves accurate identification of words that cause prediction bias during the text processing model training phase, and provides a solution to avoid the occurrence of prediction bias.
Smart Images

Figure CN120654686A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence technology, and in particular to a method, device, electronic device, computer program product, and computer-readable storage medium for determining a target word. Background Art
[0002] With the development of artificial intelligence technology, text processing models have greatly facilitated people's lives. However, during the training stage of the text processing model, there are words in the samples of the trained text processing model that cause the text processing model to produce prediction deviations, which will lead to a decrease in the prediction effect of the text processing model. The relevant technology cannot obtain the words that cause the text processing model to produce prediction deviations. Summary of the Invention
[0003] The embodiments of the present application provide a method, device, electronic device, computer program product, and computer-readable storage medium for determining target words, which can obtain words that cause prediction deviations in text processing models, and provide a solution to avoid prediction deviations in text processing models.
[0004] The technical solution of the embodiment of the present application is implemented as follows:
[0005] This embodiment of the present application provides a method for determining a target word, the method comprising:
[0006] Performing text prediction on the plurality of first text samples respectively by using a text processing model to obtain a first probability distribution corresponding to each of the first text samples;
[0007] Based on each of the first probability distributions and the plurality of first text samples, construct at least one second text sample including a target word; wherein the target word is a word whose word frequency in the plurality of first text samples meets a preset condition;
[0008] Performing text prediction on each of the second text samples using the text processing model to obtain a second probability distribution corresponding to each of the second text samples;
[0009] Combining the first probability distribution corresponding to the first text sample and the second probability distribution corresponding to the second text sample, a deviation result of the target word is determined; wherein the deviation result is used to characterize the prediction deviation of the text processing model.
[0010] This embodiment of the present application provides a device for determining a target word, the device comprising:
[0011] A prediction module, configured to perform text prediction on each of the plurality of first text samples using a text processing model to obtain a first probability distribution corresponding to each of the first text samples;
[0012] A construction module, configured to construct at least one second text sample including a target word based on each of the first probability distributions and the plurality of first text samples; wherein the target word is a word in the plurality of first text samples whose word frequency satisfies a preset condition;
[0013] The prediction module is further configured to perform text prediction on each of the second text samples using the text processing model to obtain a second probability distribution corresponding to each of the second text samples;
[0014] A determination module is used to determine the deviation result of the target word by combining the first probability distribution corresponding to the first text sample and the second probability distribution corresponding to the second text sample; wherein the deviation result is used to characterize the prediction deviation of the text processing model.
[0015] In the above scheme, the construction module is also used to group the multiple first text samples based on each of the first probability distributions to obtain a first sample group and a second sample group; wherein the uncertainty of the first text sample in the first sample group is greater than the uncertainty of the first text sample in the second sample group; select at least one target word from the second sample group; and construct at least one second text sample based on the target word and the first sample group.
[0016] In the above scheme, the construction module is also used to obtain the entropy of each first probability distribution; for each first probability distribution, compare the entropy of the first probability distribution with the entropy threshold; if the entropy of the first probability distribution is greater than the entropy threshold, divide the first text sample corresponding to the first probability distribution into the first sample group; if the entropy of the first probability distribution is less than or equal to the entropy threshold, divide the first text sample corresponding to the first probability distribution into the second sample group.
[0017] In the above scheme, the construction module is also used to cluster the first text sample in the second sample group to obtain one or more sample clusters; obtain the word frequency of each word in each of the sample clusters; and select at least one word whose word frequency reaches the first word frequency threshold from each of the sample clusters as the target word.
[0018] In the above scheme, the construction module is also used to calculate the first difference between the first probability distributions corresponding to any two first text samples in the second sample group; based on the first difference, the first text samples in the second sample group are clustered to obtain one or more sample clusters.
[0019] In the above scheme, the construction module is also used to obtain the number of occurrences of each word in the second sample group; compare the number of occurrences with the number of occurrences threshold; obtain the word frequency of the words whose number of occurrences is greater than the number of occurrences threshold; and select, from the words whose number of occurrences is greater than the number of occurrences threshold, the words whose frequency reaches the first word frequency threshold as the target words.
[0020] In the above scheme, the construction module is also used to perform the following processing for each of the target words: for the second number of first text samples in the first sample group, the target word is inserted into each of the first text samples to obtain the second number of second text samples; wherein the second number is less than or equal to the number of first text samples in the first sample group.
[0021] In the above scheme, the construction module is also used to obtain the number of the first text samples in the first sample group as the third number when the number of the target words is multiple; when the number of the target words is greater than the third number, select the third number of first target words from the multiple target words based on the word frequency of the target words; insert the third number of first target words into each of the first text samples one by one to obtain the third number of second text samples.
[0022] In the above scheme, the construction module is also used to compare the word frequency of the target word with the second word frequency threshold, and the second word frequency threshold is greater than the first word frequency threshold; if there is a target word with a word frequency greater than the second word frequency threshold, the number of target words with a word frequency greater than the second word frequency threshold is obtained as the fourth number, and when the fourth number is greater than or equal to the third number, the first target words of the third number are selected from the target words with a word frequency greater than the second word frequency threshold; if there is no target word with a word frequency greater than the second word frequency threshold, or the fourth number is less than the third number, the multiple target words are sorted in descending order of the word frequency to obtain a target word sequence, and starting from the first target word in the target word sequence, the first target words of the third number are selected.
[0023] In the above scheme, the determination module is also used to determine the target probability distribution from the first probability distributions corresponding to multiple first text samples; calculate the second difference between the first probability distribution corresponding to the first text sample and the target probability distribution; calculate the third difference between the second probability distribution corresponding to the second text sample and the target probability distribution; and determine the deviation result of the target word based on the second difference and the third difference.
[0024] In the above solution, the determination module is further configured to determine the first probability distribution corresponding to any first text sample in the second sample group to which the target word belongs as the target probability distribution.
[0025] In the above solution, the second sample group includes one or more sample clusters obtained by clustering the first text sample in the second sample group, each sample cluster including a central sample. The determination module is further configured to determine the first probability distribution corresponding to the central sample in the second sample group of the target term as the target probability distribution.
[0026] In the above scheme, when the number of the second differences and the number of the third differences are both 1, the determination module is also used to compare the second difference and the third difference; when the second difference is greater than the third difference, the deviation result of the target word is determined to be a first deviation result, and the first deviation result is used to characterize that when the text processing model is trained with a sample containing the target word, the target word causes the text processing model to produce a prediction deviation; when the second difference is less than or equal to the third difference, the deviation result of the target word is determined to be a second deviation result, and the second deviation result is used to characterize that when the text processing model is trained with a sample containing the target word, the target word will not cause the text processing model to produce a prediction deviation.
[0027] In the above solution, when the number of the second differences and the number of the third differences are both plural, the target words corresponding to the second differences and the third differences are consistent, and the second differences and the third differences correspond one to one.
[0028] The determination module is also used to compare the second difference and the third difference with respect to the second difference and the third difference that have a corresponding relationship; count the number of the second differences that are greater than the third difference as the fifth number; obtain the ratio of the fifth number to the number of the second differences; compare the ratio with a preset ratio threshold; when the ratio is greater than the ratio threshold, determine that the deviation result of the target word is a first deviation result, and the first deviation result is used to characterize that when the sample containing the target word is used to train the text processing model, the target word causes the text processing model to produce a prediction deviation; when the ratio is less than or equal to the ratio threshold, determine that the deviation result of the target word is a second deviation result, and the second deviation result is used to characterize that when the sample containing the target word is used to train the text processing model, the target word will not cause the text processing model to produce a prediction deviation.
[0029] An embodiment of the present application provides an electronic device, comprising:
[0030] a memory for storing computer-executable instructions;
[0031] The processor is configured to implement the target word determination method provided in the embodiment of the present application when executing the computer executable instructions stored in the memory.
[0032] An embodiment of the present application provides a computer-readable storage medium storing a computer program or computer-executable instructions for implementing the target word determination method provided in the embodiment of the present application when executed by a processor.
[0033] An embodiment of the present application provides a computer program product, including a computer program or computer-executable instructions. When the computer program or computer-executable instructions are executed by a processor, the method for determining a target word provided in the embodiment of the present application is implemented.
[0034] The embodiments of the present application have the following beneficial effects:
[0035] The target word determination method provided in the embodiment of the present application can obtain a first probability distribution of a first text sample, construct a second text sample including the target word based on the first probability distribution and multiple first text samples, and obtain a second probability distribution of the second text sample, and determine the deviation result of the target word by combining the first probability distribution corresponding to the first text sample and the second probability distribution corresponding to the second text sample. That is, the embodiment of the present application constructs a second text sample including the target word, and then combines the prediction result of the original first text sample and the prediction result of the second text sample including the target word to identify the words that cause the text processing model to produce prediction deviation. In this way, it is achieved that in the training stage of the text processing model, the words that cause the model to produce prediction deviation are accurately identified in the samples used to train the text processing model, providing a solution to avoid the text processing model from producing prediction deviation. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] Figure 1 Schematic diagram of the architecture of a target word determination system provided in an embodiment of the present application;
[0037] Figure 2 is a structural diagram of an electronic device provided in an embodiment of the present application;
[0038] Figure 3 This is a flow chart of the method for determining target words provided in the embodiment of the present application. Figure 1 ;
[0039] Figure 4 This is a flow chart of the method for determining target words provided in the embodiment of the present application. Figure 2 ;
[0040] Figure 5 This is a flow chart of the method for determining target words provided in the embodiment of the present application. Figure 3 ;
[0041] Figure 6 This is a flow chart of the method for determining target words provided in the embodiment of the present application. Figure 4 ;
[0042] Figure 7 This is a flow chart of the method for determining target words provided in the embodiment of the present application. Figure 5 ;
[0043] Figure 8 This is a flow chart of the method for determining target words provided in the embodiment of the present application. Figure 6 ;
[0044] Figure 9 This is a flow chart of the method for determining target words provided in the embodiment of the present application. Figure 7 ;
[0045] Figure 10 Schematic diagram of the process of determining the target word provided in the embodiment of the present application Figure 8 ;
[0046] Figure 11 It is a structural diagram of the text classification model provided in the embodiment of the present application. DETAILED DESCRIPTION
[0047] In order to make the purpose, technical solutions and advantages of this application clearer, the application will be further described in detail below with reference to the accompanying drawings. The described embodiments should not be regarded as limiting this application. All other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0048] In the following description, reference is made to “some embodiments”, which describes a subset of all possible embodiments, but it will be understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.
[0049] In the following description, the terms "first\second\third" involved are merely used to distinguish similar objects and do not represent a specific ordering of the objects. It can be understood that "first\second\third" can be interchanged with a specific order or sequence where permitted, so that the embodiments of the present application described herein can be implemented in an order other than that illustrated or described herein.
[0050] In the embodiments of the present application, the term "module" or "unit" refers to a computer program or a part of a computer program that has a predetermined function and works together with other related parts to achieve a predetermined goal, and can be implemented in whole or in part by using software, hardware (such as processing circuits or memories) or a combination thereof. Similarly, a processor (or multiple processors or memories) can be used to implement one or more modules or units. In addition, each module or unit can be part of an overall module or unit that includes the function of the module or unit.
[0051] Unless otherwise defined, all technical and scientific terms used in the embodiments of the present application have the same meanings as those commonly understood by those skilled in the art. The terms used in the embodiments of the present application are only for the purpose of describing the embodiments of the present application and are not intended to limit the present application.
[0052] The relevant data collection and processing in the embodiments of this application should be strictly in accordance with the requirements of relevant national laws and regulations when applied in examples, and the informed consent or separate consent of the personal information subject should be obtained. Subsequent data use and processing should be carried out within the scope of authorization of laws and regulations and the personal information subject.
[0053] While studying the performance of large language models in contextual learning, the inventors discovered that large language models exhibit a shortcut phenomenon. The following uses a text classification model as an example to describe the process of discovering this shortcut phenomenon. For sample 1, which outputs a text classification result of category a for the training model, a word unrelated to category a is obtained and inserted into a fixed position in sample 1 to obtain sample 2. During the large language model testing process, sample 2 is input as a test sample into the large prediction model to obtain an output result that is not category a, indicating that the large language model exhibits a shortcut phenomenon.
[0054] In order to avoid prediction bias in text processing models, embodiments of the present application provide a method, device, electronic device, computer program product, and computer-readable storage medium for determining target words, which can obtain words in samples that cause prediction bias in text processing models, and can provide a solution to avoid prediction bias in text processing models.
[0055] See also Figure 1 , Figure 1 This is a schematic diagram of the architecture of the target word determination system 100 provided in an embodiment of the present application. To support an exemplary application, the terminal 400 is connected to the server 200 via the network 300. The network 300 can be a wide area network or a local area network, or a combination of the two.
[0056] When a user needs to determine the words that cause the model to produce a prediction deviation, terminal 400 can obtain a target word determination request. Terminal 400 can send the target word determination request to server 200 via network 300. The target word determination request can be obtained by the user clicking a button displayed on graphical interface 410 or by receiving a voice command from the user.
[0057] After receiving the target word determination request, server 200 may obtain a first text sample based on the target word determination request. The target word determination request may include the first text sample and a text processing model identifier. If the target word determination request includes the text processing model identifier, server 200 may determine the first text sample corresponding to the text processing model identifier based on the correspondence between the candidate text processing model identifiers and the candidate first text samples.
[0058] Furthermore, server 200 can perform text prediction on each of the multiple first text samples using a text processing model to obtain a first probability distribution corresponding to each first text sample. Based on each first probability distribution and the multiple first text samples, at least one second text sample including a target word is constructed, where the target word is a word whose frequency in the multiple first text samples meets a preset condition. The text processing model can be used to perform text prediction on each of the second text samples to obtain a second probability distribution corresponding to each second text sample. The deviation result of the target word is determined by combining the first probability distribution corresponding to the first text sample and the second probability distribution corresponding to the second text sample.
[0059] After obtaining the deviation result, the server 200 may send the deviation result to the terminal 400 via the network 300. The terminal 400 is configured to display the deviation result on a graphical interface 410, so that the user can learn about the deviation result.
[0060] In some embodiments, the server 200 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers. It can also be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms.
[0061] The terminal 400 can be various types of user terminals such as a laptop computer, a tablet computer, a desktop computer, a set-top box, a mobile device (for example, a mobile phone, a portable music player, a personal digital assistant, a dedicated messaging device, a portable gaming device), a smart phone, a smart speaker, a smart watch, a smart TV, a car terminal, etc. The terminal 400 and the server 200 can be directly or indirectly connected via wired or wireless communication, which is not limited in the embodiments of the present application.
[0062] See also Figure 2 , Figure 2 is a structural diagram of an electronic device provided in an embodiment of the present application, the electronic device is used to implement the method for determining a target word, and the electronic device may be a terminal or a server. Figure 2 The electronic device shown includes: at least one processor 410, a memory 450, at least one network interface 420 and a user interface 430. The various components in the electronic device are coupled together via a bus system 440. It is understood that the bus system 440 is used to achieve connection and communication between these components. In addition to including a data bus, the bus system 440 also includes a power bus, a control bus and a status signal bus. However, for the sake of clarity, the bus system 440 is not shown in FIG. Figure 2 Various buses are labeled as bus system 440 .
[0063] The processor 410 can be an integrated circuit chip with signal processing capabilities, such as a general-purpose processor, a digital signal processor (DSP), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc., where the general-purpose processor can be a microprocessor or any conventional processor, etc.
[0064] The user interface 430 includes one or more output devices 431 that enable presentation of media content, including one or more speakers and / or one or more visual display screens. The user interface 430 also includes one or more input devices 432, including user interface components that facilitate user input, such as a keyboard, mouse, microphone, touch screen display, camera, other input buttons and controls.
[0065] The memory 450 may be removable, non-removable, or a combination thereof. Exemplary hardware devices include solid-state memory, hard drives, optical drives, etc. The memory 450 may optionally include one or more storage devices that are physically remote from the processor 410.
[0066] The memory 450 includes volatile memory or non-volatile memory, or may include both volatile and non-volatile memory. The non-volatile memory may be a read-only memory (ROM), and the volatile memory may be a random access memory (RAM). The memory 450 described in the embodiments of the present application is intended to include any suitable type of memory.
[0067] In some embodiments, the memory 450 can store data to support various operations, examples of which include programs, modules, and data structures, or a subset or superset thereof, as exemplified below.
[0068] Operating system 451, including system programs for processing various basic system services and performing hardware-related tasks, such as the framework layer, core library layer, and driver layer, which are used to implement various basic services and process hardware-based tasks;
[0069] A network communication module 452 is used to reach other electronic devices via one or more (wired or wireless) network interfaces 420. Exemplary network interfaces 420 include Bluetooth, Wi-Fi, and Universal Serial Bus (USB);
[0070] a presentation module 453 for enabling presentation of information via one or more output devices 431 (e.g., a display screen, a speaker, etc.) associated with the user interface 430 (e.g., a user interface for operating peripheral devices and displaying content and information);
[0071] The input processing module 454 is configured to detect one or more user inputs or interactions from one of the one or more input devices 432 and to translate the detected inputs or interactions.
[0072] In some embodiments, the target word determination device provided in the embodiments of the present application can be implemented in software. Figure 2 Target word determination device 455 stored in memory 450 is shown. This device can be software in the form of a program or plug-in, and includes the following software modules: a prediction module 4551, a construction module 4552, and a determination module 4553. These modules are logical and can be arbitrarily combined or further separated according to the functions they implement. The functions of each module will be described below.
[0073] In other embodiments, the target word determination device provided in the embodiments of the present application can also be implemented in hardware. As an example, the device provided in the embodiments of the present application can be a processor in the form of a hardware decoding processor, which is programmed to execute the target word determination method provided in the embodiments of the present application. For example, the processor in the form of a hardware decoding processor can adopt one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), programmable logic devices (PLDs), complex programmable logic devices (CPLDs), field-programmable gate arrays (FPGAs) or other electronic components.
[0074] The method for determining the target word provided in the embodiment of the present application relates to the field of artificial intelligence (AI). Artificial intelligence is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results. In other words, artificial intelligence is a comprehensive technology in computer science that attempts to understand the essence of intelligence and produce a new intelligent machine that can respond in a similar way to human intelligence. Artificial intelligence is to study the design principles and implementation methods of various intelligent machines so that machines have the functions of perception, reasoning and decision-making.
[0075] Artificial intelligence (AI) is a comprehensive discipline encompassing a wide range of fields, encompassing both hardware and software technologies. Foundational AI technologies generally include sensors, specialized AI chips, cloud computing, distributed storage, big data processing, pre-trained models, operating / interaction systems, and mechatronics. Pre-trained models, also known as large models or foundational models, can, after fine-tuning, be widely applied to downstream tasks across various AI domains.
[0076] The model involved in the embodiments of the present application can be a natural language processing model. Natural language processing is an important direction in the fields of computer science and artificial intelligence. It studies various theories and methods that can enable effective communication between people and computers using natural language. Natural language processing involves natural language, that is, the language people use in daily life, and is closely related to linguistic research; it also involves important technologies for model training in the fields of computer science and mathematical artificial intelligence, and pre-training models, that is, developed from large language models (Large Language Model) in the field of natural language processing. After fine-tuning, large language models can be widely used in downstream tasks. Natural language processing technology generally includes text processing, semantic understanding, machine translation, robot question answering, knowledge graphs and other technologies.
[0077] The model involved in the embodiments of this application is a pre-training model (PTM), also known as a cornerstone model or a large model. It refers to a deep neural network (DNN) with a large number of parameters. It is trained on massive amounts of unlabeled data. The function approximation capability of the large-parameter DNN is used to enable the PTM to extract common features from the data. Through fine tuning, efficient parameter fine tuning (PEFT), prompt-tuning and other techniques, it is suitable for downstream tasks. Therefore, the pre-training model can achieve ideal results in few-shot or zero-shot scenarios.
[0078] The following describes the target word determination method provided by the embodiment of the present application. As previously mentioned, the electronic device implementing the target word determination method of the embodiment of the present application can be a terminal, a server, or a combination of the two. Therefore, the execution entity of each step will not be repeated below.
[0079] Next, the method for determining the target word provided in the embodiment of the present application is described by taking the server implementing the method as an example. Figure 3 , Figure 3 This is a flow chart of the method for determining target words provided in the embodiment of the present application. Figure 1 , combined with Figure 3 The steps shown illustrate the method for determining the target word provided in the embodiment of the present application.
[0080] In step 101, text prediction is performed on a plurality of first text samples respectively through a text processing model to obtain a first probability distribution corresponding to each first text sample.
[0081] In order to obtain words that cause prediction deviations in the text processing model, the pre-trained text processing model can be used to perform text prediction on multiple first text samples to obtain a first probability distribution corresponding to each first text sample.
[0082] The number of the first text samples can be set according to actual usage requirements. The text processing model can be a natural language processing model, specifically a text classification model, a named entity recognition model, a language translation model, a sentiment analysis model, etc.
[0083] The structure of a text processing model varies depending on the function it performs. For example, if the text processing model is a text classification model, the text classification model may be composed of an embedding layer, an encoding layer, and a fully connected layer. For each first text sample, the embedding layer maps each word in the first text sample to a word vector. The encoding layer extracts features from the word vector to obtain semantic information and contextual information. The fully connected layer maps the first text sample to a first probability distribution based on the semantic information and contextual information. The first probability distribution includes probability values for the first text sample belonging to each category. The category with the highest probability value in the first probability distribution is the category corresponding to the first text sample.
[0084] For another example, when the text processing model is a language translation model, the language translation model may include an encoding layer and a decoding layer. The language corresponding to the first text sample is the source language. The encoding layer can map the first text sample to a vector, and obtain context information through the vector. The decoding layer is used to map the first text vector to a first probability distribution based on the context information. The first probability distribution is a probability distribution of mapping the source language to the target language, so that the first text sample can be translated into the target language.
[0085] In some embodiments, the first text sample is used for in-context learning of a text processing model. The following introduces the method for constructing the first text sample, obtaining multiple demonstration samples (demonstration) and multiple verification samples (validation). Each demonstration sample includes text and a label, and the verification sample only includes text.
[0086] For each demonstration sample, the demonstration sample is combined with each verification sample to construct a first text sample. The number of first text samples constructed for each demonstration sample is the same as the number of verification samples. The number of first text samples is the number of demonstration samples multiplied by the number of verification samples.
[0087] For example, to obtain multiple demonstration samples, one demonstration sample can be represented by xd, and multiple demonstration samples can be represented by Dd, where xd∈Dd; to obtain multiple verification samples, one verification sample can be represented by xv, and multiple verification samples can be represented by Dv, where xv∈Dv.
[0088] Assume that Dd includes xd1, xd2 and xd3, and Dv includes xv1 and xv2. For xd1, xd1 can be combined with xv1 and xv2 to form the first text sample. For xd2, xd2 can be combined with xv1 and xv2 to form the first text sample. For xd3, xd3 can be combined with xv1 and xv2 to form the first text sample. In this way, 6 first text samples can be obtained, namely (xd1, xv1), (xd1, xv2), (xd2, xv1), (xd2, xv2), (xd3, xv1) and (xd3, xv2).
[0089] In some embodiments, the first text sample is constructed based on the demonstration sample and the verification sample by, for each demonstration sample, concatenating the demonstration sample with each verification sample, and adding a separator between the demonstration sample and each verification sample to form the first text sample.
[0090] For example, the demonstration sample is xd4, and the verification sample is xv3. Concatenate xd4 and xv3, and add symbol 1 (i.e., separator) in the form of [symbol 1] between xd4 and xv3. The first text sample is "xd4 [symbol 1] xv3".
[0091] In some embodiments, when the first text sample is used for context learning of a text processing model, the first prediction distribution may represent a prediction result of a verification sample corresponding to the demonstration sample given the demonstration sample.
[0092] Through step 101 , the first probability distribution of each first text sample can be accurately obtained.
[0093] In step 102 , at least one second text sample including a target word is constructed based on each first probability distribution and a plurality of first text samples.
[0094] In some embodiments, see Figure 4 , Figure 4 This is a flow chart of the method for determining target words provided in the embodiment of the present application. Figure 2 , Figure 3 The illustrated step 102 can be implemented by following steps 1021 to 1023 , which are described in detail below.
[0095] In step 1021 , a plurality of first text samples are grouped based on the first probability distributions to obtain a first sample group and a second sample group.
[0096] In some embodiments, see Figure 5 , Figure 5 This is a flow chart of the method for determining target words provided in the embodiment of the present application. Figure 3 , Figure 4 The illustrated step 1021 can be implemented by following steps 10211 to 10214, which are described in detail below.
[0097] In step 10211, the entropy of each first probability distribution is obtained.
[0098] Entropy measures the uncertainty of a random variable. Depending on the function performed by a text processing model, the random variable may be different. For example, in a text classification model, the random variable may be the category corresponding to the first probability distribution. Another example is in a translation model, where the random variable may be the word corresponding to the target language.
[0099] In some embodiments, the entropy of each first probability distribution can be calculated by formula (1), where H(p(x) dv ) is the entropy of the first probability distribution, p(x) dv is the first probability distribution.
[0100] H(p(x) dv )=-∑[p(x) dv *log(p(x) dv )] (1)
[0101] Through step 10211, the entropy of each first probability distribution can be obtained, which is equivalent to obtaining the uncertainty of predicting each first text sample through the text processing model.
[0102] In step 10212, for each first probability distribution, the entropy of the first probability distribution is compared with the entropy threshold. In step 10213, if the entropy of the first probability distribution is greater than the entropy threshold, the first text sample corresponding to the first probability distribution is assigned to the first sample group. In step 10214, if the entropy of the first probability distribution is less than or equal to the entropy threshold, the first text sample corresponding to the first probability distribution is assigned to the second sample group.
[0103] After obtaining the entropy of each first probability distribution, the entropy of the first probability distribution can be compared with a preset entropy threshold, where the entropy threshold can be set based on actual usage requirements. If the entropy of the first probability distribution is greater than the entropy threshold, it indicates that the uncertainty of the prediction of the first text sample by the text processing model is large. Therefore, the first text sample corresponding to the first probability distribution can be classified into the first sample group.
[0104] If the entropy of the first probability distribution is less than or equal to the entropy threshold, it indicates that the uncertainty of the prediction of the first text sample by the text processing model is small. Therefore, the first text sample corresponding to the first probability distribution can be classified into the second sample group. The uncertainty of the first text sample in the first sample group is greater than the uncertainty of the first text sample in the second sample group.
[0105] Through steps 10211 to 10214 , the first text sample can be accurately divided based on the entropy of the first probability distribution and the entropy threshold, thereby obtaining an accurate first sample group and a second sample group.
[0106] Continue to see Figure 4 In step 1022, at least one target word is selected from the second sample group.
[0107] In some embodiments, see Figure 6 , Figure 6 This is a flow chart of the method for determining target words provided in the embodiment of the present application. Figure 4 , Figure 4 The illustrated step 1022 can be implemented by following steps 10221A to 10223A, which are described in detail below.
[0108] In step 10221A, the first text sample in the second sample group is clustered to obtain one or more sample clusters.
[0109] In some embodiments, step 10221A may be implemented by calculating, for any two first text samples in the second sample group, a first difference between first probability distributions corresponding to any two first text samples.
[0110] In some embodiments, a KL distance (Kullback-Leibler Divergence) between the first probability distributions corresponding to any two first text samples may be calculated, and the KL distance between the first probability distributions corresponding to any two first text samples may be used as the first difference.
[0111] The KL distance, also known as the Kullback-Leibler difference or relative entropy, measures the difference between two probability distributions in the same event space. Its physical meaning is: in the same event space, if each event corresponding to the probability distribution p(x) is encoded using the probability distribution q(x), the average increase in the encoding length of each basic event (symbol) is expressed in bits.
[0112] Wherein, p(x) is the first probability distribution corresponding to one of any two first text samples, q(x) is the first probability distribution corresponding to the other of any two first text samples, the first difference can be calculated using formula (2), and KL(p||q) is the first difference.
[0113] KL(p||q)=∑[p(x)*log(p(x) / q(x))] (2)
[0114] In some embodiments, the cross entropy between the first probability distributions corresponding to any two first text samples may be calculated, and the cross entropy between the first probability distributions corresponding to any two first text samples may be used as the first difference.
[0115] In some embodiments, the Wasserstein distance between the first probability distributions corresponding to any two first text samples may be calculated, and the Wasserstein distance between the first probability distributions corresponding to any two first text samples may be used as the first difference.
[0116] After obtaining the first difference, the first text samples in the second sample group can be clustered based on the first difference to obtain one or more sample clusters. The clustering algorithm used in the clustering process can be a k-means algorithm, a k-means++ algorithm, etc., and the first difference can be used as a distance metric.
[0117] Below, taking the first difference as the KL distance between the first probability distributions corresponding to any two first text samples and the clustering algorithm as the k-means algorithm as an example, a method of clustering the first text samples in the second sample group based on the first difference to obtain one or more sample clusters is described.
[0118] Iterate the following steps 1 and 2: 1. Select one or more first text samples from the first text samples in the second sample group as the central sample. 2. Calculate the first difference between each other first text sample in the second sample group and the central sample, that is, calculate the KL distance between the first probability distributions corresponding to the other first text samples and the central sample. Group the other first text samples into the central sample with the smallest first difference. Select the optimal central sample until the number of iterations exceeds a threshold, and then form a sample cluster with the other first text samples grouped into the optimal central sample and the optimal central sample.
[0119] When the number of central samples is 1, the number of sample clusters is 1. When the number of central samples is multiple, the number of sample clusters is multiple, that is, the number of central samples is consistent with the number of sample clusters. In this way, accurate classification of the first text samples in the second sample group can be achieved, and one or more sample clusters can be obtained. The similarity of the first probability distributions of the first text samples in the same sample cluster is greater than a preset similarity threshold, and the difference of the first probability distributions of the first text samples in different sample clusters is greater than a preset difference threshold.
[0120] In step 10222A, the word frequency of each word in each sample cluster is obtained respectively.
[0121] A sample cluster includes at least one first text sample, and each first text sample includes at least one word. For each sample cluster, the word frequency of each word in the sample cluster can be counted. In some embodiments, for each word, the number of occurrences of the word can be divided by the number of occurrences of all words in the sample cluster to obtain the word frequency of each word in the sample cluster. In this way, the word frequency of each word in each sample cluster can be accurately obtained.
[0122] In step 10223A, at least one word whose word frequency reaches a first word frequency threshold is selected from each sample cluster as a target word.
[0123] The first text sample in each sample cluster corresponds to a large number of words. To more accurately determine target words while reducing processing time, target words can be determined based on word frequency and a first word frequency threshold. If a word's frequency is less than the first word frequency threshold, it indicates that the word occurs less frequently and can be ignored.
[0124] In some embodiments, step 10223A can be implemented in the following manner: for each sample cluster, the word frequency of each word in the sample cluster can be compared with a first word frequency threshold, wherein the first word frequency threshold can be set according to actual usage requirements. When the word frequency of a word is greater than or equal to the first word frequency threshold, it indicates that the word has a high frequency of occurrence, and the word can be used as a target word. When the word frequency of a word is greater than or equal to the first word frequency threshold, it indicates that the word has a high frequency of occurrence, and the word can be used as a target word. In this way, the target word can be accurately acquired.
[0125] In some embodiments, the target words can be used to construct a second text sample to obtain a deviation result. When the number of target words is reduced, the number of second text samples and the number of deviation results are both reduced, which can reduce the processing volume and thus improve the efficiency of determining the deviation results.
[0126] In some embodiments, see Figure 7 , Figure 7 This is a flow chart of the method for determining target words provided in the embodiment of the present application. Figure 5 , Figure 4 The illustrated step 1022 may be implemented by following steps 10221B to 10224B, which are described in detail below.
[0127] In step 10221B, the number of occurrences of each word in the second sample group is obtained.
[0128] The second sample group includes at least one first text sample, each of which includes at least one word. The number of occurrences of each word in the second sample group can be counted. In this way, the number of occurrences of each word in the second sample group can be accurately obtained.
[0129] In step 10222B, the number of occurrences is compared with the number of occurrences threshold.
[0130] The first text sample in the second sample combination corresponds to a larger number of words. In order to further determine a more accurate target word, the number of occurrences and the occurrence threshold can be compared. When the number of occurrences of a word is less than or equal to the occurrence threshold, it can be considered that the probability of the word causing the text processing model to produce a prediction deviation is small, so the words whose occurrences are less than or equal to the occurrence threshold can be ignored.
[0131] When the number of occurrences of a word is greater than the occurrence threshold, it can be considered that the word has a high probability of causing the text processing model to produce prediction deviations, and words whose occurrences are greater than the occurrence threshold can be obtained. In this way, the words corresponding to the first text sample in the second sample combination can be screened.
[0132] In step 10223B, the word frequencies of the words whose occurrence times are greater than the occurrence threshold are obtained. In step 10224B, from the words whose occurrence times are greater than the occurrence threshold, the words whose frequency reaches the first word frequency threshold are selected as target words.
[0133] After obtaining words whose occurrence times are greater than the occurrence threshold, the word frequencies of the words whose occurrence times are greater than the occurrence threshold can be obtained, and then, from the words whose occurrence times are greater than the occurrence threshold, words whose frequency is greater than or equal to the first word frequency threshold can be selected as target words. In this way, accurate target words can be obtained.
[0134] The target words are words whose word frequencies in the plurality of first text samples meet a preset condition. The preset condition is that words whose word frequencies in sample clusters obtained by clustering the first text samples in the second sample group reach a first word frequency threshold are selected as target words. The preset condition can also be that words whose occurrences exceed the occurrence threshold and whose word frequencies exceed the first word frequency threshold are selected as target words.
[0135] Continue to see Figure 4 In step 1023, at least one second text sample is constructed based on the target word and the first sample group.
[0136] In some embodiments, step 1023 can be implemented by performing the following processing on each target word: for a second number of first text samples in the first sample group, the target word is inserted into each first text sample to obtain a second number of second text samples. In other words, for each target word, the target word can be inserted into a second number of first text samples in the first sample group to obtain a second text sample, where the number of second text samples is the product of the second number and the number of target words, and the second number is less than or equal to the number of first text samples in the first sample group.
[0137] As an example of step 1023, the number of target words is 1, that is, the target word is target word 1, and the first sample group includes 10 first text samples. The second number can be 3, and the target word 1 can be split into any 3 first text samples in the first sample group to obtain 3 second text samples. The second number can also be 10, and the target word 1 can be split into 10 first text samples in the first sample group to obtain 10 second text samples. In this way, the second text sample can be accurately obtained.
[0138] In some embodiments, step 1023 can be implemented in the following manner: Figure 8 , Figure 8 This is a flow chart of the method for determining target words provided in the embodiment of the present application. Figure 6 , Figure 4 The illustrated step 1023 can be implemented by following the steps 10231 to 10223, which are described in detail below.
[0139] In step 10231 , when there are multiple target words, the number of first text samples in the first sample group is obtained as the third number.
[0140] When there are multiple target words, in order to obtain accurate second text samples, the number of first text samples in the first sample group may be obtained and used as the third number.
[0141] Comparing the number of target words and the third number, for the case where the number of target words is less than or equal to the third number, in some embodiments, for each target word, the target word can be inserted into any first text sample to obtain a second text sample. The first text sample inserted for each target word can be the same or different, and the number of second text samples is consistent with the number of target words.
[0142] In step 10232, when the number of target words is greater than the third number, a third number of first target words are selected from the plurality of target words based on the word frequencies of the target words.
[0143] In some embodiments, step 10232 can be implemented by comparing the frequency of the target word with a second frequency threshold, where the second frequency threshold is greater than the first frequency threshold. If there is a target word with a frequency greater than the second frequency threshold, a higher frequency indicates a higher probability that the word will cause a prediction bias in the text processing model. To obtain more accurate target words, the number of target words with a frequency greater than the second frequency threshold can be obtained as the fourth number.
[0144] When the fourth number is greater than or equal to the third number, in order to reduce the processing amount, the third number of first target words can be selected from the target words whose word frequency is greater than the second word frequency threshold. In some embodiments, the target words whose word frequency is greater than the second word frequency threshold can be arranged in descending order of word frequency, so as to select the first third number of target words as the first target words. In some embodiments, the third number of first target words can also be randomly selected from the target words whose word frequency is greater than the second word frequency threshold. In this way, a more accurate first target word can be obtained.
[0145] In some embodiments, the first target words can be used to construct a second text sample to obtain a deviation result. When the number of first target words is further reduced, the number of second text samples and the number of deviation results are further reduced, which can further reduce the processing volume and thus improve the efficiency of determining the deviation results.
[0146] If there is no target word with a frequency greater than the second frequency threshold, or the fourth number is less than the third number, the multiple target words are sorted in descending order of frequency to obtain a target word sequence, and starting from the first target word in the target word sequence, the third number of first target words are selected. In this way, a more accurate first target word can be obtained.
[0147] In step 10233, a third number of first target words are inserted into each first text sample one by one to obtain a third number of second text samples.
[0148] In some embodiments, step 10233 can be implemented by inserting a third number of first target words into each first text sample in a one-to-one correspondence to obtain a third number of second text samples. The first text sample inserted into each target word can be the same or different. In this way, the second text sample can be accurately obtained.
[0149] In some embodiments, when the first text sample consists of a demonstration sample and a verification sample, the target word can be inserted into any position in the verification sample in the first text sample to obtain a second text sample. In this way, the second text sample can be accurately obtained.
[0150] Continue to see Figure 3 In step 103, text prediction is performed on each second text sample using a text processing model to obtain a second probability distribution corresponding to each second text sample.
[0151] The difference between step 103 and step 101 is that the text samples are different. For detailed description, please refer to the description of step 101 and will not be repeated here. Through step 103, the second probability distribution of each second text sample can be obtained.
[0152] In step 104 , the deviation result of the target word is determined by combining the first probability distribution corresponding to the first text sample and the second probability distribution corresponding to the second text sample.
[0153] The deviation result is used to characterize the prediction deviation of the text processing model. The prediction deviation of the text processing model refers to whether the target word causes the text processing model to produce a prediction deviation when the text processing model is trained using samples containing the target word. In other words, the deviation result can indicate whether the target word causes the text processing model to produce a prediction deviation when the text processing model is trained using samples containing the target word. The deviation result can also indicate whether the target word does not cause the text processing model to produce a prediction deviation when the text processing model is trained using samples containing the target word.
[0154] In some embodiments, see Figure 9 , Figure 9 This is a flow chart of the method for determining target words provided in the embodiment of the present application. Figure 7 , Figure 3 The illustrated step 104 can be implemented by following steps 1041 to 1044 , which are described in detail below.
[0155] In step 1041 , a target probability distribution is determined from the first probability distributions corresponding to the plurality of first text samples.
[0156] In some embodiments, step 1041 can be implemented by determining, for the plurality of first text samples, a first probability distribution of the first text sample including the target word among the plurality of first text samples as the target probability distribution. In this way, the target probability distribution can be determined.
[0157] In some embodiments, step 1041 can be implemented by determining the first probability distribution corresponding to any first text sample in the second sample group to which the target word belongs as the target probability distribution. In this way, a more accurate target probability distribution can be determined.
[0158] In some embodiments, step 1041 can be implemented as follows: the second sample group includes one or more sample clusters obtained by clustering the first text sample in the second sample group, each sample cluster including a central sample. The first probability distribution corresponding to the central sample in the second sample group of the target word can be determined as the target probability distribution. In this way, a more accurate target probability distribution can be determined.
[0159] In some embodiments, step 1041 may be implemented by determining, for a plurality of first text samples, a first probability distribution of a first text sample including the target word among the plurality of first text samples as a target probability distribution.
[0160] In step 1042 , a second difference between the first probability distribution corresponding to the first text sample and the target probability distribution is calculated.
[0161] In some embodiments, step 1042 can be implemented by calculating the KL distance between the first probability distribution corresponding to the first text sample and the target probability distribution, and using the KL distance between the first probability distribution corresponding to the first text sample and the target probability distribution as the second difference.
[0162] For example, the second difference can be obtained using formula (3).
[0163] KL_{before}=KL(p(x) dv ||pk) (3)
[0164] Among them, KL_{before} is the second difference, p(x) dv is the first probability distribution, and pk is the target probability distribution. The specific calculation method can be found in formula (2). Replacing q(x) with pk in formula (2) can obtain KL(p(x) dv ||pk).
[0165] In some embodiments, a cross entropy between the first probability distribution corresponding to the first text sample and the target probability distribution may be calculated, and the cross entropy between the first probability distribution corresponding to the first text sample and the target probability distribution may be used as the second difference.
[0166] In some embodiments, the Wasserstein distance between the first probability distribution corresponding to the first text sample and the target probability distribution can be calculated, and the Wasserstein distance between the first probability distribution corresponding to the first text sample and the target probability distribution can be used as the second difference. In this way, an accurate second difference can be obtained.
[0167] In step 1043 , a third difference between the second probability distribution corresponding to the second text sample and the target probability distribution is calculated.
[0168] In some embodiments, step 1042 can be implemented by calculating the KL distance between the second probability distribution corresponding to the second text sample and the target probability distribution, and taking the KL distance between the second probability distribution corresponding to the second text sample and the target probability distribution as the third difference.
[0169] For example, the third difference can be obtained using formula (3).
[0170] KL_{after}=KL(pnew||pk) (4)
[0171] Where KL_{after} is the third difference, pnew is the second probability distribution, and pk is the target probability distribution. The specific calculation method can be seen in Formula (2). Replace p(x) with phew and q(x) with pk in Formula (2) to obtain KL(pnew||pk).
[0172] In some embodiments, a cross entropy between the second probability distribution corresponding to the second text sample and the target probability distribution may be calculated, and the cross entropy between the second probability distribution corresponding to the second text sample and the target probability distribution may be used as the third difference.
[0173] In some embodiments, the Wasserstein distance between the second probability distribution corresponding to the second text sample and the target probability distribution can be calculated, and the Wasserstein distance between the second probability distribution corresponding to the second text sample and the target probability distribution can be used as the third difference. In this way, an accurate third difference can be obtained.
[0174] In step 1044 , a deviation result of the target word is determined based on the second difference and the third difference.
[0175] In some embodiments, step 1044 can be implemented in the following manner: when the number of the second differences and the number of the third differences are both 1, the second differences and the third differences can be compared. When the second difference is greater than the third difference, the deviation result of the target word is determined to be a first deviation result, where the first deviation result is used to indicate that when a text processing model is trained using a sample containing the target word, the target word causes the text processing model to generate a prediction deviation.
[0176] If the second difference is less than or equal to the third difference, the deviation result for the target word is determined to be the second deviation result. The second deviation result is used to indicate that when a text processing model is trained using a sample containing the target word, the target word does not cause the text processing model to produce a prediction deviation. In this way, an accurate deviation result can be obtained.
[0177] In some embodiments, when the number of second differences and the number of third differences are both plural, the target words corresponding to the second differences and the third differences are consistent, and the second differences and the third differences correspond one-to-one. For the second differences and the third differences that have a corresponding relationship, the second differences and the third differences are compared.
[0178] Counting the number of second differences that are greater than the third difference as a fifth number, obtaining a ratio of the fifth number to the number of second differences, comparing the ratio with a preset ratio threshold, and determining, when the ratio is greater than the ratio threshold, that the deviation result of the target word is a first deviation result, the first deviation result being used to characterize that, when a text processing model is trained using a sample containing the target word, the target word causes the text processing model to produce a prediction deviation;
[0179] If the ratio is less than or equal to the ratio threshold, the deviation result for the target word is determined to be a second deviation result. The second deviation result is used to indicate that when a text processing model is trained using a sample containing the target word, the target word does not cause the text processing model to produce a prediction deviation. In this way, an accurate third difference can be obtained.
[0180] In some embodiments, when it is determined that a target word causes a text processing model to produce a prediction deviation, the training text sample used to train the text processing model can be adjusted. In some embodiments, the target word that causes the text processing model to produce a prediction deviation in the training sample can be deleted. In some embodiments, the number of occurrences of the target word that causes the text processing model to produce a prediction deviation in the training sample can be reduced. In some embodiments, the parameters of the text processing model can also be adjusted to reduce the weight corresponding to the target word that causes the text processing model to produce a prediction deviation. In this way, the accuracy and robustness of the text processing model can be improved. When the text processing model implements functions such as language translation, text classification, and sentiment analysis, it can obtain prediction results that are more in line with actual needs.
[0181] In some embodiments, in the face of data attacks and data anomalies, the text processing model can be optimized in a targeted manner based on the deviation results, which can improve the stability and security of the text processing environment in the face of data attacks and data anomalies.
[0182] See also Figure 10 , Figure 10 Schematic diagram of the process of determining the target word provided in the embodiment of the present application Figure 8 , combined with Figure 10 The method for determining the target word provided in the embodiment of the present application is introduced with examples.
[0183] In step 1001, a first text sample is obtained.
[0184] The first text sample can be a sample constructed based on the demonstration sample and the verification sample. The specific process is consistent with the method of constructing the first text sample in step 101. For details, please refer to the description of the method of constructing the first text sample in step 101, which will not be repeated here.
[0185] In step 1002, text prediction is performed on a plurality of first text samples respectively through a text processing model to obtain a first probability distribution corresponding to each first text sample.
[0186] The description of step 1002 is consistent with that of step 101 , and for details, please refer to the description of step 101 , which will not be repeated here.
[0187] In step 1003, the entropy of each first probability distribution is obtained.
[0188] For each first probability distribution, the entropy of the first probability distribution can be calculated using the above formula (1). Step 1003 is consistent with step 10211. For details, please refer to the description of step 10211, which will not be repeated here.
[0189] In step 1004 , first text samples corresponding to the first probability distribution whose entropy is less than or equal to the entropy threshold are clustered to obtain a plurality of sample clusters.
[0190] The first text sample corresponding to the first probability distribution whose entropy is less than or equal to the entropy threshold is the first text sample in the second sample group. The clustering method can be referred to step 10221A and will not be described in detail here.
[0191] In step 1005, the word frequency of each word in each sample cluster is obtained respectively, and at least one word whose word frequency reaches a first word frequency threshold is selected from each sample cluster as a target word.
[0192] For each sample cluster, the frequency of the words in the sample cluster can be counted, and then at least one word from each sample cluster whose frequency reaches a first frequency threshold can be selected as a target word. Step 1005 is consistent with steps 10222A-10223A. For details, please refer to the description of steps 10222A-10223A and will not be repeated here.
[0193] In step 1006 , at least one second text sample is constructed based on the target word and the first text sample.
[0194] In some embodiments, for the second number of first text samples in the first sample group, the target words are respectively inserted into each first text sample to obtain the second number of second text samples. In some embodiments, the number of first text samples in the first sample group (a third number) can be taken, and the target words can be screened according to the number of target words and the third number to obtain the first target words, thereby inserting the third number of first target words into each first text sample in a one-to-one correspondence to obtain the third number of second text samples. Step 1006 is consistent with step 1023. For details, please refer to the description of step 1023 and will not be repeated here.
[0195] In step 1007, text prediction is performed on each second text sample using a text processing model to obtain a second probability distribution corresponding to each second text sample.
[0196] Step 1007 is consistent with step 103. For details, please refer to the description of step 103 and will not be repeated here.
[0197] In step 1008, the deviation result of the target word is determined by combining the first probability distribution corresponding to the first text sample and the second probability distribution corresponding to the second text sample.
[0198] In some embodiments, a target probability distribution is determined from the first probability distributions corresponding to multiple first text samples, a second difference between the first probability distribution corresponding to the first text sample and the target probability distribution is calculated, a third difference between the second probability distribution corresponding to the second text sample and the target probability distribution is calculated, and based on the second difference and the third difference, a deviation result of the target word is determined.
[0199] The deviation results include a first deviation result and a second deviation result. The first deviation result is used to indicate that when a sample containing the target word is used to train a text processing model, the target word causes the text processing model to produce a prediction deviation. The second deviation result is used to indicate that when a sample containing the target word is used to train a text processing model, the target word does not cause the text processing model to produce a prediction deviation. Step 1008 is consistent with step 104. For details, please refer to the description of step 104 and will not be repeated here.
[0200] The target word determination method provided in the embodiment of the present application can obtain a first probability distribution of a first text sample, construct a second text sample including the target word based on the first probability distribution and multiple first text samples, and obtain a second probability distribution of the second text sample, and determine the deviation result of the target word by combining the first probability distribution corresponding to the first text sample and the second probability distribution corresponding to the second text sample. That is, the embodiment of the present application constructs a second text sample including the target word, and then combines the prediction result of the original first text sample and the prediction result of the second text sample including the target word to identify the words that cause the text processing model to produce prediction deviation. In this way, it is achieved that in the training stage of the text processing model, the words that cause the model to produce prediction deviation are accurately identified in the samples used to train the text processing model, providing a solution to avoid the text processing model from producing prediction deviation.
[0201] See also Figure 11 , Figure 11 This is a structural diagram of the text classification model provided in the embodiment of the present application. Figure 11 Taking the example, the method for determining the target words provided in the embodiment of the present application is introduced in combination with the structure of the text classification model.
[0202] exist Figure 11 In the example, the text classification model 1101 may include an embedding layer 1102, an encoding layer 1103, and a fully connected layer 1104. For each first text sample, the embedding layer 1102 maps each word in the first text sample to a word vector, the encoding layer 1103 performs feature extraction on the word vector to obtain semantic information and context information, and the fully connected layer 1104 maps the first text sample to a first probability distribution based on the semantic information and context information.
[0203] Obtain the entropy of the first probability distribution, cluster the first text samples corresponding to the first probability distribution whose entropy is less than or equal to the entropy threshold to obtain multiple sample clusters, obtain the word frequency of each word in each sample cluster, and select at least one word whose word frequency reaches the first word frequency threshold from each sample cluster as the target word, which is equivalent to obtaining the target word based on the first probability distribution.
[0204] Then, a second text sample can be constructed based on the target word and the first text sample. For each second text sample, each word in the second text sample is mapped to a word vector through the embedding layer 1102, and the word vector is subjected to feature extraction through the encoding layer 1103 to obtain semantic information and context information. The second text sample is mapped to a second probability distribution based on the semantic information and context information through the fully connected layer 1104. The deviation result of the target word is determined by combining the first probability distribution corresponding to the first text sample and the second probability distribution of the second text sample. In the training phase of the text processing model, the words that cause the model to produce prediction deviations are accurately identified in the samples used to train the text processing model, providing a solution to avoid the text processing model from producing prediction deviations.
[0205] The following continues to describe the exemplary structure of the target word determination device 455 provided in the embodiment of the present application implemented as a software module. In some embodiments, such as Figure 2 As shown, the software modules stored in the target word determination device 455 of the memory 440 may include:
[0206] The prediction module 4551 is configured to perform text prediction on each of the plurality of first text samples using a text processing model to obtain a first probability distribution corresponding to each of the first text samples.
[0207] The construction module 4552 is used to construct at least one second text sample including a target word based on each of the first probability distributions and the multiple first text samples; wherein the target word is a word in the multiple first text samples whose word frequency meets a preset condition.
[0208] The prediction module 4551 is further configured to perform text prediction on each of the second text samples using the text processing model to obtain a second probability distribution corresponding to each of the second text samples.
[0209] Determination module 4553 is used to determine the deviation result of the target word by combining the first probability distribution corresponding to the first text sample and the second probability distribution corresponding to the second text sample; wherein the deviation result is used to characterize the prediction deviation of the text processing model.
[0210] In some embodiments, the construction module 4552 is further used to group the multiple first text samples based on each of the first probability distributions to obtain a first sample group and a second sample group; wherein the uncertainty of the first text sample in the first sample group is greater than the uncertainty of the first text sample in the second sample group; select at least one target word from the second sample group; and construct at least one second text sample based on the target word and the first sample group.
[0211] In some embodiments, the construction module 4552 is also used to obtain the entropy of each first probability distribution; for each first probability distribution, compare the entropy of the first probability distribution with the entropy threshold; if the entropy of the first probability distribution is greater than the entropy threshold, divide the first text sample corresponding to the first probability distribution into the first sample group; if the entropy of the first probability distribution is less than or equal to the entropy threshold, divide the first text sample corresponding to the first probability distribution into the second sample group.
[0212] In some embodiments, the construction module 4552 is further used to cluster the first text sample in the second sample group to obtain one or more sample clusters; obtain the word frequency of each word in each of the sample clusters; and select at least one word whose word frequency reaches a first word frequency threshold from each of the sample clusters as the target word.
[0213] In some embodiments, the construction module 4552 is further used to calculate, for any two first text samples in the second sample group, a first difference between the first probability distributions corresponding to the any two first text samples; and cluster the first text samples in the second sample group based on the first difference to obtain one or more sample clusters.
[0214] In some embodiments, the construction module 4552 is further used to obtain the number of occurrences of each word in the second sample group; compare the number of occurrences with the number of occurrences threshold; obtain the word frequency of the words whose number of occurrences is greater than the number of occurrences threshold; and select, from the words whose number of occurrences is greater than the number of occurrences threshold, the words whose frequency reaches the first word frequency threshold as the target words.
[0215] In some embodiments, the construction module 4552 is further used to perform the following processing on each of the target words: for a second number of first text samples in the first sample group, the target words are inserted into each of the first text samples to obtain a second number of second text samples; wherein the second number is less than or equal to the number of first text samples in the first sample group.
[0216] In some embodiments, the construction module 4552 is further used to obtain the number of the first text samples in the first sample group as the third number when the number of the target words is multiple; when the number of the target words is greater than the third number, select the third number of first target words from the multiple target words based on the word frequency of the target words; and insert the third number of first target words into each of the first text samples one by one to obtain the third number of second text samples.
[0217] In some embodiments, the construction module 4552 is also used to compare the word frequency of the target word with a second word frequency threshold, and the second word frequency threshold is greater than the first word frequency threshold; if there is a target word with a word frequency greater than the second word frequency threshold, the number of target words with a word frequency greater than the second word frequency threshold is obtained as a fourth number, and when the fourth number is greater than or equal to the third number, the first target words of the third number are selected from the target words with a word frequency greater than the second word frequency threshold; if there is no target word with a word frequency greater than the second word frequency threshold, or the fourth number is less than the third number, the multiple target words are sorted in descending order of the word frequency to obtain a target word sequence, and starting from the first target word in the target word sequence, the first target words of the third number are selected.
[0218] In some embodiments, the determination module 4553 is also used to determine a target probability distribution from the first probability distributions corresponding to multiple first text samples; calculate the second difference between the first probability distribution corresponding to the first text sample and the target probability distribution; calculate the third difference between the second probability distribution corresponding to the second text sample and the target probability distribution; and determine the deviation result of the target word based on the second difference and the third difference.
[0219] In some embodiments, the determination module 4553 is further configured to determine a first probability distribution corresponding to any first text sample in the second sample group to which the target word belongs as a target probability distribution.
[0220] In some embodiments, the second sample group includes one or more sample clusters obtained by clustering the first text sample in the second sample group, each of which includes a central sample. Determination module 4553 is further configured to determine the first probability distribution corresponding to the central sample in the second sample group of the target term as the target probability distribution.
[0221] In some embodiments, when the number of the second differences and the number of the third differences are both 1, the determination module 4553 is further used to compare the second difference and the third difference; when the second difference is greater than the third difference, the deviation result of the target word is determined to be a first deviation result, and the first deviation result is used to characterize that when the text processing model is trained with a sample containing the target word, the target word causes the text processing model to produce a prediction deviation; when the second difference is less than or equal to the third difference, the deviation result of the target word is determined to be a second deviation result, and the second deviation result is used to characterize that when the text processing model is trained with a sample containing the target word, the target word will not cause the text processing model to produce a prediction deviation.
[0222] In some embodiments, when the number of the second differences and the number of the third differences are both plural, the target words corresponding to the second differences and the third differences are consistent, and the second differences and the third differences correspond one-to-one.
[0223] The determination module 4553 is also used to compare the second difference and the third difference with respect to the second difference and the third difference that have a corresponding relationship; count the number of the second differences that are greater than the third difference as the fifth number; obtain the ratio of the fifth number to the number of the second differences; compare the ratio with a preset ratio threshold; when the ratio is greater than the ratio threshold, determine that the deviation result of the target word is a first deviation result, and the first deviation result is used to characterize that when the sample containing the target word is used to train the text processing model, the target word causes the text processing model to produce a prediction deviation; when the ratio is less than or equal to the ratio threshold, determine that the deviation result of the target word is a second deviation result, and the second deviation result is used to characterize that when the sample containing the target word is used to train the text processing model, the target word will not cause the text processing model to produce a prediction deviation.
[0224] An embodiment of the present application provides a computer program product, which includes a computer program or computer-executable instructions stored in a computer-readable storage medium. A processor of an electronic device reads the computer-executable instructions from the computer-readable storage medium and executes the computer-executable instructions, causing the electronic device to perform the target word determination method described in the embodiment of the present application.
[0225] The embodiment of the present application provides a computer-readable storage medium storing computer-executable instructions, wherein the computer-executable instructions or computer programs are stored. When the computer-executable instructions or computer programs are executed by a processor, the processor will execute the method for determining the target word provided by the embodiment of the present application, for example, Figure 3 The method for determining the target word is shown.
[0226] In some embodiments, the computer-readable storage medium may be a memory such as RAM, ROM, flash memory, magnetic surface memory, optical disk, or CD-ROM; or may be various devices including one or any combination of the above memories.
[0227] In some embodiments, computer-executable instructions may be in the form of a program, software, software module, script, or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and may be deployed in any form, including as a stand-alone program or as a module, component, subroutine, or other unit suitable for use in a computing environment.
[0228] As an example, computer-executable instructions may, but need not, correspond to a file in a file system, may be stored as part of a file that stores other programs or data, such as in one or more scripts in a HyperText Markup Language (HTML) document, in a single file dedicated to the program in question, or in multiple coordinating files (e.g., files storing one or more modules, subroutines, or code portions).
[0229] By way of example, computer-executable instructions may be deployed to be executed on one electronic device, or on multiple electronic devices located at one site, or on multiple electronic devices distributed across multiple sites and interconnected by a communication network.
[0230] In summary, through the embodiments of the present application, it is possible to obtain words that cause the text processing model to produce prediction deviations, providing a solution to avoid the text processing model from producing prediction deviations. In addition, the embodiments of the present application can reduce the number of target words, thereby reducing the processing volume, thereby improving the efficiency of determining deviation results. The embodiments of the present application can improve the accuracy and robustness of the text processing model, so that the text processing model can obtain prediction results that are more in line with actual needs when implementing functions such as language translation, text classification, and sentiment analysis. It can also improve the stability and security of the text processing environment in the face of data attacks and data anomalies.
[0231] The above description is merely an embodiment of the present application and is not intended to limit the scope of protection of the present application. Any modifications, equivalent replacements, and improvements made within the spirit and scope of the present application are included in the scope of protection of the present application.
Claims
1. A method for determining a target word, characterized in that: The method comprises: Performing text prediction on the plurality of first text samples respectively by using a text processing model to obtain a first probability distribution corresponding to each of the first text samples; Based on each of the first probability distributions and the plurality of first text samples, construct at least one second text sample including a target word; wherein the target word is a word whose word frequency in the plurality of first text samples meets a preset condition; Performing text prediction on each of the second text samples using the text processing model to obtain a second probability distribution corresponding to each of the second text samples; Combining the first probability distribution corresponding to the first text sample and the second probability distribution corresponding to the second text sample, a deviation result of the target word is determined; wherein the deviation result is used to characterize the prediction deviation of the text processing model.
2. The method according to claim 1, characterized in that The step of constructing at least one second text sample including a target word based on each of the first probability distributions and the plurality of first text samples comprises: Grouping the plurality of first text samples based on the first probability distributions to obtain a first sample group and a second sample group; wherein the uncertainty of the first text sample in the first sample group is greater than the uncertainty of the first text sample in the second sample group; Selecting at least one target word from the second sample group; At least one second text sample is constructed based on the target word and the first sample group.
3. The method according to claim 2, characterized in that The grouping of the plurality of first text samples based on the first probability distributions to obtain a first sample group and a second sample group includes: Obtaining the entropy of each of the first probability distributions; For each of the first probability distributions, comparing the entropy of the first probability distribution with an entropy threshold; If the entropy of the first probability distribution is greater than the entropy threshold, dividing the first text sample corresponding to the first probability distribution into the first sample group; If the entropy of the first probability distribution is less than or equal to the entropy threshold, the first text sample corresponding to the first probability distribution is divided into the second sample group.
4. The method according to claim 2, characterized in that The selecting at least one target word from the second sample group includes: Clustering the first text sample in the second sample group to obtain one or more sample clusters; Obtaining the word frequency of each word in each of the sample clusters respectively; At least one word whose word frequency reaches a first word frequency threshold is selected from each of the sample clusters as the target word.
5. The method according to claim 4, characterized in that The clustering of the first text sample in the second sample group to obtain one or more sample clusters includes: For any two first text samples in the second sample group, calculating a first difference between first probability distributions corresponding to the any two first text samples; Based on the first difference, the first text samples in the second sample group are clustered to obtain one or more sample clusters.
6. The method according to claim 2, characterized in that The selecting at least one target word from the second sample group includes: Obtaining the number of occurrences of each word in the second sample group; comparing the number of occurrences to an occurrence threshold; Obtaining the word frequency of the words whose occurrence times are greater than the occurrence threshold; From the words whose occurrence times are greater than the occurrence times threshold, a word whose frequency reaches a first frequency threshold is selected as the target word.
7. The method according to claim 2, characterized in that The constructing at least one second text sample based on the target word and the first sample group includes: The following processing is performed for each target word: For a second number of first text samples in the first sample group, insert the target word into each of the first text samples to obtain a second number of second text samples; The second number is less than or equal to the number of first text samples in the first sample group.
8. The method according to claim 2, characterized in that The constructing at least one second text sample based on the target word and the first sample group includes: In the case that there are multiple target words, obtaining the number of the first text samples in the first sample group as a third number; When the number of the target words is greater than the third number, selecting the third number of first target words from the plurality of target words based on the word frequencies of the target words; The third number of first target words are inserted into each of the first text samples in a one-to-one correspondence to obtain the third number of second text samples.
9. The method according to claim 8, characterized in that The selecting the first number of first target words from the plurality of target words based on the word frequency of the target words includes: Comparing the word frequency of the target word with a second word frequency threshold, the second word frequency threshold being greater than the first word frequency threshold; If there are target words whose word frequency is greater than the second word frequency threshold, obtaining the number of target words whose word frequency is greater than the second word frequency threshold as a fourth number, and if the fourth number is greater than or equal to the third number, selecting the first target words of the third number from the target words whose word frequency is greater than the second word frequency threshold; If there is no target word with a frequency greater than the second frequency threshold, or the fourth number is less than the third number, sort the multiple target words in descending order of the frequency to obtain a target word sequence, and starting from the first target word in the target word sequence, select the first target words of the third number.
10. The method according to claim 2, characterized in that The determining the deviation result of the target word by combining the first probability distribution corresponding to the first text sample and the second probability distribution corresponding to the second text sample includes: Determining a target probability distribution from first probability distributions corresponding to the plurality of first text samples; Calculating a second difference between a first probability distribution corresponding to the first text sample and the target probability distribution; Calculating a third difference between a second probability distribution corresponding to the second text sample and the target probability distribution; Based on the second difference and the third difference, a deviation result of the target word is determined.
11. The method according to claim 10, characterized in that Determining a target probability distribution from the first probability distributions corresponding to the plurality of first text samples includes: A first probability distribution corresponding to any first text sample in the second sample group to which the target word belongs is determined as a target probability distribution.
12. The method according to claim 10, characterized in that The second sample group includes one or more sample clusters obtained by clustering the first text sample in the second sample group, and the sample cluster includes a central sample; Determining a target probability distribution from the first probability distributions corresponding to the plurality of first text samples includes: The first probability distribution corresponding to the central sample in the second sample group of the target word is determined as the target probability distribution.
13. The method according to claim 10, characterized in that When the number of the second differences and the number of the third differences are both 1, determining the deviation result of the target word based on the second differences and the third differences includes: comparing the second difference and the third difference; When the second difference is greater than the third difference, determining the deviation result of the target word as a first deviation result, the first deviation result being used to indicate that when the text processing model is trained using a sample containing the target word, the target word causes the text processing model to produce a prediction deviation; When the second difference is less than or equal to the third difference, the deviation result of the target word is determined to be the second deviation result, and the second deviation result is used to characterize that when the text processing model is trained using a sample containing the target word, the target word will not cause the text processing model to produce a prediction deviation.
14. The method according to claim 10, characterized in that When the number of the second differences and the number of the third differences are both plural, the target words corresponding to the second differences and the third differences are the same, and the second differences and the third differences correspond one-to-one; The determining of the deviation result of the target word based on the second difference and the third difference includes: For the second difference and the third difference that have a corresponding relationship, compare the second difference with the third difference; Counting the number of the second differences that are greater than the third difference as a fifth number; obtaining a ratio of the fifth quantity to the quantity of the second difference; comparing the ratio with a preset ratio threshold; When the ratio is greater than the ratio threshold, determining the deviation result of the target word as a first deviation result, the first deviation result being used to represent that when the text processing model is trained with a sample containing the target word, the target word causes the text processing model to generate a prediction deviation; When the ratio is less than or equal to the ratio threshold, the deviation result of the target word is determined to be a second deviation result, and the second deviation result is used to characterize that when the text processing model is trained using a sample containing the target word, the target word will not cause the text processing model to produce a prediction deviation.
15. A device for determining a target word, characterized in that: The device comprises: A prediction module, configured to perform text prediction on each of the plurality of first text samples using a text processing model to obtain a first probability distribution corresponding to each of the first text samples; A construction module, configured to construct at least one second text sample including a target word based on each of the first probability distributions and the plurality of first text samples; wherein the target word is a word in the plurality of first text samples whose word frequency satisfies a preset condition; The prediction module is further configured to perform text prediction on each of the second text samples using the text processing model to obtain a second probability distribution corresponding to each of the second text samples; A determination module is used to determine the deviation result of the target word by combining the first probability distribution corresponding to the first text sample and the second probability distribution corresponding to the second text sample; wherein the deviation result is used to characterize the prediction deviation of the text processing model.
16. An electronic device, characterized in that: The electronic device comprises: a memory for storing computer-executable instructions; A processor, configured to implement the target word determination method according to any one of claims 1 to 14 when executing the computer-executable instructions stored in the memory.
17. A computer-readable storage medium storing computer-executable instructions or a computer program, characterized in that: When the computer executable instructions or computer program are executed by a processor, the method for determining a target word according to any one of claims 1 to 14 is implemented.
18. A computer program product comprising computer executable instructions or a computer program, characterized in that When the computer executable instructions or computer program are executed by a processor, the method for determining a target word according to any one of claims 1 to 14 is implemented.