Training method of text classification model, text classification method and device thereof
By randomly masking high-frequency words in the training samples of the text classification model, the problem of the deep attention mechanism paying too much attention to high-frequency words is solved, and the generalization ability and classification effect of the model are improved.
Patent Information
- Application Number
- CN202310010897.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-01-04
- Publication Date
- 2024-09-06
- Estimated Expiration
- 2043-01-04
AI Technical Summary
Text classification methods based on deep attention mechanisms focus too much on high-frequency words, resulting in incorrect classification results.
By obtaining the category label of the sample text, counting keywords, and randomly masking high-frequency words according to the masking probability, a second sample text is generated for model training to avoid excessive attention to high-frequency words.
The generalization ability of the model is improved, allowing the model to dig deeper into the semantic information of text and improve the classification effect.
Smart Images

Figure CN116049400B
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence, in particular to natural language processing (NLP) and deep learning technology, and in particular to a training method for a text classification model, a text classification method and a device thereof. Background Art
[0002] Text classification is the most basic task in Natural Language Processing (NLP), and is involved in many scenarios, such as conversational robots, search recommendations, emotion recognition, sentiment classification, content understanding, enterprise risk control, quality inspection, etc. In related technologies, text classification research based on deep learning has gradually replaced traditional machine learning methods and become the mainstream research direction in the field of text classification. The deep learning models used include convolutional neural networks, recurrent neural networks, attention mechanisms, etc. These deep learning models have achieved good experimental results in the field of text classification. However, methods based on deep attention mechanisms will pay too much attention to certain keywords to a large extent, resulting in incorrect classification results. Summary of the invention
[0003] The present application provides a text classification model training method, a text classification method, a device, an electronic device, and a storage medium.
[0004] According to a first aspect of the present application, a method for training a text classification model is provided, comprising:
[0005] Obtaining a first sample text and a category label of the first sample text;
[0006] Acquire keywords in the first sample text based on the category label;
[0007] Determine the mask probability corresponding to the category label, and obtain a second sample text according to the mask probability corresponding to the category label, the keyword and the first sample text;
[0008] An initial text classification model is trained according to the second sample text and the category label to obtain a trained text classification model.
[0009] According to a second aspect of the present application, a text classification method is provided, comprising:
[0010] Get the text to be processed;
[0011] Inputting the text to be processed into a preset text classification model to obtain a classification prediction result of the text to be processed;
[0012] The text classification model is a model trained by the training method described in the first aspect above.
[0013] According to a third aspect of the present application, a training device for a text classification model is provided, comprising:
[0014] A first acquisition module, used to acquire a first sample text and a category label of the first sample text;
[0015] A second acquisition module, configured to acquire keywords in the first sample text based on the category label;
[0016] A determination module, used to determine the mask probability corresponding to the category label;
[0017] A third acquisition module, configured to acquire a second sample text according to the mask probability corresponding to the category label, the keyword and the first sample text;
[0018] The training module is used to train an initial text classification model according to the second sample text and the category label to obtain a trained text classification model.
[0019] According to a fourth aspect of the present application, a text classification device is provided, comprising:
[0020] An acquisition module is used to obtain the text to be processed;
[0021] A prediction module, used for inputting the text to be processed into a preset text classification model to obtain a classification prediction result of the text to be processed;
[0022] Among them, the text classification model is a model trained using the training device as described in the third aspect above.
[0023] According to a fifth aspect of the present application, there is provided an electronic device, including:
[0024] at least one processor; and
[0025] a memory communicatively connected to the at least one processor; wherein,
[0026] The memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the method described in the first aspect, or to enable the at least one processor to execute the method described in the second aspect.
[0027] According to the sixth aspect of the present application, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to enable the computer to execute the method described in the first aspect above, or to enable the computer to execute the method described in the second aspect above.
[0028] According to the seventh aspect of the present application, a computer program product is provided, comprising a computer program, wherein when the computer program is executed by a processor, the computer program implements the steps of the method described in the first aspect, or implements the steps of the method described in the second aspect.
[0029] According to the technical solution of the present application, it is possible to avoid excessive focus on high-frequency words due to the attention mechanism, and the generalization ability of the attention mechanism can be improved, so that the model can more deeply mine the semantic information of the text, thereby improving the effect of the model.
[0030] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present application, nor is it intended to limit the scope of the present application. Other features of the present application will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present application.
[0032] Figure 1 A flowchart of a text classification model training method provided in an embodiment of the present application;
[0033] Figure 2 A flowchart of another text classification model training method provided in an embodiment of the present application;
[0034] Figure 3 A flowchart of another text classification model training method provided in an embodiment of the present application;
[0035] Figure 4 A flowchart of a text classification method provided in an embodiment of the present application;
[0036] Figure 5 A block diagram of a text classification model training device provided in an embodiment of the present application;
[0037] Figure 6 A block diagram of a text classification device provided in an embodiment of the present application;
[0038] Figure 7 It is a block diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0039] The following is a description of exemplary embodiments of the present application in conjunction with the accompanying drawings, including various details of the embodiments of the present application to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the present application. Similarly, for the sake of clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0040] Text classification is one of the most basic tasks in Natural Language Processing (NLP), and is involved in many scenarios, such as conversational robots, search recommendations, emotion recognition, sentiment classification, content understanding, enterprise risk control, quality inspection, etc. In recent years, text classification research based on deep learning has gradually replaced traditional machine learning methods and become the mainstream research direction in the field of text classification. The deep learning models used include convolutional neural networks (CNN), recurrent neural networks (RNN), and attention mechanisms. These deep learning models have achieved good experimental results in the field of text classification. However, methods based on deep attention mechanisms will pay too much attention to certain keywords to a large extent, resulting in incorrect classification results.
[0041] In related technologies, the attention mechanism is widely used in text classification methods based on deep neural networks. The attention mechanism is a new text processing mechanism proposed by Bahdanau et al. in 2014. It imitates the internal process of human visual observation behavior. It was popular in the image field in the early stage, and was later introduced into the NLP field and gradually developed into an independent research direction. The attention mechanism improves the input encoding requirements from fixed-length vectors to vector sequences for transmission. It pays full attention to the "attention range" information, can quickly extract important features of sparse data, and gradually becomes the standard for solving text problems. Google proposed the Transformer model, which uses the full Attention structure to replace the RNN / CNN part, making the model structure simpler. In terms of performance, the Transformer avoids the model architecture of time sequence and cycle, and completely relies on the Attention mechanism to construct the global dependency relationship between input and output, thereby supporting the parallel calculation of training samples and significantly improving the calculation efficiency and model performance.
[0042] However, methods based on deep attention mechanisms tend to over-focus on certain keywords, resulting in incorrect classification results. For example, the category label of the text "Where is A?" is "addressing", but because the word "A" is more frequent in the "legal consultation" category text, the model over-focuses on this word, causing the model to misclassify the text as "legal consultation".
[0043] In response to the above problems, this application proposes a training method for a text classification model, which can randomly mask the high-frequency words in each sentence. This can avoid excessive focus on high-frequency words like the attention mechanism, allowing the model to more deeply explore the semantic information of the text, thereby improving the model's effectiveness.
[0044] The following describes a text classification model training method, a text classification method, and a device thereof according to an embodiment of the present application with reference to the accompanying drawings.
[0045] Figure 1 This is a flowchart of a text classification model training method provided in an embodiment of the present application. It should be noted that the method can be executed by an electronic device. Figure 1 As shown, the method may include but is not limited to the following steps.
[0046] In step 101, a first sample text and a category label of the first sample text are obtained.
[0047] In a possible implementation, a training sample may be obtained, and the training sample may include a first sample text. A category label of the first sample text may also be obtained.
[0048] It should be noted that, in an embodiment of the present application, the category label may be one or more. The number of the category labels is related to the text classification task. As an example, if the text classification task is multi-label classification, the category label may be multiple, for example, the first sample text may involve multiple categories at the same time. As another example, if the text classification task is single-label text classification, the category label is a single label, and the first sample text belongs to a certain category. In an embodiment of the present application, the category label of the first sample text is a single label.
[0049] In step 102, keywords in the first sample text are obtained based on the category label.
[0050] In a possible implementation, the first sample text may be segmented and stop words may be processed, the word frequency corresponding to each word under each category label may be counted, and the words in the first sample text whose word frequency is greater than or equal to the word frequency threshold may be determined as keywords in the first sample text. As an example, the word frequency threshold may be a word frequency threshold corresponding to the category label, for example, a word frequency threshold is set for each category label, and the word frequency threshold may be a hyperparameter, or an empirical value set based on experience.
[0051] In step 103, the mask probability corresponding to the category label is determined, and the second sample text is obtained according to the mask probability corresponding to the category label, the keyword and the first sample text.
[0052] In a possible implementation, a mask probability may be set for each category label. As an example, the mask probability may be a hyperparameter, such as an empirical value set based on experience.
[0053] In an embodiment of the present application, the mask probability corresponding to the category label of the first sample text can be determined, and whether to mask the keywords in the first sample text can be determined according to the mask probability corresponding to the category label, and the processed first sample text can be determined as the second sample text, thereby obtaining the second sample text.
[0054] In step 104, an initial text classification model is trained according to the second sample text and the category label to obtain a trained text classification model.
[0055] It is understandable that the category label of the first sample text can also be used as the category label of the second sample text. In the embodiment of the present application, the second sample text and its category label can be used to train the initial text classification model, so as to obtain a trained text classification model.
[0056] Optionally, in an embodiment of the present application, the text classification model may be constructed based on a Transformer model.
[0057] By implementing the embodiments of the present application, the keywords in the sample text can be counted based on the category labels, and the keywords can be randomly masked according to the masking probability. The masked sample text can be used to train the text classification model. This can avoid excessive focus on high-frequency words due to the attention mechanism, improve the generalization ability of the attention mechanism, and enable the model to more deeply explore the semantic information of the text, thereby improving the effect of the model.
[0058] Figure 2 This is a flowchart of another text classification model training method provided in an embodiment of the present application. It should be noted that the method can be executed by an electronic device. Figure 2 As shown, the method may include but is not limited to the following steps.
[0059] In step 201, a first sample text and a category label of the first sample text are obtained.
[0060] In the embodiments of the present application, the implementation method of step 201 can be implemented by any method in the embodiments of the present application, which is not limited here and will not be repeated.
[0061] In step 202, word segmentation processing is performed on the first sample text, and stop word processing is performed on the result of the word segmentation processing to obtain the word segmentation result of the first sample text.
[0062] In a possible implementation, the first sample text may be segmented based on natural language processing technology, and stop words in the result of the segmentation may be removed, and the result of the segmentation after the stop words are removed may be determined as the segmentation result of the first sample text.
[0063] In step 203, word frequency statistics are performed on the words in the word segmentation result of the first sample text under the category label to obtain the word frequency corresponding to each word under the category label.
[0064] In a possible implementation, word frequency statistics are performed on the words in the word segmentation results of the training samples under each category label to obtain the word frequency corresponding to each word under each category label.
[0065] In step 204, a word frequency threshold corresponding to the category label is determined.
[0066] As an example, a word frequency threshold may be set for each category label, and the word frequency threshold may be a word frequency threshold corresponding to the category label. For example, a word frequency threshold may be set for each category label, and the word frequency threshold may be a hyperparameter, or an empirical value set based on experience.
[0067] In step 205, words whose word frequencies are greater than or equal to the word frequency threshold in the word segmentation results of the first sample text are determined as keywords in the first sample text.
[0068] In one implementation, when one or more words in the word segmentation results of the first sample text satisfy a word frequency greater than or equal to the word frequency threshold, the one or more words may be determined as keywords in the first sample text.
[0069] In step 206, a second sample text is obtained according to the mask probability corresponding to the category label, the keyword and the first sample text.
[0070] In a possible implementation, the keywords in the first sample text may be masked according to the mask probabilities corresponding to the category labels; and the masked first sample text may be determined as the second sample text.
[0071] As an example of a possible implementation, the key words in the first sample text are replaced with MASK according to the mask probability corresponding to the category label. That is, the word "MASK" can be used to replace the key words in the sample text. The sample text after the mask processing is determined as the second sample text.
[0072] For example, assume that there are training samples of category label 1, category label 2, and category label 3 in the training sample set. A word frequency threshold h and a mask probability P can be set for each category label. The training samples are segmented, and after the stop words are removed, the word frequency corresponding to each word under each category label is counted. When one or some words in the training sample satisfy the condition that their word frequency is greater than or equal to the word frequency threshold h under the corresponding category label, the one or some words can be randomly masked according to the mask probability P under the corresponding category label to obtain the masked training sample. Therefore, the present application uses a priori keyword masking to enable the deep network to not rely too much on certain keywords, thereby improving the generalization ability of the model and further improving the accuracy and recall of the model.
[0073] It should be noted that the word frequency threshold h under each category label may be the same or different. The mask probability P under each category label may be the same or different. This application does not make specific limitations on this.
[0074] In step 207, an initial text classification model is trained according to the second sample text and the category label to obtain a trained text classification model.
[0075] It is understandable that the category label of the first sample text can also be used as the category label of the second sample text. In the embodiment of the present application, the second sample text and its category label can be used to train the initial text classification model, so as to obtain a trained text classification model. In a possible implementation, Figure 3 As shown, the above-mentioned training of the initial text classification model based on the second sample text and the category label to obtain the trained text classification model may include but is not limited to the following steps.
[0076] In step 301, the second sample text is input into an initial text classification model.
[0077] In an embodiment of the present application, the initial text classification model may be constructed based on a Transformer model.
[0078] In step 302, the classification prediction result output by the text classification model is obtained.
[0079] In an embodiment of the present application, the second sample text is used as the input of the Transformer model, and the Transformer model embeds each character in the second sample text, wherein the embedding process includes: word embedding and position embedding. Position embedding may include embedding the position of each character in the second sample text in the sentence and embedding the number of the text paragraph where each character is located. The result of the embedding process is mapped to the space of the category label dictionary to obtain a classification prediction result. That is to say, during the training process of the text classification model, the classification prediction of the text classification model is limited to the category label. When mapping the result of the embedding process in the text classification model, the mapping layer can only map to the space of the category label, and the obtained classification prediction result can only be the classification in the category label.
[0080] In step 303, the model loss value is obtained according to the prediction result and the category label.
[0081] In an embodiment of the present application, the training goal of the Transformer model is to minimize the difference between the classification prediction result and the category label annotated for the second sample text. The training goal can be used to construct a loss function, and the loss function is used to calculate the model loss value based on the prediction result and the category label.
[0082] In step 304, the text classification model is trained according to the model loss value to obtain a trained text classification model.
[0083] Optionally, the model loss value can be used to update the model parameters of the Transformer model in each round of iteration until a preset training end condition is reached. The training end condition may include that the model loss value is less than or equal to a preset threshold, or the number of iterations reaches a preset maximum number threshold, etc.
[0084] In a possible implementation, the model parameters of the above Transformer model can be adjusted by using a back propagation algorithm (BP algorithm) and a gradient descent method (such as a random mini-batch gradient descent algorithm). Thus, the trained Transformer model is determined as a trained text classification model, so that the training of the text classification model can be completed.
[0085] By implementing the embodiments of the present application, the high-frequency words in each sentence can be counted and then randomly masked. This can avoid excessive attention to high-frequency words due to the attention mechanism, improve the generalization ability of the attention mechanism, and enable the model to more deeply explore the semantic information of the text, thereby improving the effect of the model and further improving the accuracy and recall rate of the model.
[0086] Figure 4 The flowchart of a text classification method provided in an embodiment of the present application is as follows. It should be noted that the method can be executed by an electronic device. Figure 4 As shown, the method may include but is not limited to the following steps.
[0087] In step 401, the text to be processed is obtained.
[0088] In step 402, the text to be processed is input into a preset text classification model to obtain a classification prediction result of the text to be processed.
[0089] Optionally, the text to be processed may be input into the text classification model, and the classification to which the text to be processed belongs may be predicted by the text classification model, thereby obtaining a classification prediction result of the text to be processed.
[0090] Among them, in the embodiments of the present application, the text classification model can be a model trained by using the training method described in any embodiment of the present application, which is not limited here and will not be repeated.
[0091] By implementing the embodiment of the present application, in the training stage of the text classification model, after the high-frequency words in each sentence in the training sample are counted, the high-frequency words are randomly masked, which can avoid excessive attention to high-frequency words due to the attention mechanism, and can improve the generalization ability of the attention mechanism, so that the model can more deeply mine the semantic information of the text, thereby improving the effect of the model, and further improving the accuracy and recall rate of the model. The text classification model trained by this training method can improve the accuracy of the text classification results when performing text classification.
[0092] Figure 5 A block diagram of a text classification model training device provided in an embodiment of the present application. Figure 5 As shown, the training device of the text classification model may include: a first acquisition module 501, a second acquisition module 502, a determination module 503, a third acquisition module 504 and a training module 505.
[0093] The first acquisition module 501 is used to acquire the first sample text and the category label of the first sample text.
[0094] The second acquisition module 502 is used to acquire keywords in the first sample text based on the category label. In a possible implementation, the second acquisition module 502 is specifically used to: perform word segmentation processing on the first sample text, and perform stop word processing on the result of the word segmentation processing to obtain the word segmentation result of the first sample text; perform word frequency statistics on the words in the word segmentation result of the first sample text under the category label to obtain the word frequency corresponding to each word under the category label; determine the word frequency threshold corresponding to the category label; and determine the words in the word segmentation result of the first sample text whose word frequency is greater than or equal to the word frequency threshold as keywords in the first sample text.
[0095] The determination module 503 is used to determine the mask probability corresponding to the category label.
[0096] The third acquisition module 504 is used to acquire the second sample text according to the mask probability corresponding to the category label, the keyword and the first sample text. In a possible implementation, the third acquisition module 504 is specifically used to: perform mask processing on the keyword in the first sample text according to the mask probability corresponding to the category label; and determine the first sample text after the mask processing as the second sample text.
[0097] Optionally, in one implementation, the third acquisition module 504 may replace the keyword in the first sample text with MASK according to the mask probability corresponding to the category label.
[0098] The training module 505 is used to train an initial text classification model according to the second sample text and the category label to obtain a trained text classification model.
[0099] In one possible implementation, the training module 505 is specifically used to: input the second sample text into an initial text classification model; wherein the initial text classification model is constructed based on a Transformer model; obtain the classification prediction result output by the text classification model; obtain the model loss value based on the prediction result and the category label; and train the text classification model based on the model loss value to obtain a trained text classification model.
[0100] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.
[0101] By implementing the embodiments of the present application, the keywords in the sample text can be counted based on the category labels, and the keywords can be randomly masked according to the masking probability. The masked sample text can be used to train the text classification model. This can avoid excessive focus on high-frequency words due to the attention mechanism, improve the generalization ability of the attention mechanism, and enable the model to more deeply explore the semantic information of the text, thereby improving the effect of the model.
[0102] Figure 6 This is a block diagram of a text classification device provided in an embodiment of the present application. Figure 6 As shown, the text classification device may include: an acquisition module 601 and a prediction module 602.
[0103] The acquisition module 601 is used to acquire the text to be processed.
[0104] The prediction module 602 is used to input the text to be processed into a preset text classification model to obtain a classification prediction result of the text to be processed. The text classification model is a model trained by the training device described in any embodiment of the present application.
[0105] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.
[0106] By implementing the embodiment of the present application, in the training stage of the text classification model, after counting the high-frequency words in each sentence in the training sample, the high-frequency words are randomly masked, which can avoid excessive attention to high-frequency words due to the attention mechanism, and can improve the generalization ability of the attention mechanism, so that the model can more deeply mine the semantic information of the text, thereby improving the effect of the model, and further improving the accuracy and recall rate of the model. The text classification model trained by this training method can improve the accuracy of the text classification results when performing text classification.
[0107] According to an embodiment of the present application, the present application also provides an electronic device and a readable storage medium.
[0108] like Figure 7 , is a block diagram of an electronic device provided by an embodiment of the present application. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workbenches, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present application described and / or required herein.
[0109] like Figure 7As shown, the electronic device includes: one or more processors 701, a memory 702, and interfaces for connecting various components, including high-speed interfaces and low-speed interfaces. The various components are interconnected using different buses and can be installed on a common mainboard or installed in other ways as needed. The processor can process instructions executed in the electronic device, including instructions stored in or on the memory to display the graphical information of the GUI on an external input / output device (such as a display device coupled to the interface). In other embodiments, if necessary, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Similarly, multiple electronic devices can be connected, and each device provides some necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system). Figure 7 A processor 701 is taken as an example.
[0110] The memory 702 is a non-transitory computer-readable storage medium provided in the present application. The memory stores instructions executable by at least one processor, so that the at least one processor executes the training method of the text classification model and / or the text classification method provided in the present application. The non-transitory computer-readable storage medium of the present application stores computer instructions, which are used to cause a computer to execute the training method of the text classification model and / or the text classification method provided in the present application.
[0111] The memory 702 is a non-transient computer-readable storage medium that can be used to store non-transient software programs, non-transient computer executable programs and modules, such as the training method of the text classification model and / or the program instructions / modules corresponding to the text classification method in the embodiment of the present application. The processor 701 executes various functional applications and data processing of the server by running the non-transient software programs, instructions and modules stored in the memory 702, that is, implementing the training method of the text classification model and / or the text classification method in the above method embodiment.
[0112] The memory 702 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created according to the use of the electronic device, etc. In addition, the memory 702 may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory 702 may optionally include a memory remotely arranged relative to the processor 701, and these remote memories may be connected to the electronic device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0113] The electronic device may further include: an input device 703 and an output device 704. The processor 701, the memory 702, the input device 703 and the output device 704 may be connected via a bus or other means. Figure 7 The example of connecting through bus is taken in the following.
[0114] The input device 703 can receive input digital or character information, and generate key signal input related to user settings and function control of the electronic device, such as a touch screen, a keypad, a mouse, a track pad, a touch pad, an indicator bar, one or more mouse buttons, a trackball, a joystick and other input devices. The output device 704 may include a display device, an auxiliary lighting device (e.g., an LED) and a tactile feedback device (e.g., a vibration motor), etc. The display device may include, but is not limited to, a liquid crystal display (LCD), a light emitting diode (LED) display and a plasma display. In some embodiments, the display device may be a touch screen.
[0115] Various implementations of the systems and techniques described herein can be realized in digital electronic circuit systems, integrated circuit systems, dedicated ASICs (application specific integrated circuits), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0116] These computer programs (also referred to as programs, software, software applications, or code) include machine instructions for programmable processors and can be implemented using high-level procedural and / or object-oriented programming languages, and / or assembly / machine languages. As used herein, the terms "machine-readable medium" and "computer-readable medium" refer to any computer program product, device, and / or means (e.g., disk, optical disk, memory, programmable logic device (PLD)) for providing machine instructions and / or data to a programmable processor, including a machine-readable medium that receives machine instructions as a machine-readable signal. The term "machine-readable signal" refers to any signal for providing machine instructions and / or data to a programmable processor.
[0117] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0118] The systems and techniques described herein can be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), the Internet, and a blockchain network.
[0119] A computer system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The relationship between the client and the server is generated by computer programs that run on the corresponding computers and have a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or a cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services ("Virtual Private Server", or "VPS" for short). The server may also be a server for a distributed system, or a server combined with a blockchain.
[0120] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this application can be executed in parallel, sequentially or in different orders, as long as the expected results of the technical solution disclosed in this application can be achieved, and this document is not limited here.
[0121] The above specific implementations do not constitute a limitation on the protection scope of this application. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principles of this application should be included in the protection scope of this application.
Claims
1. A training method for a text classification model, comprising: Obtaining a first sample text and a category label of the first sample text; Acquire keywords in the first sample text based on the category label; Determine the mask probability corresponding to the category label, and obtain a second sample text according to the mask probability corresponding to the category label, the keyword and the first sample text; Training an initial text classification model according to the second sample text and the category label to obtain a trained text classification model; The step of training an initial text classification model according to the second sample text and the category label to obtain a trained text classification model includes: Inputting the second sample text into an initial text classification model; wherein the initial text classification model is constructed based on a Transformer model; Obtaining the classification prediction result output by the initial text classification model; Obtaining a model loss value according to the prediction result and the category label; Training the initial text classification model according to the model loss value to obtain a trained text classification model; The obtaining of the classification prediction result output by the initial text classification model includes: Inputting the second sample text into the initial text classification model, and performing embedding processing on each character in the second sample text; Map the result of the embedding process to the space of the category label dictionary to obtain the classification prediction result; The acquiring of keywords in the first sample text based on the category label includes: Performing word segmentation processing on the first sample text, and performing stop word processing on the result of the word segmentation processing to obtain a word segmentation result of the first sample text; Performing word frequency statistics on the words in the word segmentation result of the first sample text under the category label to obtain the word frequency corresponding to each word under the category label; Determine a word frequency threshold corresponding to the category label; Determine the words whose word frequency is greater than or equal to the word frequency threshold in the word segmentation results of the first sample text as keywords in the first sample text; The step of acquiring the second sample text according to the mask probability corresponding to the category label, the keyword and the first sample text includes: masking the keywords in the first sample text according to the mask probabilities corresponding to the category labels, so as to prevent the attention mechanism of the text classification model from over-focusing on high-frequency words; The first sample text after the mask processing is determined as the second sample text.
2. The method of claim 1, wherein: The masking process of the keyword in the first sample text according to the mask probability corresponding to the category label includes: The keyword in the first sample text is replaced with MASK according to the mask probability corresponding to the category label.
3. A text classification method, comprising: Get the text to be processed; Inputting the text to be processed into a preset text classification model to obtain a classification prediction result of the text to be processed; The text classification model is a model trained by the training method described in any one of claims 1 to 2.
4. A training device for a text classification model, comprising: A first acquisition module, used to acquire a first sample text and a category label of the first sample text; A second acquisition module, configured to acquire keywords in the first sample text based on the category label; A determination module, used to determine the mask probability corresponding to the category label; A third acquisition module, configured to acquire a second sample text according to the mask probability corresponding to the category label, the keyword and the first sample text; A training module, used for training an initial text classification model according to the second sample text and the category label to obtain a trained text classification model; Wherein, the training module is specifically used for: Inputting the second sample text into an initial text classification model; wherein the initial text classification model is constructed based on a Transformer model; Obtaining the classification prediction result output by the initial text classification model; Obtaining a model loss value according to the prediction result and the category label; Training the initial text classification model according to the model loss value to obtain a trained text classification model; The training module is also specifically used for: Inputting the second sample text into the initial text classification model, and performing embedding processing on each character in the second sample text; Map the result of the embedding process to the space of the category label dictionary to obtain the classification prediction result; Wherein, the second acquisition module is specifically used for: Performing word segmentation processing on the first sample text, and performing stop word processing on the result of the word segmentation processing to obtain a word segmentation result of the first sample text; Performing word frequency statistics on the words in the word segmentation result of the first sample text under the category label to obtain the word frequency corresponding to each word under the category label; Determine a word frequency threshold corresponding to the category label; Determine the words whose word frequency is greater than or equal to the word frequency threshold in the word segmentation results of the first sample text as keywords in the first sample text; Wherein, the third acquisition module is specifically used for: masking the keywords in the first sample text according to the mask probabilities corresponding to the category labels, so as to prevent the attention mechanism of the text classification model from over-focusing on high-frequency words; The first sample text after the mask processing is determined as the second sample text.
5. The device according to claim 4, wherein: The third acquisition module is specifically used for: The keyword in the first sample text is replaced with MASK according to the mask probability corresponding to the category label.
6. A text classification device, comprising: An acquisition module is used to obtain the text to be processed; A prediction module, used for inputting the text to be processed into a preset text classification model to obtain a classification prediction result of the text to be processed; Wherein, the text classification model is a model trained using the training device described in any one of claims 4 to 5.
7. An electronic device comprising: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the method of any one of claims 1 to 2, or to enable the at least one processor to execute the method of claim 3.
8. A non-transitory computer-readable storage medium storing computer instructions, wherein: The computer instructions are used to enable the computer to execute the method according to any one of claims 1 to 2, or to enable the computer to execute the method according to claim 3.
9. A computer program product comprising a computer program, wherein: When the computer program is executed by a processor, the computer program implements the steps of the method according to any one of claims 1 to 2, or implements the steps of the method according to claim 3.
