Adaptive text classification method and device based on large language model
Through the adaptive text classification method based on large language model, using prompt templates and context learning technology, the problem of insufficient dependence and flexibility of existing text classification methods on labeling data is solved, and high-precision and flexible text classification capabilities are achieved.
Patent Information
- Application Number
- CN202411929873.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-25
- Publication Date
- 2025-04-11
AI Technical Summary
Existing text classification methods rely on a large amount of labeled data and are difficult to adapt to flexible downstream analysis needs, especially when users pay attention to changes in agenda and differences in expression habits.
Adaptive text classification method based on large language models is adopted, and the intrinsic knowledge of the large model is activated by designing appropriate prompt templates, and combined with context learning methods, business personnel are supported to customize text categories and provide sample data to meet different business analysis needs.
It realizes high-precision text classification under zero-sample and small-sample conditions, reduces dependence on labeled data, and supports flexible text category customization to adapt to changeable downstream analysis tasks.
Smart Images

Figure CN119807424A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of natural language understanding and text classification, and in particular to an adaptive text classification method, device, electronic device, computer-readable storage medium and computer program product based on a large language model. Background Art
[0002] The task of text classification aims to infer various types of information contained in the text content posted by users, such as topics, fields, etc. Text classification has important applications in many scenarios such as business intelligence, public safety, and customer service. For example, in the field of public safety, real-time statistical analysis of the tendencies of the public on social media can timely discover potential hot events, which helps prevent and respond to social crises.
[0003] Existing text classification methods usually follow a supervised learning framework: given a target category, the model is trained using a manually annotated text classification dataset, and then the trained model is used to infer the category of unknown text. Existing text classification methods mainly include methods based on traditional machine learning and methods based on deep learning. Both methods extract text features first, and then use classification models such as naive Bayes, multi-layer perceptron, and support vector machine to infer categories. However, methods based on traditional machine learning mainly rely on manually designed feature sets, while methods based on deep learning use deep models such as recurrent neural networks (RNNs), convolutional neural networks (CNNs), and self-attention mechanisms (such as Transformers) to automatically extract deep features in text, thereby achieving more accurate text classification results.
[0004] Although existing text classification methods have been applied in many practical scenarios, the text content involved in different downstream tasks is diverse and the requirements are complex and changeable, and the existing text classification methods still have some shortcomings and deficiencies.
[0005] First, most current text classification methods rely on supervised learning, which requires a large amount of annotated data to ensure the accuracy of the model. However, in actual application scenarios, the topics that users are concerned about are constantly changing, and there are significant differences in the way users participate and their expression habits under different topics, making it difficult to build a universal annotated dataset suitable for all analysis scenarios. In addition, data collection and annotation are not only cumbersome but also costly. It is not feasible to build sufficient annotated datasets for each specific topic in practice. Therefore, how to achieve high-precision text classification under the conditions of small or even zero samples has become one of the key challenges that need to be solved in this field.
[0006] Secondly, existing text classification methods often focus on training and inference of preset categories. However, in actual application scenarios, there are significant differences in the categories that different business fields focus on. Even within the same business field, the dimensions of text classification may change over time and with changing needs. Therefore, how to flexibly adjust the text categories supported by the model in real time according to the specific needs of business analysis has become another challenge that text classification needs to overcome in practical applications.
[0007] In summary, existing text classification methods have two main problems: (1) They use a supervised learning framework, which has a very high demand for labeled data; (2) Model training and inference are both based on preset classification categories and cannot adapt to the flexible needs of business analysis. Summary of the invention
[0008] The purpose of the present invention is to solve the problem that the existing text classification methods have high requirements for annotation data and are difficult to adapt to flexible downstream analysis requirements, and propose an adaptive text classification method and system based on a large language model. The method and system use the powerful semantic understanding and context learning capabilities of the large language model to improve the accuracy of text classification through carefully designed prompt templates and context learning samples; at the same time, the method also references a text category customization framework to support business personnel to set the category system according to their actual needs, so as to better adapt to flexible and changeable downstream analysis tasks.
[0009] Specifically, in view of the shortcomings of existing technologies, such as Figure 3 As shown, the present invention proposes an adaptive text classification method based on a large language model, which includes:
[0010] In the initial step, a text category set is formulated according to the requirements of the text classification task, and multiple example samples are created for each text category in the text category set;
[0011] The analysis step comprises: formulating a prompt template for text classification according to the definition of the text classification task; obtaining the text to be classified, selecting an example sample of the text to be classified as sample data; assembling the text category and the sample data according to the prompt template to obtain a prompt text; inputting the prompt text into a large language model to obtain an output result of the large language model;
[0012] The classification step is to parse the output result to obtain the text category of the text to be classified.
[0013] The adaptive text classification method based on a large language model, wherein the prompt template includes: system instructions for informing the large language model of the text categories included in the text classification task and the output format requirements, and the sample data selected from the example samples of each text category.
[0014] The adaptive text classification method based on a large language model, wherein the classification step includes: truncating and segmenting the output result, using the last field in the output result as a category label, determining whether the category label is included in the category set, and if so, using the category label as the text category of the text to be classified.
[0015] In the adaptive text classification method based on a large language model, the example sample is the example sample with the highest similarity to the text to be classified.
[0016] like Figure 4 As shown, the present invention also proposes an adaptive text classification device based on a large language model, which includes:
[0017] The initial module formulates a text category set according to the requirements of the text classification task and creates multiple example samples for each text category in the text category set;
[0018] The analysis module formulates a prompt template for text classification according to the definition of the text classification task; obtains the text to be classified, selects an example sample of the text to be classified as sample data; assembles the text category and the sample data according to the prompt template to obtain a prompt text; inputs the prompt text into the large language model to obtain an output result of the large language model;
[0019] The classification module parses the output result to obtain the text category of the text to be classified.
[0020] The adaptive text classification method and device based on a large language model, wherein the prompt template includes: system instructions for informing the large language model of the text categories included in the text classification task and the output format requirements, and the sample data selected from the example samples of each text category.
[0021] The adaptive text classification method and device based on a large language model, wherein the classification module includes: truncating and segmenting the output result, taking the last field in the output result as a category label, judging whether the category label is included in the category set, and if so, taking the category label as the text category of the text to be classified; the example sample is the example sample with the highest similarity to the text to be classified.
[0022] The present invention also proposes an electronic device, including the adaptive text classification device based on a large language model, and the electronic device is connected to an information display device, which is used to display the text category according to display parameters and attributes set by the user or through an artificial intelligence model.
[0023] The present invention also proposes a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps of the adaptive text classification method based on a large language model are implemented.
[0024] The present invention also proposes a computer program product, comprising a computer program, wherein the computer program implements the steps of the adaptive text classification method based on a large language model when executed by a processor.
[0025] It can be seen from the above scheme that the advantages of the present invention are:
[0026] 1. In response to the problem that existing text classification methods have a strong dependence on annotated data, the present invention proposes a text classification method based on a large language model. This method activates the intrinsic knowledge of the large model through carefully designed prompt templates to achieve high-precision text classification. At the same time, this method supports the introduction of a small number of annotated examples to achieve contextual learning, further improving the accuracy of text classification.
[0027] 2. Aiming at the problem that existing text classification methods only support preset text categories, the present invention proposes a text category customization framework. The framework supports business personnel to customize the target categories of text analysis, and allows business personnel to provide a small amount of sample text. User-defined text categories and sample data can be directly assembled into the prompt template of the large language model, so as to quickly adapt to different business analysis needs.
[0028] 3. The present invention constructs an adaptive text classification system based on a large language model, covering the entire text classification process including text category definition, prompt template design, prompt example selection, template assembly, category inference, etc., which can efficiently, accurately and flexibly infer the category information contained in the text. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] Figure 1 This is a flowchart of a text classification method based on a large language model;
[0030] Figure 2 This is a business logic diagram of an adaptive text classification system based on a large language model;
[0031] Figure 3 is a flow chart of the method of the present invention;
[0032] Figure 4 It is a module diagram of the device of the present invention;
[0033] Figure 5 This is a schematic diagram of the structure of a first electronic device of the present invention;
[0034] Figure 6 This is a schematic diagram of the application environment structure of the first electronic device of the present invention;
[0035] Figure 7 It is a schematic diagram of the structure of a second electronic device of the present invention.
[0036] Reference numerals:
[0037] A-First electronic device;
[0038] B-Adaptive text classification device;
[0039] C-data acquisition equipment;
[0040] D-information display device;
[0041] 1000 - second electronic device;
[0042] Ⅰ-computational unit;
[0043] II-ROM;
[0044] III-RAM;
[0045] IV-bus;
[0046] V-interface;
[0047] VI - input unit;
[0048] VII-output unit;
[0049] VIII- Storage medium;
[0050] Ⅸ-Communication unit. DETAILED DESCRIPTION
[0051] It should be noted that, in this application, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprises" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device.
[0052] Without more constraints, an element defined by the phrase "comprising a..." does not exclude the existence of other identical elements in the process, method, article or apparatus comprising the element.
[0053] The processor described in the present invention is the control center of the electronic device, which can be a processor or a general term for multiple processing elements. For example, it can be one or more central processing units (CPUs), or application specific integrated circuits (ASICs), or one or more integrated circuits configured to implement the embodiments of the present invention, such as one or more microprocessors (digital signal processors, DSPs), or one or more field programmable gate arrays (FPGAs).
[0054] Optionally, the processor can perform various functions of the electronic device by running or executing a software program stored in the memory, and calling data stored in the memory.
[0055] In a specific implementation, as an embodiment, the processor may include one or more CPUs. Each of these processors may be a single-core processor (single-CPU) or a multi-core processor (multi-CPU). The processor here may refer to one or more devices, circuits, and / or processing cores for processing data (such as computer program instructions). Electronic devices may include: servers, desktop computers, laptops, smart phones, tablet computers, embedded computers, etc., wherein the embedded computers include vehicles and robots, etc.
[0056] The memory is used to store the software program for executing the solution of the present invention, and the execution is controlled by the processor. The specific implementation method can refer to the above method embodiment and will not be repeated here.
[0057] It should be noted that the structure of the electronic device shown in the drawings of the present invention does not constitute a limitation thereto, and the actual knowledge structure recognition device may include more or fewer components than shown in the drawings, or a combination of certain components, or a different arrangement of components.
[0058] The above embodiments can be implemented in whole or in part by software, hardware (such as circuits), firmware or any other combination. When implemented by software, the above embodiments can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions or computer programs. When the computer instructions or computer programs are loaded or executed on a computer, the process or function described in the embodiment of the present invention is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from one website, computer, server or data center to another website, computer, server or data center by wired (such as infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server or data center that contains one or more available media sets. The available medium can be a magnetic medium (for example, a floppy disk, a hard disk, a tape), an optical medium (for example, a DVD), or a semiconductor medium. The semiconductor medium can be a solid-state hard disk.
[0059] It should also be understood that the term "and / or" in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. A and B can be singular or plural. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship, but it may also indicate an "and / or" relationship. Please refer to the context for specific understanding.
[0060] In the present invention, "at least one" means one or more, and "more than one" means two or more. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b, or c can be represented by: a, b, c, ab, ac, bc, or abc, where a, b, c can be single or multiple.
[0061] It should also be understood that in various embodiments of the present invention, the size of the serial numbers of the above-mentioned processes does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.
[0062] In the several embodiments provided by the present invention, it should be understood that the disclosed devices, apparatuses and methods can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of the units is only a logical function division, and there may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0063] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0064] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0065] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in various embodiments of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0066] In view of the high demand for labeled data in existing text classification methods, the inventors of the present invention proposed a text classification method based on a large language model. By designing a suitable prompt template, the method can effectively activate the internal knowledge contained in the large language model, thereby realizing text classification under zero samples. At the same time, the method also combines the in-context learning method to realize small sample text classification by adding a small number of pre-labeled samples to the prompt template, further improving the accuracy of text classification.
[0067] In view of the problem that existing text classification methods are difficult to adapt to the needs of customized analysis categories, the inventors of the present invention proposed a text category customization framework. The framework supports business personnel to set the categories of text classification according to their own analysis needs, including the names of each category and the sample data under the category. With the support of this framework, business personnel can flexibly customize the required text categories, and combine with the analysis framework based on the large language model to achieve adaptive text classification inference under zero-sample and small-sample conditions.
[0068] Specifically, in order to achieve the above technical effects, the present invention proposes the following key technical points:
[0069] Key point 1: To address the problem that existing text classification methods are overly dependent on large-scale annotated data, a text classification method based on a large language model is proposed. This method can significantly improve the accuracy of text classification under zero-sample and small-sample conditions.
[0070] Key point 2: To address the problem that existing text classification methods only support preset categories and lack business flexibility, a text category customization framework is proposed. This framework supports business users to customize text categories according to business needs and improves the adaptability of text classification methods to downstream tasks.
[0071] Key point 3: We have built an adaptive text classification system based on a large language model. We have implemented the entire process of adaptive text classification based on a large language model, including text category definition, prompt template design, prompt example selection, template assembly, category inference, etc., to support business analysts to customize the entire analysis process and achieve better analysis results.
[0072] In order to make the above features and effects of the present invention more clearly and understandably described, embodiments are given below and described in detail with reference to the accompanying drawings. This specification discloses one or more embodiments that include the features of the present invention. The disclosed embodiments are only for illustration. The scope of protection of the present invention is not limited to the disclosed embodiments, and the present invention is defined by the attached claims.
[0073] In view of the defects of the above-mentioned prior art, the present invention proposes a text classification method based on a large language model, which includes the following processing flow:
[0074] Step 1: According to the actual analysis business needs, formulate text categories and create multiple sample examples for different text categories;
[0075] Step 2: According to the definition of the text classification task, a prompt template for text classification is formulated;
[0076] Step 3, select similar sample data according to the text to be classified;
[0077] Step 4, assembling text categories and sample data according to the prompt template to obtain prompt text input into the large model; the large language model can adopt the existing open source large model, and the present invention uses the MiniCPM-2B-sft-bf16 open source model;
[0078] Step 5, input the prompt text into the large language model, and collect the output result of the large language model;
[0079] Step 6: parse the output results of the large language model to obtain the final text category, such as "finance", "culture", "entertainment", etc., and the analysis process ends.
[0080] For the specific process, please refer to the attached Figure 1 , described as:
[0081] 1. Text category customization: Users can customize text categories according to their needs. Each text category contains two fields: name and samples, and is stored in JSON format. The category name is used to summarize the semantics of the category, and sample data can be obtained by extracting from existing datasets or manually annotating.
[0082] A typical example of a custom category is as follows:
[0083] {
[0084] "name":"Sports",
[0085] "samples":[
[0086] "On Xth day of Xth month, the semi-finals of the World Professional Go Championship ended in XX. In the end, Chinese player XX, playing with black pieces in XXX moves, defeated the defending champion, Korean player XXX, in the middle game and advanced to the finals of the world championship for the first time.",
[0087] "In the early morning of XX / XX, the men's tennis team finals came to an end. The defending champion Italian team, led by XX and XX, won X singles matches and defeated the Dutch team, led by XX and XX, 2-0, winning the championship for the second consecutive year.",
[0088] "On XX / XX, the Intercontinental Cup final was held in Doha, with XX defeating XX 3-0 to win the championship."]
[0089] }
[0090] 2. Prompt template design: According to the needs of the text classification task, a large language model prompt template for text classification is designed. The template mainly consists of two parts: the first part is the system instruction (system), which is used to inform the large model of the text categories and output format requirements included in the text classification task; the second part is the context example, which is responsible for selecting appropriate example data from the example samples of each text category and splicing them into the prompt, thereby using the context learning ability of the large language model to improve the accuracy of text classification. A typical text classification task prompt template is as follows: [
[0092] {
[0093] "role":"system",
[0094] "content":"You are a text classification assistant and need to classify the input text into the following categories: "+$senti_labels$+". Please directly give the category label to which each text belongs."
[0095] },
[0096] {
[0097] "role":"user",
[0098] "content":"$sample$"
[0099] },
[0100] {
[0101] "role":"assistant",
[0102] "content":"$label$"
[0103] },
[0104] {
[0105] "role":"user",
[0106] "content":"$text$"
[0107] }, ]
[0109] In the template, $senti_labels$, $sample$, $label$, and $text$ are all placeholders, where $senti_labels$ represents the target category of the text classification task, represented by a string, and different categories are connected by commas, such as "sports, politics, economy, entertainment, finance, education". $sample$ and $label$ represent the text part and label part of the sample data in pairs, while $text$ represents the text to be classified.
[0110] 3. Sample data selection: Based on the text to be classified, similar text can be selected from the sample data provided when the user customizes the text category as context sample data, and the context learning ability of the large language model can be used to improve the effect of text analysis. The selection of sample data supports three strategies:
[0111] Strategy 1, random selection: select a category from the user-defined text categories, and then randomly select a piece of data from the sample data of the category as the sample data;
[0112] Strategy 2, shallow semantic matching: Use the existing BM25 model to calculate the similarity between the text to be classified and all sample texts, and use the K texts with the highest similarity as context sample data. Considering the limitation of context length, the recommended value of parameter K is 3.
[0113] Strategy 3, deep semantic matching: Use the BERT model to obtain the semantic vectors of the text to be classified and all sample texts, and select the most similar K texts as context sample data based on cosine similarity. Considering the limitation of context length, the recommended value of parameter K is 3.
[0114] 4. Template assembly: Fill the user-defined text category, context example data and the text to be classified into the corresponding fields of the text classification task template defined in step 2 to obtain the prompt text that is finally input into the large language model.
[0115] 5. Large language model generation: Input the assembled prompt text into the large language model, receive the output of the large language model and decode it into text.
[0116] 6. Text category extraction: The output of the large language model contains historical conversation information, which needs to be intercepted to obtain the final classification label. Use " <ai>" is used as a delimiter to split the output of the large model, and the last field is used as the category label. If the parsed category label is included in the user-defined category set, the category label is directly returned as the result; otherwise, the "undefined" label is returned.
[0117] An adaptive text classification system based on a large language model. Its business logic is shown in the attached Figure 2 , including at least the following modules:
[0118] Text category management module: mainly responsible for text category customization, supporting business users to manage text categories according to business needs, including category names, category sample data, category collections, etc., and persisting the corresponding data to the database. Supports adding, deleting, modifying and querying text categories, sample data and category collections.
[0119] Text classification template management module: mainly responsible for the management of text classification templates, supporting business users to design different classification templates according to business needs, including but not limited to the modification of prompt text, placeholder fields, number of examples and other fields. Supports the functions of adding, deleting, modifying and checking text classification templates.
[0120] Text classification template assembly module: supports users to customize text category sets, text classification templates, sample data selection strategies and other dimensions according to business needs.
[0121] Category module: Assemble the prompt text according to the text classification customized template provided by the business personnel and the text to be classified, input it into the large language model, and parse the output text to obtain the final text category.
[0122] The following is a system embodiment corresponding to the above method embodiment. This embodiment can be implemented in conjunction with the above embodiment. The relevant technical details mentioned in the above embodiment are still valid in this embodiment. In order to reduce repetition, they are not repeated here. Accordingly, the relevant technical details mentioned in this embodiment can also be applied in the above embodiment.
[0123] like Figure 4 As shown, the present invention also proposes an adaptive text classification device based on a large language model, which includes:
[0124] The initial module formulates a text category set according to the requirements of the text classification task and creates multiple example samples for each text category in the text category set;
[0125] The analysis module formulates a prompt template for text classification according to the definition of the text classification task; obtains the text to be classified, selects an example sample of the text to be classified as sample data; assembles the text category and the sample data according to the prompt template to obtain a prompt text; inputs the prompt text into the large language model to obtain an output result of the large language model;
[0126] The classification module parses the output result to obtain the text category of the text to be classified.
[0127] The adaptive text classification method and device based on a large language model, wherein the prompt template includes: system instructions for informing the large language model of the text categories included in the text classification task and the output format requirements, and the sample data selected from the example samples of each text category.
[0128] The adaptive text classification method and device based on a large language model, wherein the classification module includes: truncating and segmenting the output result, taking the last field in the output result as a category label, judging whether the category label is included in the category set, and if so, taking the category label as the text category of the text to be classified; the example sample is the example sample with the highest similarity to the text to be classified.
[0129] like Figure 5 As shown, the present invention further proposes, in another embodiment, a first electronic device A including the adaptive text classification device based on a large language model.
[0130] like Figure 6 As shown, the first electronic device A can also be connected to the data acquisition device C and the information display device D through a wired or wireless information transmission scheme, the data acquisition device C is used to collect the text to be classified, and the information display device D is used to display the text category of the text to be classified obtained by the analysis of the present invention.
[0131] The information display device D can sort and process the data output by the first electronic device A based on the information display mechanism to improve the readability of the data output by the first electronic device A. The information display mechanism can be manually preset, for example, the data output by the first electronic device A is visually displayed, which can be based on the display parameters and / or attributes set by the user. The display parameters can be, for example, the display data range, and the display attributes can be, for example, the display font, color, whether to scroll and play, etc. The user is presented with the key information specified by the user, such as the key text category of the key text to be classified, etc. The user can understand this information more timely without having to access the secondary page or scroll the page, saving the user's operation. Or the information display mechanism can be an artificial intelligence AI display model, which can learn the user's key information based on the user's previous usage habits, such as viewing time, number of clicks, number of edits, etc., and then automatically present rich and necessary key information to the user.
[0132] The present invention also provides a computer program product, which includes a computer program. The computer program can be stored on a readable storage medium. When the computer program is executed by a processor, the computer can execute the adaptive text classification method based on a large language model provided by the above methods.
[0133] The present invention also proposes a storage medium VIII in another embodiment for storing a computer program for executing the adaptive text classification method based on a large language model. It should be understood that the storage medium in the embodiment of the present invention can be a volatile memory or a non-volatile memory, or can include both volatile and non-volatile memories. Among them, the non-volatile memory can be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM) or a flash memory. The volatile memory can be a random access memory (RAM), which is used as an external cache. By way of example and not limitation, many forms of random access memory (RAM) are available, such as static RAM (SRAM), dynamic random access memory (DRAM), synchronous DRAM (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link DRAM (SLDRAM), and direct RAM bus random access memory (DR RAM).
[0134] Figure 7 A schematic block diagram of a second electronic device 1000 that can be used to implement an embodiment of the present invention is shown. The second electronic device 1000 electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workbenches, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The second electronic device 1000 can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples, and are not intended to limit the implementation of the present invention described and / or required herein. The second electronic device 1000 may be the same or different from the first electronic device A.
[0135] The second electronic device 1000 includes a computing unit I, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory II (ROM) or a computer program loaded from a storage medium VIII into a random access memory (RAM) III. In RAM III, various programs and data required for the operation of the device 1000 can also be stored. The computing unit I, ROM II, and RAM III are connected to each other via a bus IV. An input / output (I / O) interface V is also connected to the bus IV.
[0136] A plurality of components in the second electronic device 1000 are connected to the I / O interface V, including: an input unit VI, such as a keyboard, a mouse, etc.; an output unit VII, such as various types of displays, speakers, etc.; a storage medium VIII, such as a disk, an optical disk, etc.; and a communication unit IX, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit IX allows the second electronic device 1000 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0137] The computing unit I may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of computing unit I include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit I performs the various methods and processes described above, such as method steps S1-S3. For example, in some embodiments, the method may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage medium VIII. In some embodiments, part or all of the computer program may be loaded and / or installed on the device 1000 via ROM II and / or a communication unit IX. When the computer program is loaded into RAM III and executed by the computing unit I, one or more steps of the method described above may be performed. Alternatively, in other embodiments, the computing unit I may be configured to execute the method in any other appropriate manner (e.g., by means of firmware).
[0138] Although the embodiments of the present invention have been disclosed as above, they are not limited to the applications listed in the specification and the implementation modes, and they can be fully applied to various fields suitable for the present invention. For those familiar with the art, additional modifications can be easily implemented. Therefore, without departing from the general concept defined by the claims and the scope of equivalents, the present invention is not limited to the specific details and the illustrations shown and described herein.< / ai>
Claims
1. An adaptive text classification method based on a large language model, characterized in that: include: In the initial step, a text category set is formulated according to the requirements of the text classification task, and multiple example samples are created for each text category in the text category set; The analysis step is to formulate a prompt template for text classification according to the definition of the text classification task; Obtaining a text to be classified, selecting an example sample of the text to be classified as sample data; assembling the text category and the sample data according to the prompt template to obtain a prompt text; inputting the prompt text into a large language model to obtain an output result of the large language model; The classification step is to parse the output result to obtain the text category of the text to be classified.
2. The adaptive text classification method based on a large language model as claimed in claim 1, characterized in that: The prompt template includes: system instructions for informing the large language model of the text categories included in the text classification task and the output format requirements, and the sample data selected from the example samples of each text category.
3. The adaptive text classification method based on a large language model as claimed in claim 1, characterized in that: The classification step includes: truncating and segmenting the output result, taking the last field in the output result as a category label, determining whether the category label is included in the category set, and if so, taking the category label as the text category of the text to be classified.
4. The adaptive text classification method based on a large language model as claimed in claim 1, characterized in that: The example sample is the example sample with the highest similarity to the text to be classified.
5. An adaptive text classification device based on a large language model, characterized in that: include: The initial module formulates a text category set according to the requirements of the text classification task and creates multiple example samples for each text category in the text category set; The analysis module formulates a prompt template for text classification according to the definition of the text classification task; Obtaining a text to be classified, selecting an example sample of the text to be classified as sample data; assembling the text category and the sample data according to the prompt template to obtain a prompt text; inputting the prompt text into a large language model to obtain an output result of the large language model; The classification module parses the output result to obtain the text category of the text to be classified.
6. The method and device for adaptive text classification based on a large language model according to claim 5, characterized in that: The prompt template includes: system instructions for informing the large language model of the text categories included in the text classification task and the output format requirements, and the sample data selected from the example samples of each text category.
7. The method and device for adaptive text classification based on a large language model according to claim 5, characterized in that: The classification module includes: truncating and segmenting the output result, taking the last field in the output result as a category label, judging whether the category label is included in the category set, and if so, taking the category label as the text category of the text to be classified; the example sample is the example sample with the highest similarity to the text to be classified.
8. An electronic device, characterized in that: It includes an adaptive text classification device based on a large language model as described in claims 5-7, and the electronic device is connected to an information display device, which is used to display the text category according to display parameters and attributes set by the user or through an artificial intelligence model.
9. A computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the steps of the adaptive text classification method based on a large language model described in any one of claims 1 to 4 are implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the adaptive text classification method based on a large language model described in any one of claims 1 to 4 are implemented.
Citation Information
Cited By
Text processing method, system and device based on large language model multi-round decision
CN120910272A