Method, device, electronic device and storage medium for determining target text category
Through the Q matrix-based object detection model, the text on social media platforms is automatically classified, which solves the problem of low manual detection accuracy and achieves more efficient text category detection and processing.
Patent Information
- Application Number
- CN202210435829.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-24
- Publication Date
- 2025-03-14
- Estimated Expiration
- 2042-04-24
AI Technical Summary
In the prior art, the accuracy of manual detection of text categories is low, making it difficult to effectively screen and process speech content on social media platforms.
Through the target detection model based on the Q matrix, the target vocabulary in the detected text is processed, vocabulary scores are generated, and the text category is determined based on the vocabulary scores. This model continuously updates and optimizes the reinforcement learning algorithm to improve the accuracy of text category detection.
Improve the accuracy of text category detection, enables more efficient screening and processing of speech content on social media platforms, and reduces the need for manual intervention.
Smart Images

Figure CN114912444B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of text, and in particular to a method, device, electronic device and storage medium for determining a target text category. Background Art
[0002] With the development of the Internet, more and more users are posting speech content on major social media platforms, including but not limited to public account articles, personal dynamics and comments. Operators need to filter out speech content of certain specific text categories according to actual conditions and process these speech content. For example, some spam content needs to be deleted or blocked, and some positive content needs to be pushed to more users.
[0003] The current method of determining text categories is to manually detect specific words in the full text and then determine the text category based on the specific words, but manual detection results in low accuracy of text categories. Summary of the invention
[0004] In order to solve the above technical problem or at least partially solve the above technical problem, the present application provides a method, device, electronic device and storage medium for determining a target text category.
[0005] In a first aspect, the present application provides a method for determining a target text category, the method comprising:
[0006] Selecting at least one target word from the text to be detected;
[0007] Processing the at least one target vocabulary according to a target detection model to obtain a vocabulary score of the target vocabulary, wherein the target detection model is obtained based on a Q matrix;
[0008] Determining a text score of the to-be-detected text according to the vocabulary score of the at least one target vocabulary;
[0009] According to the correspondence between a preset score range and a text category, the text category corresponding to the text score is used as the target text category of the text to be detected.
[0010] Optionally, after taking the text category corresponding to the text score as the target text category of the text to be detected, the method further includes:
[0011] Using the target vocabulary and the target text category as training samples, updating a reward matrix, wherein the reward value in the reward matrix is determined based on the sample vocabulary and the text category of the sample text, and the sample vocabulary exists in the sample text;
[0012] Generate an updated Q matrix based on the updated reward matrix;
[0013] The updated target detection model is obtained according to the updated Q matrix.
[0014] Optionally, before processing the to-be-detected text containing the target vocabulary according to the target detection model, the method further includes:
[0015] Establishing an initial Q matrix and an initial reward matrix, wherein the initial Q matrix and the initial reward matrix each include N×N element values initialized to 0, where N is the number of sample words arranged in a preset manner;
[0016] Based on the initial reward matrix, determining a reward matrix by sample categories of sample vocabulary and sample text;
[0017] For the order of vocabulary in each sample text, a Q matrix is constructed based on the initial Q matrix and the reward matrix, wherein each row in the Q matrix indicates a vocabulary, and each column in the Q matrix indicates an action of jumping from a current vocabulary to a next vocabulary;
[0018] The target detection model is generated by the Q matrix.
[0019] Optionally, the determining the reward matrix based on the initial reward matrix by sample categories of sample vocabulary and sample text includes:
[0020] Determine an adjacent word of the sample word, wherein the adjacent word indicates a next word of the sample word in the initial reward matrix, and the initial reward matrix and the reward matrix have the same sample words;
[0021] In the case where the sample vocabulary and the adjacent vocabulary do not belong to the same sample text, determining the reward value of the sample vocabulary to be a first preset value, wherein the first preset value does not indicate a reward or a penalty;
[0022] In the case where the sample vocabulary and the adjacent vocabulary belong to the same sample text, determining the sample category of the sample text;
[0023] Determining the reward value as a second preset value according to the sample category, wherein the second preset value indicates a reward or a penalty;
[0024] The reward matrix is constructed based on the first preset value and the second preset value.
[0025] Optionally, determining the reward value as a second preset value according to the sample category includes:
[0026] When the sample category is a preset category, determining a reward value in a reward matrix as a reward value;
[0027] When the sample category is a non-preset category, determining a reward value in a reward matrix as a penalty value;
[0028] The reward value and the penalty value are used as the second preset value.
[0029] Optionally, constructing a Q matrix based on the initial Q matrix and the reward matrix for the vocabulary arrangement order in each sample text includes:
[0030] Traverse each sample word in each sample text in the following way:
[0031] determining a current vocabulary in the sample text;
[0032] Determine a preset word corresponding to the current word according to the order of words in the sample text, wherein the preset word is the next word of the current word in the sample text;
[0033] Determine the matrix value of the current vocabulary based on the reward value of the current vocabulary in the reward matrix and the matrix value of the preset vocabulary in the initial Q matrix;
[0034] The Q matrix is constructed based on each matrix value.
[0035] Optionally, according to the correspondence between a preset score range and a text category, taking the text category corresponding to the text score as the target text category of the text to be detected includes:
[0036] Obtaining the correspondence between the preset score range and the text category stored in the database;
[0037] Selecting a target score range for the text score from the preset score range;
[0038] According to the corresponding relationship, the text category corresponding to the target score range is used as the target text category of the text to be detected.
[0039] In a second aspect, a device for determining a target text category is provided, the device comprising:
[0040] A selection module, used for selecting at least one target word from the text to be detected;
[0041] A processing module, configured to process the at least one target word according to a target detection model to obtain a text category of the text to be detected, wherein the target detection model is obtained based on a reward matrix, and the reward matrix is determined based on sample words and sample categories in a training sample;
[0042] An updating module, used to update the reward matrix by taking the target vocabulary and the text category as new training samples to obtain an updated target detection model;
[0043] A determination module is used to determine the text category of the new text to be detected based on the updated object detection model.
[0044] In a third aspect, an electronic device is provided, characterized in that it includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus;
[0045] Memory, used to store computer programs;
[0046] The processor is used to implement any method step when executing the program stored in the memory.
[0047] According to a fourth aspect, a computer-readable storage medium is provided, wherein a computer program is stored in the computer-readable storage medium, and when the computer program is executed by a processor, any method step is implemented.
[0048] The above technical solution provided by the embodiment of the present application has the following advantages compared with the prior art:
[0049] In the method provided by the embodiment of the present application, the server can obtain the target detection model according to the Q matrix, thereby obtaining the vocabulary score of the target vocabulary through the target detection model, and then obtain the text score of the text to be detected according to the vocabulary score of at least one target vocabulary, and determine the target text category of the text to be detected according to the text score. Compared with manually determining the text category, the present application uses the Q matrix to determine the generated target detection model to determine the text category, thereby improving the accuracy of text category detection. BRIEF DESCRIPTION OF THE DRAWINGS
[0050] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.
[0051] In order to more clearly illustrate the embodiments of the present invention 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, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0052] Figure 1 Flow chart of a method for determining a target text category provided by an embodiment of the present application;
[0053] Figure 2 Schematic diagram of the flow of a method for determining a target text category provided by an embodiment of the present application;
[0054] Figure 3 Schematic diagram of the structure of a device for determining a target text category provided by an embodiment of the present application;
[0055] Figure 4 Schematic diagram of the structure of an electronic device provided by an embodiment of the present application. Detailed implementation manners
[0056] To make the objectives, technical solutions, and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application. Apparently, the described embodiments are some but not all of the embodiments of the present application. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present application without creative efforts shall fall within the protection scope of the present application.
[0057] An embodiment of the present application provides a method for determining a target text category, which can be applied to a terminal or a server and is used to determine the text category of a text to be detected containing a target vocabulary.
[0058] The following will, in combination with the detailed implementation manners, take the application to a server as an example to elaborate in detail on a method for determining a target text category provided by an embodiment of the present application, as Figure 1 shown, the specific steps are as follows:
[0059] Step 101: Select at least one target vocabulary from the text to be detected.
[0060] In the embodiment of the present application, the server uses a word segmentation method to split the text to be obtained into words. The split words include valid words and invalid words. The invalid words have no actual meaning, such as modal particles, "de", etc. The server selects valid words from multiple word segments according to a preset selection scheme and uses the valid words as target vocabulary. Among them, the preset selection scheme can be selected according to the part of speech of the words or obtained by matching with the valid words in the database.
[0061] Step 102: Process at least one target vocabulary according to a target detection model to obtain a vocabulary score of the target vocabulary.
[0062] Among them, the target detection model is obtained based on the Q matrix;
[0063] After the server generates a target detection model according to the Q matrix, the target detection model processes at least one target word to obtain a matrix value of the target word, and then uses the matrix value as a vocabulary score of the target word.
[0064] Step 103: Determine the text score of the text to be detected according to the vocabulary score of at least one target vocabulary.
[0065] There are at least two ways for the server to obtain the text score of the text to be detected based on the vocabulary score of at least one target vocabulary: the total score of each vocabulary score can be used as the text score, or the average score of each vocabulary score can be used as the text score. This application does not limit the specific method for determining the text score.
[0066] Step 104: according to the correspondence between the preset score range and the text category, the text category corresponding to the text score is used as the target text category of the text to be detected.
[0067] The database pre-stores the correspondence between the preset score range and the text category. The server selects the target score range where the text score lies from the preset score range, and then determines the target text category of the text to be detected based on the text category corresponding to the target score range.
[0068] For example, the text score is 89 points, and the correspondence pre-stored in the database is [0-80] - non-excellent text, [81-100] - excellent text. Then the text score is within the score range of [81-100], and the target text category corresponding to the text to be detected is excellent text.
[0069] Exemplarily, if the target vocabulary is a junk vocabulary, the text category of the text to be detected containing the junk vocabulary is junk text or non-junk text, for example, the junk text can be a sales promotion text containing sales promotion vocabulary. If the target vocabulary is a non-junk vocabulary, the text category of the text to be detected containing the non-junk vocabulary is junk text or non-junk text. The present application can detect whether the text to be detected containing the junk vocabulary is junk text through the target detection model, so that the junk text can be deleted or processed.
[0070] Exemplarily, if the target vocabulary is an excellent vocabulary, then the text category of the text to be detected containing the excellent vocabulary is excellent text or non-excellent text. For example, the excellent text can be a push text containing a eulogy vocabulary. If the target vocabulary is a non-excellent vocabulary, then the text category of the text to be detected containing the non-excellent vocabulary is excellent text or non-excellent text. The present application can detect whether the text to be detected containing the excellent vocabulary is an excellent text through a target detection model, so that the excellent text can be pushed and other processing can be performed. The present application does not specifically limit the target vocabulary and text category.
[0071] In the present application, the server can obtain a target detection model based on the Q matrix, thereby obtaining the vocabulary score of the target vocabulary through the target detection model, and then obtain the text score of the text to be detected based on the vocabulary score of at least one target vocabulary, and determine the target text category of the text to be detected based on the text score. Compared with manually determining the text category, the present application uses the target detection model generated by the Q matrix to determine the text category, thereby improving the accuracy of text category detection.
[0072] Optionally, after taking the text category corresponding to the text score as the target text category of the text to be detected, the method also includes: taking the target vocabulary and the target text category as training samples, updating the reward matrix, wherein the reward value in the reward matrix is determined based on the text category of the sample vocabulary and the sample text, and the sample vocabulary exists in the sample text; generating an updated Q matrix based on the updated Q matrix; and obtaining an updated target detection model based on the updated Q matrix.
[0073] In an embodiment of the present application, the reward value in the reward matrix is determined based on the sample vocabulary and sample category of the sample text in the training sample, and the server uses the target vocabulary and target text category as new training samples to update the reward matrix. For the same target vocabulary, the corresponding sample category may include at least two, such as a first sample category and a second sample category. If the probability of the first sample category appearing is large, it means that the accuracy of the sample text being the first sample category is high. As the number of training times increases, the number of times the reward value generated based on the target vocabulary and the first sample category appears in the reward matrix is large, that is, the number of times the reward value is accurate will increase. Since the Q matrix is generated based on the reward matrix, as the number of training times increases, the matrix value of the Q matrix will also be more accurate, and the target detection model obtained according to the updated Q matrix will also more accurately output the text category of the text to be detected.
[0074] In the embodiment of the present application, after the server obtains the updated target detection model, it processes the newly input text to be detected, obtains the text score of the text to be detected according to the vocabulary score of each target word in the text to be detected, and thus obtains the corresponding target text category according to the text score. Then, according to the target vocabulary and target text category in the newly input text to be detected, the reward matrix is continuously updated to obtain the target detection model that is updated again, and the above method is continuously cycled to continuously update the target detection model.
[0075] This application adopts a reinforcement learning algorithm. Reinforcement learning includes three elements: environment, agent, and control strategy. The purpose of reinforcement learning is to construct a control strategy to maximize the possible performance of agent behavior prediction, thereby analyzing and predicting the target behavior through learning.
[0076] In this application, the server updates the reward matrix by using the input (target vocabulary) and output (target text category) of the target detection model as training samples, thereby obtaining an updated target detection model, which can make the text category output by the updated target detection model more accurate. This application uses reinforcement learning to continuously improve the accuracy of the target detection model with the latest training samples, thereby improving the accuracy of the detected target text category.
[0077] As an optional implementation, before processing at least one target word according to the target detection model, the method also includes: establishing an initial Q matrix and an initial reward matrix, wherein the initial Q matrix and the initial reward matrix each include N×N element values initialized to 0, and N is the number of sample words arranged in a preset manner; based on the initial reward matrix, determining the reward matrix through sample words and sample categories of sample texts; for the order of word arrangement in each sample text, constructing a Q matrix based on the initial Q matrix and the reward matrix, wherein each row in the Q matrix indicates a word, and each column in the Q matrix indicates an action of jumping from a current word to a next word; and generating a target detection model through the Q matrix.
[0078] In the embodiment of the present application, the server first establishes an initial Q matrix and an initial R matrix, wherein the initial Q matrix and the initial R matrix both include N×N element values initialized to 0. Then, the reward values in the reward matrix (R matrix) are obtained by the sample vocabulary and sample category in the training sample, and then the Q matrix is obtained based on the initial Q matrix and the R matrix, and finally the target detection model is generated according to the Q matrix.
[0079] Specifically, the server first determines N according to the number of words in the preset word library, where the words in the preset word library are selected from the text, and the text refers to the sentence to which the word belongs. For example, there are five texts, each of which includes five valid words, then the preset word library is constructed based on these 25 valid words. The preset word library contains as many words as possible, so that the words in the initial Q matrix can be as many as possible to cover any text.
[0080] The order of the words in the preset word library is determined according to a preset method, and does not need to be in the order of the text or the order of the words in the text. The preset method can be determined randomly or in alphabetical order according to the pinyin of the words. This application does not impose any specific restrictions on the preset method.
[0081] For example, the preset word library includes five words abcde, and the arrangement order of these five words can be a cedb or acebd.
[0082] The server establishes an N×N initial Q matrix Q(s, a). The words in the initial Q matrix come from the preset vocabulary and are arranged in a preset manner. Each row of the initial Q matrix represents a word Is, and each column of the initial Q matrix represents an action corresponding to each word, jumping to any of the other (N-1) words or staying where it is. Action a represents the action of jumping from word Is to any word Ia.
[0083] In this way, we construct an N×N matrix Q and initialize the matrix values in the matrix Q to 0, as follows.
[0084]
[0085] If a vocabulary jump is performed on a sample text, the jump order is determined according to the vocabulary arrangement order in the sample text. Then, during the jump process, action a represents the action of jumping from the current vocabulary Is to the preset vocabulary Ia, where the preset vocabulary Ia is the next vocabulary of the current vocabulary Is in the sample text.
[0086] Exemplarily, the arrangement in the initial Q matrix is shown in Table 1. It can be seen that in the initial Q matrix, it is possible to jump from the current vocabulary to any vocabulary. If the vocabulary order of the first sample text is xyz, then in the initial Q matrix, the matrix value of x jumping to y and the matrix value of y jumping to z can be determined (the matrix value is represented by r in Table 1). If the vocabulary order of the second sample text is z yx, then in the initial Q matrix, the matrix value of z jumping to y and the matrix value of y jumping to x can be determined.
[0087] x y z x 0 r 0 y 0 0 r z 0 0 0
[0088] Table 1
[0089] The server establishes an initial R matrix, in which the matrix values are initialized to 0. The server obtains the return value through the sample vocabulary and sample category in the training sample, thereby obtaining the R matrix R(s, a).
[0090] In the embodiment of the present application, the sample vocabulary in the initial R matrix is the same as the vocabulary in the initial Q matrix, the arrangement order of the vocabulary and vocabulary in the initial R matrix and the R matrix is the same, and only the reward values are not exactly the same. The reward values in the initial R matrix are all 0, and the present application determines the reward values in the reward matrix by the sample vocabulary and the sample category of the sample text.
[0091] The server obtains sample texts containing sample words from training samples, wherein the training samples come from historical data and each sample text has a pre-labeled sample category. The sample word has a corresponding adjacent word, which is the next word of the sample word in the reward matrix.
[0092] If the server determines that the sample word and the adjacent word belong to a sample text, the server determines the category of the sample text. If the sample category is detected to be a preset category, the reward value in the reward matrix corresponding to the current sample word is determined to be a reward value, exemplarily, R(s, a)=1; if the server detects that the sample category is not a preset category, the reward value in the reward matrix corresponding to the current sample word is determined to be a penalty value, exemplarily, R(s, a)=-1.
[0093] If the server determines that the sample word and the adjacent word do not belong to the same sample text, the reward value in the reward matrix corresponding to the current sample word is used as the first preset value, and the first preset value does not indicate reward or penalty.
[0094] The server refers to the reward value and the penalty value as second preset values, the second preset value indicates a reward or a penalty, and the server constructs a reward matrix according to the first preset value and the second preset value.
[0095] Exemplarily, the sample vocabulary includes xyz, x and y belong to the same sample text A, z belongs to sample text B, x is a junk word, y is a non-junk word, z is a junk word, A is a junk text, and B is a junk text.
[0096]
[0097]
[0098] Table 2
[0099] Taking x as an example, as shown in Table 2, since x and y belong to the same sample text A, and x is a junk word and A is a junk text, the reward value corresponding to the action of jumping from x to y is -1; since x and z do not belong to the same sample text, the reward value corresponding to the action of jumping from x to z is 0; the reward value corresponding to the action of jumping from x to x is 0.
[0100] The server obtains each reward value in the above manner, and then constructs an N×N reward matrix R(s, a) based on the reward value.
[0101] For example, if the sample word is a junk word, then when the sample text is junk text, the server sets the reward value as a penalty value; when the sample text is non-junk text, the server sets the reward value as a reward value. If the sample word is a non-junk word, then when the sample text is junk text, the server sets the reward value as a penalty value; when the sample text is non-junk text, the server sets the reward value as a reward value.
[0102] For example, if the sample word is an excellent word, then when the sample text is an excellent text, the server sets the reward value as a reward value; when the sample text is a non-excellent text, the server sets the reward value as a penalty value. If the sample word is a non-excellent word, then when the sample text is an excellent text, the server sets the reward value as a reward value; when the sample text is a non-excellent text, the server sets the reward value as a penalty value.
[0103] The server obtains the Q matrix according to the Q-learning state transfer equation, where the formula of the Q-learning state transfer equation is:
[0104]
[0105] Among them, γ is the greed factor (0<γ<1), s represents the current state, and a represents the current action. Indicates the next state, Indicates the next action.
[0106] The learning process of the Q matrix is as follows
[0107] For a sample text, perform steps 1 to 6.
[0108] Step 1: Set a current vocabulary Is;
[0109] Step 2: Determine action a according to the current word Is, where action a indicates jumping to a preset word, where the preset word is the next word of the current word in the sample text;
[0110] Step 3: Using this specified behavior a, we obtain the preset vocabulary Ia;
[0111] Step 4: Calculate according to the above formula to obtain the reward value of the current vocabulary Is and the matrix value of the preset vocabulary Ia in the initial Q matrix, and then use the sum of the reward value and the matrix value of the preset vocabulary Ia as the new value of Q(s, a) of the current vocabulary Is. In this way, a Q value in the Q matrix is obtained.
[0112] Step 5: Starting from the preset vocabulary Ia, using steps 2 to 4, the new Q value of the preset vocabulary Ia can be obtained.
[0113] Step 6: According to the above method, for all words in the sample text, obtain the Q value in the Q matrix.
[0114] Since a sample text cannot cover all the words in the Q matrix, other sample texts need to be used to repeat steps 1 to 6 until a complete Q matrix is obtained, which includes N×N Q values (matrix values).
[0115] For example, the matrix Q is as follows
[0116]
[0117] As an optional implementation, determining the vocabulary score of each target vocabulary through the Q matrix in the target detection model includes: the server determines the target vocabulary, the action corresponding to the target vocabulary will indicate a jump to the next vocabulary of the target vocabulary in the text to be detected, and according to the Q-learning state transition equation, the reward value of the target vocabulary and the matrix value of the next vocabulary can be determined. The server uses the sum of the reward value and the matrix value of the next vocabulary as the matrix value of the target vocabulary, and uses the matrix value as the vocabulary score of the target vocabulary. In this way, the vocabulary score of each target vocabulary is obtained using the Q-learning state transition equation.
[0118] Based on the same technical concept, the embodiment of the present application also provides a method flow for determining the target text category, such as Figure 2 As shown, the process includes:
[0119] Step 201: Establish an initial Q matrix.
[0120] Step 202: Create an initial R matrix.
[0121] Step 203: Obtain an R matrix through sample words and sample categories in the training samples.
[0122] Step 204: Obtain a Q matrix according to the initial Q matrix and the R matrix, and generate a target detection model.
[0123] Step 205: Input the text to be detected containing the target vocabulary into the target detection model, and output the text category of the text to be detected.
[0124] Step 206: Use the target vocabulary and text category as training samples and return to step 203.
[0125] There is no particular order in which step 201 and step 202 are performed.
[0126] Based on the same technical concept, the embodiment of the present application also provides a device for determining the category of a target text, such as Figure 3 As shown, the device comprises:
[0127] A selection module 301 is used to select at least one target word from the text to be detected;
[0128] A processing module 302 is used to process at least one target word according to a target detection model to obtain a vocabulary score of the target word, wherein the target detection model is obtained based on a Q matrix;
[0129] A determination module 303, configured to determine a text score of the text to be detected according to a vocabulary score of at least one target vocabulary;
[0130] As module 304, it is used to use the text category corresponding to the text score as the target text category of the text to be detected according to the corresponding relationship between the preset score range and the text category.
[0131] Optionally, the device is also used for:
[0132] Using the target vocabulary and the target text category as training samples, updating the reward matrix, wherein the reward value in the reward matrix is determined based on the sample vocabulary and the text category of the sample text, and the sample vocabulary exists in the sample text;
[0133] Generate an updated Q matrix based on the updated reward matrix;
[0134] Obtain an updated target detection model based on the updated Q matrix;
[0135] The text category of the new text to be detected is determined based on the updated object detection model.
[0136] Optionally, the device further comprises:
[0137] An establishment module is used to establish an initial Q matrix and an initial reward matrix, wherein the initial Q matrix and the initial reward matrix each include N×N element values initialized to 0, where N is the number of sample words arranged in a preset manner;
[0138] A determination module, for determining a reward matrix based on an initial reward matrix by using sample vocabulary and sample categories of sample text;
[0139] A construction module is used to construct a Q matrix based on the initial Q matrix and the reward matrix according to the order of vocabulary in each sample text, wherein each row in the Q matrix indicates a vocabulary, and each column in the Q matrix indicates an action of jumping from a current vocabulary to a next vocabulary;
[0140] The generation module is used to generate the target detection model through the Q matrix.
[0141] Optionally, the determination module is used to:
[0142] Determine an adjacent word of the sample word, wherein the adjacent word indicates a next word of the sample word in an initial reward matrix, and the initial reward matrix and the reward matrix have the same sample word;
[0143] In the case where the sample vocabulary and the adjacent vocabulary do not belong to the same sample text, determining the reward value of the sample vocabulary to be a first preset value, wherein the first preset value does not indicate a reward or a penalty;
[0144] In the case where the sample word and the adjacent word belong to the same sample text, determining the sample category of the sample text;
[0145] Determine the reward value as a second preset value according to the sample category, wherein the second preset value indicates a reward or a penalty;
[0146] A reward matrix is constructed based on the first preset value and the second preset value.
[0147] Optionally, the determination module is further configured to:
[0148] When the sample category is a preset category, determining the reward value in the reward matrix as a reward value;
[0149] When the sample category is not a preset category, the reward value in the reward matrix is determined to be a penalty value;
[0150] The reward value and the penalty value are used as the second preset value.
[0151] Optionally, building blocks are used to:
[0152] Traverse each sample word in each sample text in the following way:
[0153] Identify the current vocabulary in the sample text;
[0154] Determine the preset word corresponding to the current word according to the order of words in the sample text, wherein the preset word is the next word of the current word in the sample text;
[0155] Determine the matrix value of the current vocabulary based on the reward value of the current vocabulary in the reward matrix and the matrix value of the preset vocabulary in the initial Q matrix;
[0156] Construct a Q matrix based on each matrix value.
[0157] Optionally, the module 304 is used to:
[0158] Obtaining the correspondence between the preset score range and the text category stored in the database;
[0159] Select a target score range for the text score from the preset score range;
[0160] According to the corresponding relationship, the text category corresponding to the target score range is used as the target text category of the text to be detected.
[0161] Based on the same technical concept, an embodiment of the present invention further provides an electronic device, such as Figure 4 As shown, it includes a processor 401, a communication interface 402, a memory 403 and a communication bus 404, wherein the processor 401, the communication interface 402, and the memory 403 communicate with each other through the communication bus 404.
[0162] Memory 403, used for storing computer programs;
[0163] The processor 401 is used to implement the above steps when executing the program stored in the memory 403.
[0164] The communication bus mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.
[0165] The communication interface is used for communication between the above electronic device and other devices.
[0166] The memory may include a random access memory (RAM) or a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0167] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0168] In another embodiment of the present invention, a computer-readable storage medium is provided, in which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above methods are implemented.
[0169] In another embodiment of the present invention, a computer program product including instructions is provided, which enables the computer to execute any one of the methods in the above embodiments when the computer program product is executed on the computer.
[0170] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented by software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present invention is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from one website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server or data center that includes one or more available media integrated. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk SolidStateDisk (SSD)), etc.
[0171] It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0172] The foregoing is merely a specific embodiment of the present invention, which enables those skilled in the art to understand or implement the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features claimed herein.
Claims
1. A method for determining a target text category, characterized in that: The method comprises: Selecting at least one target word from the text to be detected; Processing the at least one target word according to a target detection model to obtain a word score of the target word, wherein the target detection model is obtained based on a Q matrix, each row in the Q matrix indicates a word, and each column in the Q matrix indicates an action of jumping from a current word to a next word; Determining a text score of the to-be-detected text according to the vocabulary score of the at least one target vocabulary; According to the correspondence between the preset score range and the text category, the text category corresponding to the text score is used as the target text category of the text to be detected; The step of processing the at least one target vocabulary according to the target detection model to obtain a vocabulary score of the target vocabulary includes: Determine the reward value of the target vocabulary and the matrix value of the next vocabulary according to the target detection model; use the sum of the reward value and the matrix value as the matrix value of the target vocabulary; and use the matrix value as the vocabulary score of the target vocabulary.
2. The method according to claim 1, characterized in that After taking the text category corresponding to the text score as the target text category of the text to be detected, the method further includes: Using the target vocabulary and the target text category as training samples, updating a reward matrix, wherein the reward value in the reward matrix is determined based on the sample vocabulary and the text category of the sample text, and the sample vocabulary exists in the sample text; Generate an updated Q matrix based on the updated reward matrix; Obtain an updated target detection model based on the updated Q matrix; The text category of the new text to be detected is determined based on the updated object detection model.
3. The method according to claim 1, characterized in that Before processing the at least one target word according to the target detection model, the method further includes: Establishing an initial Q matrix and an initial reward matrix, wherein the initial Q matrix and the initial reward matrix each include N×N element values initialized to 0, where N is the number of sample words arranged in a preset manner; Based on the initial reward matrix, determining a reward matrix by sample categories of sample vocabulary and sample text; According to the order of vocabulary in each sample text, a Q matrix is constructed based on the initial Q matrix and the reward matrix; The target detection model is generated by the Q matrix.
4. The method according to claim 3, characterized in that The step of determining the reward matrix based on the initial reward matrix by using sample vocabulary and sample text sample categories includes: Determine an adjacent word of the sample word, wherein the adjacent word indicates a next word of the sample word in the initial reward matrix, and the initial reward matrix and the reward matrix have the same sample words; In the case where the sample vocabulary and the adjacent vocabulary do not belong to the same sample text, determining the reward value of the sample vocabulary to be a first preset value, wherein the first preset value does not indicate a reward or a penalty; In the case where the sample vocabulary and the adjacent vocabulary belong to the same sample text, determining the sample category of the sample text; Determining the reward value as a second preset value according to the sample category, wherein the second preset value indicates a reward or a penalty; The reward matrix is constructed based on the first preset value and the second preset value.
5. The method according to claim 4, characterized in that Determining the reward value as a second preset value according to the sample category includes: When the sample category is a preset category, determining a reward value in a reward matrix as a reward value; When the sample category is a non-preset category, determining a reward value in a reward matrix as a penalty value; The reward value and the penalty value are used as the second preset value.
6. The method according to claim 3, characterized in that The constructing of the Q matrix based on the initial Q matrix and the reward matrix for the vocabulary arrangement order in each sample text includes: Each sample word in each sample text is traversed as follows: determining a current vocabulary in the sample text; Determine a preset word corresponding to the current word according to the order of words in the sample text, wherein the preset word is the next word of the current word in the sample text; Determine the matrix value of the current vocabulary based on the reward value of the current vocabulary in the reward matrix and the matrix value of the preset vocabulary in the initial Q matrix; The Q matrix is constructed based on each matrix value.
7. The method according to claim 1, characterized in that The step of taking the text category corresponding to the text score as the target text category of the text to be detected according to the correspondence between the preset score range and the text category includes: Obtaining the correspondence between the preset score range and the text category stored in the database; Selecting a target score range for the text score from the preset score range; According to the corresponding relationship, the text category corresponding to the target score range is used as the target text category of the text to be detected.
8. A device for determining a target text category, characterized in that: The device comprises: A selection module, used for selecting at least one target word from the text to be detected; a processing module, configured to process the at least one target vocabulary according to a target detection model to obtain a vocabulary score of the target vocabulary, wherein the target detection model is obtained based on a Q matrix, each row in the Q matrix indicates a vocabulary, and each column in the Q matrix indicates an action of jumping from a current vocabulary to a next vocabulary; A determination module, configured to determine a text score of the to-be-detected text according to a vocabulary score of the at least one target vocabulary; As a module, used for taking the text category corresponding to the text score as the target text category of the text to be detected according to the correspondence between the preset score range and the text category; Wherein, the processing module is used for: Determine the reward value of the target vocabulary and the matrix value of the next vocabulary according to the target detection model; use the sum of the reward value and the matrix value as the matrix value of the target vocabulary; and use the matrix value as the vocabulary score of the target vocabulary.
9. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor is used to implement any method step of claims 1-7 when executing a program stored in a memory.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method steps of any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Searching method and device
CN106294618A
Answer providing method and device for question answering system
CN107480149A