Sample construction method, classification model training method, and text classification method and device
By identifying target text segments as positive label texts and other text segments as training texts within a text paragraph, training samples are constructed. A self-supervised fine-tuning method is then used to train the classification model, solving the problem of low training efficiency caused by manually labeled samples in existing technologies. This achieves efficient zero-label sample training and improved model accuracy.
Patent Information
- Application Number
- CN202310482560.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-27
- Publication Date
- 2026-01-16
- Estimated Expiration
- 2043-04-27
AI Technical Summary
In existing technologies, the training methods for classification models require a large number of manually labeled samples, resulting in low training efficiency.
By obtaining the target text fragment from the text paragraph as the positive label text, and combining it with other text fragments as training text, training samples are constructed, and a self-supervised fine-tuning method is used to train the classification model, avoiding manual labeling.
This enabled training of the classification model with zero-labeled samples, improving training efficiency and the accuracy of the classification model.
Smart Images

Figure CN116881445B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer, and particularly relates to a sample construction method, a classification model training method, a text classification method and device. BACKGROUND
[0002] The classification model can be applied to various speech or text classification tasks, for example, analyzing whether a user comment is positive or negative and predicting the category of a product.
[0003] In the related art, the sample is input into the classification model, and the label of the sample is used to train the classification model. This training method requires a large number of labeled samples, which reduces the training efficiency of the classification model. SUMMARY
[0004] The aspects of the present application provide a sample construction method, a classification model training method, a text classification method and device to improve the training efficiency of the classification model.
[0005] The first aspect of the embodiment of the present application provides a sample construction method, comprising: obtaining a first text paragraph, the first text paragraph comprising a plurality of text segments; determining a target text segment in the plurality of text segments as a positive label text of a training text, the positive label text summarizing the first text paragraph; determining a text segment other than the target text segment in the plurality of text segments as a training text; determining a training sample according to the positive label text and the training text, the training sample and the positive label text being used to train a classification model.
[0006] The second aspect of the embodiment of the present application provides a classification model training method, comprising: obtaining a training sample and a positive label text corresponding to the training sample, the training sample being constructed by the sample construction method of any one of the first aspect, the training sample comprising the positive label text and a training text; inputting the training sample into the classification model for classification to obtain a predicted category text of the training text; determining a first loss value according to the positive label text and the predicted category text; if the first loss value is greater than a first threshold, adjusting the model parameters of the classification model using the first loss value.
[0007] The third aspect of the embodiment of the present application provides a text classification method applied to a cloud server, the text classification method comprising: obtaining a text to be classified and a plurality of category texts set in advance; combining the text to be classified and the plurality of category texts to obtain a target text; inputting the target text into a pre-trained classification model for classification processing to obtain a target category of the text to be classified, the target category being one of the plurality of category texts, the classification model being trained according to the classification model training method of the second aspect.
[0008] The fourth aspect of the embodiment of the present application provides a text classification method, the text classification method comprising: obtaining a text to be classified; sending the text to be classified to a cloud server; and receiving a target category sent by the cloud server, the target category being determined by the cloud server according to the text classification method of the third aspect.
[0009] The fifth aspect of the embodiment of the present application provides a sample construction method, applied to a cloud server, the sample construction method comprising: obtaining a first text paragraph, the first text paragraph comprising a plurality of text segments; determining a target text segment in the plurality of text segments as a positive label text of a training text, the positive label text being capable of summarizing the first text paragraph; determining text segments other than the target text segment in the plurality of text segments as training texts; determining a training sample according to the positive label text and the training texts, the training sample and the positive label text being used to train a classification model.
[0010] The sixth aspect of the embodiment of the present application provides a text classification system, comprising:
[0011] a cloud server and a terminal device, the cloud server being deployed with a classification model;
[0012] the terminal device, configured to obtain a text to be classified and send the text to be classified to the cloud server;
[0013] the cloud server, configured to obtain the text to be classified and a plurality of category texts pre-set; combine the text to be classified and the plurality of category texts to obtain a target text; input the target text into a pre-trained classification model for classification processing to obtain a target category of the text to be classified, the target category being one of the plurality of category texts, and the classification model being trained according to the classification model training method of the second aspect;
[0014] the terminal device, configured to receive the target category sent by the cloud server.
[0015] The seventh aspect of the embodiment of the present application provides an electronic device, comprising: a processor, a memory, and a computer program stored on the memory and executable on the processor, the processor implementing the sample construction method of the first aspect, and / or the classification model training method of the second aspect, and / or the text classification method of the third aspect when executing the computer program.
[0016] The eighth aspect of the embodiment of the present application provides a computer readable storage medium, the computer readable storage medium storing a computer program, the computer program causing a processor to implement the sample construction method of the first aspect, and / or the classification model training method of the second aspect, and / or the text classification method of the third aspect when the computer program is executed by the processor.
[0017] The embodiment of the application is applied to a scene of training sample construction, a first text paragraph is obtained, the first text paragraph includes a plurality of text segments; a target text segment in the plurality of text segments is determined as a positive label text of a training text, and the positive label text can summarize the first text paragraph; a text segment other than the target text segment in the plurality of text segments is determined as a training text; a training sample is determined according to the positive label text and the training text, the training sample and the positive label text are used to train a classification model, manual labeling of the training sample can be avoided, and then zero-label sample training of the classification model is realized, and the training efficiency of the classification model is improved. BRIEF DESCRIPTION OF DRAWINGS
[0018] The accompanying drawings, which are included to provide a further understanding of the application and are incorporated in and constitute a part of this application, illustrate embodiments of the application and serve to explain the principles of the application, and do not limit the application in any way. In the drawings:
[0019] Figure 1 An application scenario diagram provided for the exemplary embodiments of the application;
[0020] Figure 2 A step flowchart of a sample construction method provided for the exemplary embodiments of the application;
[0021] Figure 3 A schematic diagram of a sample construction method provided for the exemplary embodiments of the application;
[0022] Figure 4 A step flowchart of a classification model training method provided for the exemplary embodiments of the application;
[0023] Figure 5 A step flowchart of a text classification method provided for the exemplary embodiments of the application;
[0024] Figure 6 A schematic diagram of a text classification method provided for the exemplary embodiments of the application;
[0025] Figure 7 A structural block diagram of a sample construction device provided for the exemplary embodiments of the application;
[0026] Figure 8 A structural schematic diagram of an electronic device provided for the exemplary embodiments of the application. DETAILED DESCRIPTION
[0027] In order to make the purposes, technical solutions and advantages of the present application clearer, the technical solutions of the present application will be described clearly and completely below in combination with specific embodiments of the present application and corresponding drawings. Obviously, the described embodiments are only some of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative work fall within the scope of protection of the present application.
[0028] Currently, the training method of the classification model mainly includes prompt learning of a pre-trained model or fine-tuning of the pre-trained model on a large amount of labeled data, so that the model obtains the ability of text classification of zero-labeled samples. In the prompt learning, a template and an expresser are designed to process the training text, and the classification effect of the classification model obtained by the method is poor. In addition, the fine-tuning of the pre-trained model on a large amount of labeled data specifically includes reformatting the labeled samples into instruction templates, question and answer pairs, multiple-choice questions or implication pairs, and fine-tuning the pre-trained model by using these data. The method needs manual labeling of the training text, which can result in low training efficiency of the classification model.
[0029] Based on the above method, the present application provides a sample construction method, which includes obtaining a first text paragraph, the first text paragraph including a plurality of text segments; determining a target text segment in the plurality of text segments as a positive label text of a training text, the positive label text summarizing the first text paragraph; determining the text segments other than the target text segment in the plurality of text segments as training texts; determining a training sample according to the positive label text and the training texts, the training sample and the positive label text being used to train a classification model, thereby improving the training efficiency of the classification model.
[0030] In the present embodiment, the execution device of the training sample construction method is not limited. Alternatively, the training sample construction method can be applied to a terminal, and the overall sample construction method can also be implemented by means of a cloud computing system. For example, the training sample construction method can be applied to a cloud server, so as to run various models by means of the advantages of resources on the cloud; compared with being applied to the cloud, the training sample construction method can also be applied to a server device such as a general server, a cloud server or a server array.
[0031] In addition, with reference to Figure 1 Fig. 1 is an application scenario diagram of the present application. A server 11 constructs a training sample, then trains a classification model by using the constructed training sample, and then puts the classification model online. After being put online, the classification model classifies a to-be-classified text received by a terminal device 12 by using the classification model, and obtains a target category of the to-be-classified text.
[0032] For example, the classification model can be applied to a classification task, such as classifying user review text. The user review text is input into the classification model to determine whether the user review is positive or negative. For another example, the classification model can be applied to a classification task, such as classifying product description text. The product description text is input into the classification model to determine the product category corresponding to the product description.
[0033] Figure 1 The application can be applied to other related scenarios, which are not limited herein.
[0034] The technical solutions provided by the embodiments of the application will be described in detail below with reference to the accompanying drawings.
[0035] Figure 2 A sample construction method provided by an exemplary embodiment of the application is shown in a step flowchart. Figure 2 The sample construction method includes the following steps:
[0036] S201, obtaining a first text paragraph.
[0037] In the embodiments of the application, the first text paragraph can be an article, a review, or the like from a network or a database. The first text paragraph is the text in a paragraph.
[0038] The first text paragraph includes a plurality of text segments. It can be understood that the first text paragraph is composed of a plurality of text segments.
[0039] For example, referring to Figure 3 , the first text paragraph is "Jimmy was born in February 1947… He was the former mayor of Adrian…". Among them, "Jimmy was born in February 1947…" is a text segment, and "He was the former mayor of Adrian…" is another text segment. There can be multiple text segments after "He was the former mayor of Adrian…".
[0040] S202, determining a target text segment in the plurality of text segments as a positive label text of the training text.
[0041] The positive label text can be summarized from the first text paragraph.
[0042] Further, determining the target text segment in the plurality of text segments as the positive label text of the training text includes determining a first sentence text segment in the first text paragraph as the positive label text.
[0043] In the embodiment of the present application, the first sentence text segment can be regarded as the positive label text because the first sentence text segment can generally summarize the content expressed by the first sentence text segment. In addition, other text segments can also be regarded as the positive label text if they can summarize the first text segment, such as the last sentence text segment of the first text paragraph.
[0044] For example, referring to Figure 3 The first sentence text segment "Jimmy was born in February 1947…" in the first text paragraph can be determined as the positive label text.
[0045] In S203, the text segments other than the target text segment in the plurality of text segments are determined as training texts.
[0046] For example, referring to , the training texts are "He was the former mayor of Adrian…".
[0047] Figure 3 In S204, the training sample is determined according to the positive label text and the training text.
[0048] In the embodiment of the present application, the training sample includes the positive label text and the training text. In addition, the positive label text and the training text are combined according to a preset rule.
[0049] For example, referring to The training text can be added with an identifier, the positive label text can be added with an identifier, and then the training sample can be obtained by combining them, such as
[0050] the training sample in the first text paragraph, which includes the training text "[SEP] He was the former mayor of Adrian…" added with an identifier and the positive label text "(B) Jimmy was born in February 1947…" added with an identifier, and in addition, the training sample can also include other text content. Figure 3 Figure 3 In an optional embodiment, the training sample can only include the training text and the positive label text. For example, the training sample can also be "(B) Jimmy was born in February 1947… [SEP] He was the former mayor of Adrian…", in which (B) is the identifier of the positive label text and [SEP] is the identifier of the training text.
[0051] In S205, the classification model is trained according to the training sample.
[0052] In the embodiment of the present application, the positive label text can be regarded as the positive label of the training sample to train the classification model.
[0053] For example, referring to
[0054] Further, based on the positive label text and the training text, the training samples are determined, including: obtaining the second text paragraph; determining the first sentence fragment in the second text paragraph as the first negative label text; and combining the positive label text, the first negative label text, and the training text in a preset order to obtain the training samples.
[0055] In this embodiment of the application, the training samples also include first negative label text, which can be one or more. The second text paragraph can include multiple text fragments, and the first negative label text can be derived from the first sentence fragment of the second text paragraph.
[0056] The second text paragraph is a different text paragraph from the first text paragraph.
[0057] Furthermore, the second text paragraph and the first text paragraph are different paragraphs from the same article.
[0058] For example, refer to Figure 3 The second text paragraph reads, "January 6, 2012, Jimmy… He ran against the incumbent president…", and since this second text paragraph and the first text paragraph are from the same article, the first sentence of the second text paragraph, "January 6, 2012, Jimmy…", can be used as the first negative-labeled text. Figure 3 In the training samples, the first negative label text is marked with an identifier, such as "(A) January 6, 2012, Jimmy...", where (A) is the identifier of the first negative label text.
[0059] Optionally, the training samples may consist only of training text, positive label text, and first negative label text. For example, the training sample could also be “(A) January 6, 2012, Jimmy…(B) Jimmy was born in February 1947…[SEP] He is Adrian’s former mayor…”.
[0060] In this embodiment of the application, the first negatively labeled text can be used as the negative label of the training sample to train the classification model.
[0061] Furthermore, the training samples also include a second negative label text. The positive label text, the first negative label text, and the training text are combined in a preset order to obtain the training samples, which include: obtaining a third text paragraph, the third text paragraph and the first text paragraph coming from different articles; determining the first sentence fragment in the third text paragraph as the second negative label text; and combining the positive label text, the first negative label text, the second negative label text, and the training text in a preset order to obtain the training samples.
[0062] The third text paragraph and the first text paragraph are text paragraphs from different articles. There can be one or more third text paragraphs. For example, refer to... Figure 3, including two third text paragraphs (third text paragraph A and third text paragraph B).
[0063] Further, the third text paragraph includes a plurality of text segments, and the second negative label text can be a text segment from a first sentence in the third text paragraph. In addition, the second negative label text can also be a text segment from another sentence in the third text paragraph, which is not limited.
[0064] For example, referring to Figure 3 , the third text paragraph a1 is "Since the end of 1960, Flint has faced several crises. The city has experienced…", and the corresponding second negative label text a2 is "Since the end of 1960, Flint has faced several crises". The third text paragraph b1 is "XX company is…", and the second negative label text b2 is "XX company is…".
[0065] In Figure 3 , the second negative label text contained in the training sample is increased with an identifier, such as "(C) Since the end of 1960, Flint has faced several crises. (E) XX company is…", wherein (C) is an identifier of the second negative label text a2. (E) is an identifier of the second negative label text b2.
[0066] For example, referring to Figure 3 , the training sample includes: training text, positive label text, first negative label text, and second negative label text.
[0067] Alternatively, the training sample can only include training text, positive label text, and second negative label text. For example, the training sample can also be "(A) On January 6, 2012, Jimmy… (B) Since the end of 1960, Flint has faced several crises (C) XX company is… [SEP] He is the former mayor of Adrian…".
[0068] In the embodiments of the present application, the second negative label text can be used as a negative label to train the classification model.
[0069] Further, after the positive label text, the first negative label text, the second negative label text, and the training text are combined in the preset order to obtain the training sample, the method further includes: obtaining the number of categories required for training; and if the number of label texts in the training sample is less than the number of categories, filling an identifier text in the training sample, wherein the number of identifier texts is equal to the difference between the number of categories and the number of label texts.
[0070] In the embodiments of the present application, the number of label texts refers to the total number of the positive label text, the first negative label text, and the second negative label text. For example, referring to Figure 3In the specific implementation, the number of the label texts in the training sample is 4. In addition, the number of the categories is determined according to the training requirement of the training task. For example, if the training task is to identify, by a classification model, to which of the five categories a to-be-classified text belongs, the number of the categories is 5.
[0071] Further, if the number of the categories is 5 and the number of the label texts is 4, the difference between the two is 1, and the identification text can be equal to 1. Referring to Figure 3 , the identification text in the training sample is, for example, [PAD], and the identification text also has a corresponding identification, for example, [CLS]. Figure 3 In the specific implementation, the number of the label texts in the training sample is 4. In addition, the number of the categories is determined according to the training requirement of the training task. For example, if the training task is to identify, by a classification model, to which of the five categories a to-be-classified text belongs, the number of the categories is 5.
[0072] In the embodiments of the present application, the identification text plays a role of placeholder, so that the structure of the text input into the classification model when the classification model classifies the to-be-classified text is consistent with the structure of the training sample input into the classification model during training, and thus the classification performance of the classification model can be improved.
[0073] To sum up, the embodiments of the present application are applied to the scenario of training sample construction, a first text paragraph is obtained, the first text paragraph includes a plurality of text segments, a target text segment in the plurality of text segments is determined as a positive label text of a training text, the positive label text can summarize the first text paragraph, and a text segment other than the target text segment in the plurality of text segments is determined as a training text. According to the positive label text and the training text, a training sample is determined, the training sample and the positive label text are used to train a classification model, manual labeling of the training sample can be avoided, and thus zero-labeled sample training of the classification model is realized, and the training efficiency of the classification model is improved.
[0074] Referring to Figure 4 , a step flowchart of a classification model training method provided by an exemplary embodiment of the present application is provided.
[0075] As Figure 4 shown, the classification model training method specifically includes the following steps:
[0076] S401, a training sample and a positive label text corresponding to the training sample are obtained.
[0077] In the specific implementation, the number of the label texts in the training sample is 4. In addition, the number of the categories is determined according to the training requirement of the training task. For example, if the training task is to identify, by a classification model, to which of the five categories a to-be-classified text belongs, the number of the categories is 5.
[0078] Referring to Figure 3, the training sample is "(A) On January 6, 2012, Jimmy…(B) Jimmy was born in February 1947…(C) Since the end of 1960, Flint has faced several crises (D) [PAD] (E) XX company is…[SEP] He is the former mayor of Adrian…", and the training sample can also be "(A) Jimmy was born in February 1947…(B) [PAD] (C) (D) [PAD] ([SEP] He is the former mayor of Adrian…". The positive label text is "Jimmy was born in February 1947…".
[0079] S402, input the training sample into the classification model for classification to obtain the predicted category text of the training text.
[0080] In the embodiment of the application, the classification model can be a pre-trained pre-trained language model, and in this step, the constructed training sample is used to adjust the classification model to obtain a classification model that can be applied to the corresponding task.
[0081] Further, the constructed training sample is input into the classification model, and the classification model is used for prediction to obtain the predicted category text of the training text. In the embodiment of the application, the classification model is used to predict the category of the training text.
[0082] In the embodiment of the application, the training sample can also be a voice. After the training sample is input into the classification model, the classification model first performs voice recognition on the voice training sample to obtain a corresponding text sample, and then performs prediction on the text sample to obtain the predicted category text of the training text.
[0083] S403, determining a first loss value according to the positive label text and the predicted category text.
[0084] In the embodiment of the application, the loss value between the positive label text and the predicted category text is determined as the first loss value according to the preset loss function. For example, the loss function is a cross-entropy loss function. The positive label text and the predicted category text are substituted into the cross-entropy loss function, and the loss value between the positive label text and the predicted category text can be calculated.
[0085] In addition, the preset loss function can also be other loss functions, which are not limited herein.
[0086] S404, if the first loss value is greater than a first threshold, adjusting the model parameters of the classification model by using the first loss value.
[0087] In the embodiments of the present application, the first threshold value is pre-set. If the first loss value is greater than the first threshold value, it can be determined that the predicted category text and the positive label text are quite different. After the model parameters of the classification model are adjusted using the first loss value, the predicted category text output by the classification model can be closer to the positive label text, and the classification accuracy of the classification model can be improved. If the first loss value is less than the first threshold value, the training of the classification model can be continued using other training samples until the classification model meets the training requirements.
[0088] Further, the training sample further includes a first negative label text, and the classification model training method further includes: determining a second loss value according to the first negative label text and the predicted category text; and adjusting the model parameters of the classification model using the second loss value if the second loss value is less than a second threshold value.
[0089] In the embodiments of the present application, the second threshold value is pre-set, and the first negative label text is constructed according to the above sample construction method.
[0090] For example, referring to Figure 3 , the training sample is "(A) On January 6, 2012, Jimmy… (B) Jimmy was born in February 1947… (C) Since the end of 1960, Flint has faced several crises (D) [PAD] (E) XX company is… [SEP] He is the former mayor of Adrian…", and in addition, the training sample can be "(A) On January 6, 2012, Jimmy… (B) Jimmy was born in February 1947… (C) (D) [PAD] ([SEP] He is the former mayor of Adrian…". The first negative label text is "On January 6, 2012, Jimmy…".
[0091] In the embodiments of the present application, if the second loss value is less than the second threshold value, it indicates that the loss value of the first negative label text and the predicted category text is small, and the predicted category text is close to the first negative label text. After the model parameters of the classification model are adjusted using the second loss value, the gap between the predicted category text output by the classification model and the first negative label text can be larger, and the classification accuracy of the classification model can be improved. If the second loss value is greater than or equal to the second threshold value, the training of the classification model can be continued using other training samples until the classification model meets the training requirements.
[0092] Further, the training sample further includes a second negative label text, and the method further includes: determining a third loss value according to the second negative label text and the predicted category text; and adjusting the model parameters of the classification model using the third loss value if the third loss value is less than a third threshold value.
[0093] In the embodiments of the present application, the third threshold value is pre-set, and the second negative label text is constructed according to the above sample construction method.
[0094] For example, referring toFigure 3 The second negative label text is "Since the end of 1960, Flint has faced several crises" and "XX Company is…".
[0095] In the embodiment of the present application, if the third loss value is less than the third threshold value, it indicates that the loss value of the second negative label text and the predicted category text is smaller, and the predicted category text and the second negative label text are closer. After adjusting the model parameters of the classification model using the third loss value, the gap between the predicted category text and the second negative label text output by the classification model can be made larger, and the classification accuracy of the classification model can be improved. If the third loss value is greater than or equal to the third threshold value, other training samples can be used to continue training the classification model until the classification model meets the training requirements.
[0096] In the embodiment of the present application, since the first negative label text and the training text come from the same article, and the second negative label text and the training text come from different texts, the correlation of the first negative label text and the training text is greater than the correlation of the second negative label text and the training text. Therefore, the second threshold value can be set to be less than the third threshold value. In addition, the second threshold value and the third threshold value can also be set to be the same, which is not limited herein.
[0097] To sum up, the present application uses the constructed training sample to train the classification model, which can improve the efficiency of the classification model.
[0098] In addition, the present application proposes a method of self-supervised fine-tuning to solve the task of zero-labeled sample text classification, which can effectively construct large-scale training samples without human annotation. Further, a simple and effective learning goal is designed, i.e., the first sentence text segment as the positive label text, to improve the training efficiency of the classification model.
[0099] With reference to Figure 5 The present application also provides a text classification method, which is applied to a cloud server, and specifically includes the following steps:
[0100] S501, obtaining a to-be-classified text and a plurality of preset category texts.
[0101] In the embodiment of the present application, the category texts are preset. For example, when the to-be-classified text is a review text, the plurality of category texts include positive and negative. For another example, when the to-be-classified text is a description text, the plurality of category texts include a plurality of categories.
[0102] With reference to Figure 6, the text to be classified is "Cunning credit card strategy Pay close attention to your credit card issuer, they may raise your interest rate", and the multiple category texts are "entertainment, sports, business, technology, and culture" respectively.
[0103] In the implementation of the present application, if the category text is a word, the category text can be expanded to a sentence (category input text), which does not affect the meaning of the category text. For example, referring to Figure 6 , the multiple category texts "entertainment, sports, business, technology, and culture" correspond to the category input texts "This text is about entertainment. This text is about sports. This text is about business. This text is about technology. This text is about culture" respectively.
[0104] S502, combining the text to be classified and the multiple category texts to obtain a target text.
[0105] In the embodiment of the present application, the target text can be obtained by combining the text to be classified and the multiple category input texts, wherein, in the process of combination, an identifier is added to the category input text and the text to be classified. Referring to Figure 6 , the obtained target text is "(A) This text is about entertainment. (B) This text is about sports. (C) This text is about business. (D) This text is about technology. (E) This text is about culture [SEP] Cunning credit card strategy Pay close attention to your credit card issuer, they may raise your interest rate".
[0106] In an alternative embodiment, the text to be classified and the multiple category texts can also be directly combined to obtain a target text, which can be "(A) entertainment (B) sports (C) business (D) technology (E) culture [SEP] Cunning credit card strategy Pay close attention to your credit card issuer, they may raise your interest rate".
[0107] Further, the present application can also add an identifier text such as [PAD] to the target text as needed. For example, the target text can be "(A) This text is about entertainment. (B) This text is about sports. (C) This text is about business. (D) This text is about technology. (E) This text is about culture. (F) [PAD] [SEP] Cunning credit card strategy Pay close attention to your credit card issuer, they may raise your interest rate".
[0108] Among them, (A) (B) (C) (D) (E) (F) are identifiers in the target text, and the number of these identifiers is the same as the number of corresponding identifiers in the training sample in the training process.
[0109] S503, input the target text into the pre-trained classification model for classification processing to obtain a target category of the text to be classified.
[0110] The target category is one of the multiple category texts, and the classification model is trained by the classification model training method.
[0111] Referring to Figure 6 The target category is "this text is about business", and the target category is one of the category input texts. In addition, the target category can also be "business", and the target category is one of the multiple category texts.
[0112] In the embodiment of the application, by obtaining the text to be classified and the pre-set multiple category texts, combining the text to be classified and the multiple category texts, obtaining the target text, inputting the target text into the pre-trained classification model for classification processing, and obtaining the target category of the text to be classified, the accurate classification of the text to be classified can be realized.
[0113] In addition, the application also provides a text classification method applied to a terminal device, and the text classification method comprises: obtaining a text to be classified; sending the text to be classified to a cloud server; and receiving a target category sent by the cloud server, wherein the target category is determined by the cloud server according to the text classification method.
[0114] In the embodiment of the application, the terminal device only needs to send the text to be classified to the server, and the target category of the text to be classified can be obtained. The specific implementation process is described above, and will not be described here.
[0115] In the embodiment of the application, in addition to providing a sample construction method, a sample construction device is also provided, as shown in Figure 7 The sample construction device 70 comprises:
[0116] The acquisition module 71 is configured to acquire a first text paragraph, and the first text paragraph comprises multiple text segments.
[0117] The first determination module 72 is configured to determine a target text segment in the multiple text segments as a positive label text of a training text, and the positive label text can summarize the first text paragraph.
[0118] The second determination module 73 is configured to determine a text segment other than the target text segment in the multiple text segments as the training text.
[0119] The third determination module 74 is configured to determine a training sample according to the positive label text and the training text, and the training sample and the positive label text are used to train a classification model.
[0120] In an optional embodiment, the second determining module 73 is specifically configured to determine that the first sentence text segment in the first text paragraph is positive label text.
[0121] In an optional embodiment, the third determining module 74 is specifically configured to obtain a second text paragraph, determine that a first sentence text segment in the second text paragraph is first negative label text, and combine the positive label text, the first negative label text and the training text in a preset order to obtain the training sample.
[0122] In an optional embodiment, the second text paragraph and the first text paragraph are different paragraphs from the same article.
[0123] In an optional embodiment, when the third determining module 74 combines the positive label text, the first negative label text and the training text in a preset order to obtain the training sample, the third determining module 74 is specifically configured to obtain a third text paragraph, the third text paragraph and the first text paragraph are from different articles, determine that a first sentence text segment in the third text paragraph is second negative label text, and combine the positive label text, the first negative label text, the second negative label text and the training text in a preset order to obtain the training sample.
[0124] In an optional embodiment, the sample construction method further includes that a filling module (not shown) is configured to obtain a required number of categories after the positive label text, the first negative label text, the second negative label text and the training text are combined in a preset order to obtain the training sample, and if the number of label texts in the training sample is less than the number of categories, fill the training sample with identification texts, and the number of the identification texts is equal to the difference between the number of categories and the number of label texts.
[0125] The sample construction device provided in the embodiments of the present application can avoid manual annotation of training samples, thereby realizing zero-annotation sample training of the classification model and improving the training efficiency of the classification model. The specific implementation process is described above in the method embodiments, which will not be described here.
[0126] In addition, the present application also provides a model training device (not shown), which includes:
[0127] The obtaining module is configured to obtain a training sample and positive label text corresponding to the training sample, the training sample being constructed by the above sample construction method, and the training sample including the positive label text and training text.
[0128] The classification module is configured to input the training sample into a classification model for classification to obtain predicted category text of the training text.
[0129] The determining module is configured to determine a first loss value according to the positive label text and the predicted category text.
[0130] The adjusting module is configured to adjust the model parameters of the classification model by using the first loss value if the first loss value is greater than the first threshold value.
[0131] In an optional embodiment, the training sample further comprises a first negative label text, and the training module (not shown) is further configured to determine a second loss value according to the first negative label text and the predicted category text; and adjust the model parameters of the classification model by using the second loss value if the second loss value is less than a second threshold value.
[0132] In an optional embodiment, the training sample further comprises a second negative label text, and the training module is further configured to determine a third loss value according to the second negative label text and the predicted category text; and adjust the model parameters of the classification model by using the third loss value if the third loss value is less than a third threshold value.
[0133] In addition, the present application further provides a text classification device (not shown) applied to a cloud server, comprising:
[0134] The obtaining module is configured to obtain the text to be classified and a plurality of category texts preset in advance;
[0135] The combining module is configured to combine the text to be classified and the plurality of category texts to obtain a target text;
[0136] The classification module is configured to input the target text into a pre-trained classification model for classification processing to obtain a target category of the text to be classified, the target category being one of the plurality of category texts, and the classification model being trained according to the above-mentioned classification model training method.
[0137] In addition, the present application further provides a text classification device (not shown) applied to a terminal device, comprising:
[0138] The obtaining module is configured to obtain the text to be classified;
[0139] The sending module is configured to send the text to be classified to the cloud server;
[0140] The receiving module is configured to receive a target category sent by the cloud server, the target category being determined by the cloud server according to the above-mentioned text classification method.
[0141] In addition, the present application further provides a text classification system, comprising:
[0142] The cloud server and the terminal device, and the classification model is deployed on the cloud server;
[0143] The terminal device is configured to obtain the text to be classified and send the text to be classified to the cloud server;
[0144] A cloud server is used to acquire the text to be classified and multiple pre-set category texts; combine the text to be classified and multiple category texts to obtain the target text; input the target text into a pre-trained classification model for classification processing to obtain the target category of the text to be classified, wherein the target category is one of the multiple category texts, and the classification model is trained according to the classification model training method according to any one of claims 7 to 9;
[0145] Terminal devices are used to receive target categories sent by cloud servers.
[0146] The specific implementation process is the same as described in the above embodiments, and will not be repeated here.
[0147] Furthermore, in some of the processes described in the above embodiments and accompanying drawings, multiple operations appear in a specific order. However, it should be clearly understood that these operations may not be executed in the order they appear herein, or may be executed in parallel. The sequence numbers are merely used to distinguish different operations, and the sequence numbers themselves do not represent any execution order. Additionally, these processes may include more or fewer operations, and these operations may be executed sequentially or in parallel. It should be noted that the descriptions such as "first," "second," etc., in this document are used to distinguish different messages, devices, modules, etc., and do not represent a sequential order, nor do they limit "first" and "second" to different types.
[0148] Figure 8 This is a schematic diagram of the structure of an electronic device 80 provided for an exemplary embodiment of this application. This electronic device is used to run the above-described sample construction method. Figure 8 As shown, the electronic device 80 includes a memory 84 and a processor 85.
[0149] Memory 84 is used to store computer programs and can be configured to store various other data to support operation on electronic devices. This memory 84 may be object storage (OSS).
[0150] The memory 84 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk or optical disk.
[0151] The processor 85 is coupled with the memory 84 and configured to execute a computer program in the memory 84 to obtain a first text paragraph, the first text paragraph comprising a plurality of text segments; determine a target text segment in the plurality of text segments as a positive label text of a training text, the positive label text summarizing the first text paragraph; and determine a training sample according to the positive label text and the training text, the training sample and the positive label text being used to train a classification model.
[0152] Further optionally, when determining the target text segment in the plurality of text segments as the positive label text of the training text, the processor 85 is specifically configured to determine a first sentence text segment in the first text paragraph as the positive label text.
[0153] Further optionally, when determining the training sample according to the positive label text and the training text, the processor 85 is specifically configured to obtain a second text paragraph; determine a first sentence text segment in the second text paragraph as a first negative label text; and combine the positive label text, the first negative label text and the training text in a preset order to obtain the training sample.
[0154] Further optionally, when combining the positive label text, the first negative label text and the training text in the preset order to obtain the training sample, the processor 85 is specifically configured to obtain a third text paragraph, the third text paragraph and the first text paragraph being from different articles; determine a first sentence text segment in the third text paragraph as a second negative label text; and combine the positive label text, the first negative label text, the second negative label text and the training text in the preset order to obtain the training sample.
[0155] In an optional embodiment, after combining the positive label text, the first negative label text, the second negative label text and the training text in the preset order to obtain the training sample, the processor 85 is further configured to obtain a required number of categories for training; and if a number of label texts in the training sample is less than the number of categories, fill an identification text in the training sample, the number of identification texts being equal to a difference between the number of categories and the number of label texts.
[0156] In an optional embodiment, the processor 85 is coupled with the memory 84 and configured to execute a computer program in the memory 84 to further obtain a training sample and a positive label text corresponding to the training sample, the training sample being constructed by any one of the sample construction methods, the training sample comprising the positive label text and a training text; input the training sample into a classification model to obtain a predicted category text of the training text; and determine a first loss value according to the positive label text and the predicted category text.
[0157] In an optional embodiment, the processor 85 is further configured to determine a second loss value according to the first negative label text and the predicted category text; and adjust the model parameters of the classification model using the second loss value if the second loss value is less than a second threshold value.
[0158] In an optional embodiment, the processor 85 is further configured to determine a third loss value according to the second negative label text and the predicted category text; and adjust the model parameters of the classification model using the third loss value if the third loss value is less than a third threshold value.
[0159] In an optional embodiment, the processor 85, coupled to the memory 84, is configured to execute a computer program in the memory 84, and is further configured to: obtain the text to be classified and a plurality of preset category texts; combine the text to be classified and the plurality of category texts to obtain a target text; and input the target text into a pre-trained classification model for classification processing to obtain a target category of the text to be classified, the target category being one of the plurality of category texts, and the classification model being trained according to the classification model training method of any one of the above embodiments.
[0160] In an optional embodiment, the processor 85, coupled to the memory 84, is configured to execute a computer program in the memory 84, and is further configured to: obtain the text to be classified; send the text to be classified to a cloud server; and receive a target category sent by the cloud server, the target category being determined by the cloud server according to the text classification method of the above embodiments.
[0161] Further, as shown in Figure 8 the electronic device further includes a firewall 81, a load balancer 82, a communication component 86, a power supply component 83, and other components. Figure 8 The electronic device is only schematically shown with some components, and does not mean that the electronic device only includes Figure 8 the components shown in the figure.
[0162] Correspondingly, the embodiments of the present application further provide a computer readable storage medium storing a computer program, when the computer program / instruction is executed by a processor, the processor is caused to implement the steps in the above-mentioned method.
[0163] Correspondingly, the embodiments of the present application further provide a computer program product, including a computer program / instruction, when the computer program / instruction is executed by a processor, the processor is caused to implement the steps in the above-mentioned method.
[0164] The above Figure 8The communication component is configured to facilitate wired or wireless communication between the device containing the communication component and other devices. The device containing the communication component can access wireless networks based on communication standards, such as WiFi, 2G, 3G, 4G / LTE, 5G, or combinations thereof. In one exemplary embodiment, the communication component receives broadcast signals or broadcast-related text from an external broadcast management system via a broadcast channel. In one exemplary embodiment, the communication component also includes a Near Field Communication (NFC) module to facilitate short-range communication. For example, the NFC module may be implemented based on Radio Frequency Identification (RFID), Infrared Data Association (IrDA) technology, Ultra-Wideband (UWB) technology, Bluetooth (BT) technology, and other technologies.
[0165] The above Figure 8 The power supply component provides power to the various components of the device in which it resides. The power supply component may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to the device in which it resides.
[0166] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0167] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable text processing device to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable text processing device, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0168] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable text processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1the function(s) specified in the block or blocks.
[0169] These computer program instructions can also be loaded onto a computer or other programmable text processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer-implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the flowchart Figure 1 one or more flowcharts and / or blocks Figure 1 Figure 1 steps of the function(s) specified in the block or blocks.
[0170] In one typical configuration, the computing device includes one or more processors, such as a central processing unit (CPU) and / or a graphics processing unit (GPU), an input / output interface, a network interface, and a memory.
[0171] The memory can include non-persistent memory and / or persistent memory, such as flash memory, read-only memory (ROM), and / or random access memory (RAM), among others. The memory is an example of computer readable media.
[0172] Computer readable media includes permanent and non-permanent, removable and non-removable media implemented in any method or technology for storage of information such as computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile discs (DVDs) or other optical storage, magnetic cassettes, magnetic tapes, magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device. According to the definition herein, computer readable media does not include transitory media, such as modulated data signals and carrier waves.
[0173] It is also important to note that the terms "comprises", "comprising", or any other variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but can also include other elements not expressly listed or inherent to such process, method, article, or apparatus. An element proceeded by "comprises... a" does not, without more constraints, exclude the presence of additional identical elements in the process, method, article, or apparatus that includes the element.
[0174] The above merely provides an example of the present application, and is not intended to limit the present application. For those skilled in the art, the present application can have various modifications and changes. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principle of the present application shall fall into the scope of claims of the present application.
Claims
1. A method of sample construction, characterized by, The method comprises the following steps: obtaining a first text paragraph, the first text paragraph comprising a plurality of text segments; determining a target text segment in the plurality of text segments as a positive label text of a training text, the positive label text summarizing the first text paragraph; determining the text segments other than the target text segment in the plurality of text segments as the training text; determining a training sample according to the positive label text and the training text, the training sample and the positive label text being used to train a classification model; the step of determining a training sample according to the positive label text and the training text comprises: obtaining a second text paragraph; determining a first sentence text segment in the second text paragraph as a first negative label text; combining the positive label text, the first negative label text and the training text in a preset order to obtain the training sample.
2. The sample building method of claim 1, wherein, The step of determining a target text segment in the plurality of text segments as a positive label text of a training text comprises: determining a first sentence text segment in the first text paragraph as the positive label text.
3. The sample building method according to claim 1 or 2, characterized in that, The second text paragraph and the first text paragraph are different paragraphs from the same article.
4. The sample building method of claim 3, wherein, The step of combining the positive label text, the first negative label text and the training text in a preset order to obtain the training sample comprises: obtaining a third text paragraph, the third text paragraph and the first text paragraph being from different articles; determining a first sentence text segment in the third text paragraph as a second negative label text; combining the positive label text, the first negative label text, the second negative label text and the training text in a preset order to obtain the training sample.
5. The sample building method of claim 4, wherein, After the step of combining the positive label text, the first negative label text, the second negative label text and the training text in a preset order to obtain the training sample, the method further comprises: obtaining a required number of categories; if the number of label texts in the training sample is less than the number of categories, filling an identification text in the training sample, the number of the identification text being equal to the difference between the number of categories and the number of label texts.
6. A classification model training method characterized by, The method comprises the following steps: obtaining a training sample and a positive label text corresponding to the training sample, the training sample being constructed by the sample construction method of any one of claims 1 to 5, the training sample comprising a positive label text and a training text; inputting the training sample into a classification model for classification to obtain a predicted category text of the training text; determining a first loss value according to the positive label text and the predicted category text; if the first loss value is greater than a first threshold value, adjusting model parameters of the classification model by using the first loss value; the training sample further comprises a first negative label text, and the classification model training method further comprises: determining a second loss value according to the first negative label text and the predicted category text; if the second loss value is less than a second threshold value, adjusting the model parameters of the classification model by using the second loss value.
7. The classification model training method according to claim 6, characterized in that, the training sample further comprises a second negative label text, and the classification model training method further comprises: determining a third loss value according to the second negative label text and the predicted category text; if the third loss value is less than a third threshold value, adjusting model parameters of the classification model by using the third loss value.
8. A method of text classification characterized by, The text classification method is applied to a cloud server, and the text classification method comprises: obtaining a text to be classified and a plurality of category texts set in advance; combining the text to be classified and the plurality of category texts to obtain a target text; inputting the target text into a pre-trained classification model for classification processing to obtain a target category of the text to be classified, the target category being one of the plurality of category texts, and the classification model being trained according to the classification model training method of claim 6 or 7.
9. A method of text classification characterized by, The text classification method is applied to a terminal device, and the text classification method comprises: obtaining a text to be classified; sending the text to be classified to a cloud server; receiving a target category sent by the cloud server, the target category being determined by the cloud server according to the text classification method of claim 8.
10. A method of sample construction, characterized by, The sample construction method is applied to a cloud server, and the sample construction method comprises: obtaining a first text paragraph, the first text paragraph comprising a plurality of text segments; determining a target text segment in the plurality of text segments as positive label text of a training text, the positive label text being capable of summarizing the first text paragraph; determining text segments other than the target text segment in the plurality of text segments as the training text; determining a training sample according to the positive label text and the training text, the training sample and the positive label text being used to train a classification model; the determining of the training sample according to the positive label text and the training text comprises: obtaining a second text paragraph; determining a first sentence text segment in the second text paragraph as first negative label text; combining the positive label text, the first negative label text and the training text in a preset order to obtain the training sample.
11. A text classification system characterized by, comprise: a cloud server and a terminal device, the cloud server being deployed with a classification model; the terminal device is configured to obtain a text to be classified and send the text to be classified to the cloud server; the cloud server is configured to obtain a text to be classified and a plurality of category texts set in advance; combine the text to be classified and the plurality of category texts to obtain a target text; input the target text into a pre-trained classification model for classification processing to obtain a target category of the text to be classified, the target category being one of the plurality of category texts, and the classification model being trained according to the classification model training method of claim 6 or 7; the terminal device is configured to receive a target category sent by the cloud server.
12. An electronic device, comprising: comprise: a processor, a memory and a computer program stored on the memory and executable on the processor, the processor executing the computer program to implement the sample construction method of any one of claims 1 to 5, and / or the classification model training method of claim 6 or 7, and / or the text classification method of claim 8 or 9.
Citation Information
Patent Citations
Long text classification method and device for unsupervised importance extraction
CN115905515A