A text category determination method and related device
By training an initial category classification model with multiple category recognition modules, and using correlation probability and loss function constraint training, the problem of inconsistent text classification recognition effect from different sources is solved, achieving higher text classification accuracy.
Patent Information
- Application Number
- CN202110112234.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-01-27
- Publication Date
- 2025-02-07
- Estimated Expiration
- 2041-01-27
AI Technical Summary
The prior art is difficult to effectively distinguish texts from different sources in text category recognition, resulting in inconsistent classification recognition effects.
By obtaining text samples from multiple text fields, a preliminary category classification model is trained, which includes a category recognition module corresponding to each text field, and trains through the correlation probability and loss function constraint model, so that the model can learn the various text fields of Features and related knowledge.
Improve the accuracy of text classification, allowing the model to more accurately judge the categories of text to be identified from different text fields.
Smart Images

Figure CN113569043B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing, and in particular to a text category determination method and related devices. Background Art
[0002] With the development of Internet technology, a large number of users use the Internet for learning, work and socializing. In the process of using the Internet, users will send, receive and view a large amount of text content. The information contained in these text contents is of varying quality. In addition, the Internet spreads information at a fast speed. If problematic text content is not identified and controlled, it will have an adverse impact on the Internet.
[0003] How to accurately identify text categories is one of the important means to maintain Internet security. However, text content has different sources, such as keywords entered by users during search, articles on web pages, articles on public accounts, etc. The current related technologies mainly use general classification models to identify the categories of texts from all sources.
[0004] Since there are large domain differences between texts from different sources, it is difficult for general classification models to notice these differences, resulting in large differences in text classification and recognition effects for different sources. Summary of the invention
[0005] In order to solve the above technical problems, the present application provides a text category determination method, so that the category classification model can not only learn the characteristics of each field itself during training, but also integrate the relevant knowledge between different fields, thereby improving the accuracy of text classification.
[0006] The embodiments of the present application disclose the following technical solutions:
[0007] In a first aspect, an embodiment of the present application provides a method for determining a text category, characterized in that the method comprises:
[0008] Acquire a first sample set including text samples from N text fields, wherein the target sample is any text sample in the first sample set, and the target sample is annotated with a corresponding actual text category, where N≥2;
[0009] Determine input data of an initial category classification model according to the target sample, and output N category recognition results corresponding to the target sample through the initial category classification model, wherein the initial category classification model includes N category recognition modules corresponding to the N text fields one by one, and one of the category recognition modules outputs one category recognition result;
[0010] Determine the association probabilities between the target sample and the N text fields respectively;
[0011] Determine loss functions corresponding to N category recognition modules respectively according to the association probability, the category recognition result and the actual text category;
[0012] The initial category classification model is trained according to the loss function to obtain a category classification model, and the category classification model is used to determine the text category of the text to be recognized.
[0013] In a second aspect, an embodiment of the present application provides a text category determination device, the device comprising a first acquisition unit, a first determination unit, a second determination unit, a third determination unit and a training unit:
[0014] The first acquisition unit is used to acquire a first sample set including text samples from N text fields, wherein the target sample is any text sample in the first sample set, and the target sample is annotated with a corresponding actual text category, where N≥2;
[0015] The first determination unit is used to determine input data of an initial category classification model according to the target sample, and output N category recognition results corresponding to the target sample through the initial category classification model, wherein the initial category classification model includes N category recognition modules corresponding to the N text fields one by one, and one of the category recognition modules outputs one category recognition result;
[0016] The second determination unit is used to determine the association probabilities between the target sample and the N text fields respectively;
[0017] The third determination unit is used to determine the loss functions corresponding to the N category recognition modules respectively according to the association probability, the category recognition result and the actual text category;
[0018] The training unit is used to train the initial category classification model according to the loss function to obtain a category classification model, and the category classification model is used to determine the text category of the text to be recognized.
[0019] In a third aspect, an embodiment of the present application provides a computer device, the device comprising a processor and a memory:
[0020] The memory is used to store program code and transmit the program code to the processor;
[0021] The processor is used to execute the text category determination method described in the first aspect according to the instructions in the program code.
[0022] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, characterized in that the computer-readable storage medium is used to store a computer program, and the computer program is used to execute the text category determination method described in the first aspect.
[0023] It can be seen from the above technical solution that by obtaining a first sample set including text samples from N text fields, the text field from which the text sample comes can be marked as its actual text category, and the initial category classification model is trained by the first sample set to obtain a category classification model. The initial category classification model includes N category recognition modules corresponding to the N text fields, and different category recognition modules are dedicated to identifying the text in the corresponding text field. Although the texts from the same text field have similarities in expression, they also have certain relevance with the expressions of other text fields. Therefore, in order to improve the category recognition accuracy of the category classification model for the texts in the N text fields, it is necessary to enable each category recognition module to learn the knowledge applicable to the field of this article in other text fields through training. For the input data determined according to the target sample in the first sample set, the N category recognition results corresponding to the target sample can be output respectively by the N category recognition modules in the initial category classification model, that is, the category recognition modules corresponding to different text fields will make category recognition results for the target sample from a text field. In order to enable the category recognition module to reasonably learn effective knowledge in other text fields, the association probability between the target sample and the N text fields can be determined. The association probability can reflect the degree of association between the target sample and the N text fields in terms of expression. According to the association probability, the category recognition result and the actual text category, the loss function of the N category recognition modules is determined respectively or correspondingly. Through the loss function, the model can learn effective knowledge in other text fields appropriately based on the degree of association between the target sample and each text field. The category classification model trained in this way can more accurately judge the text category of the text to be recognized from different text fields based on the text characteristics of each text field itself and the related characteristics between different text fields, thereby improving the rationality and accuracy of classification. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0025] Figure 1 A schematic diagram of a method for determining a text category in an actual application scenario provided by an embodiment of the present application;
[0026] Figure 2 A flowchart of a text category determination method provided in an embodiment of the present application;
[0027] Figure 3 A schematic diagram of a text category determination method provided in an embodiment of the present application;
[0028] Figure 4 A schematic diagram of a text category determination method provided in an embodiment of the present application;
[0029] Figure 5 A flowchart of a method for determining a text category in an actual application scenario provided by an embodiment of the present application;
[0030] Figure 6 A schematic diagram of a method for determining a text category in an actual application scenario provided by an embodiment of the present application;
[0031] Figure 7 A structural block diagram of a text category determination device provided in an embodiment of the present application;
[0032] Figure 8 A structural diagram of a computer device provided in an embodiment of the present application;
[0033] Fig. 9 A structural diagram of a server provided in an embodiment of the present application. DETAILED DESCRIPTION
[0034] The embodiments of the present application are described below in conjunction with the accompanying drawings.
[0035] In order to be able to identify and classify text content from multiple text fields, a multi-task model is usually used in related technologies to process text content from multiple text fields. A corresponding recognition module is set for each text field in the multi-task model. However, in the process of training the multi-task model, each text sample is only input into the recognition module corresponding to the field described by the sample for training, which will cause other recognition modules to fail to learn the text characteristics of the text field corresponding to the text sample, making it difficult to improve the accuracy of the classification model.
[0036] In order to solve the above technical problems, the present application provides a text category determination method. When training the model, the processing device can input target samples from a certain text field into multiple category recognition modules at the same time, and use the association probability between the target sample and multiple text fields to constrain the model's learning of related knowledge between different fields. In this way, the final category classification model can not only learn the characteristics of each field itself, but also integrate the related knowledge between different fields, thereby improving the accuracy of text classification to a certain extent.
[0037] It is understandable that the method can be applied to a processing device, which is a processing device with a text category determination function, for example, it can be a terminal device or a server with a text category determination function. The method is independently executed by a terminal device or a server, and can also be applied to a network scenario in which a terminal device and a server communicate, and the terminal device and the server cooperate to run. Among them, the terminal device can be a mobile phone, a desktop computer, a personal digital assistant (PDA for short), a tablet computer and other devices. The server can be understood as an application server or a Web server. In actual deployment, the server can be an independent physical server or a server cluster or distributed system composed of multiple physical servers. The terminal and the server can be directly or indirectly connected by wired or wireless communication, and this application is not limited here.
[0038] In addition, the present application also relates to artificial intelligence technology (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.
[0039] Artificial intelligence technology is a comprehensive discipline that covers a wide range of fields, including both hardware-level and software-level technologies. Basic artificial intelligence technologies generally include sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, big data processing technology, operating / interactive systems, mechatronics and other technologies. Artificial intelligence software technology mainly includes computer vision technology, speech processing technology, natural language processing technology, and machine learning / deep learning. Among them, the technical solution of this application mainly involves machine learning technology, natural language processing technology and computer vision technology.
[0040] Computer vision technology (CV) is a science that studies how to make machines "see". To put it more specifically, it refers to using cameras and computers to replace human eyes to identify targets, trace and measure targets, and further perform image processing to make computer processing into images that are more suitable for human eye observation or transmission to instruments for detection. As a scientific discipline, computer vision studies related theories and technologies, and attempts to establish an artificial intelligence system that can obtain information from images or multi-dimensional data. Computer vision technology usually includes image processing, image recognition, image semantic understanding, image retrieval, OCR, video processing, video semantic understanding, video content / behavior recognition, three-dimensional object reconstruction, 3D technology, virtual reality, augmented reality, simultaneous positioning and map construction, and other technologies, as well as common biometric recognition technologies such as face recognition and fingerprint recognition.
[0041] Machine Learning (ML) is a multi-disciplinary subject that involves probability theory, statistics, approximation theory, convex analysis, algorithm complexity theory and other disciplines. It specializes in studying how computers simulate or implement human learning behavior to acquire new knowledge or skills and reorganize existing knowledge structures to continuously improve their performance. Machine learning is the core of artificial intelligence and the fundamental way to make computers intelligent. Its applications are spread across all areas of artificial intelligence. Machine learning and deep learning usually include artificial neural networks, belief networks, reinforcement learning, transfer learning, inductive learning, and self-learning.
[0042] Natural language processing (NLP) is an important direction in the fields of computer science and artificial intelligence. It studies various theories and methods that can achieve effective communication between people and computers using natural language. Natural language processing is a science that integrates linguistics, computer science, and mathematics. Therefore, research in this field will involve natural language, that is, the language people use in daily life, so it is closely related to the study of linguistics. Natural language processing technology usually includes text processing, semantic understanding, machine translation, robot question answering, knowledge graph and other technologies.
[0043] For example, in the embodiment of the present application, the processing device can identify the text content of the sample text through computer vision technology, and then understand the semantics corresponding to the text content through natural language processing technology, and classify the text content through the semantics. In addition, the processing device can also use machine learning technology to perform more complex repeated training on the initial category classification model through a loss function, so as to obtain a more accurate category classification model.
[0044] In order to facilitate understanding of the technical solution of the present application, a method for determining a text category in an actual application scenario provided by an embodiment of the present application will be introduced below in conjunction with the accompanying drawings.
[0045] See also Figure 1 , Figure 1 A schematic diagram of a method for determining a text category in an actual application scenario provided in an embodiment of the present application. In the actual application scenario, the processing device is a server 101, and an initial category classification model exists in the server 101. The initial category classification model can be used to train to obtain category classification models for multiple text fields.
[0046] Among them, Figure 1 As shown, the initial category classification model includes three category recognition modules, category recognition module 1, category recognition module 2 and category recognition module 3, which are respectively used to determine the text categories of texts in text field 1, text field 2 and text field 3. Based on this, in order to enable the initial category classification model to learn the relevant knowledge between different text fields, the server 101 can enable each category recognition module to learn the relevant characteristics of the text field corresponding to other category recognition modules.
[0047] First, the server 101 may obtain a first sample set including text samples from three text fields, namely, text field 1, text field 2, and text field 3, and arbitrarily select a text sample as a target sample, wherein the target sample is annotated with a corresponding actual text category. In order to enable the model to understand the text sample more accurately, the server 101 may first determine the input data of the initial category classification model based on the target sample, for example, the input data may be the target sample after feature extraction processing.
[0048] In this actual application scenario, the text field to which the target sample belongs may be text field 1. In order to enable the category recognition modules corresponding to text field 2 and text field 3 to also learn the relevant information of text field 1, during the training process, server 101 can input the input data into category recognition module 2 and category recognition module 3 in addition to inputting the input data into category recognition module 1, so that the three category recognition modules can all output a corresponding category recognition result. Among them, in addition to category recognition result 1 being able to reflect the characteristics of text field 1 itself, category recognition result 2 and category recognition result 3 can respectively reflect the relevant knowledge between text field 2 and text field 3 and text field 1.
[0049] At this time, in order to further improve the accuracy of training, the server 101 can also determine the association probability between the target sample and the three text fields respectively, and the association probability can reflect the degree of association between the target sample and the three text fields. Under normal circumstances, the higher the degree of association between the target sample and a text field, the more relevant knowledge the text field can learn from the target sample. The server 101 can determine the loss function corresponding to the three category recognition modules according to the association probability, the three category recognition results and the actual text category. For example, for category recognition module 2, the difference between category recognition result 2 and the actual text category can reflect the relevant knowledge in text field 1 that is conducive to classifying the text in the text field to a certain extent; through the association probability between the target sample and text field 2, the learning of the relevant knowledge by category recognition module 2 can be reasonably constrained.
[0050] Therefore, when the initial category classification model is trained according to the loss function, the degree of learning can be controlled while learning the relevant knowledge between different text fields, so that each category recognition module in the category classification model finally trained can reasonably integrate the effective knowledge of different text fields, thereby improving the accuracy of the model in classifying the text to be recognized.
[0051] Next, a text category determination method provided in an embodiment of the present application will be introduced in conjunction with the accompanying drawings.
[0052] See also Figure 2 , Figure 2 A flowchart of a text category determination method provided in an embodiment of the present application, the method comprising:
[0053] S201: Acquire a first sample set including text samples from N text fields.
[0054] In order to enable the model to improve the accuracy of text classification by learning the characteristics of multiple text fields, the processing device may first obtain a sample set of text samples from multiple text fields when training the model, such as texts from web pages, articles, and query information. For example, in an embodiment of the present application, the processing device may obtain a first sample set including text samples from N text fields, all of which have clear text field sources, where N≥2.
[0055] The processing device may train an initial category classification model based on the first sample set. For ease of explanation, a text sample in the first sample set: a target sample is taken as an example to describe the solution.
[0056] The processing device determines the model input for this model training based on the target sample. The target sample is annotated with a corresponding actual text category, and the actual text category is used to identify the actual text category of the target sample in the classification scenario targeted by the model to be trained. For example, when the model to be trained is a model for determining whether a text is pornographic text, the actual text category can mark whether the target sample is a text containing pornographic content.
[0057] S202: Determine input data of an initial category classification model according to the target sample, and output N category recognition results corresponding to the target sample through the initial category classification model.
[0058] Among them, the initial category classification model is the above-mentioned model to be trained for text category judgment. The initial category classification model includes N category recognition modules, and the N category recognition modules correspond one-to-one to N text fields, that is, one category recognition module is used to perform text category recognition on text in a text field.
[0059] In the related art, when training a model with a similar structure, the processing device will only input the text sample into the category recognition module corresponding to its text field, which will result in that only the category recognition module can learn the characteristics of the text field during the training process, and the category recognition modules corresponding to other text fields cannot be learned. In actual situations, since texts in different text fields may have certain similarities in expression, for example, there may be related parts in text characteristics and expression forms, therefore, by learning relevant knowledge in other text fields, it is helpful for the category recognition module to more accurately classify texts in its own text field.
[0060] Based on this, in an embodiment of the present application, the processing device can input multiple category recognition modules according to the same target sample during the training process, thereby realizing mutual learning between different text fields. First, in order to enable the model to be trained based on the target sample, the processing device can first determine the input data of the initial category classification model according to the target sample, that is, convert the target sample into a data format that enables the initial category classification model to be trained more efficiently, for example, the word vector data corresponding to the target sample can be used as the input data.
[0061] In order to enable each category recognition module in the initial category classification model to learn relevant knowledge of other text fields outside its own text field, the processing device not only inputs the input data into the category recognition module corresponding to the text field to which the target sample belongs, but also further inputs the input data into other N-1 category recognition modules, so that the initial category recognition module can output N category recognition results corresponding to the target sample, one of which can output a category recognition result, and the category recognition result can reflect the recognition of the input data by the category recognition module. For example, the category recognition module can express the category of the input data by outputting 0 or 1. When identifying whether it is an abnormal text, if the output is 0, it means that it is not an abnormal text, and if the output is 1, it means that it is an abnormal text.
[0062] S203: Determine the association probabilities between the target sample and the N text fields respectively.
[0063] It is understandable that not all knowledge related to the text field itself needs to be fully accepted and learned by the category recognition module. For example, when the text style difference between a certain text field and the text field corresponding to the category recognition module is too large, if the relevant knowledge of the text field is over-learned, the category recognition module may integrate more invalid knowledge, which will lead to a decrease in the accuracy of text classification in its own text field. Therefore, reasonable control of the learning degree of the category recognition module is the key to improving classification accuracy.
[0064] Generally speaking, when the text features of two text fields are relatively close, the category recognition module is likely to be able to learn more relevant knowledge. The text features are features related to the text's own expression form in addition to the semantics of the text content, such as text style, text format and other information. For example, since many texts on web pages are also in the form of articles, the writing styles of the source and web page texts and the source and article texts may be similar, while the texts from the query information are mostly independent fields, such as query keywords, query key sentences, etc. The writing style of this type of text will be quite different from that of the text from the article. Therefore, there may be more relevant knowledge between the article field and the web page field, and less relevant knowledge between the article field and the query field.
[0065] Based on this, in an embodiment of the present application, the processing device can constrain the learning process of the category recognition module based on the degree of association between text fields. First, the processing device can determine the association probability between the target sample and N text fields respectively. The association probability can reflect the degree of association between the target text and other text fields in terms of expression. The greater the association probability of the target text for a text field, the higher the degree of association between the target sample and the text field in terms of expression, that is, the category recognition module corresponding to the text field can learn more relevant knowledge from the text field to which the target sample belongs. The processing device can adjust the degree to which the category recognition module learns knowledge of other text fields based on the association probability.
[0066] S204: Determine the loss functions of the N corresponding category recognition modules according to the association probability, the category recognition result and the actual text category.
[0067] Among them, through the category recognition result and the actual text category, the processing device can adjust the parameters of each category recognition module, that is, the category recognition result output by the category recognition module can be close to the actual text category. In the parameter adjustment process, since the actual text category is the actual category corresponding to the target sample, and the target sample comes from a different text field, the category recognition module will learn the knowledge related to its own text field from the text field in order to make the output category recognition result close to the actual text category, so that it can recognize the text in a certain text field and output a result close to the actual text category for the target sample.
[0068] Through the association probability, the processing device can determine the reasonable learning degree of the category recognition module when learning the relevant knowledge of other text fields. For example, when the association probability of the target sample corresponding to a certain text field is 10%, it means that the feature similarity between the text field corresponding to the target sample and the text field may be only 10%. At this time, the category recognition module corresponding to the text field adjusts the parameters based on the output category recognition result and the actual text category. In the process of learning relevant knowledge, learning 10% of them is more conducive to improving its own category recognition accuracy, that is, only 10% of the output category recognition result needs to be able to fit the actual text category. This learning degree is more in line with the actual situation between the two text fields. If more than 10% of the part is learned, although the output category recognition result may be more in line with the actual text category, due to the large difference between the text fields, the category recognition module may over-integrate some invalid information, resulting in a decrease in model accuracy and inability to accurately recognize the text in the text field corresponding to itself.
[0069] Based on this, through the association probability, category recognition result and actual text category, the processing device can determine the loss function for each category recognition module, and N loss functions can be obtained for N category recognition modules. Among them, each loss function can be used to learn and train the corresponding category recognition module. Through this loss function, each category recognition module can more reasonably learn relevant knowledge in other text fields that is beneficial to its own classification of the target sample.
[0070] S205: Training the initial category classification model according to the loss function to obtain a category classification model, where the category classification model is used to determine the text category of the text to be recognized.
[0071] Through the above process, after inputting the target sample, the processing device can obtain N loss functions corresponding to N category recognition modules respectively, and the processing device can train the category recognition modules in the initial category classification model through the loss function, so that each category recognition module can learn the relevant knowledge of the text field corresponding to the target sample. Based on this, by continuously training the initial category classification model with the text samples in the first sample set as the target text, the processing device can make the N category recognition modules in the initial category classification model fully and reasonably learn the relevant knowledge between different text fields, and then obtain the category classification model. Since the category classification model already has a category recognition module that can accurately classify texts in multiple text fields, the category classification model can be used to determine the text category of the text to be recognized.
[0072] It can be seen from the above technical scheme that for the input data determined according to the target sample in the first sample set, the N category recognition results corresponding to the target sample can be output respectively by the N category recognition modules in the initial category classification model, that is, the category recognition modules corresponding to different text fields will make category recognition results for the target sample from a text field. In order to enable the category recognition module to reasonably learn effective knowledge in other text fields, the association probability between the target sample and the N text fields can be determined, and the association probability can reflect the degree of association between the target text and other text fields in the form of expression. According to the association probability, the category recognition result and the actual text category, the loss function of the N category recognition modules is determined respectively or corresponding to each other, and the loss function can enable the model to learn effective knowledge in other text fields appropriately based on the degree of association between the target sample and each text field. The category classification model obtained by this training can judge the text category of the text to be identified from different text fields more accurately based on the text characteristics of each text field itself and the related characteristics between different text fields, and improve the rationality and accuracy of classification to a certain extent.
[0073] As mentioned above, the association probability can reflect the degree of association between the target sample and other text fields in terms of expression form. Therefore, the processing device can determine the association probability by learning the expression forms of different text fields. In a possible implementation, in order to more accurately identify the expression forms of different text fields, the processing device can train a field classifier, and determine the degree of association between the target sample and N text fields respectively through the field classifier.
[0074] In order to train the domain classifier, the processing device may first obtain a second sample set including text samples from N text domains, wherein the N text domains in the second sample set are the same as the N text domains in the first sample set, so that the determined association probability can be used to train the initial category classification model. The text samples in the second sample set are annotated with corresponding actual text domains, which are the text domains to which the text samples actually belong.
[0075] The processing device can obtain an initial domain classifier, which can obtain a certain classification result of the text domain based on the input text sample. The processing device can determine the input data of the initial domain classifier based on the text sample in the second sample set, output the corresponding predicted text domain through the initial domain classifier, and train the initial domain classifier through the difference between the predicted text domain and the actual text domain to obtain a domain classifier.
[0076] Among them, by predicting the difference between the text domain and the actual text domain, the initial domain classifier can learn the difference in expression between different text domains, that is, it can learn the expression characteristics of each text domain. Therefore, the trained domain classifier can analyze the matching degree between the expression of the input text and the expression of different domains based on the expression of the input text, and then determine the association probability for N text domains.
[0077] For example, Figure 3 As shown, Figure 3 A flowchart for training an initial domain classifier is shown. The training process includes:
[0078] S301: Obtain text samples from multiple text fields.
[0079] Among them, these text samples are annotated with clear actual text fields.
[0080] S302: Determine the word vector corresponding to the text sample.
[0081] In order to enable the input data to be used for more efficient model training, the processing device may first convert the data format of the text sample. In an embodiment of the present application, the processing device may determine the word vector corresponding to the text sample and use the word vector as the model input for model training.
[0082] S303: Setting training labels according to the actual text domain corresponding to the text sample, and training an initial domain classifier.
[0083] For example, the processing device can set the training label of text sample A from the web page to 1, the training label of text sample B from the article to 2, and the training label of text sample C from the query information to 3. Then the training data of the input model can be <text sample A word vector, 1>, <text sample B word vector, 2> and <text sample C word vector, 3>.
[0084] S304: Save the trained domain classifier.
[0085] Among them, Figure 4 As shown, Figure 4 A schematic diagram of a domain classifier is shown. The processing device can input the text "I have eaten dinner" into the domain classifier, and the domain classifier will perform word segmentation on the text, that is, divide the text into individual words, such as "I", "eat", "dinner", etc. The domain classifier can convert the words into corresponding word vectors through the word2vec word vector model, such as the word vectors "I E1", "eat E1", etc., and then input the word vector into the transformer model for feature extraction, such as extracting features related to the text expression form. The domain classifier can input the extracted features into the fully connected layer for judgment, thereby outputting the association probability of the text corresponding to each text field.
[0086] The trained domain classifier can be retained. If the category classification model needs to be trained again in the future, the retained domain classifier can be used directly without having to train the corresponding domain classifier every time.
[0087] Among them, in addition to the transformer model, other models with similar functions can also be used as substitutes for feature extraction, such as the Long Short-Term Memory model (LSTM), the text classification convolutional neural network model (Textcnn), and the bidirectional encoder model based on deformation (Bidirectional Encoder Representations from Transformers, referred to as Bert), etc. These models all have certain feature extraction functions and can also be applied to the technical content of semantic feature extraction described below.
[0088] It is understandable that since the first sample set and the second sample set are both text sample sets for the above-mentioned N text fields, in a possible implementation, in order to reduce the training cost and reduce the burden of obtaining training samples, the processing device can mark the text samples in the second sample set with the required labels, that is, the actual text categories of the text samples, so that the first sample set can be directly obtained, that is, the first sample set and the second sample set include the same text samples, but the labels used during training are different. This method of determining the sample set makes it unnecessary to obtain additional text samples during the training of the initial category classification model and the initial field classifier. One set of sample sets can meet the training of the two models, reducing the sample acquisition cost during training.
[0089] As mentioned above, the processing device can determine N loss functions for N category recognition modules for training and learning. In order to facilitate understanding of the technical solution provided in the embodiment of the present application, next, any one of the above-mentioned N category recognition modules is used as an example of a target recognition module for explanation. The target recognition module corresponds to a target field in the N text fields, that is, after training and learning, the target recognition module can be used to perform category recognition on the text to be recognized from the target field.
[0090] In a specific training process, the processing device may first determine the difference parameter between the category recognition result of the target recognition module and the actual text category. Based on the difference parameter, the processing device may adjust the relevant parameters in the target recognition module so that the category recognition result output by the target recognition module is close to the actual text category. For example, the target recognition module may output a value between 0 and 1 to represent the text category of the target sample. The closer the value is to 1, the greater the probability that the target sample is an abnormal text. When the actual text category of the target sample is an abnormal text, the difference parameter may be the difference between the value output by the target recognition module and 1. In the training process, the purpose of adjusting the parameters of the target recognition module is to make the difference as close to 0 as possible.
[0091] It can be understood that since the category recognition module corresponds to the target domain, the text sample also has a corresponding text domain, and the actual category result is the category in the text domain corresponding to the text sample, therefore, if the target recognition module wants to output the actual category result, it is necessary to introduce the relevant knowledge in the text domain corresponding to the text sample to classify the text sample. It can be seen that in the process of adjusting the parameters to make the output category recognition result close to the actual text category, the target recognition module can learn the relevant knowledge of the text domain corresponding to the text sample.
[0092] In order to reasonably control the learning of the relevant knowledge of the text field to which the target sample belongs by the target recognition module, the processing device also needs to introduce the association probability of the target sample corresponding to the target field in the loss function corresponding to the target recognition module. In the loss function, the association probability can be equivalent to the weight of the difference parameter, which plays a role in limiting the learning ratio, so that the target recognition module can learn a moderate part of the knowledge in the text field to which the target sample belongs according to the loss function during the training based on the loss function, which can avoid the target recognition module from overfitting the text field to which the target sample belongs, thereby reducing the recognition accuracy of the text to be recognized in the target field. For example, in the above example, the difference parameter can be expressed as the difference between the output value and 1. For example, when the output recognition result is 0.3, the difference parameter can be initially (1-0.3). If the association probability between the target sample and the target field is 10%, then the target recognition module only needs to learn about 10% of the relevant knowledge between the two text fields during the parameter adjustment training process. At this time, the loss function can be expressed as 10%*(1-recognition result). In this way, in the parameter adjustment training process to make the loss function close to 0, only one tenth of the original part needs to be adjusted to complete the training of the target recognition module. In this process, the target recognition module only needs to learn 10% of the relevant knowledge, thus achieving moderate control of the learning content.
[0093] For example, as shown in the following formula, this formula is a loss function for training the target recognition module.
[0094] L M_S =DP M_S *Cross-entropy(p S ,y M )
[0095] The target domain is represented by S, and the text domain to which the target sample belongs is represented by M. S and M can represent the same text domain or different text domains.
[0096] L M_Sis the loss function of the target recognition module in the text domain S when inputting target samples from the text domain M for training, DP M_S represents the association probability of the target sample corresponding to the text domain S, p S is the category recognition result of the target sample by the target recognition module, y M is the actual text category of the target sample, Cross-entropy(p S ,y M ) is the difference parameter. It can be seen that through DP M_S , in the use of L M_S When training the object recognition module, the extent to which it learns relevant knowledge from the text domain M can be restricted.
[0097] In addition to being able to train the category recognition module through the loss function, in order to further improve the model accuracy, the processing device can also train other components in the initial category classification model.
[0098] It is understandable that in many cases, the category recognition module classifies text categories by understanding the semantics of the text. For example, when the category recognition module is used to determine whether a text is entertainment news, it can understand the semantics of the text to determine whether it involves celebrities, events, etc. in the entertainment industry. As mentioned above, different text fields may have some common related knowledge, which helps the category recognition module to classify the text. It can be seen that this related knowledge helps to understand the semantic features of the text to a certain extent.
[0099] Based on this, in order to enable the category recognition module to have a deeper understanding of the semantic characteristics of the input data, in a possible implementation method, the initial category classification model can also include a feature extraction module shared by the N text fields, and the feature extraction module is used to extract the semantic feature vector corresponding to the target sample as the input data of the N category recognition modules. The semantic feature vector can more prominently reflect the semantic characteristics of the target sample. For example, the feature extraction module can be a two-layer transformer model. Among them, since the feature extraction module is shared by the N text fields, the module can obtain input data from the N text fields for feature extraction. In the process of feature extraction of the input data of the N text fields, the feature extraction module can learn the relevant knowledge between multiple different text fields and realize feature fusion to a certain extent, so that the extracted semantic feature vector can fuse the semantic characteristics between different text fields, and then the category recognition module can more accurately perform text category recognition.
[0100] As mentioned above, through the loss function, each category recognition module can learn relevant knowledge in multiple different text fields that is beneficial to its own text classification. It can be seen that the loss function has the function of enabling the model to learn the characteristics of different text fields. At the same time, since in the embodiment of the present application, the text classification in the category recognition module is based on the semantics of the text, if the accuracy of the semantic feature vector output by the feature extraction module can be improved, the category recognition module can be trained more accurately to a certain extent.
[0101] From the above content, it can be seen that different text fields have some related knowledge features, which help to analyze the text in each text field more accurately. Based on this, in a possible implementation, the processing device can also use the loss function to train the feature extraction module, so that the feature extraction module can comprehensively extract the semantic features of the input text based on the related knowledge between different text fields.
[0102] For example, after determining the loss function of the target recognition module, the processing device can train the target recognition module and the feature extraction module in the initial category classification model based on the loss function of the target recognition module. In the process of training the feature extraction module, the processing device can also adjust the relevant parameters in the feature extraction module through the difference parameter so that the difference parameter approaches the target value. In the process of parameter adjustment, the feature extraction module can determine the differences and correlations of the semantic understanding of the target sample in different text fields. This part of the differences and correlations can reflect the knowledge related to semantics in different text fields; through the association probability, the processing device can also constrain the learning of the feature extraction module for this part of the related knowledge based on the association probability between the target sample and different text fields, so that the trained feature extraction module can pay attention to the information related to the semantics of the input data in multiple different text fields during the process of extracting semantic features from the input data itself, which can improve the accuracy of the feature extraction module to a certain extent.
[0103] It is understandable that since the processing device can determine N loss functions for N category recognition modules, and each loss function has the ability to enable the model to learn relevant knowledge between two different text fields. Since the feature extraction module is a feature extraction module shared by N text fields, when using the loss function to train it, different loss function training methods can be used for training based on different training purposes. For example, the processing device can train it through each individual loss function, or integrate N loss functions into a unified loss function and train it. There is no limitation here. The above different training methods can enable the feature extraction module to learn relevant knowledge between different text fields to a certain extent.
[0104] After the category classification model is trained, the processing device can use the model to determine the text category of the text to be recognized. In a possible implementation, the processing device can obtain the text to be recognized from a first field. In order to enable the category classification model to effectively classify the text, the first field can be any one of the N text fields mentioned above.
[0105] Similar to the training process of the model, in order to enable the category classification model to analyze the text to be recognized, the processing device can first determine the input data of the category classification model according to the text to be recognized. As mentioned above, through model training, the processing device can enable each category recognition module in the obtained category classification model to fully learn the relevant knowledge in other different text fields that is beneficial to its own text classification, so each category recognition module obtained by training can classify the text content of its corresponding text field more accurately. Based on this, in an embodiment of the present application, the processing device can determine the category recognition result of the text to be recognized through the category recognition module corresponding to the first field in the category classification model. For example, if the text to be recognized is a text from a web page, the category recognition result corresponding to the text to be recognized can be determined by combining the input data corresponding to the text to be recognized through the category recognition module corresponding to the web page text field. It can be understood that the category recognition module itself may not be able to output the final recognition result, but is only a more critical model part in the model for determining the category. For example, the category recognition module may be a hidden layer in a category classification model, the category recognition module may output probabilities corresponding to various text categories, and the output layer of the category classification model may output a final category recognition result according to the probabilities.
[0106] In actual situations, the category classification model is applied in various forms. For example, a processing device may use the category classification model to classify text content involved in a certain software, and the software may be any software having text content or related to text content.
[0107] It is understandable that, since the training samples used in the model training process are text samples from the above-mentioned N text fields, most of the relevant knowledge learned by the trained category classification model is relevant knowledge in the N text fields, that is, the category classification model is more suitable for classifying the texts to be identified in the N text fields. Based on this, in order to improve the accuracy of the category classification model during the application process, the processing device can determine the above-mentioned N text fields according to the text sources involved in the target software, and the target software can be any software that can involve text content.
[0108] For example, in a possible implementation, the target software may be a social software, and the text sources involved in the social software may include chat sources, blog sources, article sources, web page sources, etc. In order to accurately classify the text to be identified involved in the social software, the processing device may obtain the first sample set of the above multiple text sources to train the initial category classification model.
[0109] Furthermore, based on different classification scenarios, the recognition results set by the processing device during model training may also include multiple types. Among them, in order to make the results output by the model have distinguishability, the category recognition result includes recognition results for at least two text categories, so that the category classification model can have a classification function, for example, the two text categories can be "pornographic content" and "non-pornographic content". In other classification scenarios, the category recognition result may also include recognition results for three or more text categories, such as "official release content", "player release content", "customer service release content", "system automatic reply content", etc., so that the text to be recognized can be classified more carefully and accurately, so that the obtained recognition results can be more conveniently applied.
[0110] In order to facilitate understanding of the technical solution provided by the present application, a text category determination method provided by an embodiment of the present application will be introduced below in combination with an actual application scenario.
[0111] See also Figure 5 , Figure 5 A flowchart of a method for determining a text category in an actual application scenario provided by an embodiment of the present application, in which the processing device is a server capable of model training, and the N text fields include text from web page sources (Hypertext Markup Language, referred to as HTML), text from query information (Query) sources, and text from three sources of public account articles (Media Public, referred to as MP), that is, N=3. The method includes:
[0112] S501: Obtain text samples from three text fields.
[0113] S502: Read in the word vector model and domain classifier.
[0114] like Figure 6 As shown, Figure 6 A schematic diagram of training an initial text category classification model in an actual application scenario provided by an embodiment of the present application. M , X S , X Q Represent text samples from MP, HTML, and Query respectively. Through the transformation of the word vector model, the input data word vector E can be obtained respectively. M 、E S 、E Q The server can input the word vector into the domain classifier model. For each word vector input, the domain classifier can determine the association probability λ for the three text domains. M , S , Q .
[0115] S503: Train an initial category classification model.
[0116] In this actual application scenario, the category recognition module can be in the form of a fully connected layer network. The server can input each word vector into the fully connected layer MP, the fully connected layer HTML and the fully connected layer Query to obtain the corresponding category recognition result. The fully connected layer is equivalent to the category recognition module mentioned above. The server can generate a loss function corresponding to each fully connected layer based on the category recognition result, the actual text category and association probability of the text sample. M For example, the category recognition result obtained after the text sample is input into the fully connected layer HTML can be p S , the actual text category is y M , then the loss function of the text sample for the fully connected layer HTML is:
[0117] L M_S =DP M_S *Cross-entropy(p S ,y M )
[0118] Among them, DP M_S For this sample X M The λ obtained after inputting the domain classifier S .
[0119] The overall loss function of the model can be expressed as:
[0120] Lall =L M_M +L M_S +L M_Q +L S_M +L S_S +L S_Q +L Q_M +L Q_S +L Q_Q
[0121] In addition, for the text samples of the fully connected layer corresponding to the input text field, the text probability can also be set to 1, with X M For example, the loss function of the sample for the fully connected layer MP can be:
[0122] L M_M =Cross-entropy(p M ,y M )
[0123] That is, the impact of the associated probability is ignored.
[0124] Based on the above loss function, the server can iteratively train the two-layer transformer layer and the fully connected layer in the initial category classification model to obtain a category classification model. Among them, the category recognition module can be a fully connected layer network structure or other more complex network structures, as long as it has the function of recognizing text categories.
[0125] S504: Save the trained category classification model.
[0126] Based on the text category determination method provided in the above embodiment, the present application embodiment also provides a text category determination device, see Figure 7 , Figure 7 The structural block diagram of a text category determination device 700 provided in an embodiment of the present application, the device 700 includes a first acquisition unit 701, a first determination unit 702, a second determination unit 703, a third determination unit 704 and a training unit 705:
[0127] A first acquisition unit 701 is used to acquire a first sample set including text samples from N text fields, wherein a target sample is any text sample in the first sample set, and the target sample is annotated with a corresponding actual text category, where N≥2;
[0128] A first determining unit 702 is used to determine input data of an initial category classification model according to the target sample, and output N category recognition results corresponding to the target sample through the initial category classification model, wherein the initial category classification model includes N category recognition modules corresponding to the N text fields one by one, and one of the category recognition modules outputs one category recognition result;
[0129] The second determination unit 703 is used to determine the association probability between the target sample and the N text fields respectively;
[0130] A third determining unit 704 is used to determine the loss functions corresponding to the N category recognition modules respectively according to the association probability, the category recognition result and the actual text category;
[0131] The training unit 705 is used to train the initial category classification model according to the loss function to obtain a category classification model, and the category classification model is used to determine the text category of the text to be recognized.
[0132] In a possible implementation manner, the second determining unit 703 is specifically configured to:
[0133] Determine the association probabilities between the target sample and the N text fields respectively through a field classifier;
[0134] The domain classifier is trained as follows:
[0135] Acquire a second sample set including text samples from the N text fields, wherein the text samples in the second sample set are annotated with corresponding actual text fields;
[0136] The input data of the initial domain classifier is determined according to the text samples in the second sample set, the corresponding predicted text domain is output by the initial domain classifier, and the initial domain classifier is trained according to the difference between the predicted text domain and the actual text domain to obtain a domain classifier.
[0137] In a possible implementation, the target recognition module is any one of the N category recognition modules, and the target recognition module corresponds to the target field in the N text fields. For the target recognition module, the third determination unit 704 is specifically used to:
[0138] Determining a difference parameter between the category recognition result of the target recognition module and the actual text category;
[0139] According to the association probability of the target sample corresponding to the target domain and the difference parameter, a loss function corresponding to the target recognition module is determined.
[0140] In a possible implementation, the initial category classification model further includes a feature extraction module shared by the N text fields, the feature extraction module is used to extract the semantic feature vector corresponding to the target sample as input data of the N category recognition modules, and the training unit 705 is specifically used to:
[0141] The target recognition module and the feature extraction module in the initial category classification model are trained according to the loss function of the target recognition module.
[0142] In a possible implementation manner, the apparatus 700 further includes a second acquiring unit and a fourth determining unit:
[0143] A second acquisition unit is used to acquire the text to be recognized from a first field, where the first field is any one of the N text fields;
[0144] The fourth determination unit is used to determine the input data of the category classification model according to the text to be recognized, and determine the category recognition result of the text to be recognized through the category recognition module corresponding to the first field in the category classification model.
[0145] In a possible implementation manner, the first sample set and the second sample set are the same sample set.
[0146] In a possible implementation, the N text fields are determined according to text sources involved in the target software.
[0147] In a possible implementation manner, the category recognition result includes recognition results for at least two text categories.
[0148] The present application also provides a computer device, which is described below in conjunction with the accompanying drawings. Figure 8 As shown, the embodiment of the present application provides a device, which may also be a terminal device. The terminal device may be any intelligent terminal including a mobile phone, a tablet computer, a personal digital assistant (PDA), a point of sales (POS), a vehicle-mounted computer, etc., and the terminal device is a mobile phone as an example:
[0149] Figure 8 FIG. 1 is a block diagram showing a partial structure of a mobile phone related to a terminal device provided in an embodiment of the present application. Figure 8The mobile phone includes: a radio frequency (RF) circuit 810, a memory 820, an input unit 830, a display unit 840, a sensor 850, an audio circuit 860, a wireless fidelity (WiFi) module 870, a processor 880, and a power supply 890. Those skilled in the art will understand that Figure 8 The mobile phone structure shown in the figure does not constitute a limitation on the mobile phone, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.
[0150] Combine the following Figure 8 A detailed introduction to the various components of the mobile phone:
[0151] The RF circuit 810 can be used for receiving and sending signals during the process of sending and receiving information or making calls. In particular, after receiving the downlink information of the base station, it is sent to the processor 880 for processing; in addition, the designed uplink data is sent to the base station. Usually, the RF circuit 810 includes but is not limited to an antenna, at least one amplifier, a transceiver, a coupler, a low noise amplifier (Low Noise Amplifier, referred to as LNA), a duplexer, etc. In addition, the RF circuit 810 can also communicate with the network and other devices through wireless communication. The above-mentioned wireless communication can use any communication standard or protocol, including but not limited to the Global System of Mobile communication (Global System of Mobile communication, referred to as GSM), General Packet Radio Service (General Packet Radio Service, referred to as GPRS), Code Division Multiple Access (Code Division Multiple Access, referred to as CDMA), Wideband Code Division Multiple Access (Wideband Code Division Multiple Access, referred to as WCDMA), Long Term Evolution (Long Term Evolution, referred to as LTE), email, Short Messaging Service (Short Messaging Service, referred to as SMS), etc.
[0152] The memory 820 can be used to store software programs and modules. The processor 880 executes various functional applications and data processing of the mobile phone by running the software programs and modules stored in the memory 820. The memory 820 can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area can store data created according to the use of the mobile phone (such as audio data, a phone book, etc.), etc. In addition, the memory 820 can include a high-speed random access memory, and can also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.
[0153] The input unit 830 can be used to receive input digital or character information, and to generate key signal input related to the user settings and function control of the mobile phone. Specifically, the input unit 830 may include a touch panel 831 and other input devices 832. The touch panel 831, also known as a touch screen, can collect the user's touch operation on or near it (such as the user's operation on the touch panel 831 or near the touch panel 831 using any suitable object or accessory such as a finger, stylus, etc.), and drive the corresponding connection device according to a pre-set program. Optionally, the touch panel 831 may include two parts: a touch detection device and a touch controller. Among them, the touch detection device detects the user's touch orientation, detects the signal brought by the touch operation, and transmits the signal to the touch controller; the touch controller receives the touch information from the touch detection device, converts it into contact coordinates, and then sends it to the processor 880, and can receive and execute commands sent by the processor 880. In addition, the touch panel 831 can be implemented in various types such as resistive, capacitive, infrared, and surface acoustic waves. In addition to the touch panel 831, the input unit 830 may also include other input devices 832. Specifically, the other input devices 832 may include but are not limited to one or more of a physical keyboard, function keys (such as volume control keys, switch keys, etc.), a trackball, a mouse, a joystick, etc.
[0154] The display unit 840 can be used to display information input by the user or information provided to the user and various menus of the mobile phone. The display unit 840 may include a display panel 841. Optionally, the display panel 841 may be configured in the form of a liquid crystal display (Liquid Crystal Display, LCD), an organic light-emitting diode (Organic Light-Emitting Diode, OLED), etc. Further, the touch panel 831 may cover the display panel 841. When the touch panel 831 detects a touch operation on or near it, it is transmitted to the processor 880 to determine the type of touch event. Subsequently, the processor 880 provides a corresponding visual output on the display panel 841 according to the type of touch event. Although in Figure 8 In the embodiment, the touch panel 831 and the display panel 841 are used as two independent components to realize the input and output functions of the mobile phone, but in some embodiments, the touch panel 831 and the display panel 841 can be integrated to realize the input and output functions of the mobile phone.
[0155] The mobile phone may also include at least one sensor 850, such as a light sensor, a motion sensor, and other sensors. Specifically, the light sensor may include an ambient light sensor and a proximity sensor, wherein the ambient light sensor may adjust the brightness of the display panel 841 according to the brightness of the ambient light, and the proximity sensor may turn off the display panel 841 and / or the backlight when the mobile phone is moved to the ear. As a type of motion sensor, the accelerometer sensor can detect the magnitude of acceleration in all directions (generally three axes), and can detect the magnitude and direction of gravity when stationary. It can be used for applications that identify the posture of the mobile phone (such as horizontal and vertical screen switching, related games, magnetometer posture calibration), vibration recognition related functions (such as pedometer, tapping), etc.; as for other sensors that can be configured in the mobile phone, such as gyroscopes, barometers, hygrometers, thermometers, infrared sensors, etc., they will not be repeated here.
[0156] The audio circuit 860, the speaker 861, and the microphone 862 can provide an audio interface between the user and the mobile phone. The audio circuit 860 can transmit the received audio data to the speaker 861 after converting the received audio data into an electrical signal, which is converted into a sound signal for output; on the other hand, the microphone 862 converts the collected sound signal into an electrical signal, which is received by the audio circuit 860 and converted into audio data, and then the audio data is output to the processor 880 for processing, and then sent to another mobile phone through the RF circuit 810, or the audio data is output to the memory 820 for further processing.
[0157] WiFi is a short-range wireless transmission technology. The mobile phone can help users send and receive emails, browse web pages and access streaming media through the WiFi module 870. It provides users with wireless broadband Internet access. Figure 8A WiFi module 870 is shown, but it is understandable that it is not an essential component of the mobile phone and can be omitted as needed without changing the essence of the invention.
[0158] The processor 880 is the control center of the mobile phone. It uses various interfaces and lines to connect various parts of the entire mobile phone. It executes various functions of the mobile phone and processes data by running or executing software programs and / or modules stored in the memory 820, and calling data stored in the memory 820. Optionally, the processor 880 may include one or more processing units; preferably, the processor 880 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and application programs, and the modem processor mainly processes wireless communications. It is understandable that the above-mentioned modem processor may not be integrated into the processor 880.
[0159] The mobile phone also includes a power supply 890 (such as a battery) for supplying power to various components. Preferably, the power supply can be logically connected to the processor 880 through a power management system, so that the power management system can manage charging, discharging, power consumption and other functions.
[0160] Although not shown, the mobile phone may also include a camera, a Bluetooth module, etc., which will not be described in detail here.
[0161] In this embodiment, the processor 880 included in the terminal device also has the following functions:
[0162] Acquire a first sample set including text samples from N text fields, wherein the target sample is any text sample in the first sample set, and the target sample is annotated with a corresponding actual text category, where N≥2;
[0163] Determine input data of an initial category classification model according to the target sample, and output N category recognition results corresponding to the target sample through the initial category classification model, wherein the initial category classification model includes N category recognition modules corresponding to the N text fields one by one, and one of the category recognition modules outputs one category recognition result;
[0164] Determine the association probabilities between the target sample and the N text fields respectively;
[0165] Determine loss functions corresponding to N category recognition modules respectively according to the association probability, the category recognition result and the actual text category;
[0166] The initial category classification model is trained according to the loss function to obtain a category classification model, and the category classification model is used to determine the text category of the text to be recognized.
[0167] The present application also provides a server. Fig. 9 As shown, Fig. 9 The structural diagram of the server 900 provided in the embodiment of the present application, the server 900 may have relatively large differences due to different configurations or performances, and may include one or more central processing units (CPU) 922 (for example, one or more processors) and a memory 932, and one or more storage media 930 (for example, one or more mass storage devices) storing application programs 942 or data 944. Among them, the memory 932 and the storage medium 930 can be temporary storage or permanent storage. The program stored in the storage medium 930 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations on the server. Furthermore, the central processing unit 922 can be configured to communicate with the storage medium 930 and execute a series of instruction operations in the storage medium 930 on the server 900.
[0168] The server 900 may also include one or more power supplies 926, one or more wired or wireless network interfaces 950, one or more input and output interfaces 958, and / or one or more operating systems 941, such as Windows ServerTM, Mac OS XTM, UnixTM, LinuxTM, FreeBSDTM, etc.
[0169] The steps performed by the server in the above embodiment can be based on Fig. 9 The server structure shown.
[0170] The embodiment of the present application further provides a computer-readable storage medium for storing a computer program, wherein the computer program is used to execute any one of the implementation methods of the text category determination methods described in the above embodiments.
[0171] A person of ordinary skill in the art can understand that all or part of the steps of implementing the above-mentioned method embodiment can be completed by hardware related to program instructions, and the above-mentioned program can be stored in a computer-readable storage medium. When the program is executed, it executes the steps of the above-mentioned method embodiment; and the above-mentioned storage medium can be at least one of the following media: read-only memory (English: read-only memory, abbreviated: ROM), RAM, magnetic disk or optical disk, etc. Various media that can store program codes.
[0172] It should be noted that each embodiment in this specification is described in a progressive manner, and the same and similar parts between the embodiments can refer to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device and system embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can refer to the partial description of the method embodiments. The device and system embodiments described above are merely schematic, in which the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative work.
[0173] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed in the present application should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A method for determining a text category, characterized in that: The method comprises: Acquire a first sample set including text samples from N text fields, wherein the target sample is any text sample in the first sample set, and the target sample is annotated with a corresponding actual text category, where N≥2; Determine input data of an initial category classification model according to the target sample, and output N category recognition results corresponding to the target sample through the initial category classification model, wherein the initial category classification model includes N category recognition modules corresponding to the N text fields one by one, and one of the category recognition modules outputs one category recognition result; Determine the association probabilities between the target sample and the N text fields respectively; Determine loss functions corresponding to N category recognition modules respectively according to the association probability, the category recognition result and the actual text category; The initial category classification model is trained according to the loss function to obtain a category classification model, wherein the category classification model is used to determine the text category of the text to be recognized; Among them, the target recognition module is any one of the N category recognition modules, and the target recognition module corresponds to the target field in the N text fields. For the target recognition module, the loss functions corresponding to the N category recognition modules are determined according to the association probability, the category recognition result and the actual text category, including: Determining a difference parameter between the category recognition result of the target recognition module and the actual text category; The product of the association probability of the target sample corresponding to the target field and the difference parameter is determined as the loss function corresponding to the target recognition module.
2. The method according to claim 1, characterized in that The determining the association probabilities between the target sample and the N text fields respectively includes: Determine the association probabilities between the target sample and the N text fields respectively through a field classifier; The domain classifier is trained as follows: Acquire a second sample set including text samples from the N text fields, wherein the text samples in the second sample set are annotated with corresponding actual text fields; The input data of the initial domain classifier is determined according to the text samples in the second sample set, the corresponding predicted text domain is output by the initial domain classifier, and the initial domain classifier is trained according to the difference between the predicted text domain and the actual text domain to obtain a domain classifier.
3. The method according to claim 1, characterized in that The initial category classification model further includes a feature extraction module shared by the N text fields, the feature extraction module is used to extract the semantic feature vector corresponding to the target sample as input data of the N category recognition modules, and the training of the initial category classification model according to the loss function includes: The target recognition module and the feature extraction module in the initial category classification model are trained according to the loss function of the target recognition module.
4. The method according to any one of claims 1 to 3, characterized in that: The method further comprises: Acquire the text to be recognized from a first field, where the first field is any one of the N text fields; The input data of the category classification model is determined according to the text to be recognized, and the category recognition result of the text to be recognized is determined by the category recognition module corresponding to the first field in the category classification model.
5. The method according to claim 2, characterized in that: The first sample set and the second sample set are the same sample set.
6. The method according to any one of claims 1 to 3, characterized in that: The N text fields are determined according to text sources involved in the target software.
7. The method according to any one of claims 1 to 3, characterized in that: The category recognition result includes recognition results of at least two text categories.
8. A text category determination device, characterized in that: The device comprises a first acquisition unit, a first determination unit, a second determination unit, a third determination unit and a training unit: The first acquisition unit is used to acquire a first sample set including text samples from N text fields, wherein the target sample is any text sample in the first sample set, and the target sample is annotated with a corresponding actual text category, where N≥2; The first determination unit is used to determine input data of an initial category classification model according to the target sample, and output N category recognition results corresponding to the target sample through the initial category classification model, wherein the initial category classification model includes N category recognition modules corresponding to the N text fields one by one, and one of the category recognition modules outputs one category recognition result; The second determination unit is used to determine the association probabilities between the target sample and the N text fields respectively; The third determination unit is used to determine the loss functions corresponding to the N category recognition modules respectively according to the association probability, the category recognition result and the actual text category; The training unit is used to train the initial category classification model according to the loss function to obtain a category classification model, and the category classification model is used to determine the text category of the text to be recognized; The target recognition module is any one of the N category recognition modules, and the target recognition module corresponds to the target field in the N text fields. For the target recognition module, the third determination unit is specifically used to: Determining a difference parameter between the category recognition result of the target recognition module and the actual text category; The product of the association probability of the target sample corresponding to the target field and the difference parameter is determined as the loss function corresponding to the target recognition module.
9. The device according to claim 8, characterized in that The second determining unit is specifically configured to: Determine the association probabilities between the target sample and the N text fields respectively through a field classifier; The domain classifier is trained as follows: Acquire a second sample set including text samples from the N text fields, wherein the text samples in the second sample set are annotated with corresponding actual text fields; The input data of the initial domain classifier is determined according to the text samples in the second sample set, the corresponding predicted text domain is output by the initial domain classifier, and the initial domain classifier is trained according to the difference between the predicted text domain and the actual text domain to obtain a domain classifier.
10. The device according to claim 8, characterized in that The initial category classification model further includes a feature extraction module shared by the N text fields, the feature extraction module is used to extract the semantic feature vector corresponding to the target sample as input data of the N category recognition modules, and the training unit is specifically used to: The target recognition module and the feature extraction module in the initial category classification model are trained according to the loss function of the target recognition module.
11. The device according to any one of claims 8 to 10, characterized in that: The device also includes a second obtaining unit and a fourth determining unit: The second acquisition unit is used to acquire the text to be recognized from a first field, where the first field is any one of the N text fields; The fourth determination unit is used to determine the input data of the category classification model according to the text to be recognized, and determine the category recognition result of the text to be recognized through the category recognition module corresponding to the first field in the category classification model.
12. A computer device, characterized in that: The device comprises a processor and a memory: The memory is used to store program code and transmit the program code to the processor; The processor is used to execute the text category determination method according to any one of claims 1 to 7 according to the instructions in the program code.
13. A computer-readable storage medium, characterized in that: The computer-readable storage medium is used to store a computer program, and the computer program is used to execute the text category determination method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Entity relationship extraction method based on multi-head self-attention mechanism
CN111767409A
Text classification method and related device
CN112214605A