CN116595175A - Text classification method, device, equipment and storage medium - Google Patents

Text classification method, device, equipment and storage medium Download PDF

Info

Publication number
CN116595175A
CN116595175A CN202310554123.9A CN202310554123A CN116595175A CN 116595175 A CN116595175 A CN 116595175A CN 202310554123 A CN202310554123 A CN 202310554123A CN 116595175 A CN116595175 A CN 116595175A
Authority
CN
China
Prior art keywords
text
word
vectors
word segmentation
attention
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202310554123.9A
Other languages
Chinese (zh)
Inventor
舒畅
肖京
陈又新
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ping An Technology Shenzhen Co Ltd
Original Assignee
Ping An Technology Shenzhen Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Ping An Technology Shenzhen Co Ltd filed Critical Ping An Technology Shenzhen Co Ltd
Priority to CN202310554123.9A priority Critical patent/CN116595175A/en
Publication of CN116595175A publication Critical patent/CN116595175A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/30Information retrieval; Database structures therefor; File system structures therefor of unstructured textual data
    • G06F16/35Clustering; Classification
    • G06F16/353Clustering; Classification into predefined classes
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F17/00Digital computing or data processing equipment or methods, specially adapted for specific functions
    • G06F17/10Complex mathematical operations
    • G06F17/16Matrix or vector computation, e.g. matrix-matrix or matrix-vector multiplication, matrix factorization
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/10Text processing
    • G06F40/12Use of codes for handling textual entities
    • G06F40/151Transformation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/20Natural language analysis
    • G06F40/279Recognition of textual entities
    • G06F40/289Phrasal analysis, e.g. finite state techniques or chunking
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/04Architecture, e.g. interconnection topology
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/04Architecture, e.g. interconnection topology
    • G06N3/047Probabilistic or stochastic networks
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Abstract

The application relates to an artificial intelligence technology, which performs title classification on insurance knowledge training videos and discloses a text classification method, comprising the following steps: obtaining a text to be classified, and word segmentation is carried out on the text to be classified to obtain word segmentation words; converting the word segmentation words into vectors to obtain word segmentation word vectors; the word segmentation word vectors are weighted in attention based on a multi-head attention mechanism, and all weighted word segmentation word vectors are combined to obtain text characterization vectors; and carrying out text classification on the text to be classified based on the text characterization vector to obtain a classification result. The application also provides a text classification device, equipment and medium, which can be applied to the financial field and can improve the accuracy of text classification of insurance knowledge training video title texts and the like.

Description

Text classification method, device, equipment and storage medium
Technical Field
The present application relates to the field of artificial intelligence technology and financial technology, and in particular, to a text classification method, apparatus, electronic device, and storage medium.
Background
Along with the development of natural language processing technology, various natural language processing technologies are gradually applied to various business problems, such as title classification of insurance knowledge training videos by using a text classification method, so that automatic classification of the insurance knowledge training videos is realized according to the result of the title classification.
However, the existing text classification technology only converts the text to be classified (such as the title of insurance knowledge training video) into a vector, classifies the converted vector, ignores the influence of irrelevant text features in the converted vector on text classification, and further leads to lower accuracy of text classification.
Disclosure of Invention
The application provides a text classification method, a text classification device, electronic equipment and a storage medium, and mainly aims to improve the accuracy of text classification of insurance knowledge training video title texts and the like.
Obtaining a text to be classified, and word segmentation is carried out on the text to be classified to obtain word segmentation words;
converting the word segmentation words into vectors to obtain word segmentation word vectors;
the word segmentation word vectors are weighted in attention based on a multi-head attention mechanism, and all weighted word segmentation word vectors are combined to obtain text characterization vectors;
and carrying out text classification on the text to be classified based on the text characterization vector to obtain a classification result.
Optionally, the multi-head attention mechanism is used for carrying out attention weighting on the word segmentation word vectors, and combining all weighted word segmentation word vectors to obtain text characterization vectors, including:
acquiring an attention network constructed based on a multi-attention mechanism and containing a preset number of attention heads;
carrying out attention weighting on the word segmentation word vectors by using the attention network to obtain word feature vectors;
and combining all the word feature vectors to obtain the text characterization vector.
Optionally, the performing attention weighting on the word segmentation word vector by using the attention network to obtain a word feature vector includes:
extracting a query weight matrix and a key weight matrix corresponding to each attention head in the attention network;
calculating by using the word segmentation term vector and the query weight matrix of the attention head to obtain an attention query matrix corresponding to the word segmentation term vector;
calculating by using the word segmentation word vector and the key weight matrix of the attention head to obtain an attention key matrix corresponding to the word segmentation word vector;
calculating an attention query matrix corresponding to the word segmentation vector and each attention key matrix to obtain an attention initial weight corresponding to the word segmentation vector;
calculating according to all attention initial weights corresponding to the word segmentation word vectors to obtain attention weights corresponding to the word segmentation word vectors;
performing linear conversion on the word segmentation word vectors to obtain target word vectors corresponding to the word segmentation word vectors;
and calculating based on the target word vector and the attention weight corresponding to the word segmentation word vector to obtain a word feature vector corresponding to the word segmentation word vector.
Optionally, the combining all the term feature vectors to obtain the text feature vector includes:
determining the vector sequence of word feature vectors corresponding to the word segmentation word vectors according to the sequence of the word segmentation words corresponding to the word segmentation word vectors in the text to be classified;
and taking the word feature vectors as columns, and taking the vector sequence of the word feature vectors as the sequence of the columns so as to fill all the word feature vectors into a preset blank matrix to obtain the text characterization vector.
Optionally, the text classification is performed on the text to be classified based on the text characterization vector to obtain a classification result, including:
acquiring a text class set of a text to be classified and a pre-constructed multi-layer perceptron, wherein output nodes of the multi-layer perceptron are in one-to-one correspondence with each text class of the text class set;
inputting the text characterization vector into the multi-layer perceptron, extracting the output value of each output node of the multi-layer perceptron, and obtaining the class characteristic value of the text class corresponding to the output node;
normalizing the category characteristic value of the text category by using a softmax function to obtain a characteristic probability value of the text category;
and screening all the text categories according to the characteristic probability value to obtain the classification result.
Optionally, the screening all the text categories according to the feature probability value to obtain the classification result includes:
selecting the maximum value of all the characteristic probability values to obtain a target characteristic probability value;
determining the text category corresponding to the target feature probability value as a target text category;
and determining the target text category as a classification result of the text to be classified.
In order to solve the above problems, the present application also provides a text classification apparatus, including:
the vector conversion module is used for obtaining a text to be classified, and word segmentation is carried out on the text to be classified to obtain word segmentation words; converting the word segmentation words into vectors to obtain word segmentation word vectors;
the attention weighting module is used for carrying out attention weighting on the word segmentation word vectors based on a multi-head attention mechanism, and combining all the weighted word segmentation word vectors to obtain text characterization vectors;
and the text classification module is used for carrying out text classification on the text to be classified based on the text characterization vector to obtain a classification result.
Optionally, the text classification is performed on the text to be classified based on the text characterization vector to obtain a classification result, including:
acquiring a text class set of a text to be classified and a pre-constructed multi-layer perceptron, wherein output nodes of the multi-layer perceptron are in one-to-one correspondence with each text class of the text class set;
inputting the text characterization vector into the multi-layer perceptron, extracting the output value of each output node of the multi-layer perceptron, and obtaining the class characteristic value of the text class corresponding to the output node;
normalizing the category characteristic value of the text category by using a softmax function to obtain a characteristic probability value of the text category;
and screening all the text categories according to the characteristic probability value to obtain the classification result.
In order to solve the above-mentioned problems, the present application also provides an electronic apparatus including:
a memory storing at least one computer program; a kind of electronic device with high-pressure air-conditioning system
And a processor executing the computer program stored in the memory to implement the text classification method.
In order to solve the above-described problems, the present application also provides a computer-readable storage medium having stored therein at least one computer program that is executed by a processor in an electronic device to implement the above-described text classification method.
The embodiment of the application carries out attention weighting on the word segmentation word vectors based on a multi-head attention mechanism, and combines all the weighted word segmentation word vectors to obtain text characterization vectors; and carrying out text classification on the text to be classified based on the text characterization vector to obtain a classification result. The influence of irrelevant features is removed by extracting effective features in word segmentation word vectors through a multi-head attention mechanism, so that the text characterization vectors can more accurately characterize text features of texts to be classified, and the accuracy of text classification based on the text characterization vectors is improved. Therefore, the text classification method, the device, the electronic equipment and the readable storage medium provided by the embodiment of the application improve the accuracy of text classification of insurance knowledge training video title texts and the like.
Drawings
FIG. 1 is a flow chart of a text classification method according to an embodiment of the present application;
fig. 2 is a schematic block diagram of a text classification device according to an embodiment of the application;
fig. 3 is a schematic diagram of an internal structure of an electronic device for implementing a text classification method according to an embodiment of the present application;
the achievement of the objects, functional features and advantages of the present application will be further described with reference to the accompanying drawings, in conjunction with the embodiments.
Detailed Description
It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the scope of the application.
The embodiment of the application provides a text classification method. The execution subject of the text classification method includes, but is not limited to, at least one of a server, a terminal, and the like, which can be configured to execute the method provided by the embodiment of the application. In other words, the text classification method may be performed by software or hardware installed in a terminal device or a server device, and the software may be a blockchain platform. The service end includes but is not limited to: the server can be an independent server, or can be a cloud server for providing cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery networks (Content Delivery Network, CDNs), basic cloud computing services such as big data and artificial intelligent platforms, and the like.
Referring to fig. 1, a flowchart of a text classification method according to an embodiment of the present application is shown, where in the embodiment of the present application, the text classification method includes:
s1, acquiring a text to be classified, and segmenting the text to be classified to obtain segmented words;
the text to be classified in the embodiment of the application is text to be subjected to text classification, is video title text of the insurance knowledge training video, and is subjected to text classification to realize labeling of the insurance knowledge training video, so that automatic classification management of the insurance knowledge training video is realized.
Further, in the embodiment of the application, the text to be classified can be segmented by using a method of segmentation such as barking segmentation, and the method of segmentation is not limited.
S2, converting the word segmentation words into vectors to obtain word segmentation word vectors;
in order to characterize the video title text of the insurance knowledge training video to be classified into a vector form, each word in the video title text of the insurance knowledge training video needs to be converted into a vector, namely the word segmentation word is converted into a vector, and the word segmentation word vector is obtained.
Optionally, in the embodiment of the present application, the embedded layer of the pre-built deep learning model (such as the bert model) may be used to convert the word segmentation word into a vector, or an algorithm such as one-hot may be used to convert the word segmentation word into a vector.
In another embodiment of the application, the word segmentation word vectors can be stored in the blockchain node, and the high throughput characteristic of the blockchain node is utilized to improve the data taking efficiency.
S3, carrying out attention weighting on the word segmentation word vectors based on a multi-head attention mechanism, and combining all weighted word segmentation word vectors to obtain text characterization vectors;
in the embodiment of the application, in order to better characterize the video title text of the insurance knowledge training video to be classified, the word segmentation word vectors are weighted in attention based on a multi-head attention mechanism, and all the weighted word segmentation word vectors are combined to obtain the text characterization vector.
In detail, in the embodiment of the present application, attention weighting is performed on the word segmentation word vectors based on a multi-head attention mechanism, and all weighted word segmentation word vectors are combined to obtain text token vectors, including:
acquiring an attention network constructed based on a multi-attention mechanism and containing a preset number of attention heads;
carrying out attention weighting on the word segmentation word vectors by using the attention network to obtain word feature vectors;
and combining all the word feature vectors to obtain the text characterization vector.
Further, in the embodiment of the present application, the performing attention weighting on the word segmentation word vector by using the attention network to obtain a word feature vector includes:
step A: extracting a query weight matrix and a key weight matrix corresponding to each attention head in the attention network;
in the embodiment of the application, the query weight matrix and the key weight matrix are weight parameters of K, Q in an attention mechanism corresponding to each attention head by mapping the word segmentation word vector.
And (B) step (B): calculating by using the word segmentation term vector and the query weight matrix of the attention head to obtain an attention query matrix corresponding to the word segmentation term vector;
step C: calculating by using the word segmentation word vector and the key weight matrix of the attention head to obtain an attention key matrix corresponding to the word segmentation word vector;
step D: calculating an attention query matrix corresponding to the word segmentation vector and each attention key matrix to obtain an attention initial weight corresponding to the word segmentation vector;
step E: calculating according to all attention initial weights corresponding to the word segmentation word vectors to obtain attention weights corresponding to the word segmentation word vectors;
specifically, in the embodiment of the application, the initial attention weights corresponding to the word segmentation word vectors are summed to obtain the total attention weight corresponding to the word segmentation word vectors; and calculating by using the total attention weight corresponding to the word segmentation word vectors and the preset quantity to obtain the attention weight corresponding to the word segmentation word vectors.
For example: the word segmentation word vectors correspond to three initial attention weights, namely 0.1, 0.2 and 0.3 respectively, so that the total attention weight corresponding to the word segmentation word vectors is (0.1+0.2+0.3) =0.6, the preset number is 4, and the attention weight corresponding to the word segmentation word vectors is 0.6/4=0.15.
Step F: performing linear conversion on the word segmentation word vectors to obtain target word vectors corresponding to the word segmentation word vectors;
in the embodiment of the application, a value weight matrix in the attention network is extracted, and the value weight matrix is multiplied by the word segmentation word vector to obtain a target word vector corresponding to the word segmentation word vector. The value weight matrix is mapped into a weight parameter of V in an attention mechanism.
Step G: and calculating based on the target word vector and the attention weight corresponding to the word segmentation word vector to obtain a word feature vector corresponding to the word segmentation word vector.
In detail, in the embodiment of the application, the target word vector corresponding to the word segmentation word vector is multiplied by the attention weight to obtain the word feature vector corresponding to the word segmentation word vector.
Further, in the embodiment of the present application, combining all the term feature vectors to obtain the text feature vector includes:
determining the vector sequence of word feature vectors corresponding to the word segmentation word vectors according to the sequence of the word segmentation words corresponding to the word segmentation word vectors in the text to be classified;
for example: the text to be classified is a personal insurance training video, the corresponding word segmentation words are personal insurance, training and video, the sequence of the word segmentation words in the text to be classified is 1, the sequence of the word segmentation words in the training is 2, and the sequence of the word segmentation words in the text to be classified is video, so that the vector sequence of the word feature vector corresponding to the word segmentation word vector corresponding to the personal insurance is 1, the vector sequence of the word feature vector corresponding to the word segmentation word vector corresponding to the training is 2, and the vector sequence of the word feature vector corresponding to the word segmentation word vector corresponding to the video is 3.
And taking the word feature vectors as columns, and taking the vector sequence of the word feature vectors as the sequence of the columns so as to fill all the word feature vectors into a preset blank matrix to obtain the text characterization vector.
For example: the total two word feature vectors are respectivelyIs->Wherein the word feature vector ++>The corresponding vector order is 2 and the corresponding column order is the second column, word feature vector +.>The corresponding vector order is 1 and the corresponding column order is the first column, then the word feature vector +.>Filling the word feature vector as the first column into the blank matrix>Filling the second column into a blank matrix, and obtaining the text characterization vector after filling all word feature vectors
And S4, carrying out text classification on the text to be classified based on the text characterization vector to obtain a classification result.
In the embodiment of the application, text classification is carried out on the text to be classified based on the text characterization vector to obtain a classification result, which comprises the following steps:
acquiring a text class set of a text to be classified and a pre-constructed multi-layer perceptron, wherein output nodes of the multi-layer perceptron are in one-to-one correspondence with each text class of the text class set;
the text class set in the embodiment of the present application is a set of text classes that may be classified for the text to be classified, for example: the text to be classified can be classified into an A text category or a B text category (for example, the A text category is life insurance and the B text category is serious disease), and then the text category set is a set constructed by the A text category and the B text category.
Further, in the embodiment of the present application, the number of output nodes of the multi-layer perceptron is consistent with the number of text categories in the text category set, each output node corresponds to one text category, and the text categories correspond to the output nodes one by one.
Inputting the text characterization vector into the multi-layer perceptron, extracting the output value of each output node of the multi-layer perceptron, and obtaining the class characteristic value of the text class corresponding to the output node;
normalizing the category characteristic value of the text category by using a softmax function to obtain a characteristic probability value of the text category;
and screening all the text categories according to the characteristic probability value to obtain the classification result.
In the embodiment of the application, in order to further improve the processing efficiency of the multi-layer perceptron, the step of inputting the text token vector into the multi-layer perceptron may be replaced by vector dimension compression of the text token vector to obtain a target text token vector, and the target text pointer vector is input into the multi-layer perceptron. Specifically, in the embodiment of the present application, the text token vector may be vector dimension compressed by using a fully connected network, where the number of input nodes in the fully connected network is greater than the number of output nodes.
Further, in the embodiment of the present application, the filtering, according to the feature probability value, all the text categories to obtain the classification result includes: selecting the maximum value of all the characteristic probability values to obtain a target characteristic probability value; determining the text category corresponding to the target feature probability value as a target text category; and determining the target text category as a classification result of the text to be classified.
According to the embodiment of the application, the title classification of the insurance knowledge training video is realized according to the classification result of the text to be classified, so that the automatic classification of the insurance knowledge training video is realized according to the result of the title classification, such as: a. and b, the title classification results of the three insurance knowledge training videos b and c are all serious risks, so that the three insurance knowledge training videos a, b and c can be classified as one type of training video.
As shown in fig. 2, a functional block diagram of the text classification apparatus according to the present application.
The text classification apparatus 100 of the present application may be installed in an electronic device. Depending on the functions implemented, the text classification means may comprise a vector conversion module 101, an attention weighting module 102, a text classification module 103, which may also be referred to as a unit, means a series of computer program segments capable of being executed by the processor of the electronic device and of performing fixed functions, which are stored in the memory of the electronic device.
In the present embodiment, the functions concerning the respective modules/units are as follows:
the vector conversion module 101 is configured to obtain a text to be classified, and segment the text to be classified to obtain a word segment word; converting the word segmentation words into vectors to obtain word segmentation word vectors;
the attention weighting module 102 is configured to perform attention weighting on the word segmentation word vectors based on a multi-head attention mechanism, and combine all weighted word segmentation word vectors to obtain a text token vector;
the text classification module 103 is configured to perform text classification on the text to be classified based on the text token vector, so as to obtain a classification result.
In detail, each module in the text classification device 100 in the embodiment of the present application adopts the same technical means as the text classification method described in fig. 1 and can produce the same technical effects when in use, and will not be described again here.
Fig. 3 is a schematic structural diagram of an electronic device for implementing the text classification method according to the present application.
The electronic device may comprise a processor 10, a memory 11, a communication bus 12 and a communication interface 13, and may further comprise a computer program, such as a text classification program, stored in the memory 11 and executable on the processor 10.
The memory 11 includes at least one type of readable storage medium, including flash memory, a mobile hard disk, a multimedia card, a card memory (e.g., SD or DX memory, etc.), a magnetic memory, a magnetic disk, an optical disk, etc. The memory 11 may in some embodiments be an internal storage unit of the electronic device, such as a mobile hard disk of the electronic device. The memory 11 may in other embodiments also be an external storage device of the electronic device, such as a plug-in mobile hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card) or the like, which are provided on the electronic device. Further, the memory 11 may also include both an internal storage unit and an external storage device of the electronic device. The memory 11 may be used not only for storing application software installed in an electronic device and various types of data, such as codes of text classification programs, but also for temporarily storing data that has been output or is to be output.
The processor 10 may be comprised of integrated circuits in some embodiments, for example, a single packaged integrated circuit, or may be comprised of multiple integrated circuits packaged with the same or different functions, including one or more central processing units (Central Processing Unit, CPU), microprocessors, digital processing chips, graphics processors, combinations of various control chips, and the like. The processor 10 is a Control Unit (Control Unit) of the electronic device, connects various components of the entire electronic device using various interfaces and lines, and executes various functions of the electronic device and processes data by running or executing programs or modules (e.g., text classification programs, etc.) stored in the memory 11, and calling data stored in the memory 11.
The communication bus 12 may be a peripheral component interconnect standard (PerIPheralComponent Interconnect, PCI) bus, or an extended industry standard architecture (Extended Industry Standard Architecture, EISA) bus, among others. The bus may be classified as an address bus, a data bus, a control bus, etc. The communication bus 12 is arranged to enable a connection communication between the memory 11 and at least one processor 10 etc. For ease of illustration, the figures are shown with only one bold line, but not with only one bus or one type of bus.
Fig. 3 shows only an electronic device with components, and it will be understood by those skilled in the art that the structure shown in fig. 3 is not limiting of the electronic device and may include fewer or more components than shown, or may combine certain components, or a different arrangement of components.
For example, although not shown, the electronic device may further include a power source (such as a battery) for supplying power to the respective components, and preferably, the power source may be logically connected to the at least one processor 10 through a power management device, so that functions of charge management, discharge management, power consumption management, and the like are implemented through the power management device. The power supply may also include one or more of any of a direct current or alternating current power supply, recharging device, power failure classification circuit, power converter or inverter, power status indicator, etc. The electronic device may further include various sensors, bluetooth modules, wi-Fi modules, etc., which are not described herein.
Optionally, the communication interface 13 may comprise a wired interface and/or a wireless interface (e.g., WI-FI interface, bluetooth interface, etc.), typically used to establish a communication connection between the electronic device and other electronic devices.
Optionally, the communication interface 13 may further comprise a user interface, which may be a Display, an input unit, such as a Keyboard (Keyboard), or a standard wired interface, a wireless interface. Alternatively, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, an OLED (Organic Light-Emitting Diode) touch, or the like. The display may also be referred to as a display screen or display unit, as appropriate, for displaying information processed in the electronic device and for displaying a visual user interface.
It should be understood that the embodiments described are for illustrative purposes only and are not limited to this configuration in the scope of the patent application.
The text classification program stored in the memory 11 in the electronic device is a combination of a plurality of computer programs, which, when run in the processor 10, can implement:
obtaining a text to be classified, and word segmentation is carried out on the text to be classified to obtain word segmentation words;
converting the word segmentation words into vectors to obtain word segmentation word vectors;
the word segmentation word vectors are weighted in attention based on a multi-head attention mechanism, and all weighted word segmentation word vectors are combined to obtain text characterization vectors;
and carrying out text classification on the text to be classified based on the text characterization vector to obtain a classification result.
In particular, the specific implementation method of the processor 10 on the computer program may refer to the description of the relevant steps in the corresponding embodiment of fig. 1, which is not repeated herein.
Further, the electronic device integrated modules/units, if implemented in the form of software functional units and sold or used as stand-alone products, may be stored in a computer readable storage medium. The computer readable medium may be non-volatile or volatile. The computer readable medium may include: any entity or device capable of carrying the computer program code, a recording medium, a U disk, a removable hard disk, a magnetic disk, an optical disk, a computer Memory, a Read-Only Memory (ROM).
Embodiments of the present application may also provide a computer readable storage medium storing a computer program which, when executed by a processor of an electronic device, may implement:
obtaining a text to be classified, and word segmentation is carried out on the text to be classified to obtain word segmentation words;
converting the word segmentation words into vectors to obtain word segmentation word vectors;
the word segmentation word vectors are weighted in attention based on a multi-head attention mechanism, and all weighted word segmentation word vectors are combined to obtain text characterization vectors;
and carrying out text classification on the text to be classified based on the text characterization vector to obtain a classification result.
Further, the computer-usable storage medium may mainly include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required for at least one function, and the like; the storage data area may store data created from the use of blockchain nodes, and the like.
In the several embodiments provided in the present application, it should be understood that the disclosed apparatus, device and method may be implemented in other manners. For example, the above-described apparatus embodiments are merely illustrative, and for example, the division of the modules is merely a logical function division, and there may be other manners of division when actually implemented.
The modules described as separate components may or may not be physically separate, and components shown as modules may or may not be physical units, may be located in one place, or may be distributed over multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
The embodiment of the application can acquire and process the related data based on the artificial intelligence technology. Among these, artificial intelligence (Artificial Intelligence, AI) is the theory, method, technique and application system that uses a digital computer or a digital computer-controlled machine to simulate, extend and extend human intelligence, sense the environment, acquire knowledge and use knowledge to obtain optimal results.
In addition, each functional module in the embodiments of the present application may be integrated in one processing unit, or each unit may exist alone physically, or two or more units may be integrated in one unit. The integrated units can be realized in a form of hardware or a form of hardware and a form of software functional modules.
It will be evident to those skilled in the art that the application is not limited to the details of the foregoing illustrative embodiments, and that the present application may be embodied in other specific forms without departing from the spirit or essential characteristics thereof.
The present embodiments are, therefore, to be considered in all respects as illustrative and not restrictive, the scope of the application being indicated by the appended claims rather than by the foregoing description, and all changes which come within the meaning and range of equivalency of the claims are therefore intended to be embraced therein. Any reference signs in the claims shall not be construed as limiting the claim concerned.
The blockchain is a novel application mode of computer technologies such as distributed data storage, point-to-point transmission, consensus mechanism, encryption algorithm and the like. The Blockchain (Blockchain), which is essentially a decentralised database, is a string of data blocks that are generated by cryptographic means in association, each data block containing a batch of information of network transactions for verifying the validity of the information (anti-counterfeiting) and generating the next block. The blockchain may include a blockchain underlying platform, a platform product services layer, an application services layer, and the like.
Furthermore, it is evident that the word "comprising" does not exclude other elements or steps, and that the singular does not exclude a plurality. A plurality of units or means recited in the system claims can also be implemented by means of software or hardware by means of one unit or means. The terms second, etc. are used to denote a name, but not any particular order.
Finally, it should be noted that the above-mentioned embodiments are merely for illustrating the technical solution of the present application and not for limiting the same, and although the present application has been described in detail with reference to the preferred embodiments, it should be understood by those skilled in the art that modifications and equivalents may be made to the technical solution of the present application without departing from the spirit and scope of the technical solution of the present application.

Claims (10)

1. A method of text classification, the method comprising:
obtaining a text to be classified, and word segmentation is carried out on the text to be classified to obtain word segmentation words;
converting the word segmentation words into vectors to obtain word segmentation word vectors;
the word segmentation word vectors are weighted in attention based on a multi-head attention mechanism, and all weighted word segmentation word vectors are combined to obtain text characterization vectors;
and carrying out text classification on the text to be classified based on the text characterization vector to obtain a classification result.
2. The text classification method of claim 1, wherein the multi-headed attention-based mechanism performs attention weighting on the word segmentation word vectors and combines all weighted word segmentation word vectors to obtain a text token vector, comprising:
acquiring an attention network constructed based on a multi-attention mechanism and containing a preset number of attention heads;
carrying out attention weighting on the word segmentation word vectors by using the attention network to obtain word feature vectors;
and combining all the word feature vectors to obtain the text characterization vector.
3. The text classification method of claim 2, wherein said performing an attention weighting on said segmented word vectors using said attention network to obtain word feature vectors comprises:
extracting a query weight matrix and a key weight matrix corresponding to each attention head in the attention network;
calculating by using the word segmentation term vector and the query weight matrix of the attention head to obtain an attention query matrix corresponding to the word segmentation term vector;
calculating by using the word segmentation word vector and the key weight matrix of the attention head to obtain an attention key matrix corresponding to the word segmentation word vector;
calculating an attention query matrix corresponding to the word segmentation vector and each attention key matrix to obtain an attention initial weight corresponding to the word segmentation vector;
calculating according to all attention initial weights corresponding to the word segmentation word vectors to obtain attention weights corresponding to the word segmentation word vectors;
performing linear conversion on the word segmentation word vectors to obtain target word vectors corresponding to the word segmentation word vectors;
and calculating based on the target word vector and the attention weight corresponding to the word segmentation word vector to obtain a word feature vector corresponding to the word segmentation word vector.
4. The text classification method of claim 2, wherein said combining all of said term feature vectors to obtain said text token vector comprises:
determining the vector sequence of word feature vectors corresponding to the word segmentation word vectors according to the sequence of the word segmentation words corresponding to the word segmentation word vectors in the text to be classified;
and taking the word feature vectors as columns, and taking the vector sequence of the word feature vectors as the sequence of the columns so as to fill all the word feature vectors into a preset blank matrix to obtain the text characterization vector.
5. The text classification method of claim 1, wherein the text classification of the text to be classified based on the text token vector to obtain a classification result comprises:
acquiring a text class set of a text to be classified and a pre-constructed multi-layer perceptron, wherein output nodes of the multi-layer perceptron are in one-to-one correspondence with each text class of the text class set;
inputting the text characterization vector into the multi-layer perceptron, extracting the output value of each output node of the multi-layer perceptron, and obtaining the class characteristic value of the text class corresponding to the output node;
normalizing the category characteristic value of the text category by using a softmax function to obtain a characteristic probability value of the text category;
and screening all the text categories according to the characteristic probability value to obtain the classification result.
6. The text classification method of any of claims 1 to 5, wherein said screening all of the text categories according to the feature probability value to obtain the classification result comprises:
selecting the maximum value of all the characteristic probability values to obtain a target characteristic probability value;
determining the text category corresponding to the target feature probability value as a target text category;
and determining the target text category as a classification result of the text to be classified.
7. A text classification device, comprising:
the vector conversion module is used for obtaining a text to be classified, and word segmentation is carried out on the text to be classified to obtain word segmentation words; converting the word segmentation words into vectors to obtain word segmentation word vectors;
the attention weighting module is used for carrying out attention weighting on the word segmentation word vectors based on a multi-head attention mechanism, and combining all the weighted word segmentation word vectors to obtain text characterization vectors;
and the text classification module is used for carrying out text classification on the text to be classified based on the text characterization vector to obtain a classification result.
8. The text classification apparatus of claim 7, wherein the text classification of the text to be classified based on the text token vector to obtain a classification result comprises:
acquiring a text class set of a text to be classified and a pre-constructed multi-layer perceptron, wherein output nodes of the multi-layer perceptron are in one-to-one correspondence with each text class of the text class set;
inputting the text characterization vector into the multi-layer perceptron, extracting the output value of each output node of the multi-layer perceptron, and obtaining the class characteristic value of the text class corresponding to the output node;
normalizing the category characteristic value of the text category by using a softmax function to obtain a characteristic probability value of the text category;
and screening all the text categories according to the characteristic probability value to obtain the classification result.
9. An electronic device, the electronic device comprising:
at least one processor; the method comprises the steps of,
a memory communicatively coupled to the at least one processor;
wherein the memory stores a computer program executable by the at least one processor to enable the at least one processor to perform the text classification method of any of claims 1 to 6.
10. A computer readable storage medium storing a computer program, wherein the computer program when executed by a processor implements the text classification method according to any one of claims 1 to 6.
CN202310554123.9A 2023-05-16 2023-05-16 Text classification method, device, equipment and storage medium Pending CN116595175A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310554123.9A CN116595175A (en) 2023-05-16 2023-05-16 Text classification method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310554123.9A CN116595175A (en) 2023-05-16 2023-05-16 Text classification method, device, equipment and storage medium

Publications (1)

Publication Number Publication Date
CN116595175A true CN116595175A (en) 2023-08-15

Family

ID=87607570

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310554123.9A Pending CN116595175A (en) 2023-05-16 2023-05-16 Text classification method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN116595175A (en)

Similar Documents

Publication Publication Date Title
CN113626606B (en) Information classification method, device, electronic equipment and readable storage medium
CN116720497B (en) Semantic analysis-based power grid document relevance hierarchical analysis method and system
CN113837631B (en) Employee evaluation method and device, electronic equipment and readable storage medium
CN113658002B (en) Transaction result generation method and device based on decision tree, electronic equipment and medium
CN113505273B (en) Data sorting method, device, equipment and medium based on repeated data screening
CN114840684A (en) Map construction method, device and equipment based on medical entity and storage medium
CN113157739B (en) Cross-modal retrieval method and device, electronic equipment and storage medium
CN114491047A (en) Multi-label text classification method and device, electronic equipment and storage medium
CN113868528A (en) Information recommendation method and device, electronic equipment and readable storage medium
CN116705304A (en) Multi-mode task processing method, device, equipment and medium based on image text
CN115982454A (en) User portrait based questionnaire pushing method, device, equipment and storage medium
CN113806540B (en) Text labeling method, text labeling device, electronic equipment and storage medium
CN113656690B (en) Product recommendation method and device, electronic equipment and readable storage medium
CN116595175A (en) Text classification method, device, equipment and storage medium
CN114723488B (en) Course recommendation method and device, electronic equipment and storage medium
CN113592606B (en) Product recommendation method, device, equipment and storage medium based on multiple decisions
CN115204158B (en) Data isolation application method and device, electronic equipment and storage medium
CN113706204B (en) Deep learning-based rights issuing method, device, equipment and storage medium
CN114757541B (en) Performance analysis method, device, equipment and medium based on training behavior data
CN114781833B (en) Capability assessment method, device and equipment based on business personnel and storage medium
CN114723523B (en) Product recommendation method, device, equipment and medium based on user capability image
CN116486972A (en) Electronic medical record generation method, device, equipment and storage medium
CN112214556B (en) Label generation method, label generation device, electronic equipment and computer readable storage medium
CN116578696A (en) Text abstract generation method, device, equipment and storage medium
CN116340466A (en) Text feature extraction method and device, electronic equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination