WO2020147409A1 - 一种文本分类方法、装置、计算机设备及存储介质 - Google Patents
一种文本分类方法、装置、计算机设备及存储介质 Download PDFInfo
- Publication number
- WO2020147409A1 WO2020147409A1 PCT/CN2019/118342 CN2019118342W WO2020147409A1 WO 2020147409 A1 WO2020147409 A1 WO 2020147409A1 CN 2019118342 W CN2019118342 W CN 2019118342W WO 2020147409 A1 WO2020147409 A1 WO 2020147409A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- classifier
- sentiment
- level
- word vector
- classifiers
- 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.)
- Ceased
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/30—Information retrieval; Database structures therefor; File system structures therefor of unstructured textual data
- G06F16/35—Clustering; Classification
Definitions
- the natural language processing field of this application relates to a text classification method, device, computer equipment and storage medium based on contextual word vectors and deep learning.
- connection classifier has the problems of excessive calculation, long training time, and insufficient accuracy and generalization ability.
- the purpose of this application is to provide a multi-loss function text classification method, device, computer equipment and storage medium, which are used to solve the problems existing in the prior art and have better learning and generalization capabilities.
- this application provides a method for text classification with multiple loss functions, which includes the following steps:
- S20 Input the word vectors in S10 to at least two sets of emotion classifiers for training. After the emotion classifiers train the word vectors, they output the respective fully connected layers to their respective loss functions. Each emotion The classifier selects different emotional characteristics according to different classification requirements of the business;
- S30 Cross-learn and update the sentiment classifier, according to the number of sentiment classifiers, add each loss function to LOSSes with equal weight as the overall loss function, and update the sentiment classifiers according to the overall loss function , Until the overall loss function no longer decreases.
- the present application also provides a text classification device, which includes
- the word vector building module which is used to convert the input text into a word vector form
- the word vector input module and the preliminary classification module are used to input the word vectors into at least two sets of sentiment classifiers respectively, and output the respective fully connected layers of the sentiment classifiers to their respective loss functions.
- the sentiment classifier selects different sentiment features according to different classification requirements of the business;
- the overall loss function acquisition and update module is used to add the weights of the loss functions to form LOSSes as the overall loss function, and update the sentiment classifiers based on the overall loss function until the overall loss function is no longer Until lowered.
- this application also provides a computer device, including a memory, a processor, and a computer program stored in the memory and capable of running on the processor.
- the processor implements the text classification method when the computer program is executed. The following steps:
- the word vector building module which is used to convert the input text into a word vector form
- the word vector input module and the preliminary classification module are used to input the word vectors into at least two sets of sentiment classifiers respectively, and output the respective fully connected layers of the sentiment classifiers to their respective loss functions.
- the sentiment classifier selects different sentiment features according to different classification requirements of the business;
- the overall loss function acquisition and update module is used to add the weights of the loss functions to form LOSSes as the overall loss function, and update the sentiment classifiers based on the overall loss function until the overall loss function is no longer Until lowered.
- the present application also provides a computer-readable storage medium on which a computer program is stored, and when the computer program is executed by a processor, the following steps of the entity identification and linking method are realized:
- the word vector building module which is used to convert the input text into a word vector form
- the word vector input module and the preliminary classification module are used to input the word vectors into at least two sets of sentiment classifiers respectively, and output the respective fully connected layers of the sentiment classifiers to their respective loss functions.
- the sentiment classifier selects different sentiment features according to different classification requirements of the business;
- the overall loss function acquisition and update module is used to add the weights of the loss functions to form LOSSes as the overall loss function, and update the sentiment classifiers based on the overall loss function until the overall loss function is no longer Until lowered.
- This application provides a text classification method, device, computer equipment, and storage medium, which converts text input into at least two branches.
- the sentiment classifier of each branch determines multiple sets of different sentiment features according to different classification requirements of the business.
- the sentiment classifiers are finally merged in the fully connected layer and trained with different independent loss functions, and then through the cross learning of multiple classifiers (that is, the sentiment classifiers are updated according to the overall loss function until the overall loss function No more reductions so far), the model of each channel can be updated at the same time, so it has higher accuracy. At the same time, it can predict the emotional collocations that have not appeared in the training set. Compared with the original model predicting n types, It can predict n*n emotional collocations, so it has good generalization ability.
- FIG. 1 is a flowchart of an embodiment of a text classification method according to this application.
- FIG. 3 is a schematic diagram of program modules of an embodiment of a text classification device of this application.
- FIG. 4 is a schematic diagram of the hardware structure of an embodiment of the text classification device of this application.
- This application discloses a method for text classification, which is based on multiple loss functions, as shown in Fig. 1, and includes the following steps:
- step S10 Construct a word vector and convert the input text into a vector form; in step S10, use the word2vec tool to obtain the text semantic word vector.
- the CBOW model is used, and the maximum language prediction model is realized by adjusting the value of the hidden matrix of the neural network.
- S20 Input the word vectors in S10 to at least two sets of emotion classifiers for training. After the emotion classifiers train the word vectors, they output the respective fully connected layers to their respective loss functions. Each emotion The classifier selects different emotion features according to different classification requirements of the business; among them, the loss function of each emotion classifier can be a cross-entropy loss function.
- S30 Cross-learn and update the sentiment classifier, according to the number of sentiment classifiers, add each loss function to LOSSes with equal weight as the overall loss function, and update the sentiment classifiers according to the overall loss function , Until the overall loss function no longer decreases.
- the text classification method provided in this application converts the text input into at least two branches.
- the sentiment classifier of each branch determines multiple sets of different sentiment features according to different classification requirements of the business, and the sentiment classifiers are finally merged in the fully connected layer And using different independent loss functions for training, and then through the cross learning of multiple classifiers can achieve multi-label classification, with better generalization or calibration.
- the above text classification method can update the models of multiple channels at the same time, so it has higher accuracy. At the same time, it can predict the emotion collocations that have not appeared in the training set, and respectively predict n kinds of phases with the original model. In comparison, it can predict n*n kinds of emotional collocations, so it has better generalization ability.
- a total of two sets of sentiment classifiers are set up, namely, the first-level sentiment classifier and the second-level sentiment classifier.
- the first-level sentiment classifier is used to classify the positive and negative sentiments of the input text; the second-level sentiment classifier is used to input the specific emotion of the text
- the text classification method shown in this embodiment includes the following steps:
- S21 Use the word vector in S11 as the input of the first-level emotion classifier and the second-level emotion classifier, and output the fully connected layer of the first-level emotion classifier and the second-level emotion classifier to their respective loss functions
- the first-level emotion classifier can be used to classify the positive and negative emotions of the input text; the second-level emotion classifier can be used to classify the specific emotion types of the input text; the first-level emotion classifier and the second-level emotion classifier perform word vectors After training, the respective fully connected layers are output to their respective loss functions.
- a first-level emotion classifier is established based on TextRNN and attention mechanism.
- TextCNN or TextRCNN can also be used instead of the above-mentioned TextRNN and attention scheme; a second-level emotion classifier is established based on TextCNN.
- TextRNN instead of the above TextCNN solution.
- TextCNN is composed of Conv and activation function, BN, and MaxPooling.
- Conv is a convolutional layer, which is used to capture the local correlation of text.
- the activation function is to add nonlinear transformation to the network to make the network universal BN is to prevent gradient dispersion so that the model can converge better and faster. Maxpooling maximizes local features and reduces the amount of calculation.
- ⁇ in X2 is the mean
- ⁇ is the variance, which is the mean and variance of a hidden variable of a selected sample in a certain calculation
- ⁇ and ⁇ in X3 are hyperparameters for offset and scaling.
- the fully connected layers of the first-level emotion classifier and the second-level emotion classifier are output to their respective loss functions.
- the loss of the first-level emotion classifier and the second-level emotion classifier The functions are all cross entropy loss functions.
- S31 Cross learning and update the first-level emotion classifier and the second-level emotion classifier: add the loss functions of the first-level emotion classifier and the second-level emotion classifier to LOSSes according to equal weight as the overall loss function, and then according to The overall loss function is to update the hyperparameters of the two channels of the first-level sentiment classifier and the second-level sentiment classifier until the overall loss function no longer decreases. At this time, the model converges and the training is completed. among them:
- Losses 0.5*Loss RNN +0.5*Loss CNN .
- Loss RNN and Loss CNN are the cross entropy of the first-level emotion classifier and the second-level emotion classifier, respectively.
- this method can update the models of the two channels at the same time, so it has higher accuracy, and this method can predict the emotional collocation that has not appeared in the training set, for example, there are 10 kinds of'sad + sadness' in the training set.
- Our two models predict 4 kinds respectively, then we can predict 4*4 kinds instead of 10 kinds, so it has better generalization ability.
- the text input is transformed into two branches, one of which is used to classify the positive and negative emotions of the text, and the other part is used to classify the specific emotion type (sadness, gentleness, etc.) of the text, and finally merge in the fully connected layer , Using two independent loss functions for training, and then through the cross learning of the two classifiers to achieve classification, so that it has a better learning ability, generalization ability; and in the case that the two channel classifications are similar A certain calibration effect can improve the accuracy of the model.
- the text classification method 10 may include or be divided into one or more program modules, and the one or more program modules are stored in storage. In the medium, and executed by one or more processors, to complete the application, and implement the above text classification device and method.
- the program module referred to in the present application refers to a series of computer program instruction segments that can complete specific functions, and is more suitable for describing the execution process of the text classification method 10 in the storage medium than the program itself. The following description will specifically introduce the functions of each program module in this embodiment:
- the application also discloses a text classification device, including
- the word vector construction module 11 is used to convert the input text into a word vector form.
- the word vector input module 21 is used to input the word vectors into at least two sets of sentiment classifiers, and output the respective fully connected layers of the sentiment classifiers to their respective loss functions.
- the sentiment classifier selects different sentiment features according to different classification requirements of the business.
- the overall loss function acquisition and update module is used to add the weights of the loss functions to form LOSSes as the overall loss function, and update the sentiment classifiers based on the overall loss function until the overall loss function is no longer Until lowered.
- the text classification device converts the text input into at least two branches.
- the sentiment classifier of each branch determines multiple sets of different sentiment features according to different classification requirements of the business, and the sentiment classifiers are finally merged in the fully connected layer And use different independent loss functions for training, and then through the cross learning of multiple classifiers to achieve classification, can update the models of two channels at the same time, so it has higher accuracy, and at the same time, it can predict that it does not appear in the training set Compared with the original model predicting n kinds of emotion collocations, it can predict n*n kinds of emotion collocations, so it has better generalization ability.
- word2vec is used to construct the word vector.
- word2vec tool to get text semantic word vector.
- the CBOW model is used, and the maximum language prediction model is realized by adjusting the value of the hidden matrix of the neural network.
- the loss functions in the word vector input module 21 are all cross-entropy loss functions.
- a first-level emotion classifier and a second-level emotion classifier are set, and the word vector in S1 is used as the input of the first-level emotion classifier and the second-level emotion classifier, and all The fully connected layers of the first-level emotion classifier and the second-level emotion classifier are output to their respective loss functions.
- the first-level emotion classifier can be used to classify the positive and negative emotions of the input text; the second-level emotion classifier can be used to classify the specific emotion types of the input text.
- TextCNN or TextRCNN can also be used instead of the above-mentioned TextRNN combined with the attention scheme; a secondary emotion classifier is established based on TextCNN, and in addition, TextRNN can also be used instead of the above-mentioned TextCNN scheme.
- u t tanh(W w h t +b w )
- W w , U w and b w are all Attention weights and biases.
- TextCNN is composed of Conv and activation function, BN, and MaxPooling.
- Conv is a convolutional layer, which is used to capture the local correlation of text.
- the activation function is to add nonlinear transformation to the network to make the network universal The ability to transform is enhanced.
- BN is to prevent gradient dispersion so that the model can converge better and faster.
- Maxpooling is to maximize local features and reduce the amount of calculation.
- Conv is used to convolve the input word vector.
- 1D filters of 6 sizes are selected for convolution.
- ⁇ in X2 is the mean value
- ⁇ is the variance
- ⁇ and ⁇ in X3 are hyperparameters of offset and scaling.
- the fully connected layers of the first-level emotion classifier and the second-level emotion classifier are output to their respective loss functions.
- the loss functions of the above-mentioned first-level emotion classifier and the second-level emotion classifier are all crosses Entropy loss function.
- the overall loss function acquisition and update module 31 cross-learn and update the first-level emotion classifier and the second-level emotion classifier: add the loss functions of the first-level emotion classifier and the second-level emotion classifier according to equal weight Into LOSSes as the overall loss function, where:
- Losses 0.5*Loss RNN +0.5*Loss CNN .
- the two classifiers are updated.
- the text input is transformed into two branches, one of which is used to classify the positive and negative emotions of the text, and the other part is used to classify the specific emotion type (sadness, gentleness, etc.) of the text, and finally merge in the fully connected layer , Using two independent loss functions for training, and then through the cross learning of the two classifiers to achieve classification, so that it has a better learning ability, generalization ability; and in the case that the two channel classifications are similar A certain calibration effect can improve the accuracy of the model.
- this embodiment also provides a computer device, such as a smart phone, a tablet computer, a notebook computer, a desktop computer, a rack server, a blade server, a tower server or a cabinet server ( Including independent servers, or server clusters composed of multiple servers) and so on.
- the computer device 20 in this embodiment at least includes but is not limited to: a memory 21 and a processor 22 that can be communicably connected to each other through a system bus, as shown in FIG. 3. It should be pointed out that FIG. 3 only shows the computer device 20 with components 21-22, but it should be understood that it is not required to implement all the components shown, and more or fewer components may be implemented instead.
- the memory 21 (ie, readable storage medium) includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), Read only memory (ROM), electrically erasable programmable read only memory (EEPROM), programmable read only memory (PROM), magnetic memory, magnetic disk, optical disk, etc.
- the memory 21 may be an internal storage unit of the computer device 20, such as a hard disk or memory of the computer device 20.
- the memory 21 may also be an external storage device of the computer device 20, for example, a plug-in hard disk, a smart media card (SMC), and a secure digital (Secure Digital, SD) card, flash card (Flash Card), etc.
- the memory 21 may also include both the internal storage unit of the computer device 20 and its external storage device.
- the memory 21 is generally used to store an operating system and various application software installed in the computer device 20, such as the program code of the text classification apparatus 10 in the first embodiment.
- the memory 21 can also be used to temporarily store various types of data that have been output or will be output.
- the processor 22 may be a central processing unit (Central Processing Unit, CPU), a controller, a microcontroller, a microprocessor, or other data processing chips in some embodiments.
- the processor 22 is generally used to control the overall operation of the computer device 20.
- the processor 22 is used to run the program code or process data stored in the memory 21, for example, to run the text classification device 10, so as to implement the text classification device method of the first embodiment.
- this embodiment also provides a computer-readable storage medium, such as flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), random access memory (RAM), static random access Memory (SRAM), Read-Only Memory (ROM), Electrically Erasable Programmable Read-Only Memory (EEPROM), Programmable Read-Only Memory (PROM), Magnetic Memory, Disk, Optical Disk, Server, App Store, etc.
- a computer program is stored on it, and when the program is executed by the processor, the corresponding function is realized.
- the computer-readable storage medium of this embodiment is used to store the text classification device 10, and when executed by a processor, it implements the text classification device method of the first embodiment.
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Data Mining & Analysis (AREA)
- Databases & Information Systems (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
一种文本分类方法、装置、计算机设备及存储介质,包括以下步骤:S10:构建词向量,将输入文本转化为向量形式;S20:将S10中的词向量分别输入到至少两组情感分类器中,并将所述情感分类器的各自全连接层输出到各自的loss函数中,各所述情感分类器根据业务不同的分类需求选择不同情感特征;S30:交叉学习并更新所述情感分类器,根据所述情感分类器的数量,将各所述loss函数按照等权重加成到LOSSes中作为整体损失函数,通过多个分类器的交叉学习可以实现多标签分类,具有更好的泛化或者是校准作用。
Description
本申请申明享有2019年01月14日递交的申请号为CN201910038962.9、名称为“一种文本分类方法、装置、计算机设备及存储介质”的中国专利申请的优先权,该中国专利申请的整体内容以参考的方式结合在本申请中。
本申请自然语言处理领域,涉及一种基于语境词向量和深度学习的文本分类方法、装置、计算机设备及存储介质。
在互联网快速发展的今天,互联网信息呈现爆炸式增长,情感分析或意见挖掘已经渗入到人们生活的方方面面,京东、淘宝、亚马逊等互联网在线购物平台,在线音乐平台、微博、推特等社交网站、新闻传媒以及政治选举等等。例如,网上购物已经成了人们生活的潮流,针对用户在购物网站的评论进行观点挖掘及情感分析,不仅可以帮助用户更好的了解和选购产品,还能帮助产品制造商理解用户的需求,改进自身产品;在微博中,同样也可以对热搜事件中用户的观点和情感进行挖掘和处理,从而观察出现代人们的生活品质、爱好等
现阶段对于文本分类,如情感分析等大多是某一方面的分类,通过为每一个分类构建一个单独的模型实习,对于多个方面的分类大多需要采用多个模型或是多个全连接层去连接分类器,存在计算量过大,训练时间耗时久,且精度和泛化能力也达不到需求的问题。
发明内容
本申请的目的是提供一种多损失函数文本分类方法、装置、计算机设备及存储介质,用于解决现有技术存在的问题,具备了更好的学习及泛化能力。
为实现上述目的,本申请提供一种多损失函数文本分类方法,包括以下步骤:
S10:构建词向量,将输入文本转化为词向量形式;
S20:将S10中的词向量分别输入到至少两组情感分类器进行训练,所述情感分类器对所述词向量进行训练后,将各自全连接层分别输出到各自的loss函数中,各情感分类器根据业务不同的分类需求选择不同情感特征;
S30:交叉学习并更新情感分类器,根据情感分类器的数量,将各loss函数按照等权重加成到LOSSes中作为整体损失函数,并根据所述整体损失函数对所述各情感分类器进行更新,直到整体损失函数不再降低为止。
为实现上述目的,本申请还提供一种文本分类装置,其包括
词向量构建模块,其用于将输入文本转化为词向量形式;
词向量输入模块,初步分类模块,其用于所述词向量分别输入到至少两组情感分类器中,并将所述情感分类器的各自全连接层输出到各自的loss函数中,各所述情感分类器根据业务不同的分类需求选择不同情感特征;
整体损失函数获取及更新模块,用于将各所述loss函数等权重加成形成LOSSes作为整体损失函数,并基于所述整体损失函数对所述各情感分类器进行更新,直到整体损失函数不再降低为止。
为实现上述目的,本申请还提供一种计算机设备,包括存储器、处理器以及存储在存储器上并可在处理器上运行的计算机程序,所述处理器执行所述计算机程序时实现文本分类方法的以下步骤:
词向量构建模块,其用于将输入文本转化为词向量形式;
词向量输入模块,初步分类模块,其用于所述词向量分别输入到至少两组情感分类器中,并将所述情感分类器的各自全连接层输出到各自的loss函数中,各所述情感分类器根据业务不同的分类需求选择不同情感特征;
整体损失函数获取及更新模块,用于将各所述loss函数等权重加成形成 LOSSes作为整体损失函数,并基于所述整体损失函数对所述各情感分类器进行更新,直到整体损失函数不再降低为止。
为实现上述目的,本申请还提供计算机可读存储介质,其上存储有计算机程序,所述计算机程序被处理器执行时实现实体识别与链接方法的以下步骤:
词向量构建模块,其用于将输入文本转化为词向量形式;
词向量输入模块,初步分类模块,其用于所述词向量分别输入到至少两组情感分类器中,并将所述情感分类器的各自全连接层输出到各自的loss函数中,各所述情感分类器根据业务不同的分类需求选择不同情感特征;
整体损失函数获取及更新模块,用于将各所述loss函数等权重加成形成LOSSes作为整体损失函数,并基于所述整体损失函数对所述各情感分类器进行更新,直到整体损失函数不再降低为止。
本申请提供一种文本分类方法、装置、计算机设备及存储介质,将文本输入后转化为至少两个分支,每个分支的情感分类器根据业务不同的分类需求确定多组不同的情感特征,各情感分类器最终汇合在全连接层且采用不同独立的损失函数进行训练,再通过多个分类器的交叉学习(即根据所述整体损失函数对所述各情感分类器进行更新,直到整体损失函数不再降低为止过),可以同时对各通道的模型进行更新因此具有更高的精准度,同时,其可以预测训练集中未出现过的情感搭配,与原有的模型分别预测n种相比较,其可以预测n*n种情感搭配,因此具有较好的泛化能力。
图1为本申请一种文本分类方法一实施例的流程图;
图2为本申请一种文本分类方法另一实施例的流程图;
图3为本申请一种文本分类装置的一实施例程序模块示意图;
图4为本申请文本分类装置一实施例的硬件结构示意图。
为了使本申请申请的目的、技术方案及优点更加清楚明白,以下结合附图及实施例,对本申请申请进行进一步详细说明。应当理解,此处所描述的具体实施例仅用以解释本申请申请,并不用于限定本申请申请。基于本申请申请中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本申请申请保护的范围。
实施例一
本申请公开了一种文本分类方法中,其基于多损失函数进行,如图1所示,包括以下步骤:
S10:构建词向量,将输入文本转化为向量形式;步骤S10中,利用word2vec工具得到文本语义词向量。本实施例中,使用的是CBOW模型,通过调整神经网络的隐藏矩阵的值来实现最大化的语言预测模型。
S20:将S10中的词向量分别输入到至少两组情感分类器进行训练,所述情感分类器对所述词向量进行训练后,将各自全连接层分别输出到各自的loss函数中,各情感分类器根据业务不同的分类需求选择不同情感特征;其中,各情感分类器的loss函数可为交叉熵损失函数。
S30:交叉学习并更新情感分类器,根据情感分类器的数量,将各loss函数按照等权重加成到LOSSes中作为整体损失函数,并根据所述整体损失函数对所述各情感分类器进行更新,直到整体损失函数不再降低为止。
本申请提供的文本分类方法,将文本输入后转化为至少两个分支,每个分支的情感分类器根据业务不同的分类需求确定多组不同的情感特征,各情感分类器最终汇合在全连接层且采用不同独立的损失函数进行训练,再通过多个分类器的交叉学习可以实现多标签分类,具有更好的泛化或者是校准。具体而言上述文本 分类方法可以同时对多个通道的模型进行更新,因此具有更高的精准度,同时,其可以预测训练集中未出现过的情感搭配,与原有的模型分别预测n种相比较,其可以预测n*n种情感搭配,因此具有较好的泛化能力。
作为一优选方案,共设置两组情感分类器,即一级情感分类器与二级情感分类器,一级情感分类器用于输入文本的情感正负分类;二级情感分类器用于输入文本具体情绪类型的分类,则请参阅图2,本实施例的所示的文本分类方法,包括如下步骤:
S11:构建词向量,将输入文本转化为向量形式。
S21:将S11中的词向量作为一级情感分类器与二级情感分类器的输入,并将一级情感分类器与二级情感分类器全连接层输出到各自的loss函数中,
本实施例中,一级情感分类器可用于输入文本的情感正负分类;二级情感分类器可用于输入文本具体情绪类型的分类;一级情感分类器与二级情感分类器对词向量进行训练后,将各自全连接层分别输出到各自的loss函数中。
本实施例中,步骤S21,基于TextRNN结合attention机制建立一级情感分类器,此外,也可使用TextCNN或TextRCNN代替上述TextRNN结合attention方案;基于TextCNN建立二级情感分类器,此外,也可使用TextRNN代替上述TextCNN方案。
在基于TextRNN结合attention机制建立一级情感分类器中,对TextRNN中每一个节点h
t分配了权重αt,使其权重值使其更新为h
newt=α
t*h
t,以为编码的词向量进行权重加成,权重αt为:
其中,u
w与u
t为需要设置的权重,二者确定方法相同,u
t=tanh(W
wh
t+b
w),W
w、与b
w为Attention的权重与bias。
在基于TextCNN建立二级情感分类器,TextCNN由Conv与激活函数、BN、 MaxPooling组成,其中,Conv为卷积层,用于捕捉文本局部相关性,激活函数为了给网络添加非线性变换使网络泛化能力增强,BN是为了防止梯度弥散使模型可以收敛更好更快,Maxpooling为了最大化局部特征以及减少计算量,具体步骤如下:
(1)使用Conv对输入的词向量进行卷积操作,本实施例中,选取6种size(长度)的1D filter进行卷积。
(2)卷积后进行BN也就是批归一化,具体计算公式为:
X1=W*X
X3=γ*X2+β
其中X2中的μ为均值,σ为方差,即为某次计算选取样本的某个隐藏变量下的均值与方差,X3中γ与β为偏移与放缩的超参数。
(3)进入激活函数,激活函数我们选用Relu激活函数。
(4)进入Maxpooling即池化层,该部分选取向量中最大的值最为代表输出。
当S21中的词向量分别经过上述处理后,将一级情感分类器与二级情感分类器的全连接层输出到各自的loss函数中,上述一级情感分类器与二级情感分类器的loss函数均为交叉熵损失函数。
S31:交叉学习并更新一级情感分类模器与二级情感分类器:将一级情感分类器与二级情感分类器的各loss函数按照等权重加成到LOSSes中作为整体损失函数,然后根据整体损失函数,更新一级情感分类模器与二级情感分类器两个通道的超参数,直到整体损失函数不再降低为止,此时,模型收敛,训练完成。其中:
Losses=0.5*Loss
RNN+0.5*Loss
CNN。
即通过添加了损失函数LOSSes(两个损失函数加权和),更新两个分类器,其中Loss
RNN与Loss
CNN分别为一级情感分类器与二级情感分类器的交叉熵。
采用此方法可以同时对两个通道的模型进行更新因此具有更高的精准度,且该方法可以预测训练集中未出现过的情感搭配,比方说训练集有‘悲伤+哀怨’等10种,而我们的两个模型分别预测4种,那么我们可以预测4*4种而不是10种,因此具有较好的泛化能力。
上述实施例中,将文本输入后转化为两个分支,其中一个用于文本的情感正负分类,另一部分用于文本的具体情绪类型(悲伤、平缓等)的分类,最终汇合在全连接层,采用两个独立的损失函数进行训练,再通过两个分类器的交叉学习可以实现分类,从而具备了更好的学习能力、泛化能力;且在两条通道分类有相似的情况下还具备了一定的校准作用,对于模型的准确率有一定的提升。
实施例二
请继续参阅图2,本实施例示出了一种文本分类方法,在本实施例中,文本分类方法10可以包括或被分割成一个或多个程序模块,一个或者多个程序模块被存储于存储介质中,并由一个或多个处理器所执行,以完成本申请,并可实现上述文本分类装置方法。本申请所称的程序模块是指能够完成特定功能的一系列计算机程序指令段,比程序本身更适合于描述文本分类方法10在存储介质中的执行过程。以下描述将具体介绍本实施例各程序模块的功能:
本申请还公开了一种文本分类装置,包括
词向量构建模块11,其用于将输入文本转化为词向量形式。
词向量输入模块21,初步分类模块,其用于所述词向量分别输入到至少两组情感分类器中,并将所述情感分类器的各自全连接层输出到各自的loss函数中,各所述情感分类器根据业务不同的分类需求选择不同情感特征。
整体损失函数获取及更新模块,用于将各所述loss函数等权重加成形成LOSSes作为整体损失函数,并基于所述整体损失函数对所述各情感分类器进行更新,直到整体损失函数不再降低为止。
本申请提供的文本分类装置,将文本输入后转化为至少两个分支,每个分支 的情感分类器根据业务不同的分类需求确定多组不同的情感特征,各情感分类器最终汇合在全连接层且采用不同独立的损失函数进行训练,再通过多个分类器的交叉学习可以实现分类,可以同时对两个通道的模型进行更新因此具有更高的精准度,同时,其可以预测训练集中未出现过的情感搭配,与原有的模型分别预测n种相比较,其可以预测n*n种情感搭配,因此具有较好的泛化能力。
作用一优选方案,词向量构建模块11中,使用word2vec构建词向量。利用word2vec工具得到文本语义词向量。本实施例中,使用的是CBOW模型,通过调整神经网络的隐藏矩阵的值来实现最大化的语言预测模型。
作用一优选方案,词向量输入模块21中loss函数均为交叉熵损失函数。
作用一优选方案,词向量输入模块21中,设置一级情感分类器与二级情感分类器,所述S1中的词向量作为一级情感分类器与二级情感分类器的输入,并将所述一级情感分类器与二级情感分类器全连接层输出到各自的loss函数中。本实施例中,一级情感分类器可用于输入文本的情感正负分类;二级情感分类器可用于输入文本具体情绪类型的分类。
更进一步的,词向量输入模块21中,此外,也可使用TextCNN或TextRCNN代替上述TextRNN结合attention方案;基于TextCNN建立二级情感分类器,此外,也可使用TextRNN代替上述TextCNN方案。
在基于TextRNN结合attention机制建立一级情感分类器中,对TextRNN中每一个节点h
t分配了权重αt,使其权重值使其更新为h
newt=α
t*h
t,以为编码的词向量进行权重加成,权重αt为:
其中,u
t=tanh(W
wh
t+b
w),W
w、U
w与b
w均为Attention的权重与bias。
在基于TextCNN建立二级情感分类器,TextCNN由Conv与激活函数、BN、MaxPooling组成,其中,Conv为卷积层,用于捕捉文本局部相关性,激活函数 为了给网络添加非线性变换使网络泛化能力增强,BN是为了防止梯度弥散使模型可以收敛更好更快,Maxpooling为了最大化局部特征以及减少计算量,具体步骤如下
(1)使用Conv对输入的词向量进行卷积操作,本实施例中,选取6种size的1D filter进行卷积。
(2)卷积后进行BN也就是批归一化,具体计算公式为:
X1=W*X
X3=γ*X2+β
其中X2中的μ为均值,σ为方差,X3中γ与β为偏移与放缩的超参数。
(3)进入激活函数,激活函数我们选用Relu激活函数,
(4)进入Maxpooling即池化层,该部分选取向量中最大的值最为代表输出。
词向量分别经过上述处理后,将一级情感分类器与二级情感分类器的全连接层输出到各自的loss函数中,上述一级情感分类器与二级情感分类器的loss函数均为交叉熵损失函数。
相应的,整体损失函数获取及更新模块31中:交叉学习并更新一级情感分类模器与二级情感分类器:将一级情感分类器与二级情感分类器的各loss函数按照等权重加成到LOSSes中作为整体损失函数,其中:
Losses=0.5*Loss
RNN+0.5*Loss
CNN。
即通过添加了损失函数LOSSes(两个损失函数加权和),更新两个分类器。
上述实施例中,将文本输入后转化为两个分支,其中一个用于文本的情感正负分类,另一部分用于文本的具体情绪类型(悲伤、平缓等)的分类,最终汇合在全连接层,采用两个独立的损失函数进行训练,再通过两个分类器的交叉学习可以实现分类,从而具备了更好的学习能力、泛化能力;且在两条通道分类有相似的情况下还具备了一定的校准作用,对于模型的准确率有一定的提升。
实施例三
如图3所示,本实施例还提供一种计算机设备,如可以执行程序的智能手机、平板电脑、笔记本电脑、台式计算机、机架式服务器、刀片式服务器、塔式服务器或机柜式服务器(包括独立的服务器,或者多个服务器所组成的服务器集群)等。本实施例的计算机设备20至少包括但不限于:可通过系统总线相互通信连接的存储器21、处理器22,如图3所示。需要指出的是,图3仅示出了具有组件21-22的计算机设备20,但是应理解的是,并不要求实施所有示出的组件,可以替代的实施更多或者更少的组件。
本实施例中,存储器21(即可读存储介质)包括闪存、硬盘、多媒体卡、卡型存储器(例如,SD或DX存储器等)、随机访问存储器(RAM)、静态随机访问存储器(SRAM)、只读存储器(ROM)、电可擦除可编程只读存储器(EEPROM)、可编程只读存储器(PROM)、磁性存储器、磁盘、光盘等。在一些实施例中,存储器21可以是计算机设备20的内部存储单元,例如该计算机设备20的硬盘或内存。在另一些实施例中,存储器21也可以是计算机设备20的外部存储设备,例如该计算机设备20上配备的插接式硬盘,智能存储卡(Smart Media Card,SMC),安全数字(Secure Digital,SD)卡,闪存卡(Flash Card)等。当然,存储器21还可以既包括计算机设备20的内部存储单元也包括其外部存储设备。本实施例中,存储器21通常用于存储安装于计算机设备20的操作系统和各类应用软件,例如实施例一的文本分类装置装置10的程序代码等。此外,存储器21还可以用于暂时地存储已经输出或者将要输出的各类数据。
处理器22在一些实施例中可以是中央处理器(Central Processing Unit,CPU)、控制器、微控制器、微处理器、或其他数据处理芯片。该处理器22通常用于控制计算机设备20的总体操作。本实施例中,处理器22用于运行存储器21中存储的程序代码或者处理数据,例如运行文本分类装置装置10,以实现实施例一的文本分类装置方法。
实施例四
如图4所示,本实施例还提供一种计算机可读存储介质,如闪存、硬盘、多媒体卡、卡型存储器(例如,SD或DX存储器等)、随机访问存储器(RAM)、静态随机访问存储器(SRAM)、只读存储器(ROM)、电可擦除可编程只读存储器(EEPROM)、可编程只读存储器(PROM)、磁性存储器、磁盘、光盘、服务器、App应用商城等等,其上存储有计算机程序,程序被处理器执行时实现相应功能。本实施例的计算机可读存储介质用于存储文本分类装置装置10,被处理器执行时实现实施例一的文本分类装置方法。
上述本申请实施例序号仅仅为了描述,不代表实施例的优劣。
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到上述实施例方法可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件,但很多情况下前者是更佳的实施方式。
以上仅为本申请的优选实施例,并非因此限制本申请的专利范围,凡是利用本申请说明书及附图内容所作的等效结构或等效流程变换,或直接或间接运用在其他相关的技术领域,均同理包括在本申请的专利保护范围内。
Claims (20)
- 一种文本分类方法,其特征在于,包括以下步骤:S10:构建词向量,将输入文本转化为词向量形式;S20:将S10中的词向量分别输入到至少两组情感分类器进行训练,所述情感分类器对所述词向量进行训练后,将各自全连接层分别输出到各自的loss函数中,各情感分类器根据业务不同的分类需求选择不同情感特征;S30:交叉学习并更新情感分类器,根据情感分类器的数量,将各loss函数按照等权重加成到LOSSes中作为整体损失函数,并基于所述整体损失函数对所述各情感分类器进行更新,直到整体损失函数不再降低为止。
- 根据权利要求1所述的文本分类方法,其特征在于,所述步骤S10中,使用word2vec构建词向量。
- 根据权利要求1所述的文本分类方法,其特征在于,所述步骤S20中,设置一级情感分类器与二级情感分类器,所述S10中的词向量作为一级情感分类器与二级情感分类器的输入,并将所述一级情感分类器与二级情感分类器全连接层输出到各自的loss函数中。
- 根据权利要求3所述的文本分类方法,其特征在于,所述步骤S20中,所述基于TextRNN结合attention机制建立一级情感分类器;和/或,基于TextCNN建立所述二级情感分类器。
- 根据权利要求3所述的文本分类方法,其特征在于,步骤S30中,LOSSes为:Losses=0.5*Loss RNN+0.5*Loss CNN。
- 根据权利要求1或3所述的文本分类方法,其特征在于:所述loss函数均为交叉熵损失函数。
- 一种文本分类装置,其特征在于:包括词向量构建模块,其用于将输入文本转化为词向量形式;词向量输入模块,初步分类模块,其用于所述词向量分别输入到至少两组情感分类器中,并将所述情感分类器的各自全连接层输出到各自的loss函数中,各所述情感分类器根据业务不同的分类需求选择不同情感特征;整体损失函数获取及更新模块,用于将各所述loss函数等权重加成形成LOSSes作为整体损失函数,并基于所述整体损失函数对所述各情感分类器进行更新,直到整体损失函数不再降低为止。
- 根据权利要求8所述文本分类装置,其特征在于,所述词向量构建模块中,使用word2vec构建词向量。
- 根据权利要求8所述文本分类装置,其特征在于,所述词向量输入模块中,设置一级情感分类器与二级情感分类器,所述词向量作为一级情感分类器与二级情感分类器的输入,并将所述一级情感分类器与二级情感分类器全连接层输出到各自的loss函数中。
- 根据权利要求8所述文本分类装置,其特征在于,所述词向量输入模块中,所述基于TextRNN结合attention机制建立一级情感分类器;和/或,基于TextCNN建立所述二级情感分类器。
- 根据权利要求8所述文本分类装置,其特征在于,所述整体损失函数获取及更新模块中,LOSSes为:Losses=0.5*Loss RNN+0.5*Loss CNN。
- 根据权利要求8所述文本分类装置,其特征在于,所述loss函数均为交叉熵损失函数。
- 一种计算机设备,包括存储器、处理器以及存储在存储器上并可在处理器上运行的计算机程序,所述处理器执行所述计算机程序时实现文本分类方法的以下步骤:构建词向量,将输入文本转化为词向量形式;将所述词向量分别输入到至少两组情感分类器进行训练,所述情感分类器对所述词向量进行训练后,将各自全连接层分别输出到各自的loss函数中,各情感分类器根据业务不同的分类需求选择不同情感特征;交叉学习并更新情感分类器,根据情感分类器的数量,将各loss函数按照等权重加成到LOSSes中作为整体损失函数,并基于所述整体损失函数对所述各情感分类器进行更新,直到整体损失函数不再降低为止。
- 根据权利要求15所述计算机设备,其特征在于,设置一级情感分类器与二级情感分类器,所述词向量作为一级情感分类器与二级情感分类器的输入,并将所述一级情感分类器与二级情感分类器全连接层输出到各自的loss函数中。
- 一种计算机可读存储介质,其上存储有计算机程序,其特征在于:所述计算机程序被处理器执行时实现文本分类方法的以下步骤:构建词向量,将输入文本转化为词向量形式;将所述词向量分别输入到至少两组情感分类器进行训练,所述情感分类器对所述词向量进行训练后,将各自全连接层分别输出到各自的loss函数中,各情感分类器根据业务不同的分类需求选择不同情感特征;交叉学习并更新情感分类器,根据情感分类器的数量,将各loss函数按照等权重加成到LOSSes中作为整体损失函数,并基于所述整体损失函数对所述各情感分类器进行更新,直到整体损失函数不再降低为止。
- 根据权利要求18所述计算机可读存储介质,其特征在于,设置一级情感分类器与二级情感分类器,所述词向量作为一级情感分类器与二级情感分类器的输入,并将所述一级情感分类器与二级情感分类器全连接层输出到各自的loss函数中。
Applications Claiming Priority (2)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201910038962.9A CN109918499A (zh) | 2019-01-14 | 2019-01-14 | 一种文本分类方法、装置、计算机设备及存储介质 |
| CN201910038962.9 | 2019-01-14 |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| WO2020147409A1 true WO2020147409A1 (zh) | 2020-07-23 |
Family
ID=66960273
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| PCT/CN2019/118342 Ceased WO2020147409A1 (zh) | 2019-01-14 | 2019-11-14 | 一种文本分类方法、装置、计算机设备及存储介质 |
Country Status (2)
| Country | Link |
|---|---|
| CN (1) | CN109918499A (zh) |
| WO (1) | WO2020147409A1 (zh) |
Families Citing this family (9)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| WO2019216504A1 (ko) * | 2018-05-09 | 2019-11-14 | 한국과학기술원 | 인간 감정 인식을 위한 딥 생리적 정서 네트워크를 이용한 인간 감정 추정 방법 및 그 시스템 |
| CN109918499A (zh) * | 2019-01-14 | 2019-06-21 | 平安科技(深圳)有限公司 | 一种文本分类方法、装置、计算机设备及存储介质 |
| CN110309308A (zh) * | 2019-06-27 | 2019-10-08 | 北京金山安全软件有限公司 | 一种文字信息的分类方法、装置及电子设备 |
| CN110297907B (zh) * | 2019-06-28 | 2022-03-08 | 谭浩 | 生成访谈报告的方法、计算机可读存储介质和终端设备 |
| CN110489545A (zh) * | 2019-07-09 | 2019-11-22 | 平安科技(深圳)有限公司 | 文本分类方法及装置、存储介质、计算机设备 |
| CN110442723B (zh) * | 2019-08-14 | 2020-05-15 | 山东大学 | 一种基于多步判别的Co-Attention模型用于多标签文本分类的方法 |
| CN110837561A (zh) * | 2019-11-18 | 2020-02-25 | 苏州朗动网络科技有限公司 | 文本的分析方法、设备和存储介质 |
| CN112446217B (zh) * | 2020-11-27 | 2024-05-28 | 广州三七互娱科技有限公司 | 情感分析方法、装置及电子设备 |
| CN114564577B (zh) * | 2022-01-25 | 2026-03-10 | 有米科技股份有限公司 | 一种文本特征信息识别方法及装置 |
Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN107608956A (zh) * | 2017-09-05 | 2018-01-19 | 广东石油化工学院 | 一种基于cnn‑grnn的读者情绪分布预测算法 |
| CN107908635A (zh) * | 2017-09-26 | 2018-04-13 | 百度在线网络技术(北京)有限公司 | 建立文本分类模型以及文本分类的方法、装置 |
| CN108460089A (zh) * | 2018-01-23 | 2018-08-28 | 哈尔滨理工大学 | 基于Attention神经网络的多元特征融合中文文本分类方法 |
| CN108595601A (zh) * | 2018-04-20 | 2018-09-28 | 福州大学 | 一种融入Attention机制的长文本情感分析方法 |
| CN109918499A (zh) * | 2019-01-14 | 2019-06-21 | 平安科技(深圳)有限公司 | 一种文本分类方法、装置、计算机设备及存储介质 |
Family Cites Families (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN108108351B (zh) * | 2017-12-05 | 2020-05-22 | 华南理工大学 | 一种基于深度学习组合模型的文本情感分类方法 |
| CN108596470A (zh) * | 2018-04-19 | 2018-09-28 | 浙江大学 | 一种基于TensorFlow框架的电力设备缺陷文本处理方法 |
| CN108960317B (zh) * | 2018-06-27 | 2021-09-28 | 哈尔滨工业大学 | 基于词向量表示和分类器联合训练的跨语言文本分类方法 |
| CN109034281A (zh) * | 2018-07-18 | 2018-12-18 | 中国科学院半导体研究所 | 加速基于卷积神经网络的中文手写体识别的方法 |
| GB201818237D0 (en) * | 2018-11-08 | 2018-12-26 | Polyal | A dialogue system, a dialogue method, a method of generating data for training a dialogue system, a system for generating data for training a dialogue system |
-
2019
- 2019-01-14 CN CN201910038962.9A patent/CN109918499A/zh active Pending
- 2019-11-14 WO PCT/CN2019/118342 patent/WO2020147409A1/zh not_active Ceased
Patent Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN107608956A (zh) * | 2017-09-05 | 2018-01-19 | 广东石油化工学院 | 一种基于cnn‑grnn的读者情绪分布预测算法 |
| CN107908635A (zh) * | 2017-09-26 | 2018-04-13 | 百度在线网络技术(北京)有限公司 | 建立文本分类模型以及文本分类的方法、装置 |
| CN108460089A (zh) * | 2018-01-23 | 2018-08-28 | 哈尔滨理工大学 | 基于Attention神经网络的多元特征融合中文文本分类方法 |
| CN108595601A (zh) * | 2018-04-20 | 2018-09-28 | 福州大学 | 一种融入Attention机制的长文本情感分析方法 |
| CN109918499A (zh) * | 2019-01-14 | 2019-06-21 | 平安科技(深圳)有限公司 | 一种文本分类方法、装置、计算机设备及存储介质 |
Also Published As
| Publication number | Publication date |
|---|---|
| CN109918499A (zh) | 2019-06-21 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| WO2020147409A1 (zh) | 一种文本分类方法、装置、计算机设备及存储介质 | |
| WO2020224219A1 (zh) | 中文分词方法、装置、电子设备及可读存储介质 | |
| CN112199954B (zh) | 基于语音语义的疾病实体匹配方法、装置及计算机设备 | |
| CN110162766B (zh) | 词向量更新方法和装置 | |
| CN113722438B (zh) | 基于句向量模型的句向量生成方法、装置及计算机设备 | |
| WO2022048363A1 (zh) | 网站分类方法、装置、计算机设备及存储介质 | |
| WO2021051574A1 (zh) | 英文文本序列标注方法、系统及计算机设备 | |
| CN118134529B (zh) | 基于大数据的计算机数据处理方法及系统 | |
| CN111126067B (zh) | 实体关系抽取方法及装置 | |
| US20190065587A1 (en) | Page journey determination from web event journals | |
| CN112995414B (zh) | 基于语音通话的行为质检方法、装置、设备及存储介质 | |
| CN112926308B (zh) | 匹配正文的方法、装置、设备、存储介质以及程序产品 | |
| CN118485502B (zh) | 个性定制商品标签的生成方法、装置、设备及存储介质 | |
| CN115730597A (zh) | 多级语义意图识别方法及其相关设备 | |
| CN115329825A (zh) | 模型训练方法、系统、设备及计算机可读存储介质 | |
| CN114528837A (zh) | 意图识别方法、装置、计算机设备及存储介质 | |
| CN114359928B (zh) | 一种电子发票识别方法、装置、计算机设备及存储介质 | |
| CN111639164A (zh) | 问答系统的问答匹配方法、装置、计算机设备及存储介质 | |
| CN120163632A (zh) | 产品推荐策略生成方法、装置、计算机设备及存储介质 | |
| CN120688606A (zh) | 文本处理方法、装置、电子设备及介质 | |
| CN112732913A (zh) | 一种非均衡样本的分类方法、装置、设备及存储介质 | |
| CN115758211B (zh) | 文本信息分类方法、装置、电子设备和存储介质 | |
| CN114238574B (zh) | 基于人工智能的意图识别方法及其相关设备 | |
| CN116680401A (zh) | 文档处理方法、文档处理装置、设备及存储介质 | |
| CN117150317A (zh) | 一种新词确定方法、装置、终端设备和存储介质 |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| 121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 19909782 Country of ref document: EP Kind code of ref document: A1 |
|
| NENP | Non-entry into the national phase |
Ref country code: DE |
|
| 122 | Ep: pct application non-entry in european phase |
Ref document number: 19909782 Country of ref document: EP Kind code of ref document: A1 |





