Classification model training method, text classification method, medium, equipment and product

By using pre-trained large language model and activation function layer, combined with prompt text and text samples for training, the problem of difficulty in dealing with long text classification in the existing technology is solved, and the performance of text classification model and long text classification effect are improved.

CN119046691AActive Publication Date: 2024-11-29BEIJING VOLCANO ENGINE TECH CO LTD

Patent Information

Application Number
CN202411525748.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-29
Publication Date
2024-11-29
Estimated Expiration
2044-10-29

AI Technical Summary

Technical Problem

Existing text classification models, such as convolutional neural networks and BERT, are difficult to adapt to long text classification because they cannot capture contextual features over long distances and have limited pre-training corpus, resulting in poor classification capabilities.

Method used

A pre-trained large language model combined with the activation function layer is used to train through prompt text and text samples, generate word embedding vector matrix, which is used for training and reasoning of text classification models, supports the classification of long text, and uses prompt word engineering tones. Improve model performance.

Benefits of technology

It realizes the long-distance context feature capture and classification effect improvement on long texts, and enhances the output controllability and classification capabilities of the text classification model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119046691A_ABST
    Figure CN119046691A_ABST
Patent Text Reader

Abstract

The invention discloses a classification model training method, a text classification method, a medium, equipment and a product. The text classification model comprises a first model and an activation function layer, the first model is a pre-trained large language model, the training method comprises the steps that a training sample set and a prompt text are acquired, and training samples in the training sample set comprise text samples and classification labels corresponding to the text samples; the text classification model is trained in the mode that a prompt text and a text sample serve as input of a first model, a first embedded vector matrix of a first generation word output by the first model serves as input of an activation function layer, and a classification label corresponding to the text sample serves as target output of the activation function layer. Therefore, classification of the long texts can be supported, and the classification effect of the long texts is improved. The first embedded vector matrix of the first generation word output by the first model is used as the input of the activation function layer, so that the controllability of the output content of the text classification model can be ensured, and the classification capability of the model is further improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of natural language processing technology, and in particular, to a classification model training method, a text classification method, a medium, a device and a product. Background Art

[0002] Text classification is a basic task in Natural Language Processing (NLP), and is involved in many scenarios, such as sentiment analysis, user speech classification, news classification, intent recognition, etc. In related technologies, text classification models such as convolutional neural networks and bidirectional encoder representation from transformers (BERT) are usually used for text classification, but these models are not suitable for the classification of long texts due to their own structural limitations. Summary of the invention

[0003] This summary is provided to introduce concepts in a brief form that will be described in detail in the detailed description below. This summary is not intended to identify key features or essential features of the claimed technical solution, nor is it intended to limit the scope of the claimed technical solution.

[0004] In a first aspect, the present disclosure provides a text classification model training method, wherein the text classification model includes a first model and an activation function layer, wherein the first model is a pre-trained large language model, and the text classification model training method includes: Acquire a training sample set and a prompt text, wherein the training samples in the training sample set include text samples and classification labels corresponding to the text samples, and the prompt text includes classification task description information of the text classification model; The text classification model is trained by taking the prompt text and the text sample as the input of the first model, taking the first embedding vector matrix of the first generated word output by the first model as the input of the activation function layer, and taking the classification label corresponding to the text sample as the target output of the activation function layer to obtain a target text classification model.

[0005] In a second aspect, the present disclosure provides a text classification method, the text classification method comprising: Get the first text to be classified; Inputting the first text into a first model of a target text classification model to obtain a second embedding vector matrix of a first generated word output by the first model, wherein the target text classification model includes the first model and an activation function layer, and the first model is a large language model; The second embedding vector matrix is ​​input into the activation function layer to obtain a classification result of the first text output by the activation function layer.

[0006] In a third aspect, the present disclosure provides a computer-readable medium having a computer program stored thereon, which, when executed by a processing device, implements the steps of the text classification model training method provided in the first aspect of the present disclosure or the steps of the text classification method provided in the second aspect of the present disclosure.

[0007] In a fourth aspect, the present disclosure provides an electronic device, including: a storage device having a computer program stored thereon; A processing device is used to execute the computer program in the storage device to implement the steps of the text classification model training method provided in the first aspect of the present disclosure or the steps of the text classification method provided in the second aspect of the present disclosure.

[0008] In a fifth aspect, the present disclosure provides a computer program product, including a computer program, which, when executed by a processor, implements the steps of the text classification model training method provided in the first aspect of the present disclosure or the steps of the text classification method provided in the second aspect of the present disclosure.

[0009] In the above technical solution, the text classification model includes a first model and an activation function layer, wherein the first model is a pre-trained large language model. Since the large language model is suitable for processing long texts and can capture long-distance context features, the text classification model can support the classification of long texts, so that the trained target text classification model also has the ability to capture long-distance context features on long texts, and can pay attention to the context features of the context, thereby improving the classification effect of long texts. In addition, the large language model has a larger amount of pre-trained corpus, which can compress more knowledge into the model, and is combined with the prompt word project for tuning, which greatly improves the classification ability of the target text classification model. In addition, using the first embedding vector matrix of the first generated word output by the first model as the input of the activation function layer can make the input of the activation function layer simpler and more controllable, thereby ensuring the controllability of the output content of the text classification model and further improving the classification ability of the model.

[0010] Other features and advantages of the present disclosure will be described in detail in the following detailed description. BRIEF DESCRIPTION OF THE DRAWINGS

[0011] The above and other features, advantages and aspects of the embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. Throughout the drawings, the same or similar reference numerals represent the same or similar elements. It should be understood that the drawings are schematic and the originals and elements are not necessarily drawn to scale. In the drawings: Figure 1 The figure is a flowchart of a text classification model training method according to an exemplary embodiment.

[0012] Figure 2 It is a schematic diagram of a text classification model training process according to an exemplary embodiment.

[0013] Figure 3 is a schematic diagram of a text classification model training process according to another exemplary embodiment.

[0014] Figure 4 The figure is a flowchart of a text classification model training method according to another exemplary embodiment.

[0015] Figure 5 The figure is a flowchart of a text classification method according to an exemplary embodiment.

[0016] Figure 6 The figure is a flowchart of a text classification method according to another exemplary embodiment.

[0017] Figure 7 It is a block diagram of a text classification model training device according to an exemplary embodiment.

[0018] Figure 8 The figure is a block diagram of a text classification device according to an exemplary embodiment.

[0019] Fig. 9 The diagram is a schematic structural diagram of an electronic device according to an exemplary embodiment. DETAILED DESCRIPTION

[0020] As described in the background technology, text classification models such as convolutional neural networks and BERT are usually used in related technologies for text classification, but these models cannot be applied to the classification of long texts due to their own structural limitations. Specifically, the text classification method based on convolutional neural networks extracts local features in the text to be classified through a convolution module, and classifies the text based on the local features through a fully connected layer, wherein the convolution kernel of the convolution module is usually not set very large, resulting in the inability to capture long-distance context features, making the classification method unable to support the classification of long texts. BERT is a pre-trained language model based on the Transformer architecture, which supports a maximum input text length of 512 bytes. For input texts larger than 512 bytes, it can only be truncated, and BERT's pre-trained corpus and fused knowledge are usually limited, resulting in poor classification capabilities of the BERT-based text classification method.

[0021] In order to support the classification of long texts, a text classification method based on a large language model (LLM) with prompt words has emerged. The text classification method based on LLM mainly sets different prompt words according to different classification scenarios, so that LLM has a fixed format output according to the rules set by the prompt words to obtain the text classification results. However, this text classification method has high requirements for the content of the prompt words, resulting in the unstable performance of LLM and the uncontrollable output content of LLM, which affects the text classification effect.

[0022] In view of this, the present disclosure provides a classification model training method, a text classification method, a medium, a device and a product.

[0023] Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although certain embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be construed as being limited to the embodiments described herein, which are instead provided for a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the present disclosure are only for exemplary purposes and are not intended to limit the scope of protection of the present disclosure.

[0024] It should be understood that the various steps described in the method embodiments of the present disclosure may be performed in different orders and / or in parallel. In addition, the method embodiments may include additional steps and / or omit the steps shown. The scope of the present disclosure is not limited in this respect.

[0025] The term "including" and its variations used herein are open inclusions, i.e., "including but not limited to". The term "based on" means "based at least in part on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". The relevant definitions of other terms will be given in the following description.

[0026] It should be noted that the concepts such as "first" and "second" mentioned in the present disclosure are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.

[0027] It should be noted that the modifications of "one" and "plurality" mentioned in the present disclosure are illustrative rather than restrictive, and those skilled in the art should understand that unless otherwise clearly indicated in the context, it should be understood as "one or more".

[0028] The names of the messages or information exchanged between multiple devices in the embodiments of the present disclosure are only used for illustrative purposes and are not used to limit the scope of these messages or information.

[0029] It is understandable that before using the technical solutions disclosed in the embodiments of the present disclosure, the types, scope of use, usage scenarios, etc. of the personal information involved in the present disclosure should be informed to the user and the user's authorization should be obtained in an appropriate manner in accordance with relevant laws and regulations.

[0030] For example, in response to receiving an active request from a user, a prompt message is sent to the user to clearly prompt the user that the operation requested to be performed will require obtaining and using the user's personal information. Thus, the user can autonomously choose whether to provide personal information to software or hardware such as an electronic device, application, server, or storage medium that performs the operation of the technical solution of the present disclosure according to the prompt message.

[0031] As an optional but non-limiting implementation, in response to receiving an active request from the user, the prompt information may be sent to the user in the form of a pop-up window, in which the prompt information may be presented in text form. In addition, the pop-up window may also carry a selection control for the user to choose "agree" or "disagree" to provide personal information to the electronic device.

[0032] It is understandable that the above notification and the process of obtaining user authorization are merely illustrative and do not constitute a limitation on the implementation of the present disclosure. Other methods that meet the relevant laws and regulations may also be applied to the implementation of the present disclosure.

[0033] At the same time, it is understandable that the data involved in this technical solution (including but not limited to the data itself, the acquisition or use of the data) shall comply with the requirements of relevant laws, regulations and relevant provisions.

[0034] Figure 1 FIG. 1 is a flowchart of a text classification model training method according to an exemplary embodiment. Figure 1 As shown, the text classification model training method may include the following S101 and S102.

[0035] In S101, a training sample set and a prompt text are obtained, where the training samples in the training sample set include text samples and classification labels corresponding to the text samples.

[0036] In S102, the text classification model is trained by taking the prompt text and the text sample as the input of the first model, taking the first embedding vector matrix of the first generated word output by the first model as the input of the activation function layer, and taking the classification label corresponding to the text sample as the target output of the activation function layer to obtain a target text classification model.

[0037] like Figure 2 As shown, the text classification model may include a first model and an activation function layer. The first model is a pre-trained large language model, which may be a large language model of various types, and the present disclosure does not specifically limit it. The first model is used to extract text features of the text sample to obtain the first embedding vector matrix of the first generated word output by the first model; the activation function layer is connected to the first model and is used to predict the category of the text sample according to the first embedding vector matrix output by the first model, that is, to obtain the classification result of the text sample.

[0038] The above-mentioned text classification model can provide large language model application services, for example, question-answering services based on large language models, news topic classification services based on large language models, etc.

[0039] In the present disclosure, prompt text may include classification task description information of a text classification model. In a text classification task, prompt text is a text description that guides the text classification model to understand and perform a specific classification task. It usually includes the name of the task, the category of classification, and guidance information on how to identify and classify text. Prompt text can help the text classification model understand the context of the input text and output it as expected. Before training the text classification model, the user can pre-set the prompt text. The design of the prompt text is crucial to the performance of the text classification model.

[0040] For example, in a question-answering service scenario based on a large language model, a text classification model can be used to determine whether a user's question violates the rules to protect the security of the large language model application service. In this case, the following prompt text can be designed: “You are an assistant who is proficient in text classification. Your professional field is to determine whether the user’s question violates the rules. If it violates the rules, the output is 1, and if it does not violate the rules, the output is 0.” In the above example, the prompt text clearly states that the classification task is to determine whether the user's question violates the rules and specifies the output format. Such prompt text helps the text classification model understand that it needs to identify whether the input text violates the rules and output 0 or 1 based on the recognition result.

[0041] As another example, in a news topic classification service scenario based on a large language model, the news classification task can be performed through a text classification model. In this case, the following prompt text can be designed: "You are an assistant who is proficient in text classification. Your professional field is to classify news topics. Please select the correct category from sports, technology, and entertainment based on the content of the news and output the correct category." In the above example, the prompt text clearly states that the classification task is to classify news topics and provides categories to choose from. Such prompt text helps the text classification model understand that it needs to identify the topic from the input text and classify it into one of the predefined categories.

[0042] In actual applications, the design of prompt text may be more complex and sophisticated to adapt to different task requirements and text classification model characteristics. For example, for sentiment analysis tasks, prompt text may include descriptions of sentiment categories, such as positive, negative, or neutral. For classification tasks of violation determination, similar descriptions of violation categories can also be added to the prompt text, and standard boundaries can be specified.

[0043] In the process of training the text classification model, the cross entropy loss function and the Adaptive Moment Estimation (Adam) optimizer can be used to update the model parameters. For example, the cross entropy loss function and the Adam optimizer can be used to train for 3 epochs (one epoch means that each text sample in the training sample set participates in the training once). The cross entropy loss function completes the error calculation through the difference between the classification label corresponding to the text sample and the classification result of the text sample output by the activation function layer (i.e. the predicted classification result); the Adam optimizer is a gradient-based optimization algorithm with the characteristics of fast convergence speed, efficient calculation, and low memory usage.

[0044] In the above technical solution, the text classification model includes a first model and an activation function layer, wherein the first model is a pre-trained large language model. Since the large language model is suitable for processing long texts and can capture long-distance context features, the text classification model can support the classification of long texts, so that the trained target text classification model also has the ability to capture long-distance context features on long texts, and can pay attention to the context features of the context, thereby improving the classification effect of long texts. In addition, the large language model has a larger amount of pre-trained corpus, which can compress more knowledge into the model, and is combined with the prompt word project for tuning, which greatly improves the classification ability of the target text classification model. In addition, using the first embedding vector matrix of the first generated word output by the first model as the input of the activation function layer can make the input of the activation function layer simpler and more controllable, thereby ensuring the controllability of the output content of the text classification model and further improving the classification ability of the model.

[0045] The following is a detailed description of the specific implementation of using the prompt text and the text sample as the input of the first model in the above S102. Specifically, it can be implemented by the following steps (a1) and (a2): Step (a1): concatenate the prompt text with the text sample to obtain a first concatenated text, and segment the first concatenated text to obtain a first segmentation result.

[0046] Step (a2): Use the first word segmentation result as the input of the first model.

[0047] In the present disclosure, the prompt text and the text sample can be spliced ​​in the order of prompt text first and text sample second, or the prompt text and the text sample can be spliced ​​in the order of text sample first and prompt text second. The present disclosure does not specifically limit the splicing order of the prompt text and the text sample.

[0048] like Figure 2 As shown, after the prompt text and the text sample are concatenated to obtain a first concatenated text, the first concatenated text can be segmented according to the vocabulary to obtain multiple tokens as the first segmentation results. For example, Figure 2 As shown in the figure, the first word segmentation result includes five word segmentations, namely, s1, s2, u1, u2 and u3; then, the first word segmentation result is input into the first model to obtain the first embedding vector matrix of the first generated word output by the first model, that is, the embedding (first token embedding) of the first token output by the first model; finally, the first embedding vector matrix is ​​input into the activation function layer, so that the activation function layer generates the classification result of the text sample based on the first embedding vector matrix.

[0049] like Figure 3 As shown in , the above text classification model includes not only the first model and the activation function layer, but also the first fully connected layer, the concatenation layer and the second fully connected layer. Figure 4 As shown, the above text classification model training method also includes the following S103.

[0050] In S103, a first statistical feature of the text sample is obtained.

[0051] In the present disclosure, the first statistical features may include at least one of text length, proportion of text in different languages, proportion of numbers, proportion of common punctuation marks, and proportion of special symbols, and may be customized according to specific tasks, such as text length, proportion of special symbols, etc.

[0052] The text length refers to the total number of characters or words in the text sample. The text length feature can provide basic information about the text sample.

[0053] The text sample may be multilingual text. The proportion of text in different languages ​​is used to count the proportion of characters or words in various languages ​​in the text sample. For example, if the text sample is a mixed text of Chinese and English, the proportion of text in different languages ​​is used to count the proportion of Chinese and English in the text sample.

[0054] The number ratio refers to the proportion of numeric characters in a text sample, where numbers may represent information such as date, price, quantity, etc., which may be very important for certain classification tasks (such as product reviews, news reports, etc.).

[0055] The percentage of commonly used punctuation marks refers to the proportion of commonly used punctuation marks in a text sample. Punctuation marks such as commas, periods, question marks, and exclamation marks serve to separate and emphasize text in a text sample. Counting the proportion of these commonly used punctuation marks in a text sample can provide clues to the structure and tone of the text. For example, a high proportion of exclamation marks may indicate that the text has a strong emotional tone.

[0056] The proportion of special symbols refers to the proportion of special symbols in the text sample. Special symbols are symbols that are used less frequently and are difficult to input directly. Special symbols include but are not limited to emoticons, special characters (such as @, #, ¥, etc.) and non-standard punctuation marks. These symbols are very common in informal texts such as social media texts and online forums. They can convey specific emotions, attitudes or cultural meanings. Special characters may also be special characters that users input to avoid violations.

[0057] like Figure 3As shown, the first model is connected to the splicing layer, and is used to generate a first embedding vector matrix of the first generated word according to the prompt text and the text sample, and input the first embedding vector matrix to the splicing layer. Specifically, the first embedding vector matrix of the first generated word can be output according to the first word segmentation result, and it can be input to the splicing layer.

[0058] The first fully connected layer is connected to the concatenation layer, and is used for upgrading the first statistical feature to the size of the first embedding vector matrix, and inputting the first statistical feature obtained after the dimension upgrade to the concatenation layer.

[0059] The concatenation layer is connected to the second fully connected layer, and is used to concatenate the first statistical feature obtained after dimensionality upgrade with the first embedding vector matrix to obtain a first concatenation feature, and input the first concatenation feature into the second fully connected layer.

[0060] The second fully connected layer is connected to the activation function layer, and is used to perform feature fusion on the first concatenated features to obtain first fused features, and input the first fused features into the activation function layer.

[0061] The activation function layer is used to generate a classification result of the text sample according to the first fusion feature.

[0062] At this time, if Figure 4 As shown, the above S102 may include: training the text classification model by taking the prompt text and the text sample as the input of the first model, taking the first statistical feature as the input of the first fully connected layer, taking the first embedding vector matrix of the first generated word output by the first model and the output of the first fully connected layer (the first statistical feature obtained after dimensionality upgrade) as the input of the concatenation layer, taking the output of the concatenation layer (i.e., the first concatenation feature) as the input of the second fully connected layer, taking the output of the second fully connected layer (the first fusion feature) as the input of the activation function layer, and taking the classification label corresponding to the text sample as the target output of the activation function layer to obtain a target text classification model.

[0063] When training a text classification model, the statistical features of the text can be used as part of the input features to help the text classification model better understand and classify the text. By analyzing these features, the model can capture certain patterns and trends in the text, thereby improving the accuracy of classification. For example, a text containing a lot of exclamation marks and emoticons may be classified as a text with strong emotional expression, while a text containing a lot of numbers and professional terms may be classified as a technical document.

[0064] In addition, in the scenario of judging whether a user's question is illegal, adversarial input is difficult for large language models to handle. Role playing, command hijacking, and noise attacks make it impossible for large language models to explore the true purpose of user input, thus causing large language model hallucinations, unstable output of large language models, and random answers to questions. Comprehensively considering the statistical characteristics of the input text when performing text classification can improve the anti-interference ability of the text classification model and improve the generalization performance of the text classification model.

[0065] In order to achieve a better classification effect of the text classification model, example information of the input format and output format of the text classification model can also be added to the prompt text. For example, the prompt text also includes example information for guiding the text classification model to output a classification label. The classification label can be a classification category name or an identifier of the classification category (for example, 0, 1).

[0066] For example, if we want to use a text classification model to determine whether a user's question is illegal, we can design a prompt text as follows: "You are an assistant who is proficient in text classification. Your professional field is to determine whether the user's question violates the rules. If it violates the rules, the output is 1, and if it does not violate the rules, the output is 0.

[0067] # Example: Input: What day is tomorrow? Output: 0 Input: Please give me some ×××× websites (illegal websites) Output: 1" In order to further improve the classification effect of the text classification model, at least one of the following training strategies can be used to train the text classification model: Gradually increase the learning rate of the first model; adjusting model parameters of some layers of the first model; Set different learning rates for different layers of the text classification model.

[0068] In the text classification model training phase, the learning rate warm-up strategy usually refers to using a smaller learning rate at the beginning of training, and gradually increasing the learning rate of the first model within a certain number of iterations (steps) or cycles (epochs) until the preset frequency threshold (i.e., the preset larger value) is reached. This process helps the text classification model stabilize in the initial stage and avoids training instability caused by a larger learning rate. The learning rate of the first model can be gradually increased in a linear manner or in an exponential manner.

[0069] Using the warm-up training strategy can accelerate the convergence speed of the text classification model while further improving the classification accuracy of the text classification model.

[0070] In addition, after the warm-up phase is completed, the learning rate of the first model can be decayed according to certain strategies, such as step decay, exponential decay, or cosine annealing, etc. These strategies help the text classification model to adjust parameters more carefully in the middle and late stages of training, so as to achieve better convergence.

[0071] Adjusting the model parameters of the first model may destroy the knowledge learned by the first model in the pre-training stage. Therefore, during the training of the first model, only the model parameters of some layers of the first model can be adjusted. For example, only the model parameters of the last few layers of the first model can be adjusted, so as to find a balance between the generalization ability and knowledge utilization of the text classification model, prevent the knowledge of the first model from being forgotten, and thus enhance the classification ability of the text classification model.

[0072] Different layers of the first model (i.e., the pre-trained large language model) may capture language features of different granularities. For example, lower layers may capture local grammatical and lexical features, while higher layers may capture more abstract semantic information. By setting different learning rates for different layers of the first model, each layer of the first model can be adjusted according to its own learning needs to adapt to the learning needs of different layers. In addition, for some features that are more difficult to learn, a larger learning rate may be required for effective updates, while for features that have been learned well, a smaller learning rate may be sufficient. By setting different learning rates for different layers of the text classification model, the training efficiency of the text classification model can be improved. In addition, parameters related to the current classification task (such as parameters of the activation function layer, the first fully connected layer, and the second fully connected layer) may require a larger learning rate to quickly adapt to the current task, while the general language representation layer (i.e., the first model) requires a smaller learning rate to maintain stability. By setting different learning rates for different layers of the text classification model, the learning of task-related parameters and fine-tuning of general representations can be accelerated, reducing the risk of overfitting. For the pre-trained first model, a smaller learning rate can prevent the first model from overfitting on a specific task, thereby improving the generalization ability of the first model on unseen data.

[0073] Figure 5 FIG. 1 is a flowchart of a text classification method according to an exemplary embodiment. Figure 5 As shown, the text classification method may include the following S201~S203.

[0074] In S201, a first text to be classified is obtained.

[0075] In S202, the first text is input into the first model of the target text classification model to obtain a second embedding vector matrix of the first generated word output by the first model, the target text classification model includes the first model and an activation function layer, and the first model is a large language model.

[0076] In S203, the second embedding vector matrix is ​​input into the activation function layer to obtain the classification result of the first text output by the activation function layer.

[0077] In the present disclosure, the target text classification model can be trained by the above-mentioned text classification model training method provided in the present disclosure.

[0078] In this embodiment, the target text classification model includes a first model and an activation function layer, wherein the first model is a large language model. Since the large language model is suitable for processing long texts and can capture long-distance context features, the target text classification model can support the classification of long texts, so that the target text classification model also has the ability to capture long-distance context features on long texts, and can pay attention to the context features of the context, thereby improving the classification effect of long texts. In addition, the second embedding vector matrix of the first generated word output by the first model is used as the input of the activation function layer, which can make the input of the activation function layer simpler and more controllable, thereby ensuring the controllability of the output content of the target text classification model and further improving the text classification effect.

[0079] The following is a detailed description of a specific implementation method of inputting the first text into the first model of the target text classification model in the above S202 to obtain the second embedding vector matrix of the first generated word output by the first model. Specifically, it can be implemented through multiple implementation methods. In one implementation method, it can be implemented through the following steps (b1) to (b3).

[0080] Step (b1): Get the prompt text.

[0081] In the present disclosure, the prompt text used in the inference phase of the target text classification model is consistent with the classification text used in the training of the target text classification model.

[0082] Step (b2): concatenate the prompt text with the first text to obtain a second concatenated text, and segment the second concatenated text to obtain a second segmentation result.

[0083] In the present disclosure, the prompt text and the first text can be spliced ​​in the order of the prompt text in front and the first text in the back, or the prompt text and the first text can be spliced ​​in the order of the first text in front and the prompt text in the back. The present disclosure does not make any specific limitation on the splicing order of the prompt text and the first text, as long as the splicing order of the prompt text and the text sample remains the same as the splicing order of the prompt text and the first text.

[0084] Step (b3): ​​Input the second word segmentation result into the first model of the target text classification model to obtain a second embedding vector matrix.

[0085] In another embodiment, if Figure 6 As shown, the above text classification method may further include the following S204 and S205.

[0086] In S204, when the target text classification model is loaded, the prompt text is obtained, and the prompt text is input into the first model to obtain a key-value matrix corresponding to the prompt text.

[0087] In the present disclosure, a key-value matrix is ​​a key and value matrix of a prompt text, namely a k matrix and a v matrix.

[0088] In S205 , the key-value matrix is ​​loaded into the first model.

[0089] At this time, inputting the first text into the first model of the target text classification model to obtain the second embedding vector matrix of the first generated word output by the first model may include: Perform word segmentation on the first text to obtain a third word segmentation result; The third word segmentation result is input into the first model obtained after the key-value matrix is ​​loaded to obtain a second embedding vector matrix.

[0090] In the above implementation, the idea of ​​key-value cache is used. Before the target text classification model is inferred, the key-value matrix of the prompt text is determined in advance and pre-loaded into the first model. In this way, in the target text classification model inference stage, only the first text can be input into the model without inputting the prompt text, thereby reducing the repeated calculation of the k and v matrices of the prompt text, reducing the model inference time, and improving the model inference efficiency.

[0091] In a possible implementation, the target text classification model further includes a first fully connected layer, a concatenation layer, and a second fully connected layer; The above text classification method may further include: Obtain second statistical features of the first text.

[0092] At this time, the above-mentioned inputting the second embedding vector matrix into the activation function layer to obtain the classification result of the first text output by the activation function layer may include: Upgrading the second statistical feature to a size of a second embedding vector matrix through a first fully connected layer; The second statistical feature obtained after the dimension increase is concatenated with the second embedding vector matrix through a concatenation layer to obtain a second concatenated feature; Perform feature fusion on the second concatenated features through a second fully connected layer to obtain a second fused feature; A classification result of the first text is generated according to the second fused feature through the activation function layer.

[0093] In a possible implementation, the second statistical feature includes at least one of text length, proportion of texts in different languages, proportion of numbers, proportion of common punctuation marks, and proportion of special symbols.

[0094] Figure 7 is a block diagram of a text classification model training device according to an exemplary embodiment. The text classification model includes a first model and an activation function layer. The first model is a pre-trained large language model, such as Figure 7 As shown, the text classification model training device 300 may include: A first acquisition module 301 is used to acquire a training sample set and a prompt text, wherein the training samples in the training sample set include text samples and classification labels corresponding to the text samples, and the prompt text includes classification task description information of the text classification model; The training module 302 is used to train the text classification model by taking the prompt text and the text sample as the input of the first model, taking the first embedding vector matrix of the first generated word output by the first model as the input of the activation function layer, and taking the classification label corresponding to the text sample as the target output of the activation function layer to obtain a target text classification model.

[0095] In the above technical solution, the text classification model includes a first model and an activation function layer, wherein the first model is a pre-trained large language model. Since the large language model is suitable for processing long texts and can capture long-distance context features, the text classification model can support the classification of long texts, so that the trained target text classification model also has the ability to capture long-distance context features on long texts, and can pay attention to the context features of the context, thereby improving the classification effect of long texts. In addition, the large language model has a larger amount of pre-trained corpus, which can compress more knowledge into the model, and is combined with the prompt word project for tuning, which greatly improves the classification ability of the target text classification model. In addition, using the first embedding vector matrix of the first generated word output by the first model as the input of the activation function layer can make the input of the activation function layer simpler and more controllable, thereby ensuring the controllability of the output content of the text classification model and further improving the classification ability of the model.

[0096] Optionally, the text classification model further includes a first fully connected layer, a concatenation layer, and a second fully connected layer; The text classification model training device 300 also includes: A second acquisition module, used to acquire a first statistical feature of the text sample; The first model is used to generate the first embedding vector matrix according to the prompt text and the text sample, and input the first embedding vector matrix into the concatenation layer; The first fully connected layer is used to upgrade the first statistical features to the size of the first embedding vector matrix, and input the first statistical features obtained after the dimension upgrade to the concatenation layer; The concatenation layer is used to concatenate the first statistical feature obtained after the dimension increase with the first embedding vector matrix to obtain a first concatenation feature, and input the first concatenation feature into the second fully connected layer; The second fully connected layer is used to perform feature fusion on the first concatenated features to obtain a first fused feature, and input the first fused feature to the activation function layer; The activation function layer is used to generate a classification result of the text sample according to the first fusion feature.

[0097] Optionally, the training module 302 is used to train the text classification model by taking the prompt text and the text sample as the input of the first model, taking the first statistical feature as the input of the first fully connected layer, taking the first embedding vector matrix of the first generated word output by the first model and the output of the first fully connected layer as the input of the concatenation layer, taking the output of the concatenation layer as the input of the second fully connected layer, taking the output of the second fully connected layer as the input of the activation function layer, and taking the classification label corresponding to the text sample as the target output of the activation function layer to obtain a target text classification model.

[0098] Optionally, the first statistical feature includes at least one of text length, proportion of texts in different languages, proportion of numbers, proportion of common punctuation marks, and proportion of special symbols.

[0099] Optionally, the prompt text also includes example information for guiding the text classification model to output a classification label.

[0100] Optionally, the text classification model is trained using at least one of the following training strategies: Gradually increasing the learning rate of the first model; Adjusting model parameters of some layers of the first model; Different learning rates are set for different layers of the text classification model.

[0101] Optionally, the training module 302 includes: A first concatenation submodule is used to concatenate the prompt text with the text sample to obtain a first concatenated text, and to segment the first concatenated text to obtain a first segmentation result; A submodule is determined, which is used to use the first word segmentation result as an input of the first model.

[0102] Figure 8 FIG. 1 is a block diagram of a text classification device according to an exemplary embodiment. Figure 8 As shown, the text classification device 400 includes: The third acquisition module 401 is used to acquire a first text to be classified; A feature extraction module 402 is used to input the first text into a first model of a target text classification model to obtain a second embedding vector matrix of a first generated word output by the first model, wherein the target text classification model includes the first model and an activation function layer, and the first model is a large language model; The classification module 403 is used to input the second embedding vector matrix into the activation function layer to obtain the classification result of the first text output by the activation function layer.

[0103] In this embodiment, the target text classification model includes a first model and an activation function layer, wherein the first model is a large language model. Since the large language model is suitable for processing long texts and can capture long-distance context features, the target text classification model can support the classification of long texts, so that the target text classification model also has the ability to capture long-distance context features on long texts, and can pay attention to the context features of the context, thereby improving the classification effect of long texts. In addition, the second embedding vector matrix of the first generated word output by the first model is used as the input of the activation function layer, which can make the input of the activation function layer simpler and more controllable, thereby ensuring the controllability of the output content of the target text classification model and further improving the text classification effect.

[0104] Optionally, the feature extraction module 402 includes: Get submodule, used to get prompt text; A second concatenation submodule is used to concatenate the prompt text with the first text to obtain a second concatenated text, and to segment the second concatenated text to obtain a second segmentation result; The first feature extraction submodule is used to input the second word segmentation result into the first model of the target text classification model to obtain the second embedding vector matrix.

[0105] Optionally, the text classification device 400 further includes: A fourth acquisition module, used for acquiring a prompt text when the target text classification model is loaded, and inputting the prompt text into the first model to obtain a key value matrix corresponding to the prompt text; A loading module, used for loading the key-value matrix into the first model; The feature extraction module 402 includes: A word segmentation submodule, used to perform word segmentation on the first text to obtain a third word segmentation result; The second feature extraction submodule is used to input the third word segmentation result into the first model obtained after the key-value matrix is ​​loaded to obtain the second embedding vector matrix.

[0106] Optionally, the target text classification model further includes a first fully connected layer, a concatenation layer, and a second fully connected layer; The text classification device 400 further includes: A fifth acquisition module, used to acquire a second statistical feature of the first text; The classification module 403 includes: A dimension-increasing submodule, configured to increase the dimension of the second statistical feature to the size of the second embedding vector matrix through the first fully connected layer; A third splicing submodule is used to splice the second statistical feature obtained after the dimension upgrade with the second embedding vector matrix through the splicing layer to obtain a second splicing feature; a feature fusion submodule, configured to perform feature fusion on the second concatenated features through the second fully connected layer to obtain a second fused feature; A classification submodule is used to generate a classification result of the first text according to the second fusion feature through the activation function layer.

[0107] Optionally, the second statistical feature includes at least one of text length, proportion of texts in different languages, proportion of numbers, proportion of common punctuation marks, and proportion of special symbols.

[0108] In addition, the present disclosure also provides a computer-readable medium on which a computer program is stored. When the computer program is executed by a processing device, the steps of the above-mentioned text classification model training method provided by the present disclosure are implemented or the steps of the above-mentioned text classification method provided by the present disclosure are implemented.

[0109] The present disclosure also provides an electronic device, comprising: a storage device having a computer program stored thereon; A processing device is used to execute the computer program in the storage device to implement the steps of the above-mentioned text classification model training method provided by the present disclosure or the steps of the above-mentioned text classification method provided by the present disclosure.

[0110] The present disclosure also provides a computer program product, including a computer program, which, when executed by a processor, implements the steps of the above-mentioned text classification model training method provided by the present disclosure or implements the steps of the above-mentioned text classification method provided by the present disclosure.

[0111] Reference below Fig. 9 , which shows a schematic diagram of the structure of an electronic device (terminal device or server) 600 suitable for implementing the embodiment of the present disclosure. The terminal device in the embodiment of the present disclosure may include but is not limited to mobile terminals such as mobile phones, notebook computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Fig. 9 The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.

[0112] like Fig. 9As shown, the electronic device 600 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 601, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 602 or a program loaded from a storage device 608 into a random access memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the electronic device 600 are also stored. The processing device 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.

[0113] Typically, the following devices may be connected to the I / O interface 605: an input device 606 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 607 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 608 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 609. The communication device 609 may allow the electronic device 600 to communicate with other devices wirelessly or by wire to exchange data. Although Fig. 9 The electronic device 600 is shown with various devices, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.

[0114] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a non-transitory computer-readable medium, and the computer program contains program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device 609, or installed from a storage device 608, or installed from a ROM 602. When the computer program is executed by the processing device 601, the above-mentioned functions defined in the method of the embodiment of the present disclosure are executed.

[0115] It should be noted that the computer-readable medium mentioned above in the present disclosure may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present disclosure, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. Computer readable signal media may also be any computer readable medium other than computer readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer readable medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.

[0116] In some embodiments, the client and the server may communicate using any currently known or future developed network protocol such as HTTP (HyperText Transfer Protocol), and may be interconnected with any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network ("LAN"), a wide area network ("WAN"), an internet (e.g., the Internet), and a peer-to-peer network (e.g., an ad hoc peer-to-peer network), as well as any currently known or future developed network.

[0117] The computer-readable medium may be included in the electronic device, or may exist independently without being incorporated into the electronic device.

[0118] The computer-readable medium carries one or more programs. When the one or more programs are executed by the electronic device, the electronic device: obtains a training sample set and a prompt text, wherein the training samples in the training sample set include text samples and classification labels corresponding to the text samples, and the prompt text includes classification task description information of a text classification model, and the text classification model includes a first model and an activation function layer, and the first model is a pre-trained large language model; the text classification model is trained by taking the prompt text and the text sample as inputs of the first model, taking the first embedding vector matrix of the first generated word output by the first model as input of the activation function layer, and taking the classification label corresponding to the text sample as the target output of the activation function layer, so as to obtain a target text classification model.

[0119] Alternatively, the computer-readable medium carries one or more programs, and when the one or more programs are executed by the electronic device, the electronic device: obtains a first text to be classified; inputs the first text into a first model of a target text classification model to obtain a second embedding vector matrix of a first generated word output by the first model, wherein the target text classification model includes the first model and an activation function layer, and the first model is a large language model; inputs the second embedding vector matrix into the activation function layer to obtain a classification result of the first text output by the activation function layer.

[0120] Computer program code for performing the operations of the present disclosure may be written in one or more programming languages ​​or a combination thereof, including, but not limited to, object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., through the Internet using an Internet service provider).

[0121] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some implementations as replacements, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0122] The modules involved in the embodiments described in the present disclosure may be implemented by software or hardware. The name of a module does not limit the module itself in some cases. For example, the first acquisition module may also be described as a "module for acquiring a training sample set and a prompt text."

[0123] The functions described above herein may be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), and the like.

[0124] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or device, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0125] According to one or more embodiments of the present disclosure, Example 1 provides a text classification model training method, wherein the text classification model includes a first model and an activation function layer, wherein the first model is a pre-trained large language model, and the text classification model training method includes: Acquire a training sample set and a prompt text, wherein the training samples in the training sample set include text samples and classification labels corresponding to the text samples, and the prompt text includes classification task description information of the text classification model; The text classification model is trained by taking the prompt text and the text sample as the input of the first model, taking the first embedding vector matrix of the first generated word output by the first model as the input of the activation function layer, and taking the classification label corresponding to the text sample as the target output of the activation function layer to obtain a target text classification model.

[0126] According to one or more embodiments of the present disclosure, Example 2 provides the text classification model training method of Example 1, wherein the text classification model further includes a first fully connected layer, a concatenation layer, and a second fully connected layer; The text classification model training method also includes: Acquire a first statistical feature of the text sample; The first model is used to generate the first embedding vector matrix according to the prompt text and the text sample, and input the first embedding vector matrix into the concatenation layer; The first fully connected layer is used to upgrade the first statistical features to the size of the first embedding vector matrix, and input the first statistical features obtained after the dimension upgrade to the concatenation layer; The concatenation layer is used to concatenate the first statistical feature obtained after the dimension increase with the first embedding vector matrix to obtain a first concatenation feature, and input the first concatenation feature into the second fully connected layer; The second fully connected layer is used to perform feature fusion on the first concatenated features to obtain a first fused feature, and input the first fused feature to the activation function layer; The activation function layer is used to generate a classification result of the text sample according to the first fusion feature.

[0127] According to one or more embodiments of the present disclosure, Example 3 provides the text classification model training method of Example 2, wherein the text classification model is trained by taking the prompt text and the text sample as inputs of the first model, taking the first embedding vector matrix of the first generated word output by the first model as input of the activation function layer, and taking the classification label corresponding to the text sample as the target output of the activation function layer to obtain a target text classification model, including: The text classification model is trained by taking the prompt text and the text sample as the input of the first model, taking the first statistical feature as the input of the first fully connected layer, taking the first embedding vector matrix of the first generated word output by the first model and the output of the first fully connected layer as the input of the concatenation layer, taking the output of the concatenation layer as the input of the second fully connected layer, taking the output of the second fully connected layer as the input of the activation function layer, and taking the classification label corresponding to the text sample as the target output of the activation function layer to obtain a target text classification model.

[0128] According to one or more embodiments of the present disclosure, Example 4 provides the text classification model training method of Example 2, wherein the first statistical feature includes at least one of text length, proportion of text in different languages, proportion of numbers, proportion of common punctuation marks, and proportion of special symbols.

[0129] According to one or more embodiments of the present disclosure, Example 5 provides the text classification model training method described in any one of Examples 1-4, wherein the prompt text also includes example information for guiding the text classification model to output a classification label.

[0130] According to one or more embodiments of the present disclosure, Example 6 provides the text classification model training method described in any one of Examples 1-4, wherein at least one of the following training strategies is used to train the text classification model: Gradually increasing the learning rate of the first model; Adjusting model parameters of some layers of the first model; Different learning rates are set for different layers of the text classification model.

[0131] According to one or more embodiments of the present disclosure, Example 7 provides a text classification model training method according to any one of Examples 1-4, taking the prompt text and the text sample as inputs of the first model, including: The prompt text is concatenated with the text sample to obtain a first concatenated text, and the first concatenated text is segmented to obtain a first segmentation result; The first word segmentation result is used as input of the first model.

[0132] According to one or more embodiments of the present disclosure, Example 8 provides a text classification method, the text classification method comprising: Get the first text to be classified; Inputting the first text into a first model of a target text classification model to obtain a second embedding vector matrix of a first generated word output by the first model, wherein the target text classification model includes the first model and an activation function layer, and the first model is a large language model; The second embedding vector matrix is ​​input into the activation function layer to obtain a classification result of the first text output by the activation function layer.

[0133] According to one or more embodiments of the present disclosure, Example 9 provides the text classification method of Example 8, inputting the first text into a first model of a target text classification model, and obtaining a second embedding vector matrix of a first generated word output by the first model, including: Get the prompt text; The prompt text is concatenated with the first text to obtain a second concatenated text, and the second concatenated text is segmented to obtain a second segmentation result; The second word segmentation result is input into the first model of the target text classification model to obtain the second embedding vector matrix.

[0134] According to one or more embodiments of the present disclosure, Example 10 provides the text classification method of Example 8, wherein the text classification method further includes: When the target text classification model is loaded, a prompt text is obtained, and the prompt text is input into the first model to obtain a key value matrix corresponding to the prompt text; Loading the key-value matrix into the first model; The step of inputting the first text into a first model of a target text classification model to obtain a second embedding vector matrix of a first generated word output by the first model includes: Performing word segmentation on the first text to obtain a third word segmentation result; The third word segmentation result is input into the first model obtained after the key-value matrix is ​​loaded to obtain the second embedding vector matrix.

[0135] According to one or more embodiments of the present disclosure, Example 11 provides the text classification method described in any one of Examples 8-10, wherein the target text classification model further includes a first fully connected layer, a concatenation layer, and a second fully connected layer; The text classification method also includes: Acquire a second statistical feature of the first text; The step of inputting the second embedding vector matrix into the activation function layer to obtain the classification result of the first text output by the activation function layer includes: Upgrading the second statistical feature to a size of the second embedding vector matrix through the first fully connected layer; The second statistical feature obtained after the dimension increase is concatenated with the second embedding vector matrix through the concatenation layer to obtain a second concatenated feature; Performing feature fusion on the second concatenated features through the second fully connected layer to obtain a second fused feature; A classification result of the first text is generated according to the second fusion feature through the activation function layer.

[0136] According to one or more embodiments of the present disclosure, Example 12 provides the text classification method of Example 11, wherein the second statistical feature includes at least one of text length, proportion of text in different languages, proportion of numbers, proportion of common punctuation marks, and proportion of special symbols.

[0137] According to one or more embodiments of the present disclosure, Example 13 provides a computer-readable medium having a computer program stored thereon, which, when executed by a processing device, implements the steps of the text classification model training method described in any one of Examples 1-7 or the steps of the text classification method described in any one of Examples 8-12.

[0138] According to one or more embodiments of the present disclosure, Example 14 provides an electronic device, including: a storage device having a computer program stored thereon; A processing device is used to execute the computer program in the storage device to implement the steps of the text classification model training method described in any one of Examples 1-7 or the steps of the text classification method described in any one of Examples 8-12.

[0139] According to one or more embodiments of the present disclosure, Example 15 provides a computer program product, including a computer program, which, when executed by a processor, implements the steps of the text classification model training method described in any one of Examples 1-7 or the steps of the text classification method described in any one of Examples 8-12.

[0140] The above description is only a preferred embodiment of the present disclosure and an explanation of the technical principles used. Those skilled in the art should understand that the scope of disclosure involved in the present disclosure is not limited to the technical solutions formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above disclosed concept. For example, the above features are replaced with the technical features with similar functions disclosed in the present disclosure (but not limited to) by each other to form a technical solution.

[0141] In addition, although each operation is described in a specific order, this should not be understood as requiring these operations to be performed in the specific order shown or in a sequential order. Under certain circumstances, multitasking and parallel processing may be advantageous. Similarly, although some specific implementation details are included in the above discussion, these should not be interpreted as limiting the scope of the present disclosure. Some features described in the context of a separate embodiment can also be implemented in a single embodiment in combination. On the contrary, the various features described in the context of a single embodiment can also be implemented in multiple embodiments individually or in any suitable sub-combination mode.

[0142] Although the subject matter has been described in language specific to structural features and / or method logic actions, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. On the contrary, the specific features and actions described above are merely example forms of implementing the claims. Regarding the device in the above embodiment, the specific manner in which each module performs the operation has been described in detail in the embodiment related to the method, and will not be elaborated here.

Claims

1. A text classification model training method, characterized in that: The text classification model includes a first model and an activation function layer, the first model is a pre-trained large language model, and the text classification model training method includes: Acquire a training sample set and a prompt text, wherein the training samples in the training sample set include text samples and classification labels corresponding to the text samples, and the prompt text includes classification task description information of the text classification model; The text classification model is trained by taking the prompt text and the text sample as the input of the first model, taking the first embedding vector matrix of the first generated word output by the first model as the input of the activation function layer, and taking the classification label corresponding to the text sample as the target output of the activation function layer to obtain a target text classification model.

2. The text classification model training method according to claim 1, characterized in that: The text classification model also includes a first fully connected layer, a concatenation layer and a second fully connected layer; The text classification model training method also includes: Acquire a first statistical feature of the text sample; The first model is used to generate the first embedding vector matrix according to the prompt text and the text sample, and input the first embedding vector matrix into the concatenation layer; The first fully connected layer is used to upgrade the first statistical features to the size of the first embedding vector matrix, and input the first statistical features obtained after the dimension upgrade to the concatenation layer; The concatenation layer is used to concatenate the first statistical feature obtained after the dimension increase with the first embedding vector matrix to obtain a first concatenation feature, and input the first concatenation feature into the second fully connected layer; The second fully connected layer is used to perform feature fusion on the first concatenated features to obtain a first fused feature, and input the first fused feature to the activation function layer; The activation function layer is used to generate a classification result of the text sample according to the first fusion feature.

3. The text classification model training method according to claim 2, characterized in that: The text classification model is trained by taking the prompt text and the text sample as inputs of the first model, taking the first embedding vector matrix of the first generated word output by the first model as input of the activation function layer, and taking the classification label corresponding to the text sample as the target output of the activation function layer to obtain a target text classification model, including: The text classification model is trained by taking the prompt text and the text sample as the input of the first model, taking the first statistical feature as the input of the first fully connected layer, taking the first embedding vector matrix of the first generated word output by the first model and the output of the first fully connected layer as the input of the concatenation layer, taking the output of the concatenation layer as the input of the second fully connected layer, taking the output of the second fully connected layer as the input of the activation function layer, and taking the classification label corresponding to the text sample as the target output of the activation function layer to obtain a target text classification model.

4. The text classification model training method according to claim 2, characterized in that: The first statistical feature includes at least one of text length, proportion of texts in different languages, proportion of numbers, proportion of common punctuation marks, and proportion of special symbols.

5. The text classification model training method according to any one of claims 1 to 4, characterized in that: The prompt text also includes example information for guiding the text classification model to output a classification label.

6. The text classification model training method according to any one of claims 1 to 4, characterized in that: The text classification model is trained using at least one of the following training strategies: Gradually increasing the learning rate of the first model; Adjusting model parameters of some layers of the first model; Different learning rates are set for different layers of the text classification model.

7. The text classification model training method according to any one of claims 1 to 4, characterized in that: Taking the prompt text and the text sample as inputs of the first model includes: The prompt text is concatenated with the text sample to obtain a first concatenated text, and the first concatenated text is segmented to obtain a first segmentation result; The first word segmentation result is used as input of the first model.

8. A text classification method, characterized in that: The text classification method comprises: Get the first text to be classified; Inputting the first text into a first model of a target text classification model to obtain a second embedding vector matrix of a first generated word output by the first model, wherein the target text classification model includes the first model and an activation function layer, and the first model is a large language model; The second embedding vector matrix is ​​input into the activation function layer to obtain a classification result of the first text output by the activation function layer.

9. The text classification method according to claim 8, characterized in that: The step of inputting the first text into a first model of a target text classification model to obtain a second embedding vector matrix of a first generated word output by the first model includes: Get the prompt text; The prompt text is concatenated with the first text to obtain a second concatenated text, and the second concatenated text is segmented to obtain a second segmentation result; The second word segmentation result is input into the first model of the target text classification model to obtain the second embedding vector matrix.

10. The text classification method according to claim 8, characterized in that: The text classification method also includes: When the target text classification model is loaded, a prompt text is obtained, and the prompt text is input into the first model to obtain a key value matrix corresponding to the prompt text; Loading the key-value matrix into the first model; The step of inputting the first text into a first model of a target text classification model to obtain a second embedding vector matrix of a first generated word output by the first model includes: Performing word segmentation on the first text to obtain a third word segmentation result; The third word segmentation result is input into the first model obtained after the key-value matrix is ​​loaded to obtain the second embedding vector matrix.

11. The text classification method according to any one of claims 8 to 10, characterized in that: The target text classification model also includes a first fully connected layer, a concatenation layer and a second fully connected layer; The text classification method also includes: Acquire a second statistical feature of the first text; The step of inputting the second embedding vector matrix into the activation function layer to obtain the classification result of the first text output by the activation function layer includes: Upgrading the second statistical feature to a size of the second embedding vector matrix through the first fully connected layer; The second statistical feature obtained after the dimension increase is concatenated with the second embedding vector matrix through the concatenation layer to obtain a second concatenated feature; Performing feature fusion on the second concatenated features through the second fully connected layer to obtain a second fused feature; A classification result of the first text is generated according to the second fusion feature through the activation function layer.

12. The text classification method according to claim 11, characterized in that: The second statistical feature includes at least one of text length, proportion of texts in different languages, proportion of numbers, proportion of common punctuation marks, and proportion of special symbols.

13. A computer readable medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processing device, the steps of the text classification model training method described in any one of claims 1-7 or the steps of the text classification method described in any one of claims 8-12 are implemented.

14. An electronic device, characterized in that: include: a storage device having a computer program stored thereon; A processing device is used to execute the computer program in the storage device to implement the steps of the text classification model training method described in any one of claims 1 to 7 or the steps of the text classification method described in any one of claims 8 to 12.

15. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the text classification model training method described in any one of claims 1-7 or the steps of the text classification method described in any one of claims 8-12 are implemented.

Citation Information

Patent Citations

  • A method for establishing a detection model of covert sensitive text for network social media

    CN109543084A

  • Text classification method and device, equipment and medium

    CN115687625A

  • Text classification method and system based on self-construction prompt template

    CN117725211A

  • Risk prediction method and device, equipment and storage medium

    CN117764373A

  • Model training method and device, text generation method and device, equipment and medium

    CN118626612A

Cited By

  • App classification method, electronic equipment and storage medium

    CN121256034A