WO2021081837A1 - Model construction method, classification method, apparatus, storage medium and electronic device - Google Patents

Model construction method, classification method, apparatus, storage medium and electronic device Download PDF

Info

Publication number
WO2021081837A1
WO2021081837A1 PCT/CN2019/114473 CN2019114473W WO2021081837A1 WO 2021081837 A1 WO2021081837 A1 WO 2021081837A1 CN 2019114473 W CN2019114473 W CN 2019114473W WO 2021081837 A1 WO2021081837 A1 WO 2021081837A1
Authority
WO
WIPO (PCT)
Prior art keywords
matrix
label
text
level
primary
Prior art date
Application number
PCT/CN2019/114473
Other languages
French (fr)
Chinese (zh)
Inventor
刘园林
Original Assignee
深圳市欢太科技有限公司
Oppo广东移动通信有限公司
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 深圳市欢太科技有限公司, Oppo广东移动通信有限公司 filed Critical 深圳市欢太科技有限公司
Priority to PCT/CN2019/114473 priority Critical patent/WO2021081837A1/en
Priority to CN201980098836.0A priority patent/CN114175017A/en
Publication of WO2021081837A1 publication Critical patent/WO2021081837A1/en

Links

Images

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

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

A model construction method, a classification method, an apparatus, a storage medium and an electronic device. The model construction method comprises: determining a target loss value according to a first-level label prediction matrix, a first-level label reference matrix, a target matrix and a second-level label reference matrix; and once the training of a batch of data to be trained is completed, obtaining one target loss value, and each time one target loss value is obtained, passing the target loss value back to a model to be trained, so as to adjust parameters of the model to be trained until the model to be trained converges.

Description

模型构建方法、分类方法、装置、存储介质及电子设备Model construction method, classification method, device, storage medium and electronic equipment 技术领域Technical field
本申请属于电子技术领域,尤其涉及一种模型构建方法、分类方法、装置、存储介质及电子设备。This application belongs to the field of electronic technology, and in particular relates to a model construction method, classification method, device, storage medium, and electronic equipment.
背景技术Background technique
随着电子技术的不断发展,安装于智能手机或者平板电脑等电子设备中的应用程序(Application,APP)的数量越来越多。在用户使用上述APP的过程中,往往会涉及到信息流业务。信息流业务是指向上述电子设备推送信息流数据的业务。其中,信息流数据用于形成首页、列表页或者内容页等页面。With the continuous development of electronic technology, the number of applications (APP) installed in electronic devices such as smart phones or tablet computers is increasing. In the process of users using the above APP, information flow services are often involved. The information flow service refers to the service of pushing information flow data to the above-mentioned electronic devices. Among them, the information flow data is used to form pages such as a home page, a list page, or a content page.
以信息流数据为文章为例,在向电子设备推送文章之前,需要对文章标记上一级标签、二级标签和三级标签等,以供信息流推荐算法使用,从而可向不同的电子设备推送不同的文章。Take information flow data as an example. Before pushing an article to an electronic device, the article needs to be marked with upper-level tags, second-level tags, and third-level tags for the information flow recommendation algorithm to use, so that it can be sent to different electronic devices. Push different articles.
发明内容Summary of the invention
本申请实施例提供一种模型构建方法、分类方法、装置、存储介质及电子设备,可以提高对一级标签和二级标签进行联合预测的准确率。The embodiments of the present application provide a model construction method, classification method, device, storage medium, and electronic equipment, which can improve the accuracy of joint prediction of primary tags and secondary tags.
第一方面,本申请实施例提供一种模型构建方法,包括:In the first aspect, an embodiment of the present application provides a model construction method, including:
获取待训练数据,所述待训练数据包括多条文本中各文本对应的分词对应的编码所组成的分词矩阵、各文本对应的一级标签对应的编码所组成的一级标签基准矩阵和各文本对应的二级标签对应的编码所组成的二级标签基准矩阵;Obtain the data to be trained. The data to be trained includes a word segmentation matrix composed of codes corresponding to word segmentation corresponding to each text in a plurality of texts, a first-level label reference matrix composed of codes corresponding to a first-level label corresponding to each text, and each text The reference matrix of the secondary label formed by the codes corresponding to the corresponding secondary label;
获取预设关系依赖矩阵,所述预设关系依赖矩阵用于表示一级标签和二级标签的层级关系;Acquiring a preset relationship dependency matrix, where the preset relationship dependency matrix is used to represent the hierarchical relationship between the primary label and the secondary label;
将所述待训练数据和所述预设关系依赖矩阵输入待训练模型中,以得到一级标签预测矩阵和二级标签预测矩阵;Inputting the to-be-trained data and the preset relationship dependency matrix into the to-be-trained model to obtain a primary label prediction matrix and a secondary label prediction matrix;
根据所述一级标签预测矩阵和所述预设关系依赖矩阵,确定目标关系依赖矩阵;Determine a target relationship dependence matrix according to the first-level label prediction matrix and the preset relationship dependence matrix;
根据所述一级标签预测矩阵、所述一级标签基准矩阵、目标矩阵和所述二级标签基准矩阵,确定目标损失值,所述目标矩阵根据所述二级标签预测矩阵和所述目标关系依赖矩阵确定;Determine a target loss value according to the primary label prediction matrix, the primary label reference matrix, the target matrix, and the secondary label reference matrix, and the target matrix is based on the secondary label prediction matrix and the target relationship Dependent matrix determination;
每当一批待训练数据训练完成后得到一目标损失值,每得到一目标损失值,将目标损失值回传到待训练模型中,以对待训练模型的参数进行调整,直至待训练模型收敛,确认模型训练结束,得到训练后的模型。Whenever a batch of training data is trained, a target loss value is obtained. For each target loss value obtained, the target loss value is returned to the model to be trained to adjust the parameters of the model to be trained until the model to be trained converges. Confirm that the model training is over and get the trained model.
第二方面,本申请实施例提供一种分类方法,包括:In the second aspect, an embodiment of the present application provides a classification method, including:
获取待分类文本;Obtain the text to be classified;
将所述待分类文本输入训练后的模型中,得到一级标签概率矩阵和二级标签预测概率矩阵,所述一级标签概率矩阵中的每一元素对应一一级标签,所述一级标签概率矩阵中的各个元素均为实数,所述二级标签预测概率矩阵中的每一元素对应一二级标签,所述二级标签预测概率矩阵中的各个元素均为实数;Input the text to be classified into the trained model to obtain a first-level label probability matrix and a second-level label prediction probability matrix. Each element in the first-level label probability matrix corresponds to a first-level label, and the first-level label Each element in the probability matrix is a real number, each element in the secondary label prediction probability matrix corresponds to a primary and secondary label, and each element in the secondary label prediction probability matrix is a real number;
根据所述一级标签概率矩阵,确定所述待分类文本对应的一级标签,所述一级标签概率矩阵中值最大的元素对应的一级标签为所述待分类文本对应的一级标签;Determine the primary label corresponding to the text to be classified according to the primary label probability matrix, and the primary label corresponding to the element with the largest value in the primary label probability matrix is the primary label corresponding to the text to be classified;
对所述一级标签概率矩阵进行整数化处理,以使所述一级标签概率矩阵中的各个元素由实数变为整数,得到一级标签整数化矩阵,所述一级标签整数化矩阵中的元素的值为0或1;Perform integerization processing on the first-level tag probability matrix, so that each element in the first-level tag probability matrix changes from a real number to an integer to obtain a first-level tag integerization matrix. The value of the element is 0 or 1;
根据所述一级标签整数化矩阵和预设关系依赖矩阵,确定第一关系依赖矩阵;Determine the first relationship dependence matrix according to the first-level label integerization matrix and the preset relationship dependence matrix;
根据所述第一关系依赖矩阵和所述二级标签预测概率矩阵,确定二级标签概率矩阵,所述二级标签概率矩阵中的每一元素对应一二级标签;Determining a secondary label probability matrix according to the first relationship dependency matrix and the secondary label prediction probability matrix, where each element in the secondary label probability matrix corresponds to a primary and secondary label;
根据二级标签概率矩阵,确定所述待分类文本对应的二级标签,所述二级标签概率矩阵中值最大的元素对应的二级标签为所述待分类文本对应的二级标签。According to the secondary label probability matrix, the secondary label corresponding to the text to be classified is determined, and the secondary label corresponding to the element with the largest value in the secondary label probability matrix is the secondary label corresponding to the text to be classified.
第三方面,本申请实施例提供一种模型构建装置,包括:In the third aspect, an embodiment of the present application provides a model construction device, including:
第一获取模块,用于获取待训练数据,所述待训练数据包括多条文本中各文本对应的分词对应的编码所组成的分词矩阵、各文本对应的一级标签对应的编码所组成的一级标签基准矩阵和各文本对应的二级标签对应的编码所组成的二级标签基准矩阵;The first acquisition module is used to acquire data to be trained. The data to be trained includes a word segmentation matrix composed of codes corresponding to word segmentation corresponding to each text in a plurality of texts, and a word segmentation matrix composed of codes corresponding to first-level tags corresponding to each text. A level-label reference matrix and a second-level label reference matrix composed of codes corresponding to the second-level labels corresponding to each text;
第二获取模块,用于获取预设关系依赖矩阵,所述预设关系依赖矩阵用于表示一级标签和二级标签的层级关系;The second acquiring module is configured to acquire a preset relationship dependency matrix, where the preset relationship dependency matrix is used to represent the hierarchical relationship between the primary label and the secondary label;
第一训练模块,用于将所述待训练数据和所述预设关系依赖矩阵输入待训练模型中,以得到一级标签预测矩阵和二级标签预测矩阵;The first training module is configured to input the data to be trained and the preset relationship dependency matrix into the model to be trained to obtain a primary label prediction matrix and a secondary label prediction matrix;
第一确定模块,用于根据所述一级标签预测矩阵和所述预设关系依赖矩阵,确定目标关系依赖矩阵;A first determining module, configured to determine a target relationship dependence matrix according to the first-level label prediction matrix and the preset relationship dependence matrix;
第二确定模块,用于根据所述一级标签预测矩阵、所述一级标签基准矩阵、目标矩阵和所述二级标签基准矩阵,确定目标损失值,所述目标矩阵根据所述二级标签预测矩阵和所述目标关系依赖矩阵确定;The second determining module is configured to determine a target loss value according to the primary label prediction matrix, the primary label reference matrix, the target matrix, and the secondary label reference matrix, and the target matrix is based on the secondary label The prediction matrix and the target relationship dependency matrix are determined;
第二训练模块,用于每当一批待训练数据训练完成后得到一目标损失值,每得到一目标损失值,将目标损失值回传到待训练模型中,以对待训练模型的参数进行调整,直至待训练模型收敛,确认模型训练结束,得到训练后的模型。The second training module is used to obtain a target loss value after the training of a batch of training data is completed, and for each target loss value obtained, the target loss value is transmitted back to the model to be trained to adjust the parameters of the model to be trained , Until the model to be trained converges, confirm the end of the model training, and get the trained model.
第四方面,本申请实施例提供一种分类装置,包括:In a fourth aspect, an embodiment of the present application provides a classification device, including:
第三获取模块,用于获取待分类文本;The third obtaining module is used to obtain the text to be classified;
预测模块,用于将所述待分类文本输入训练后的模型中,得到一级标签概率矩阵和二级标签预测概率矩阵,所述一级标签概率矩阵中的每一元素对应一一级标签,所述一级标签概率矩阵中的各个元素均为实数,所述二级标签预测概率矩阵中的每一元素对应一二级标签,所述二级标签预测概率矩阵中的各个元素均为实数;The prediction module is used to input the text to be classified into the trained model to obtain a first-level label probability matrix and a second-level label prediction probability matrix, each element in the first-level label probability matrix corresponds to a first-level label, Each element in the primary label probability matrix is a real number, each element in the secondary label prediction probability matrix corresponds to a primary and secondary label, and each element in the secondary label prediction probability matrix is a real number;
第三确定模块,用于根据所述一级标签概率矩阵,确定所述待分类文本对应的一级标签,所述一级标签概率矩阵中值最大的元素对应的一级标签为所述待分类文本对应的一级标签;The third determining module is configured to determine the primary label corresponding to the text to be classified according to the primary label probability matrix, and the primary label corresponding to the element with the largest value in the primary label probability matrix is the to be classified The first level label corresponding to the text;
化整模块,用于对所述一级标签概率矩阵进行整数化处理,以使所述一级标签概率矩阵中的各个元素由实数变为整数,得到一级标签整数化矩阵,所述一级标签整数化矩阵中的元素的值为0或1;The rounding module is used to perform integerization processing on the first-level tag probability matrix, so that each element in the first-level tag probability matrix is changed from a real number to an integer to obtain the first-level tag integerization matrix. The value of the element in the label integerization matrix is 0 or 1;
第四确定模块,用于根据所述一级标签整数化矩阵和预设关系依赖矩阵,确定第一关系依赖矩阵;A fourth determining module, configured to determine a first relationship dependence matrix according to the first-level label integerization matrix and a preset relationship dependence matrix;
第五确定模块,用于根据所述第一关系依赖矩阵和所述二级标签预测概率矩阵,确定二级标签概率矩阵,所述二级标签概率矩阵中的每一元素对应一二级标签;A fifth determining module, configured to determine a secondary label probability matrix according to the first relationship dependency matrix and the secondary label prediction probability matrix, and each element in the secondary label probability matrix corresponds to a primary and secondary label;
第六确定模块,用于根据所述二级标签概率矩阵,确定所述待分类文本对应的二级标签,所述二级标签概率矩阵中值最大的元素对应的二级标签为所述待分类文本对应的二级标签。The sixth determining module is configured to determine the secondary label corresponding to the text to be classified according to the secondary label probability matrix, and the secondary label corresponding to the element with the largest value in the secondary label probability matrix is the to be classified The secondary label corresponding to the text.
第五方面,本申请实施例提供一种存储介质,其上存储有计算机程序,其中,当所述计算机程序在计算机上执行时,使得所述计算机执行本实施例提供的模型构建方法或分类方法。In a fifth aspect, an embodiment of the present application provides a storage medium on which a computer program is stored, wherein, when the computer program is executed on a computer, the computer is caused to execute the model construction method or classification method provided in this embodiment .
第六方面,本申请实施例提供一种电子设备,包括存储器和处理器,所述存储器中存储有计算机程序,所述处理器通过调用所述存储器中存储的所述计算机程序,用于执行:In a sixth aspect, an embodiment of the present application provides an electronic device, including a memory and a processor, the memory stores a computer program, and the processor invokes the computer program stored in the memory to execute:
获取待训练数据,所述待训练数据包括多条文本中各文本对应的分词对应的编码所组成的分词矩阵、各文本对应的一级标签对应的编码所组成的一级标签基准矩阵和各文本对应的二级标签对应的编码所组成的二级标签基准矩阵;Obtain the data to be trained. The data to be trained includes a word segmentation matrix composed of codes corresponding to word segmentation corresponding to each text in a plurality of texts, a first-level label reference matrix composed of codes corresponding to a first-level label corresponding to each text, and each text The reference matrix of the secondary label formed by the codes corresponding to the corresponding secondary label;
获取预设关系依赖矩阵,所述预设关系依赖矩阵用于表示一级标签和二级标签的层级关系;Acquiring a preset relationship dependency matrix, where the preset relationship dependency matrix is used to represent the hierarchical relationship between the primary label and the secondary label;
将所述待训练数据和所述预设关系依赖矩阵输入待训练模型中,以得到一级标签预测矩阵和二级标签预测矩阵;Inputting the to-be-trained data and the preset relationship dependency matrix into the to-be-trained model to obtain a primary label prediction matrix and a secondary label prediction matrix;
根据所述一级标签预测矩阵和所述预设关系依赖矩阵,确定目标关系依赖矩阵;Determine a target relationship dependence matrix according to the first-level label prediction matrix and the preset relationship dependence matrix;
根据所述一级标签预测矩阵、所述一级标签基准矩阵、目标矩阵和所述二级标签基准矩阵,确定目标损失值,所述目标矩阵根据所述二级标签预测矩阵和所述目标关系依赖矩阵确定;Determine a target loss value according to the primary label prediction matrix, the primary label reference matrix, the target matrix, and the secondary label reference matrix, and the target matrix is based on the secondary label prediction matrix and the target relationship Dependent matrix determination;
每当一批待训练数据训练完成后得到一目标损失值,每得到一目标损失值,将目标损失值回传到待训练模型中,以对待训练模型的参数进行调整,直至待训练模型收敛,确认模型训练结束,得到训练后的模型。Whenever a batch of training data is trained, a target loss value is obtained. For each target loss value obtained, the target loss value is returned to the model to be trained to adjust the parameters of the model to be trained until the model to be trained converges. Confirm that the model training is over and get the trained model.
第七方面,本申请实施例提供一种电子设备,包括存储器和处理器,所述存储器中存储有计算机程序,所述处理器通过调用所述存储器中存储的所述计算机程序,用于执行:In a seventh aspect, an embodiment of the present application provides an electronic device, including a memory and a processor, the memory stores a computer program, and the processor invokes the computer program stored in the memory to execute:
获取待分类文本;Obtain the text to be classified;
将所述待分类文本输入训练后的模型中,得到一级标签概率矩阵和二级标签预测概率矩阵,所述一级标签概率矩阵中的每一元素对应一一级标签,所述一级标签概率矩阵中的各个元素均为实数,所述二 级标签预测概率矩阵中的每一元素对应一二级标签,所述二级标签预测概率矩阵中的各个元素均为实数;Input the text to be classified into the trained model to obtain a first-level label probability matrix and a second-level label prediction probability matrix. Each element in the first-level label probability matrix corresponds to a first-level label, and the first-level label Each element in the probability matrix is a real number, each element in the secondary label prediction probability matrix corresponds to a primary and secondary label, and each element in the secondary label prediction probability matrix is a real number;
根据所述一级标签概率矩阵,确定所述待分类文本对应的一级标签,所述一级标签概率矩阵中值最大的元素对应的一级标签为所述待分类文本对应的一级标签;Determine the primary label corresponding to the text to be classified according to the primary label probability matrix, and the primary label corresponding to the element with the largest value in the primary label probability matrix is the primary label corresponding to the text to be classified;
对所述一级标签概率矩阵进行整数化处理,以使所述一级标签概率矩阵中的各个元素由实数变为整数,得到一级标签整数化矩阵,所述一级标签整数化矩阵中的元素的值为0或1;Perform integerization processing on the first-level tag probability matrix, so that each element in the first-level tag probability matrix changes from a real number to an integer to obtain a first-level tag integerization matrix. The value of the element is 0 or 1;
根据所述一级标签整数化矩阵和预设关系依赖矩阵,确定第一关系依赖矩阵;Determine the first relationship dependence matrix according to the first-level label integerization matrix and the preset relationship dependence matrix;
根据所述第一关系依赖矩阵和所述二级标签预测概率矩阵,确定二级标签概率矩阵,所述二级标签概率矩阵中的每一元素对应一二级标签;Determining a secondary label probability matrix according to the first relationship dependency matrix and the secondary label prediction probability matrix, where each element in the secondary label probability matrix corresponds to a primary and secondary label;
根据所述二级标签概率矩阵,确定所述待分类文本对应的二级标签,所述二级标签概率矩阵中值最大的元素对应的二级标签为所述待分类文本对应的二级标签。According to the secondary label probability matrix, the secondary label corresponding to the text to be classified is determined, and the secondary label corresponding to the element with the largest value in the secondary label probability matrix is the secondary label corresponding to the text to be classified.
附图说明Description of the drawings
下面结合附图,通过对本申请的具体实施方式详细描述,将使本申请的技术方案及其有益效果显而易见。In the following, with reference to the accompanying drawings, the technical solutions of the present application and its beneficial effects will be apparent through a detailed description of the specific implementations of the present application.
图1是本申请实施例提供的模型构建方法的第一种流程示意图。FIG. 1 is a schematic diagram of the first flow of a model construction method provided by an embodiment of the present application.
图2是本申请实施例提供的模型构建方法的第二种流程示意图。FIG. 2 is a schematic diagram of the second flow of the model construction method provided by the embodiment of the present application.
图3是本申请实施例提供的预设关系依赖矩阵M0示意图。FIG. 3 is a schematic diagram of a preset relationship dependency matrix M0 provided by an embodiment of the present application.
图4是本申请实施例提供的一级标签基准矩阵y1示意图。FIG. 4 is a schematic diagram of the primary label reference matrix y1 provided by an embodiment of the present application.
图5是本申请实施例提供的二级标签基准矩阵y2示意图。Fig. 5 is a schematic diagram of a secondary label reference matrix y2 provided by an embodiment of the present application.
图6是本申请实施例提供的一级标签预测矩阵P1示意图。FIG. 6 is a schematic diagram of the primary label prediction matrix P1 provided by an embodiment of the present application.
图7是本申请实施例提供的二级标签预测矩阵P2示意图。FIG. 7 is a schematic diagram of a secondary label prediction matrix P2 provided by an embodiment of the present application.
图8是本申请实施例提供的0-1整数矩阵P1-1示意图。Fig. 8 is a schematic diagram of a 0-1 integer matrix P1-1 provided by an embodiment of the present application.
图9是本申请实施例提供的目标关系依赖矩阵M示意图。FIG. 9 is a schematic diagram of a target relationship dependency matrix M provided by an embodiment of the present application.
图10是本申请实施例提供的词典示意图。Fig. 10 is a schematic diagram of a dictionary provided by an embodiment of the present application.
图11是本申请实施例提供的分类方法的流程示意图。FIG. 11 is a schematic flowchart of a classification method provided by an embodiment of the present application.
图12是本申请实施例提供的分类方法的场景示意图。FIG. 12 is a schematic diagram of a scene of a classification method provided by an embodiment of the present application.
图13是本申请实施例提供的模型构建装置的结构示意图。Fig. 13 is a schematic structural diagram of a model construction device provided by an embodiment of the present application.
图14是本申请实施例提供的分类装置的结构示意图。Fig. 14 is a schematic structural diagram of a classification device provided by an embodiment of the present application.
图15是本申请实施例提供的电子设备的第一种结构示意图。FIG. 15 is a schematic diagram of a first structure of an electronic device provided by an embodiment of the present application.
图16是本申请实施例提供的电子设备的第二种结构示意图。FIG. 16 is a schematic diagram of a second structure of an electronic device provided by an embodiment of the present application.
具体实施方式Detailed ways
请参照图示,其中相同的组件符号代表相同的组件,本申请的原理是以实施在一适当的运算环境中来举例说明。以下的说明是基于所例示的本申请具体实施例,其不应被视为限制本申请未在此详述的其它具体实施例。Please refer to the drawings, in which the same component symbols represent the same components, and the principle of the present application is implemented in an appropriate computing environment as an example. The following description is based on the exemplified specific embodiments of the present application, which should not be construed as limiting other specific embodiments of the present application that are not described in detail herein.
请参阅图1,图1是本申请实施例提供的模型构建方法的第一种流程示意图。该模型构建方法的流程可以包括:Please refer to FIG. 1. FIG. 1 is a schematic diagram of the first process of the model construction method provided by an embodiment of the present application. The process of the model construction method can include:
101、获取待训练数据,该待训练数据包括多条文本中各文本对应的分词对应的编码所组成的分词矩阵、各文本对应的一级标签对应的编码所组成的一级标签基准矩阵和各文本对应的二级标签对应的编码所组成的二级标签基准矩阵。101. Obtain data to be trained. The data to be trained includes a word segmentation matrix composed of codes corresponding to word segmentation corresponding to each text in a plurality of texts, a first-level label reference matrix composed of codes corresponding to a first-level label corresponding to each text, and each The secondary label reference matrix composed of the codes corresponding to the secondary labels corresponding to the text.
比如,首先,电子设备可获取多条文本,该多条文本中的每条文本均标记有一级标签和二级标签。然后,电子设备可对每条文本进行分词,并确定每条文本对应的分词对应的编码。最后,电子设备可根据每条文本对应的分词对应的编码,组成分词矩阵。其中,分词矩阵的第一维(行)表示各文本,第二维(列)表示各文本对应的分词对应的编码。例如,分词矩阵的第i行第j列表示第i条文本对应的第j个分词对应的编码。For example, first, the electronic device may obtain multiple pieces of text, and each piece of text in the multiple pieces of text is marked with a primary label and a secondary label. Then, the electronic device can segment each text and determine the code corresponding to the segmentation corresponding to each text. Finally, the electronic device can form a word segmentation matrix according to the code corresponding to the word segmentation corresponding to each text. Among them, the first dimension (row) of the word segmentation matrix represents each text, and the second dimension (column) represents the code corresponding to the word segmentation corresponding to each text. For example, the i-th row and j-th column of the word segmentation matrix represents the code corresponding to the j-th word segmentation corresponding to the i-th text.
随后,电子设备可对每条文本对应的一级标签进行编码,然后组成一级标签基准矩阵。其中,一级标签基准矩阵的第一维(行)表示各文本,第二维(列)表示各文本对应的一级标签对应的编码。例如,一级标签基准矩阵的第i行表示第i条文本对应的一级标签对应的编码。电子设备可对每条文本对应的二级标签进行编码,然后组成二级标签基准矩阵。其中,二级标签基准矩阵的第一维(行)为各文本,第二维(列)为各文本对应的二级标签对应的编码。例如,二级标签基准矩阵的第i行表示第i条文本对应的二级标签对应的编码。Subsequently, the electronic device can encode the primary label corresponding to each text, and then compose the primary label reference matrix. Among them, the first dimension (row) of the primary label reference matrix represents each text, and the second dimension (column) represents the code corresponding to the primary label corresponding to each text. For example, the i-th row of the primary label reference matrix represents the code corresponding to the primary label corresponding to the i-th text. The electronic device can encode the secondary label corresponding to each text, and then compose the secondary label reference matrix. Among them, the first dimension (row) of the secondary label reference matrix is each text, and the second dimension (column) is the code corresponding to the secondary label corresponding to each text. For example, the i-th row of the secondary label reference matrix represents the code corresponding to the secondary label corresponding to the i-th text.
分词矩阵、一级标签基准矩阵和二级标签基准矩阵构成待训练数据。The word segmentation matrix, the primary label reference matrix and the secondary label reference matrix constitute the data to be trained.
102、获取预设关系依赖矩阵,该预设关系依赖矩阵用于表示一级标签和二级标签的层级关系。102. Obtain a preset relationship dependency matrix, where the preset relationship dependency matrix is used to represent the hierarchical relationship between the primary label and the secondary label.
比如,可从数据库获取或者由用户预先收集多个一级标签和多个二级标签,并确定各一级标签和各二级标签之间的层级关系。也就是说,确定各一级标签下分别对应哪些二级标签。例如,假设一级标签为:电视剧,其下的二级标签可以为:古装、玄幻和现代,等等。又例如,假设一级标签为:体育,其下的二级标签可以为:足球、篮球、排球和乒乓球,等等。然后,电子设备可根据一级标签和二级标签的层级关系建立预设关系依赖矩阵。其中,预设关系依赖矩阵的第一维(行)表示各一级标签,第二维(列)表示各二级标签。如果第i个一级标签下包含第j个二级标签,那么预设关系依赖矩阵的第i行第j列为1,否则为0。For example, multiple primary tags and multiple secondary tags can be obtained from a database or collected by a user in advance, and the hierarchical relationship between each primary tag and each secondary tag can be determined. In other words, determine which secondary labels correspond to each primary label. For example, suppose the first-level label is: TV series, and the second-level labels may be: ancient costume, fantasy, modern, and so on. For another example, suppose the first-level label is: sports, and the second-level labels may be: football, basketball, volleyball, table tennis, and so on. Then, the electronic device can establish a preset relationship dependency matrix according to the hierarchical relationship between the primary label and the secondary label. Wherein, the first dimension (row) of the preset relationship dependence matrix represents each first-level label, and the second dimension (column) represents each second-level label. If the j-th second-level label is included under the i-th first-level label, then the preset relationship dependency matrix is 1 in the i-th row and j-th column, otherwise it is 0.
需要说明的是,在本申请实施例中,当建立出预设关系依赖矩阵之后,电子设备在需要使用该预设关系依赖矩阵时,可以直接获取该预设关系依赖矩阵进行使用,而不需要再次进行预设关系依赖矩阵的建立之后再使用。即,一次建立,多次使用。It should be noted that, in the embodiment of the present application, after the preset relationship dependency matrix is established, when the electronic device needs to use the preset relationship dependency matrix, it can directly obtain the preset relationship dependency matrix for use without the need. Perform the establishment of the preset relationship dependency matrix again before using it. That is, create it once and use it many times.
在本申请实施例中,电子设备可获取该预设关系依赖矩阵。In the embodiment of the present application, the electronic device can obtain the preset relationship dependency matrix.
需要说明的是,在获取多条文本时,用户也可根据收集到的多个一级标签和多个二级标签获取多条文本,并输入电子设备中,电子设备即获取到该多条文本。也就是说,电子设备所获取的多条文本中,各文本所对应的一级标签均为用户所收集到的多个一级标签中的其中一个一级标签;各文本所对应的二级标签均为用户所收集到的多个二级标签中的其中一个二级标签。It should be noted that when obtaining multiple texts, the user can also obtain multiple texts according to the collected multiple primary tags and multiple secondary tags, and input them into the electronic device, and the electronic device can obtain the multiple texts. . That is to say, among the multiple texts obtained by the electronic device, the primary label corresponding to each text is one of the multiple primary labels collected by the user; the secondary label corresponding to each text It is one of the second-level tags among multiple second-level tags collected by the user.
可以理解的是,为提高模型预测的准确率,电子设备所获取到的文本对应的一级标签和二级标签均可充分表示该文本。比如,可采用人工标注的方式为文本标记上一级标签和二级标签。然后,电子设备可获取这些经人工标记标签的文本。It is understandable that, in order to improve the accuracy of model prediction, the primary label and secondary label corresponding to the text obtained by the electronic device can fully represent the text. For example, a manual labeling method can be used to mark the upper level label and the second level label for the text. Then, the electronic device can obtain these manually labeled texts.
103、将待训练数据和预设关系依赖矩阵输入待训练模型中,以得到一级标签预测矩阵和二级标签预测矩阵。103. Input the to-be-trained data and the preset relationship dependency matrix into the to-be-trained model to obtain a primary label prediction matrix and a secondary label prediction matrix.
比如,当得到待训练数据和预设关系依赖矩阵之后,电子设备可将该待训练数据和预设关系依赖矩阵输入待训练模型中,以得到一级标签预测矩阵和二级标签预测矩阵。For example, after obtaining the data to be trained and the preset relationship dependency matrix, the electronic device may input the data to be trained and the preset relationship dependency matrix into the model to be trained to obtain the primary label prediction matrix and the secondary label prediction matrix.
其中,在一级标签预测矩阵中,矩阵的行数为待训练数据中所包括的文本的条数,矩阵的列数为一级标签的数量。例如,文本的条数为64条,一级标签的数量为10,那么该一级标签预测矩阵为一64*10的矩阵。一级标签预测矩阵的第一维(行)表示各文本,第二维(列)表示待训练模型所预测的各文本对应的一级标签为多个一级标签中的各一级标签的概率。例如,一级标签预测矩阵的第i行第j列表示第i条文本对应的一级标签为多个一级标签中的第j个一级标签的概率。Among them, in the first-level label prediction matrix, the number of rows of the matrix is the number of texts included in the data to be trained, and the number of columns of the matrix is the number of first-level labels. For example, if the number of texts is 64 and the number of first-level labels is 10, then the first-level label prediction matrix is a 64*10 matrix. The first dimension (row) of the primary label prediction matrix represents each text, and the second dimension (column) represents the probability that the primary label corresponding to each text predicted by the model to be trained is each primary label among multiple primary labels . For example, the i-th row and j-th column of the primary label prediction matrix indicates the probability that the primary label corresponding to the i-th text is the j-th primary label among multiple primary labels.
在二级标签预测矩阵中,矩阵的行数为待训练数据中所包括的文本的条数,矩阵的列数为二级标签的数量。例如,文本的条数为64条,二级标签的数量为200,那么该二级标签预测矩阵为一64*200的矩阵。二级标签预测矩阵的第一维(行)表示各文本,第二维(列)表示待训练模型所预测的各文本对应的二级标签为多个二级标签中的各二级标签的概率。例如,二级标签预测矩阵的第i行第j列表示第i条文本对应的二级标签为多个二级标签中的第j个二级标签的概率。In the secondary label prediction matrix, the number of rows of the matrix is the number of texts included in the data to be trained, and the number of columns of the matrix is the number of secondary labels. For example, if the number of texts is 64 and the number of secondary labels is 200, then the secondary label prediction matrix is a 64*200 matrix. The first dimension (row) of the secondary label prediction matrix represents each text, and the second dimension (column) represents the probability that the secondary label corresponding to each text predicted by the model to be trained is each secondary label among multiple secondary labels . For example, the i-th row and j-th column of the secondary label prediction matrix indicates the probability that the secondary label corresponding to the i-th text is the jth secondary label among multiple secondary labels.
在本申请实施例中,该待训练模型可先进行参数的初始化。接着,电子设备可将待训练数据和预设关系依赖矩阵输入该待训练模型,经过卷积层、下采样层、全连接层等各层的向前传播得到输出结果,即得到一级标签预测矩阵和二级标签预测矩阵。In this embodiment of the present application, the model to be trained may first initialize its parameters. Then, the electronic device can input the data to be trained and the preset relationship dependency matrix into the model to be trained, and the output result is obtained through forward propagation of the convolutional layer, down-sampling layer, fully connected layer, etc., that is, the first-level label prediction is obtained Matrix and secondary label prediction matrix.
104、根据一级标签预测矩阵和预设关系依赖矩阵,确定目标关系依赖矩阵。104. Determine the target relationship dependence matrix according to the first-level label prediction matrix and the preset relationship dependence matrix.
105、根据一级标签预测矩阵、一级标签基准矩阵、目标矩阵和二级标签基准矩阵,确定目标损失值,该目标矩阵根据二级标签预测矩阵和目标关系依赖矩阵确定。105. Determine the target loss value according to the primary label prediction matrix, the primary label reference matrix, the target matrix, and the secondary label reference matrix, the target matrix being determined according to the secondary label prediction matrix and the target relationship dependency matrix.
比如,当得到一级标签预测矩阵之后,电子设备可根据一级标签预测矩阵和预设关系依赖矩阵,确定目标关系依赖矩阵。当得到目标关系依赖矩阵之后,电子设备可根据该目标关系依赖矩阵和二级标签预测矩阵,确定目标矩阵。随后,电子设备可根据一级标签预测矩阵、一级标签基准矩阵、目标矩阵和二级标签基准矩阵,确定目标损失值。For example, after obtaining the first-level label prediction matrix, the electronic device may determine the target relationship dependency matrix according to the first-level label prediction matrix and the preset relationship dependency matrix. After obtaining the target relationship dependence matrix, the electronic device can determine the target matrix according to the target relationship dependence matrix and the secondary label prediction matrix. Subsequently, the electronic device can determine the target loss value according to the primary label prediction matrix, the primary label reference matrix, the target matrix, and the secondary label reference matrix.
106、每当一批待训练数据训练完成后得到一目标损失值,每得到一目标损失值,将目标损失值回传到待训练模型中,以对待训练模型的参数进行调整,直至待训练模型收敛,确认模型训练结束,得到训练后的模型。106. Whenever a batch of training data is trained, a target loss value is obtained, and each target loss value is obtained, the target loss value is returned to the model to be trained to adjust the parameters of the model to be trained until the model to be trained Convergence, confirm the end of model training, and get the trained model.
可以理解的是,当得到一目标损失值之后,可将该目标损失值回传到待训练模型的各层中,从而对待训练模型的参数进行调整。随后,电子设备可继续获取待训练数据,并输入调整参数后的待训练模型中,以继续对待训练模型进行训练。其中,该待训练数据与流程101中所获取的待训练数据为不同的两批数据,该待训练数据的获取流程可以参考流程101的获取流程。当本次得到一目标损失值之后,仍可将该目标损失值回传到待训练模型中,从而再次进行参数调整,直至待训练模型收敛,确认模型训练结束,得到训练后的模型。其中,目标损失值逐步逼近某个数值,或者是在某个数值附近波动,损失变化小于某个很小的正数时,可以确认待训练模型收敛。It is understandable that after a target loss value is obtained, the target loss value can be transmitted back to each layer of the model to be trained, so as to adjust the parameters of the model to be trained. Subsequently, the electronic device can continue to obtain the data to be trained and input the adjusted parameters into the model to be trained to continue training the model to be trained. The data to be trained and the data to be trained acquired in the process 101 are two different batches of data, and the acquisition process of the data to be trained can refer to the acquisition process of the process 101. After a target loss value is obtained this time, the target loss value can still be transmitted back to the model to be trained, so as to adjust the parameters again until the model to be trained converges, confirm the end of the model training, and obtain the trained model. Among them, the target loss value gradually approaches a certain value, or fluctuates around a certain value, and when the loss change is less than a small positive number, it can be confirmed that the model to be trained has converged.
可以理解的是,本实施例中,利用预设关系依赖矩阵和一级标签预测矩阵确定的目标关系依赖矩阵可对二级标签进行增强训练,并且,根据一级标签预测矩阵、一级标签基准矩阵、目标矩阵和二级标签基准矩阵确定的目标损失值可使得待训练的模型达到总体最优,从而可提高训练好的模型对一级标签和二级标签进行联合预测的准确率。It can be understood that, in this embodiment, the target relationship dependence matrix determined by the preset relationship dependence matrix and the primary label prediction matrix can be used to perform enhanced training on the secondary label, and the secondary label can be trained according to the primary label prediction matrix and the primary label benchmark. The target loss value determined by the matrix, the target matrix and the secondary label reference matrix can make the model to be trained reach the overall optimum, thereby improving the accuracy of the joint prediction of the primary label and the secondary label by the trained model.
请参阅图2,图2为本申请实施例提供的模型构建方法的第二种流程示意图。该模型构建方法可以包括:Please refer to FIG. 2, which is a schematic diagram of the second flow of the model construction method provided by the embodiment of the application. The model building method can include:
201、电子设备获取多个一级标签。201. The electronic device obtains multiple first-level tags.
202、电子设备获取多个二级标签。202. The electronic device obtains multiple secondary tags.
203、电子设备确定各一级标签和各二级标签的层级关系。203. The electronic device determines the hierarchical relationship between each primary label and each secondary label.
204、电子设备根据层级关系,建立预设关系依赖矩阵。204. The electronic device establishes a preset relationship dependency matrix according to the hierarchical relationship.
比如,201、202、203和204可以为:For example, 201, 202, 203, and 204 can be:
可由用户预先收集多个一级标签和多个二级标签。然后,用户可将收集到的多个一级标签和多个二级标签输入到电子设备中,电子设备即可获取该多个一级标签和多个二级标签。The user can collect multiple primary tags and multiple secondary tags in advance. Then, the user can input the collected multiple primary tags and multiple secondary tags into the electronic device, and the electronic device can obtain the multiple primary tags and multiple secondary tags.
接着,电子设备可确定获取到的多个一级标签和二级标签的层级关系,即每个一级标签下分别有哪些二级标签。可以理解的是,这一过程可以由用户进行分析并分类。比如,可由用户确定每个一级标签下有哪些二级标签,然后将二级标签标记上其所属的一级标签的标记。用户可将这些一级标签和标记有其所属的一级标签的二级标签输入电子设备中,电子设备可根据二级标签上的标记,确定哪个二级标签属于哪个一级标签。Then, the electronic device can determine the hierarchical relationship between the obtained multiple primary labels and secondary labels, that is, which secondary labels are under each primary label. It is understandable that this process can be analyzed and classified by the user. For example, the user can determine which secondary labels are under each primary label, and then mark the secondary labels with the mark of the primary label to which they belong. The user can input these primary labels and secondary labels marked with the primary labels to which they belong to the electronic device, and the electronic device can determine which secondary label belongs to which primary label according to the mark on the secondary label.
当确定出各一级标签和各二级标签的层级关系之后,电子设备可根据各一级标签和各二级标签的层级关系,建立预设关系依赖矩阵。其中,该预设关系依赖矩阵的第一维(行)表示多个一级标签中的各一级标签,第二维(列)表示多个二级标签中的各二级标签。如果第i个一级标签包含第j个二级标签,那么预设关系依赖矩阵的第i行第j列为1,否则为0。After determining the hierarchical relationship between each primary label and each secondary label, the electronic device can establish a preset relationship dependency matrix according to the hierarchical relationship between each primary label and each secondary label. Wherein, the first dimension (row) of the preset relationship dependency matrix represents each primary label in the plurality of primary labels, and the second dimension (column) represents each secondary label in the multiple secondary labels. If the i-th first-level label contains the j-th second-level label, then the preset relationship dependence matrix is 1 in the jth row and jth column, otherwise it is 0.
例如,假设一级标签有5个,分别为:L1、L2、L3、L4、L5,二级标签有15个,分别为:S1、S2、S3、S4、S5、S6、S7、S8、S9、S10、S11、S12、S13、S14、S15。其中,一级标签L1包含有二级标签S1、S2、S4;一级标签L2包含有二级标签S3、S5;一级标签L3包含有二级标签S5、S6、S7;一级标签L4包含有二级标签S9、S11、S12、S15;一级标签L5包含有二级标签S10、S13、S14。那么,根据5个一级标签L1、L2、L3、L4、L5和15个二级标签S1、S2、S3、S4、S5、S6、S7、S8、S9、S10、S11、S12、S13、S14、S15,建立的预设关系依赖矩阵M0中的第0行的第0、1、3列为1,其他为0; 第1行的第2、4列为1,其他为0;第2行的第5、6、7列为1,其他为0;第3行的第8、10、11、14列为1,其他为0;第4行的第9、12、13列为1,其他为0;即预设关系依赖矩阵M0如图3所示。For example, suppose there are 5 primary labels, namely: L1, L2, L3, L4, L5, and 15 secondary labels, respectively: S1, S2, S3, S4, S5, S6, S7, S8, S9 , S10, S11, S12, S13, S14, S15. Among them, the primary label L1 contains secondary labels S1, S2, S4; the primary label L2 contains secondary labels S3, S5; the primary label L3 contains secondary labels S5, S6, S7; the primary label L4 contains There are secondary labels S9, S11, S12, S15; the primary label L5 includes secondary labels S10, S13, S14. Then, according to 5 primary labels L1, L2, L3, L4, L5 and 15 secondary labels S1, S2, S3, S4, S5, S6, S7, S8, S9, S10, S11, S12, S13, S14 , S15, the established preset relationship depends on the 0th, 1st, and 3rd columns in the 0th row of the matrix M0 as 1, the others are 0; the 1st row, the 2nd and 4th columns are 1, and the others are 0; the 2nd row The 5th, 6th, and 7th columns are 1, and the others are 0; the 8th, 10th, 11th, and 14th columns of the 3rd row are 1, and the others are 0; the 9th, 12th, and 13th columns of the 4th row are 1, and the others are Is 0; that is, the preset relationship dependency matrix M0 is shown in Figure 3.
205、电子设备获取多条文本、各文本对应的一级标签和各文本对应的二级标签。205. The electronic device obtains multiple pieces of text, the primary label corresponding to each text, and the secondary label corresponding to each text.
206、电子设备对各文本进行分词处理,得到各文本对应的分词。206. The electronic device performs word segmentation processing on each text to obtain word segmentation corresponding to each text.
207、电子设备确定各文本对应的分词对应的编码。207. The electronic device determines the code corresponding to the word segmentation corresponding to each text.
208、电子设备根据各文本对应的分词对应的编码,确定分词矩阵。208. The electronic device determines the word segmentation matrix according to the code corresponding to the word segmentation corresponding to each text.
209、电子设备对各文本对应的一级标签进行独热编码处理,得到各文本对应的一级标签对应的编码。209. The electronic device performs one-hot encoding processing on the first-level label corresponding to each text to obtain the code corresponding to the first-level label corresponding to each text.
210、电子设备根据各文本对应的一级标签对应的编码,确定一级标签基准矩阵。210. The electronic device determines the primary label reference matrix according to the code corresponding to the primary label corresponding to each text.
211、电子设备对各文本对应的二级标签进行独热编码处理,得到各文本对应的二级标签对应的编码。211. The electronic device performs one-hot encoding processing on the secondary label corresponding to each text to obtain the code corresponding to the secondary label corresponding to each text.
212、电子设备根据各文本对应的二级标签对应的编码,确定二级标签基准矩阵。212. The electronic device determines a reference matrix of the secondary label according to the code corresponding to the secondary label corresponding to each text.
213、电子设备根据分词矩阵、一级标签基准矩阵和二级标签基准矩阵,确定待训练数据。213. The electronic device determines the data to be trained according to the word segmentation matrix, the primary label reference matrix, and the secondary label reference matrix.
比如,205至213可以为:For example, 205 to 213 can be:
用户可根据用户收集的多个一级标签和多个二级标签,收集多条标记有一级标签和二级标签的文本。其中,每条文本所标记的一级标签均为用户收集的多个一级标签中的其中一个一级标签;每条文本所标记的二级标签均为用户收集的多个二级标签中的其中一个二级标签。用户可将收集到的多条标记有一级标签和二级标签的文本输入电子设备中,电子设备即获取到多条文本、各文本对应的一级标签,即各文本所标记的一级标签和各文本对应的二级标签,即各文本所标记的二级标签。The user can collect multiple pieces of text marked with the primary label and the secondary label according to the multiple primary tags and multiple secondary tags collected by the user. Among them, the first-level label marked by each text is one of the multiple first-level labels collected by the user; the second-level label marked by each text is one of the multiple second-level labels collected by the user One of the secondary labels. The user can input multiple collected texts marked with primary labels and secondary labels into the electronic device, and the electronic device will obtain multiple texts and the primary labels corresponding to each text, that is, the primary labels and primary labels marked by each text. The secondary label corresponding to each text, that is, the secondary label marked by each text.
在一些实施例中,为了提高训练后的模型预测的准确率,所收集的多条标记有一级标签和二级标签的文本中,每条文本所标记的二级标签从属于每条文本所标记的一级标签。也可以说,每条文本所标记的一级标签下包含有每条文本所标记的二级标签。也就是说,若某条文本所标记的二级标签并不从属于该条文本所标记的一级标签,在收集文本时,可以不收集该条文本。In some embodiments, in order to improve the accuracy of the model prediction after training, among the collected multiple pieces of text marked with primary tags and secondary tags, the secondary label marked by each piece of text is subordinate to each piece of text marked. The first level label. It can also be said that the first-level label marked by each text contains the second-level label marked by each text. That is to say, if the second-level label marked by a certain piece of text is not subordinate to the first-level label marked by the text, the text may not be collected when collecting the text.
随后,电子设备可对多条文本中的各文本进行分词处理,得到各文本对应的分词。例如,电子设备可使用结巴(jieba)分词器对各文本进行分词处理。Subsequently, the electronic device can perform word segmentation processing on each text in the multiple texts to obtain the word segmentation corresponding to each text. For example, the electronic device may use a jieba tokenizer to perform word segmentation processing on each text.
在一些实施例中,电子设备可将各文本中无效及不常用的特殊字符过滤之后,再使用结巴(jieba)分词器对各文本进行分词处理。In some embodiments, the electronic device may filter the invalid and infrequently used special characters in each text, and then use a jieba tokenizer to perform word segmentation processing on each text.
当得到各文本对应的分词之后,电子设备可确定各文本对应的分词对应的编码。然后,电子设备可根据各文本对应的分词对应的编码,确定分词矩阵。其中,分词矩阵中的第一维(行)表示多条文本中的各文本,第二维(列)表示各文本对应的分词对应的编码。例如,分词矩阵的第i行的第j列表示第i条文本对应的第j个分词对应的编码。After the word segmentation corresponding to each text is obtained, the electronic device can determine the code corresponding to the word segmentation corresponding to each text. Then, the electronic device can determine the word segmentation matrix according to the code corresponding to the word segmentation corresponding to each text. Among them, the first dimension (row) in the word segmentation matrix represents each text in a plurality of texts, and the second dimension (column) represents the code corresponding to the word segmentation corresponding to each text. For example, the j-th column of the i-th row of the word segmentation matrix represents the code corresponding to the j-th word segmentation corresponding to the i-th text.
接着,电子设备可对各文本对应的一级标签进行独热编码处理,得到各文本对应的一级标签对应的编码。当得到各文本对应的一级标签对应的编码之后,电子设备可根据各文本对应的一级标签对应的编码,确定一级标签基准矩阵。其中,一级标签矩阵的第一维(行)表示多条文本中的各文本,第二维(列)表示多条文本中的各文本对应的一级标签对应的编码。例如,一级标签基准矩阵的第i行表示第i条文本对应的一级标签对应的编码。Then, the electronic device can perform one-hot encoding processing on the primary label corresponding to each text to obtain the code corresponding to the primary label corresponding to each text. After obtaining the code corresponding to the primary label corresponding to each text, the electronic device can determine the primary label reference matrix according to the code corresponding to the primary label corresponding to each text. Among them, the first dimension (row) of the first-level label matrix represents each text in the multiple texts, and the second dimension (column) represents the code corresponding to the first-level label corresponding to each text in the multiple texts. For example, the i-th row of the primary label reference matrix represents the code corresponding to the primary label corresponding to the i-th text.
比如,假设有5个一级标签,分别为L1、L2、L3、L4、L5,当某条文本中包含有L1时,该文本对应的一级标签对应的编码为:10000;当某条文本中包含有L2时,该文本对应的一级标签对应的编码为:01000;当某条文本中包含有L3时,该文本对应的一级标签对应的编码为:00100;当某条文本中包含有L4时,该文本对应的一级标签对应的编码为:00010;当某条文本中包含有L5时,该文本对应的一级标签对应的编码为:00001。For example, suppose there are 5 first-level tags, namely L1, L2, L3, L4, and L5. When a piece of text contains L1, the corresponding code of the first-level tag corresponding to the text is: 10000; when a piece of text When the text contains L2, the corresponding code of the first-level label of the text is: 01000; when a text contains L3, the corresponding code of the first-level label of the text is: 00100; when a text contains When there is L4, the corresponding code of the first-level label corresponding to the text is: 00010; when a piece of text contains L5, the corresponding code of the first-level label corresponding to the text is: 00001.
比如,假设有15条文本,第1条文本对应的一级标签为L2,第2条文本对应的一级标签为L3,第3条文本对应的一级标签为L1,第4条文本对应的一级标签为L2,第5条文本对应的一级标签为L5,第6条文本对应的一级标签为L4,第7条文本对应的一级标签为L1,第8条文本对应的一级标签为L5, 第9条文本对应的一级标签为L1,第10条文本对应的一级标签为L3,第11条文本对应的一级标签为L4,第12条文本对应的一级标签为L4,第13条文本对应的一级标签为L5,第14条文本对应的一级标签为L3,第15条文本对应的一级标签为L4。For example, assuming there are 15 texts, the first text corresponding to the first level label is L2, the second text corresponding to the first level label is L3, the third text corresponding to the first level label is L1, and the fourth text corresponds to The first-level label is L2, the first-level label corresponding to the text of Article 5 is L5, the first-level label corresponding to the text of Article 6 is L4, the first-level label corresponding to the text of Article 7 is L1, and the first-level label corresponding to the text of Article 8 is L1. The label is L5, the first-level label corresponding to the text in Article 9 is L1, the first-level label corresponding to the text in Article 10 is L3, the first-level label corresponding to the text in Article 11 is L4, and the first-level label corresponding to the text in Article 12 is L4, the first-level label corresponding to the text of Article 13 is L5, the first-level label corresponding to the text of Article 14 is L3, and the first-level label corresponding to the text of Article 15 is L4.
可以确定,第1条文本对应的一级标签对应的编码为:01000,第2条文本对应的一级标签对应的编码为:00100,第3条文本对应的一级标签对应的编码为:10000,第4条文本对应的一级标签对应的编码为:01000,第5条文本对应的一级标签对应的编码为:00001,第6条文本对应的一级标签对应的编码为:00010,第7条文本对应的一级标签对应的编码为:10000,第8条文本对应的一级标签对应的编码为:00001,第9条文本对应的一级标签对应的编码为:10000,第10条文本对应的一级标签对应的编码为:00100,第11条文本对应的一级标签对应的编码为:00010,第12条文本对应的一级标签对应的编码为:00010,第13条文本对应的一级标签对应的编码为:00001,第14条文本对应的一级标签对应的编码为:00100,第15条文本对应的一级标签对应的编码为:00010。那么,根据上述15条文本中的各文本对应的一级标签对应的编码组成的一级标签基准矩阵y1如图4所示。It can be determined that the corresponding code of the first-level label corresponding to the first text is: 01000, the corresponding code of the first-level label corresponding to the second text is: 00100, and the corresponding code of the first-level label corresponding to the third text is: 10000 , The code corresponding to the first level label corresponding to the text in Article 4 is: 01000, the code corresponding to the first level label corresponding to the text in Article 5 is: 00001, the code corresponding to the first level label corresponding to the text in Article 6 is: 00010, The code corresponding to the first-level label corresponding to the 7 texts is: 10000, the code corresponding to the first-level label corresponding to the 8th text is: 00001, the code corresponding to the first-level label corresponding to the 9th text is: 10000, Article 10 The code corresponding to the first-level label corresponding to the text is: 00100, the corresponding code corresponding to the first-level label corresponding to the text of Article 11 is: 00010, the corresponding code corresponding to the first-level label corresponding to the text of Article 12 is: 00010, and the text corresponding to Article 13 is corresponding to The corresponding code of the first-level label is: 00001, the corresponding code of the first-level label corresponding to the text of Article 14 is: 00100, and the corresponding code of the first-level label corresponding to the text of Article 15 is: 00010. Then, the first-level label reference matrix y1 composed of the codes corresponding to the first-level labels corresponding to each of the above 15 texts is shown in FIG. 4.
比如,电子设备可对各文本对应的二级标签进行独热编码处理,得到各文本对应的二级标签对应的编码。当得到各文本对应的二级标签对应的编码之后,电子设备可根据各文本对应的二级标签对应的编码,确定二级标签基准矩阵。其中,二级标签基准矩阵的第一维(行)为多条文本中的各文本,第二维(列)为多条文本中的各文本对应的二级标签对应的编码。例如,二级标签基准矩阵的第i行表示第i条文本对应的二级标签对应的编码。For example, the electronic device may perform one-hot encoding processing on the secondary label corresponding to each text to obtain the code corresponding to the secondary label corresponding to each text. After obtaining the code corresponding to the secondary label corresponding to each text, the electronic device can determine the secondary label reference matrix according to the code corresponding to the secondary label corresponding to each text. Among them, the first dimension (row) of the secondary label reference matrix is each text in the multiple texts, and the second dimension (column) is the code corresponding to the secondary label corresponding to each text in the multiple texts. For example, the i-th row of the secondary label reference matrix represents the code corresponding to the secondary label corresponding to the i-th text.
比如,假设有15个二级标签,分别为S1、S2、S3、S4、S5、S6、S7、S8、S9、S10、S11、S12、S13、S14、S15,当某条文本中包含有S1时,该文本对应的二级标签对应的编码为:100000000000000;当某条文本中包含有S2时,该文本对应的二级标签对应的编码为:010000000000000;当某条文本中包含有S3时,该文本对应的二级标签对应的编码为:001000000000000;当某条文本中包含有S4时,该文本对应的二级标签对应的编码为:000100000000000;当某条文本中包含有S5时,该文本对应的二级标签对应的编码为:000010000000000;当某条文本中包含有S6时,该文本对应的二级标签对应的编码为:000001000000000;当某条文本中包含有S7时,该文本对应的二级标签对应的编码为:000000100000000;当某条文本中包含有S8时,该文本对应的二级标签对应的编码为:000000010000000;当某条文本中包含有S9时,该文本对应的二级标签对应的编码为:000000001000000;当某条文本中包含有S10时,该文本对应的二级标签对应的编码为:000000000100000;当某条文本中包含有S11时,该文本对应的二级标签对应的编码为:000000000010000;当某条文本中包含有S12时,该文本对应的二级标签对应的编码为:000000000001000;当某条文本中包含有S13时,该文本对应的二级标签对应的编码为:000000000000100;当某条文本中包含有S14时,该文本对应的二级标签对应的编码为:000000000000010;当某条文本中包含有S15时,该文本对应的二级标签对应的编码为:000000000000001。For example, suppose there are 15 secondary labels, namely S1, S2, S3, S4, S5, S6, S7, S8, S9, S10, S11, S12, S13, S14, S15, when a piece of text contains S1 When, the corresponding code of the secondary label corresponding to the text is: 100000000000000; when a piece of text contains S2, the corresponding code of the secondary label corresponding to the text is: 010000000000000; when a piece of text contains S3, The code corresponding to the secondary label of the text is: 001000000000000; when a piece of text contains S4, the code corresponding to the secondary label of the text is: 000100000000000; when a piece of text contains S5, the text The corresponding code of the corresponding secondary label is: 000010000000000; when a piece of text contains S6, the corresponding code of the secondary label of the text is: 000001000000000; when a piece of text contains S7, the text corresponds to The code corresponding to the secondary label is: 000000100000000; when a piece of text contains S8, the code corresponding to the secondary label of the text is: 000000010000000; when a piece of text contains S9, the corresponding secondary label of the text The code corresponding to the label is: 000000001000000; when a piece of text contains S10, the corresponding code of the secondary label corresponding to the text is: 000000000100000; when a piece of text contains S11, the secondary label corresponding to the text corresponds to The code of is: 000000000010000; when a piece of text contains S12, the code corresponding to the secondary label of the text is: 000000000001000; when a piece of text contains S13, the code corresponding to the secondary label of the text It is: 000000000000100; when a piece of text contains S14, the corresponding code of the secondary label of the text is: 000000000000010; when a piece of text contains S15, the corresponding code of the secondary label of the text is: 000000000000001.
比如,假设有15条文本,第1条文本对应的二级标签为S3,第2条文本对应的二级标签为S7,第3条文本对应的二级标签为S4,第4条文本对应的二级标签为S5,第5条文本对应的二级标签为S10,第6条文本对应的二级标签为S12,第7条文本对应的二级标签为S1,第8条文本对应的二级标签为S14,第9条文本对应的二级标签为S2,第10条文本对应的二级标签为S6,第11条文本对应的二级标签为S11,第12条文本对应的二级标签为S15,第13条文本对应的二级标签为S13,第14条文本对应的二级标签为S8,第15条文本对应的二级标签为S9。For example, suppose there are 15 texts, the first text corresponding to the secondary label is S3, the second text corresponding to the secondary label is S7, the third text corresponding to the secondary label is S4, and the fourth text corresponds to The second-level label is S5, the second-level label corresponding to the text in Article 5 is S10, the second-level label corresponding to the text in Article 6 is S12, the second-level label corresponding to the text in Article 7 is S1, and the second-level label corresponding to the text in Article 8 is S1. The label is S14, the second-level label corresponding to the text in Article 9 is S2, the second-level label corresponding to the text in Article 10 is S6, the second-level label corresponding to the text in Article 11 is S11, and the second-level label corresponding to the text in Article 12 is S15, the second-level label corresponding to the text of Article 13 is S13, the second-level label corresponding to the text of Article 14 is S8, and the second-level label corresponding to the text of Article 15 is S9.
可以确定,第1条文本对应的二级标签对应的编码为:001000000000000,第2条文本对应的二级标签对应的编码为:000000100000000,第3条文本对应的二级标签对应的编码为:000100000000000,第4条文本对应的二级标签对应的编码为:000010000000000,第5条文本对应的二级标签对应的编码为:000000000100000,第6条文本对应的二级标签对应的编码为:000000000001000,第7条文本对应的二级标签对应的编码为:100000000000000,第8条文本对应的二级标签对应的编码为:000000000000010,第9条文本对应的二级标签对应的编码为:010000000000000,第10条文本对应的二级标签对应的编码为:000001000000000,第11条文本对应的二级标签对应的编码为:000000000010000, 第12条文本对应的二级标签对应的编码为:000000000000001,第13条文本对应的二级标签对应的编码为:000000000000100,第14条文本对应的二级标签对应的编码为:000000010000000,第15条文本对应的二级标签对应的编码为:000000001000000。那么,根据上述15条文本中的各文本对应的二级标签对应的编码组成的二级标签基准矩阵y2如图5所示。It can be determined that the corresponding code of the secondary label corresponding to the first text is: 001000000000000, the corresponding code of the secondary label corresponding to the second text is: 000000100000000, and the corresponding code of the secondary label corresponding to the third text is: 000100000000000 , The code corresponding to the secondary label corresponding to the text in Article 4 is: 000010000000000, the code corresponding to the secondary label corresponding to the text in Article 5 is: 000000000100000, and the code corresponding to the secondary label corresponding to the text in Article 6 is: 000000000001000. The code corresponding to the secondary label corresponding to the 7 texts is: 100000000000000, the code corresponding to the secondary label corresponding to the 8th text is: 000000000000010, and the code corresponding to the secondary label corresponding to the 9th text is: 010000000000000, Article 10. The code corresponding to the second-level label of the text is: 000001000000000, the corresponding code of the second-level label corresponding to the text of Article 11 is: 000000000010000, the code corresponding to the second-level label corresponding to the text of Article 12 is: 000000000000001, and the corresponding code of the text of Article 13 is: The code corresponding to the second-level label is: 000000000000100, the code corresponding to the second-level label corresponding to the text of Article 14 is: 000000010000000, and the code corresponding to the second-level label corresponding to the text of Article 15 is: 000000001000000. Then, the secondary label reference matrix y2 formed according to the code corresponding to the secondary label corresponding to each text in the above 15 texts is shown in FIG. 5.
最后,电子设备可根据分词矩阵、一级标签基准矩阵y1和二级标签基准矩阵y2,确定待训练数据。Finally, the electronic device can determine the data to be trained according to the word segmentation matrix, the primary label reference matrix y1, and the secondary label reference matrix y2.
比如,输入模型中的待训练数据的形式可以为(x,y),那么,在本申请实施例中,分词矩阵可以作为x输入模型中,一级标签基准矩阵y1和二级标签基准矩阵y2可以作为y输入模型中。For example, the form of the data to be trained in the input model can be (x, y), then, in this embodiment of the application, the word segmentation matrix can be used as the x input model, the primary label reference matrix y1 and the secondary label reference matrix y2 Can be input into the model as y.
214、电子设备获取预设关系依赖矩阵,该预设关系依赖矩阵用于表示一级标签和二级标签的层级关系。214. The electronic device obtains a preset relationship dependency matrix, where the preset relationship dependency matrix is used to represent the hierarchical relationship between the primary label and the secondary label.
比如,电子设备可获取如图3所示的预设关系依赖矩阵M0。For example, the electronic device can obtain the preset relationship dependency matrix M0 as shown in FIG. 3.
215、电子设备将待训练数据和预设关系依赖矩阵输入待训练模型中,以得到一级标签预测矩阵和二级标签预测矩阵,该一级标签预测矩阵中的各个元素均为实数。215. The electronic device inputs the data to be trained and the preset relationship dependency matrix into the model to be trained to obtain a primary label prediction matrix and a secondary label prediction matrix, each element in the primary label prediction matrix is a real number.
比如,电子设备可以将待训练数据(x,y)和预设关系依赖矩阵M0输入待训练模型中进行训练,从而可得到一级标签预测矩阵和二级标签预测矩阵。其中,x为分词矩阵,y为一级标签基准矩阵y1和二级标签基准矩阵y2。For example, the electronic device may input the data to be trained (x, y) and the preset relationship dependency matrix M0 into the model to be trained for training, so that the primary label prediction matrix and the secondary label prediction matrix can be obtained. Among them, x is the word segmentation matrix, and y is the primary label reference matrix y1 and the secondary label reference matrix y2.
在本申请实施例中,该待训练模型可先进行参数的初始化。接着,电子设备可将待训练数据和预设关系依赖矩阵输入该待训练模型,经过卷积层、下采样层、全连接层等各层的向前传播得到输出结果,即得到一级标签预测矩阵和二级标签预测矩阵。In this embodiment of the present application, the model to be trained may first initialize its parameters. Then, the electronic device can input the data to be trained and the preset relationship dependency matrix into the model to be trained, and the output result is obtained through forward propagation of the convolutional layer, down-sampling layer, fully connected layer, etc., that is, the first-level label prediction is obtained Matrix and secondary label prediction matrix.
可以理解的是,该待训练模型的网络结构可以采用CNN,也可以采用RNN中任意一种,如LSTM、GRU、Bi-LSTM等。It is understandable that the network structure of the model to be trained can adopt CNN, or any one of RNN, such as LSTM, GRU, Bi-LSTM, and so on.
经待训练模型训练后所得到的一级标签预测矩阵和二级标签预测矩阵的各个元素均为实数。其中,一级标签预测矩阵的第一维(行)表示多条文本中的各文本,第二维(列)表示该待训练模型所预测的多条文本中的各文本对应的一级标签是多个一级标签中的各一级标签的概率。例如,第i行第j列表示第i条文本对应的一级标签是第j个一级标签的概率。例如,一级标签预测矩阵P1可以如图6所示。The elements of the primary label prediction matrix and the secondary label prediction matrix obtained after the training of the model to be trained are all real numbers. Among them, the first dimension (row) of the first-level label prediction matrix represents each text in multiple texts, and the second dimension (column) represents that the first-level label corresponding to each text in the multiple texts predicted by the model to be trained is The probability of each first-level tag among multiple first-level tags. For example, the i-th row and the j-th column indicate the probability that the first-level label corresponding to the i-th text is the j-th first-level label. For example, the first-level label prediction matrix P1 may be as shown in FIG. 6.
在该图6中,第0行第0列表示第1条文本对应的一级标签为L1的概率,第1行第1列,表示第2条文本对应的一级标签为L2的概率,第2行第2列,表示第3条文本对应的一级标签为L3的概率,第3行第3列,表示第4条文本对应的一级标签为L4的概率,第4行第4列,表示第5条文本对应的一级标签为L5的概率……第10行第0列,表示第11条文本对应的一级标签为L1的概率,第11行第1列,表示第12条文本对应的一级标签为L2的概率,第12行第2列,表示第13条文本对应的一级标签为L3的概率,第13行第3列,表示第14条文本对应的一级标签为L4的概率,第14行第4列,表示第15条文本对应的一级标签为L5的概率。In Figure 6, row 0 and column 0 indicate the probability that the first-level label corresponding to the first text is L1, and the first row and first column indicate the probability that the first-level label corresponding to the second text is L2. Row 2 and column 2 indicate the probability that the primary label corresponding to the third text is L3, row 3 and column 3, indicate the probability that the primary label corresponding to the fourth text is L4, row 4 and column 4, Indicates the probability that the first level label corresponding to the fifth text is L5...the 10th row, column 0, represents the probability that the first level label corresponding to the 11th text is L1, the 11th line, the first column, represents the 12th text The corresponding first-level label is the probability of L2, the 12th row and the second column, indicate the probability that the first-level label corresponding to the 13th text is L3, the 13th row and the third column, the first-level label corresponding to the 14th text is The probability of L4, the 14th row and the 4th column, indicates the probability that the first-level label corresponding to the 15th text is L5.
二级标签预测矩阵的第一维(行)表示多条文本中的各文本,第二维(列)表示该待训练模型所预测的多条文本中的各文本对应的二级标签是多个二级标签中的各二级标签的概率。例如,第i行第j列表示第i条文本对应的二级标签是第j个二级标签的概率。例如,二级标签预测矩阵P2可以如图7所示。The first dimension (row) of the second-level label prediction matrix represents each text in multiple texts, and the second dimension (column) represents that the second-level label corresponding to each text in the multiple texts predicted by the model to be trained is multiple The probability of each second-level tag in the second-level tag. For example, the i-th row and the j-th column indicate the probability that the secondary label corresponding to the i-th text is the j-th secondary label. For example, the secondary label prediction matrix P2 may be as shown in FIG. 7.
在该图7中,第0行第0列表示第1条文本对应的二级标签为S1的概率,第1行第1列,表示第2条文本对应的二级标签为S2的概率,第2行第2列,表示第3条文本对应的二级标签为S3的概率,第3行第3列,表示第4条文本对应的二级标签为S4的概率,第4行第4列,表示第5条文本对应的二级标签为S5的概率,第5行第5列,表示第6条文本对应的二级标签为S6的概率,第6行第6列,表示第7条文本对应的二级标签为S7的概率,第7行第7列,表示第8条文本对应的二级标签为S8的概率,第8行第8列,表示第9条文本对应的二级标签为S9的概率,第9行第9列,表示第10条文本对应的二级标签为S10的概率,第10行第10列,表示第11条文本对应的二级标签为S11的概率,第11行第11列,表示第12条文本对应的二级标签为S12的概率,第12行第12列,表示第13条文本对应的二级标签为S13的概率,第13行第13列,表示第14条文本对应的二级标签为S14的概率,第14行第14列,表示第15条文本对应的二级标签为S15的概率,以此类推。In this figure 7, row 0 and column 0 indicate the probability that the second-level label corresponding to the first text is S1, and the first row and first column indicate the probability that the second-level label corresponding to the second text is S2. Row 2 and column 2 indicate the probability that the secondary label corresponding to the third text is S3, row 3 and column 3, indicate the probability that the secondary label corresponding to the fourth text is S4, row 4, column 4, Indicates the probability that the second-level label corresponding to the fifth text is S5, the fifth row and fifth column indicates the probability that the second-level label corresponding to the sixth text is S6, and the sixth row and sixth column indicate that the seventh text corresponds to The second-level label of is the probability of S7. The seventh row and seventh column indicates the probability that the second-level label corresponding to the eighth text is S8, and the eighth row and eighth column indicates that the second-level label corresponding to the ninth text is S9 The probability of, the 9th row and 9th column, indicates the probability that the secondary label corresponding to the 10th text is S10, the 10th row and 10th column, the probability that the secondary label corresponding to the 11th text is S11, the 11th row The 11th column indicates the probability that the secondary label corresponding to the 12th text is S12, the 12th row and the 12th column indicates the probability that the secondary label corresponding to the 13th text is S13, and the 13th column and 13th column indicate the probability of S13. The probability that the secondary label corresponding to the 14th text is S14, the 14th row and the 14th column, indicates the probability that the secondary label corresponding to the 15th text is S15, and so on.
216、电子设备对一级标签预测矩阵进行整数化处理,以使一级标签预测矩阵中的各个元素由实数变为整数,得到一级标签整数矩阵,该一级标签整数矩阵中的各个元素的值为0或1。216. The electronic device performs integerization processing on the first-level label prediction matrix, so that each element in the first-level label prediction matrix is changed from a real number to an integer to obtain a first-level label integer matrix. The value is 0 or 1.
比如,电子设备可对一级标签预测矩阵进行整数化处理,以使一级标签预测矩阵中的各个元素由实数变为整数,得到一级标签整数矩阵,该一级标签整数矩阵中的各个元素的值为0或1。For example, the electronic device can perform integerization processing on the first-level label prediction matrix, so that each element in the first-level label prediction matrix is changed from a real number to an integer, to obtain a first-level label integer matrix, and each element in the first-level label integer matrix The value is 0 or 1.
例如,电子设备可对一级标签预测矩阵P1进行整数化处理,将该一级标签预测矩阵P1转化为0-1整数矩阵P1-1,在该0-1整数矩阵P1-1中,只有最大概率处为1,其余为0。即,该0-1整数矩阵P1-1如图8所示。For example, the electronic device may perform integerization processing on the first-level label prediction matrix P1, and convert the first-level label prediction matrix P1 into a 0-1 integer matrix P1-1. In the 0-1 integer matrix P1-1, only the largest The probability is 1 and the rest is 0. That is, the 0-1 integer matrix P1-1 is as shown in FIG. 8.
217、电子设备将一级标签整数矩阵叉乘预设关系依赖矩阵,得到目标关系依赖矩阵。217. The electronic device cross-multiplies the first-level label integer matrix with the preset relationship dependence matrix to obtain the target relationship dependence matrix.
其中,矩阵A叉乘矩阵B表示计算矩阵A和矩阵B的乘积。Among them, the matrix A cross multiplies the matrix B to calculate the product of the matrix A and the matrix B.
比如,电子设备可计算一级标签整数矩阵和预设关系依赖矩阵的乘积,将该乘积确定为目标关系依赖矩阵。目标关系依赖矩阵M=0-1整数矩阵P1-1×M0。例如,该目标关系依赖矩阵M如图9所示。For example, the electronic device may calculate the product of the first-level label integer matrix and the preset relationship dependence matrix, and determine the product as the target relationship dependence matrix. The target relationship dependence matrix M = 0-1 integer matrix P1-1 × M0. For example, the target relationship dependency matrix M is shown in FIG. 9.
218、电子设备根据一级标签预测矩阵和一级标签基准矩阵,确定第一损失值。218. The electronic device determines the first loss value according to the primary label prediction matrix and the primary label reference matrix.
比如,电子设备可将一级标签预测矩阵P1和一级标签基准矩阵y1作为参数,输入指定的损失函数(loss function)中,从而可以计算一级标签预测矩阵P1和一级标签基准矩阵y1之间的损失值,该损失值即为第一损失值。For example, the electronic device can use the first-level label prediction matrix P1 and the first-level label reference matrix y1 as parameters, and input them into the specified loss function, so as to calculate the difference between the first-level label prediction matrix P1 and the first-level label reference matrix y1. The loss value between time, the loss value is the first loss value.
例如,该指定的损失函数可以为:H(P1,y1)=-∑ ny1(n)·logP1(n)。其中,n表示矩阵的第n列元素。 For example, the specified loss function may be: H(P1, y1)=-Σ n y1(n)·logP1(n). Among them, n represents the nth column element of the matrix.
在本申请实施例中,损失函数通常是用来估量模型的预测值(如一级标签预测矩阵P1)与真实值(如一级标签基准矩阵)的不一致程度。一般情况下,损失函数越小,模型的鲁棒性就越好。损失函数可以根据实际需求来设置,本申请并不对其进行限制。In the embodiment of the present application, the loss function is usually used to estimate the degree of inconsistency between the predicted value of the model (such as the first-level label prediction matrix P1) and the true value (such as the first-level label reference matrix). In general, the smaller the loss function, the better the robustness of the model. The loss function can be set according to actual needs, and this application does not limit it.
219、电子设备根据二级标签预测矩阵和目标关系依赖矩阵,确定目标矩阵。219. The electronic device determines the target matrix according to the secondary label prediction matrix and the target relationship dependency matrix.
220、电子设备根据目标矩阵和二级标签基准矩阵,确定第二损失值。220. The electronic device determines the second loss value according to the target matrix and the secondary label reference matrix.
比如,电子设备可根据二级标签预测矩阵P2和目标关系依赖矩阵M,确定目标矩阵P3。For example, the electronic device may determine the target matrix P3 according to the secondary label prediction matrix P2 and the target relationship dependency matrix M.
电子设备可将目标矩阵P3和二级标签基准矩阵y2作为参数,输入指定的损失函数(loss function)中,从而可以计算目标矩阵P3和二级标签基准矩阵y2之间的损失值,该损失值即为第二损失值。The electronic device can take the target matrix P3 and the secondary label reference matrix y2 as parameters and input them into the specified loss function, so that the loss value between the target matrix P3 and the secondary label reference matrix y2 can be calculated. That is the second loss value.
例如,该指定的损失函数可以为:H(P3,y2)=-∑ ny2(n)·logP3(n)。其中,n表示矩阵的第n列元素。 For example, the specified loss function may be: H(P3, y2)=-Σ n y2(n)·logP3(n). Among them, n represents the nth column element of the matrix.
其中,为了避免取对数时出现log(0)的情况,电子设备可将目标关系依赖矩阵M与一个趋近于0的正数e相加,得到第一矩阵M1。然后再将二级标签预测矩阵P2点乘该第一矩阵M1,得到目标矩阵P3。其中,矩阵A点乘矩阵B表示计算矩阵A和矩阵B的哈达马积。In order to avoid log(0) when taking the logarithm, the electronic device may add the target relationship dependence matrix M to a positive number e approaching 0 to obtain the first matrix M1. Then, the second-level label prediction matrix P2 is dot-multiplied by the first matrix M1 to obtain the target matrix P3. Among them, matrix A is multiplied by matrix B to calculate the Hadamard product of matrix A and matrix B.
221、电子设备根据第一损失值和第二损失值,确定目标损失值。221. The electronic device determines a target loss value according to the first loss value and the second loss value.
比如,当得到第一损失值和第二损失值之后,电子设备可根据该第一损失值和第二损失值,确定目标损失值。该目标损失值即为待训练模型对应的损失值,该目标损失值用于表征该待训练模型是否达到最优。For example, after obtaining the first loss value and the second loss value, the electronic device can determine the target loss value according to the first loss value and the second loss value. The target loss value is the loss value corresponding to the model to be trained, and the target loss value is used to characterize whether the model to be trained is optimal.
222、每当一批待训练数据训练完成后得到一目标损失值,每得到一目标损失值,将目标损失值回传到待训练模型中,以对待训练模型的参数进行调整,直至待训练模型收敛,确认模型训练结束,得到训练后的模型。222. Whenever a batch of training data is trained, a target loss value is obtained, and each target loss value is obtained, the target loss value is returned to the model to be trained to adjust the parameters of the model to be trained until the model to be trained Convergence, confirm the end of model training, and get the trained model.
可以理解的是,当得到一目标损失值之后,可将该目标损失值回传到待训练模型的各层中,从而对待训练模型的参数进行调整。随后,电子设备可继续获取另一批标记有一级标签和二级标签的文本,以得到另一待训练数据,并输入调整参数后的待训练模型中,以继续对待训练模型进行训练。其中,该另一待训练数据与流程213中所得到的待训练数据为不同的两批数据,该另一待训练数据的确定流程可参考流程205至流程213。当本次得到一目标损失值之后,仍可将该目标损失值回传到待训练模型的各层中,从而再次进行参数调整,直至待训练模型收敛,确认模型训练结束,得到训练后的模型。其中,目标损失值逐步逼近某个值,或者在某个数值附近波动,损失变化小于某个很小的正数时,可以确认待训 练模型收敛。It is understandable that after a target loss value is obtained, the target loss value can be transmitted back to each layer of the model to be trained, so as to adjust the parameters of the model to be trained. Subsequently, the electronic device can continue to obtain another batch of texts marked with a primary label and a secondary label to obtain another to-be-trained data, and input it into the to-be-trained model after adjusting the parameters to continue the training of the to-be-trained model. Wherein, the other data to be trained and the data to be trained obtained in the process 213 are two different batches of data, and the determination process of the other data to be trained can refer to the process 205 to the process 213. When a target loss value is obtained this time, the target loss value can still be transmitted back to the layers of the model to be trained, so as to adjust the parameters again until the model to be trained converges, confirm the end of the model training, and obtain the trained model . Among them, the target loss value gradually approaches a certain value, or fluctuates around a certain value, and when the loss change is less than a small positive number, the convergence of the model to be trained can be confirmed.
在另一些实施例中,每输入一批待训练数据对待训练模型进行训练之后,可得到一经过训练的模型,电子设备可从验证集中获取一批验证数据输入该经过训练的模型中,以验证该经过训练的模型的准确率。当本次得到的准确率大于上次得到的准确率时,电子设备可保存本次经过训练的模型。当本次得到的准确率小于上次得到的准确率时,电子设备可不对本次经过训练的模型进行保存。当多次得到的经过训练的模型的准确率不增加时,比如,当多次得到的经过训练的模型的准确率分别为:87%,86.9%,86.7%,86.8%时,电子设备可确认模型训练结束。In other embodiments, after each batch of data to be trained is input and the model to be trained is trained, a trained model can be obtained, and the electronic device can obtain a batch of verification data from the verification set and input it into the trained model to verify The accuracy of the trained model. When the accuracy rate obtained this time is greater than the accuracy rate obtained last time, the electronic device may save the trained model this time. When the accuracy rate obtained this time is less than the accuracy rate obtained last time, the electronic device may not save the trained model this time. When the accuracy of the trained model obtained multiple times does not increase, for example, when the accuracy of the trained model obtained multiple times is 87%, 86.9%, 86.7%, and 86.8%, the electronic device can confirm The model training is over.
在一些实施例中,流程221,可以包括:In some embodiments, the process 221 may include:
电子设备将第一损失值乘以第一权重值,得到第三损失值;The electronic device multiplies the first loss value by the first weight value to obtain the third loss value;
电子设备将第二损失值乘以第二权重值,得到第四损失值,该第二权重值小于所述第一权重值;The electronic device multiplies the second loss value by the second weight value to obtain a fourth loss value, where the second weight value is less than the first weight value;
电子设备根据第三损失值和第四损失值,确定目标损失值。The electronic device determines the target loss value based on the third loss value and the fourth loss value.
为了提高模型预测一级标签的准确率,在得到第一损失值和第二损失值之后,电子设备可将该第一损失值乘以一较大的权重值,得到第三损失值;将第二损失值乘以一较小的权重值,得到第四损失值。然后,电子设备可将该第三损失值和第四损失值相加,得到目标损失值。其中,第一权重值和第二权重值可以根据实际情况设置,例如,第一权重值可以为0.6,第二权重值可以为0.4。In order to improve the accuracy of the model predicting the first-level label, after obtaining the first loss value and the second loss value, the electronic device can multiply the first loss value by a larger weight value to obtain the third loss value; The second loss value is multiplied by a smaller weight value to obtain the fourth loss value. Then, the electronic device can add the third loss value and the fourth loss value to obtain the target loss value. The first weight value and the second weight value can be set according to actual conditions. For example, the first weight value can be 0.6, and the second weight value can be 0.4.
在一些实施例中,流程219,可以包括:In some embodiments, the process 219 may include:
电子设备将目标关系依赖矩阵与预设值相加,得到第一矩阵;The electronic device adds the target relationship dependence matrix to the preset value to obtain the first matrix;
电子设备将二级标签预测矩阵点乘第一矩阵,得到目标矩阵。The electronic device multiplies the second-level label prediction matrix by the first matrix to obtain the target matrix.
为了避免取对数时出现log(0)的情况,电子设备可将目标关系依赖矩阵与预设值相加,比如与一个趋近于0的正数e相加,得到第一矩阵M1。然后再将二级标签预测矩阵P2点乘该第一矩阵M1,得到目标矩阵P3。其中,矩阵A点乘矩阵B即计算矩阵A和矩阵B的哈达马积。In order to avoid log(0) when taking the logarithm, the electronic device may add the target relationship dependence matrix to a preset value, for example, to a positive number e approaching 0 to obtain the first matrix M1. Then, the second-level label prediction matrix P2 is dot-multiplied by the first matrix M1 to obtain the target matrix P3. Among them, matrix A is multiplied by matrix B to calculate the Hadamard product of matrix A and matrix B.
在一些实施例中,流程207,可以包括:In some embodiments, the process 207 may include:
电子设备根据各文本对应的分词,构建词典,该词典包括多个分词及其对应的编码;The electronic device constructs a dictionary based on the word segmentation corresponding to each text, and the dictionary includes multiple word segmentation and their corresponding codes;
电子设备根据各文本对应的分词和词典,确定各文本对应的分词对应的编码。The electronic device determines the code corresponding to the word segmentation corresponding to each text according to the word segmentation and dictionary corresponding to each text.
比如,电子设备可以对多条文本分别对应的分词进行整理,整理出该多条文本分别对应的分词中有哪些不同的分词。然后,电子设备可以对这些不同的分词进行编码,并根据这些不同的分词和这些不同的分词分别对应的编码构建词典。For example, the electronic device can sort the word segmentation corresponding to multiple pieces of text, and sort out the different word segmentation in the word segmentation corresponding to the multiple pieces of text. Then, the electronic device can encode these different word segmentation, and construct a dictionary according to the different word segmentation and the codes corresponding to the different word segmentation respectively.
例如,假设某文本对应的分词为:我们、的、祖国、是、中国。另一文本对应的分词为:我们、的、祖国、是、韩国。那么,根据该文本对应的分词和另一文本对应的分词所构建的词典可如图10所示。For example, suppose the word segmentation corresponding to a certain text is: we, 的, the motherland, is, China. The corresponding participles of the other text are: we, the, the motherland, is, and South Korea. Then, a dictionary constructed based on the word segmentation corresponding to the text and the word segmentation corresponding to another text can be as shown in FIG. 10.
然后,电子设备可根据各文本对应的分词和词典,确定各文本对应的分词对应的编码。Then, the electronic device can determine the code corresponding to the word segmentation corresponding to each text according to the word segmentation and dictionary corresponding to each text.
例如,若某文本为:我们的祖国是中国,那么该文本对应的分词对应的编码为:1、2、3、4、5。For example, if a text is: our home country is China, then the corresponding code of the word segmentation corresponding to the text is: 1, 2, 3, 4, 5.
请参阅图11,图11是本申请实施例提供的分类方法的流程示意图。该分类方法的流程可以包括:Please refer to FIG. 11, which is a schematic flowchart of a classification method provided by an embodiment of the present application. The process of the classification method can include:
301、获取待分类文本。301. Obtain the text to be classified.
比如,电子设备可以获取一需要标记上一级标签和二级标签的文本,即待分类文本。For example, the electronic device can obtain a text that needs to be marked with the upper level label and the second level label, that is, the text to be classified.
302、将待分类文本输入训练后的模型中,得到一级标签概率矩阵和二级标签预测概率矩阵,该一级标签概率矩阵中的每一元素对应一一级标签,该一级标签概率矩阵中的各个元素均为实数,该二级标签预测概率矩阵中的每一元素对应一二级标签,该二级标签预测概率矩阵中的各个元素均为实数。302. Input the text to be classified into the trained model to obtain a first-level label probability matrix and a second-level label prediction probability matrix. Each element in the first-level label probability matrix corresponds to a first-level label, and the first-level label probability matrix Each element in the secondary label prediction probability matrix is a real number, each element in the secondary label prediction probability matrix corresponds to a secondary label, and each element in the secondary label prediction probability matrix is a real number.
303、根据一级标签概率矩阵,确定待分类文本对应的一级标签,该一级标签概率矩阵中值最大的元素对应的一级标签为待分类文本对应的一级标签。303. Determine the primary label corresponding to the text to be classified according to the primary label probability matrix, and the primary label corresponding to the element with the largest value in the primary label probability matrix is the primary label corresponding to the text to be classified.
在获取到待分类文本之后,电子设备可以将该待分类文本输入训练后的模型中,得到一级标签概率矩阵。其中,该一级标签概率矩阵中的每一元素对应一一级标签。该一级标签概率矩阵中的每一元素的值表示该待分类文本对应的一级标签是多个一级标签中的各一级标签的概率。比如,如图12所示,假设多个一级标签分别为:L1、L2、L3、L4、L5,该一级标签概率矩阵可以为P4。在一级标签概率矩阵P4中,第0列表示该待分类文本对应的一级标签为L1的概率,第1列表示该待分类文本对应的一级标 签为L2的概率……第4列表示该待分类文本对应的一级标签为L5的概率。可知,在该一级标签概率矩阵P4中,第0列的概率最大,因此,该待分类文本对应的一级标签即为L1。After obtaining the text to be classified, the electronic device can input the text to be classified into the trained model to obtain the first-level label probability matrix. Wherein, each element in the first-level tag probability matrix corresponds to a first-level tag. The value of each element in the first-level label probability matrix represents the probability that the first-level label corresponding to the text to be classified is each of the multiple first-level labels. For example, as shown in FIG. 12, suppose that multiple first-level labels are respectively: L1, L2, L3, L4, L5, and the first-level label probability matrix may be P4. In the first-level label probability matrix P4, column 0 represents the probability that the first-level label corresponding to the text to be classified is L1, and the first column represents the probability that the first-level label corresponding to the text to be classified is L2...The fourth column represents The probability that the first-level label corresponding to the text to be classified is L5. It can be seen that in the first-level label probability matrix P4, the probability of the 0th column is the largest. Therefore, the first-level label corresponding to the text to be classified is L1.
在本申请实施例中,训练后的模型可以采用如上述实施例中所描述的模型构建方法而生成。具体生成过程可以参见上述实施例的相关描述,在此不再赘述。In the embodiment of the present application, the trained model may be generated using the model construction method described in the foregoing embodiment. For the specific generation process, reference may be made to the relevant description of the foregoing embodiment, which will not be repeated here.
304、对一级标签概率矩阵进行整数化处理,以使一级标签概率矩阵中的各个元素由实数变为整数,得到一级标签整数化矩阵,该一级标签整数化矩阵中的元素的值为0或1。304. Perform integerization processing on the first-level tag probability matrix, so that each element in the first-level tag probability matrix is changed from a real number to an integer to obtain the first-level tag integerization matrix, and the value of the element in the first-level tag integerization matrix is obtained It is 0 or 1.
比如,在得到一级标签概率矩阵之后,电子设备可对一级标签概率矩阵进行整数化处理,以使一级标签概率矩阵中的各个元素由实数变为整数,得到一级标签整数化矩阵。其中,该一级标签整数化矩阵中的元素的值为0或1。For example, after obtaining the first-level tag probability matrix, the electronic device may perform integerization processing on the first-level tag probability matrix, so that each element in the first-level tag probability matrix is changed from a real number to an integer to obtain the first-level tag integerization matrix. Wherein, the value of the element in the first-level label integerization matrix is 0 or 1.
例如,如图12所示,电子设备可对一级标签概率矩阵P4进行整数化处理,将该一级标签概率矩阵P4转化为0-1整数矩阵P5,在该0-1整数矩阵P5中,只有最大概率处为1,其余为0。For example, as shown in FIG. 12, the electronic device can perform integerization processing on the first-level tag probability matrix P4, and convert the first-level tag probability matrix P4 into a 0-1 integer matrix P5. In the 0-1 integer matrix P5, Only the maximum probability is 1 and the rest are 0.
305、根据一级标签整数化矩阵和预设关系依赖矩阵,确定第一关系依赖矩阵。305. Determine the first relationship dependence matrix according to the first-level label integerization matrix and the preset relationship dependence matrix.
例如,如图12所示,电子设备可将该一级标签整数化矩阵P5叉乘如图3所示的预设关系依赖矩阵M0,得到第一关系依赖矩阵M2。其中,矩阵A叉乘矩阵B即计算矩阵A和矩阵B的乘积。For example, as shown in FIG. 12, the electronic device may cross-multiply the first-level label integerization matrix P5 by the preset relationship dependency matrix M0 shown in FIG. 3 to obtain the first relationship dependency matrix M2. Among them, matrix A cross multiplies matrix B to calculate the product of matrix A and matrix B.
306、根据第一关系依赖矩阵和二级标签预测概率矩阵,确定二级标签概率矩阵,该二级标签概率矩阵中的每一元素对应一二级标签。306. Determine a secondary label probability matrix according to the first relationship dependency matrix and the secondary label prediction probability matrix, where each element in the secondary label probability matrix corresponds to a primary and secondary label.
307、根据二级标签概率矩阵,确定待分类文本对应的二级标签,该二级标签概率矩阵中值最大的元素对应的二级标签为待分类文本对应的二级标签。307. Determine the secondary label corresponding to the text to be classified according to the secondary label probability matrix, and the secondary label corresponding to the element with the largest value in the secondary label probability matrix is the secondary label corresponding to the text to be classified.
比如,在获取到待分类文本之后,电子设备可以将该待分类文本输入训练后的模型中,得到二级标签预测概率矩阵。其中,该二级标签预测概率矩阵中的每一元素对应一二级标签。该二级标签预测概率矩阵中的每一元素的值表示该待分类文本对应的二级标签是多个二级标签中的各二级标签的概率。比如,如图12所示,假设多个二级标签分别为:S1、S2、S3、S4、S5、S6、S7、S8、S9、S10、S11、S12、S13、S14、S15,该二级标签预测概率矩阵可以为P6。在二级标签预测概率矩阵P6中,第0列表示该待分类文本对应的二级标签为S1的概率,第1列表示该待分类文本对应的二级标签为S2的概率……第14列表示该待分类文本对应的二级标签为S15的概率。For example, after acquiring the text to be classified, the electronic device may input the text to be classified into the trained model to obtain the secondary label prediction probability matrix. Wherein, each element in the second-level label prediction probability matrix corresponds to a first-level and second-level label. The value of each element in the secondary label prediction probability matrix represents the probability that the secondary label corresponding to the text to be classified is each secondary label among multiple secondary labels. For example, as shown in Figure 12, suppose that multiple secondary labels are: S1, S2, S3, S4, S5, S6, S7, S8, S9, S10, S11, S12, S13, S14, S15. The label prediction probability matrix can be P6. In the second-level label prediction probability matrix P6, column 0 indicates the probability that the second-level label corresponding to the text to be classified is S1, and the first column indicates the probability that the second-level label corresponding to the text to be classified is S2... Column 14 Indicates the probability that the secondary label corresponding to the text to be classified is S15.
然后,电子设备可以将该二级标签预测概率矩阵P6点乘该第一关系依赖矩阵M2,得到二级标签概率矩阵P7。可知,在该第一关系依赖矩阵M2中仅第0列、第1列和第3列为1,其他均为0,因此,该二级标签概率矩阵P7中仅第0列、第1列和第3列存在一不为零的值,其他均为0。而该二级标签概率矩阵P7中的每一元素的值表示该待分类文本对应的二级标签是多个二级标签中的各二级标签的概率。那么,只需要从该二级标签概率矩阵P7中的第0列、第1列和第2列中确定出最大值,将最大值对应的二级标签确定为该待训练文本对应的二级标签即可。相对于相关技术中需要从二级标签概率矩阵中的所有元素对应的值中确定出最大值,将最大值对应的二级标签确定为待训练文本对应的二级标签的方案来说,本申请实施例所提供的分类方法的准确率更高。Then, the electronic device can multiply the second-level label prediction probability matrix P6 by the first relationship dependency matrix M2 to obtain the second-level label probability matrix P7. It can be seen that in the first relationship dependency matrix M2, only the 0th, 1st, and 3rd columns are 1, and the others are all 0. Therefore, only the 0th, 1st, and There is a non-zero value in the third column, and all others are 0. The value of each element in the secondary label probability matrix P7 represents the probability that the secondary label corresponding to the text to be classified is each secondary label among the multiple secondary labels. Then, it is only necessary to determine the maximum value from column 0, column 1, and column 2 of the secondary label probability matrix P7, and determine the secondary label corresponding to the maximum value as the secondary label corresponding to the text to be trained That's it. Compared with the related technology that needs to determine the maximum value from the values corresponding to all elements in the secondary label probability matrix, and the secondary label corresponding to the maximum value is determined as the secondary label corresponding to the text to be trained, this application The classification method provided by the embodiment has a higher accuracy rate.
如图12所示,在该二级标签概率矩阵P7中,第1列元素的概率最大,那么该待分类文本对应的二级标签即为S2。As shown in FIG. 12, in the second-level label probability matrix P7, the probability of the element in the first column is the largest, so the second-level label corresponding to the text to be classified is S2.
当确定出该待分类文本对应的一级标签和二级标签之后,电子设备可以将该一级标签和二级标签标记在该待分类文本上。随后,电子设备可以将该待分类文本划分到对应的类别下。例如,若一级标签为“电视剧”,二级标签为“古装”,那么,电子设备可将该待分类文本划分到电视剧类下的古装类下。After determining the primary label and secondary label corresponding to the text to be classified, the electronic device can mark the primary label and secondary label on the text to be classified. Subsequently, the electronic device can classify the text to be classified into corresponding categories. For example, if the first-level label is "TV drama" and the second-level label is "ancient costume", then the electronic device can classify the text to be classified into the ancient costume category under the TV drama category.
可以理解的是,在本申请实施例中,电子设备可以依次执行流程301至流程307,从而将不同的待分类文本标记上对应的一级标签和二级标签。当需要给某用户推荐文本时,电子设备可以获取该用户对应的标签,然后根据该用户对应的标签从标记有一级标签和二级标签的文本中选取出对应的文本,并将该文本推荐给用户。其中,用户对应的标签可以由电子设备根据用户浏览文章的偏好度确定。比如,若某用户经常浏览的文章带有一级标签L1和二级标签S2,那么该用户对应的标签即为L1和S2,那么在给该用户推送文章时,可以给他推送标记有L1和S2的文章。It can be understood that, in this embodiment of the present application, the electronic device can execute the process 301 to the process 307 in sequence, so as to mark different texts to be classified with corresponding primary labels and secondary labels. When it is necessary to recommend text to a user, the electronic device can obtain the label corresponding to the user, and then select the corresponding text from the text marked with the primary label and the secondary label according to the corresponding label of the user, and recommend the text to user. Wherein, the tag corresponding to the user can be determined by the electronic device according to the user's preference for browsing articles. For example, if a user frequently browses articles with a first-level label L1 and a second-level label S2, then the corresponding tags for the user are L1 and S2, then when pushing articles to the user, he can push the articles marked with L1 and S2 Article.
可以理解的是,若需要使得训练后的模型还可以提供标记三级标签、四级标签等服务,电子设备可以确定三级标签与二级标签的层级关系,并根据该层级关系建立三级标签与二级标签的关系依赖矩阵,建立方法可以参考一级标签和二级标签的关系依赖矩阵的建立方法。同理,电子设备也可以确定四级标签与三级标签的层级关系,并根据该层级关系建立四级标签与三级标签的关系依赖矩阵,建立方法也可以参考一级标签和二级标签的关系依赖矩阵的建立方法。电子设备可按照与一级标签相同的编码方法对多条文本的三级标签和四级标签进行编码,从而形成三级标签基准矩阵和四级标签基准矩阵。然后,电子设备还可将三级标签与二级标签的关系依赖矩阵、四级标签与三级标签的关系依赖矩阵、三级标签基准矩阵和四级标签基准矩阵输入待训练模型中,从而最终训练出可提供标记一级标签、二级标签、三级标签和四级标签服务的模型。It is understandable that if it is necessary to enable the trained model to provide services such as labeling tertiary labels and four-level labels, the electronic device can determine the hierarchical relationship between the tertiary label and the secondary label, and establish the tertiary label according to the hierarchical relationship The relationship dependence matrix with the secondary label can be established by referring to the method for establishing the relationship dependence matrix between the primary label and the secondary label. In the same way, the electronic device can also determine the hierarchical relationship between the fourth-level label and the third-level label, and establish the relationship dependency matrix between the fourth-level label and the third-level label according to the hierarchical relationship. The establishment method can also refer to the first-level label and the second-level label. The establishment method of the relationship dependence matrix. The electronic device can encode the third-level label and the fourth-level label of multiple texts according to the same coding method as the first-level label, thereby forming a three-level label reference matrix and a four-level label reference matrix. Then, the electronic device can also input the relationship dependency matrix between the third-level label and the second-level label, the relationship dependency matrix between the fourth-level label and the third-level label, the third-level label reference matrix, and the fourth-level label reference matrix into the model to be trained, so as to finally Train a model that can provide services for labeling primary, secondary, tertiary, and fourth-level labels.
请参阅图13,图13为本申请实施例提供的模型构建装置的结构示意图。该模型构建装置可以包括:第一获取模块401,第二获取模块402,第一训练模块403,第一确定模块404,第二确定模块405和第二训练模块406。Please refer to FIG. 13, which is a schematic structural diagram of a model construction device provided by an embodiment of the application. The model construction device may include: a first acquisition module 401, a second acquisition module 402, a first training module 403, a first determination module 404, a second determination module 405, and a second training module 406.
第一获取模块401,用于获取待训练数据,所述待训练数据包括多条文本中各文本对应的分词对应的编码所组成的分词矩阵、各文本对应的一级标签对应的编码所组成的一级标签基准矩阵和各文本对应的二级标签对应的编码所组成的二级标签基准矩阵;The first acquisition module 401 is configured to acquire data to be trained. The data to be trained includes a word segmentation matrix composed of codes corresponding to word segmentation corresponding to each text in a plurality of texts, and a word segmentation matrix composed of codes corresponding to first-level tags corresponding to each text. The first-level label reference matrix and the second-level label reference matrix composed of the codes corresponding to the second-level labels corresponding to each text;
第二获取模块402,用于获取预设关系依赖矩阵,所述预设关系依赖矩阵用于表示一级标签和二级标签的层级关系;The second acquiring module 402 is configured to acquire a preset relationship dependency matrix, where the preset relationship dependency matrix is used to represent the hierarchical relationship between the primary label and the secondary label;
第一训练模块403,用于将所述待训练数据和所述预设关系依赖矩阵输入待训练模型中,以得到一级标签预测矩阵和二级标签预测矩阵;The first training module 403 is configured to input the data to be trained and the preset relationship dependency matrix into the model to be trained to obtain a primary label prediction matrix and a secondary label prediction matrix;
第一确定模块404,用于根据所述一级标签预测矩阵和所述预设关系依赖矩阵,确定目标关系依赖矩阵;The first determining module 404 is configured to determine a target relationship dependence matrix according to the first-level label prediction matrix and the preset relationship dependence matrix;
第二确定模块405,用于根据所述一级标签预测矩阵、所述一级标签基准矩阵、目标矩阵和所述二级标签基准矩阵,确定目标损失值,所述目标矩阵根据所述二级标签预测矩阵和所述目标关系依赖矩阵确定;The second determining module 405 is configured to determine a target loss value according to the primary label prediction matrix, the primary label reference matrix, the target matrix, and the secondary label reference matrix, the target matrix according to the secondary label The label prediction matrix and the target relationship dependency matrix are determined;
第二训练模块406,用于每当一批待训练数据训练完成后得到一目标损失值,每得到一目标损失值,将目标损失值回传到待训练模型中,以对待训练模型的参数进行调整,直至待训练模型收敛,确认模型训练结束,得到训练后的模型。The second training module 406 is used to obtain a target loss value after the training of a batch of training data is completed, and to return the target loss value to the model to be trained to perform the parameters of the model to be trained. Adjust until the model to be trained converges, confirm the end of the model training, and get the trained model.
在一些实施例中,第二确定模块405,可以用于:根据所述一级标签预测矩阵和所述一级标签基准矩阵,确定第一损失值;根据所述二级标签预测矩阵和所述目标关系依赖矩阵,确定目标矩阵;根据所述目标矩阵和所述二级标签基准矩阵,确定第二损失值;根据所述第一损失值和所述第二损失值,确定目标损失值。In some embodiments, the second determining module 405 may be configured to: determine the first loss value according to the first-level label prediction matrix and the first-level label reference matrix; and according to the second-level label prediction matrix and the The target relationship dependence matrix is used to determine the target matrix; the second loss value is determined according to the target matrix and the secondary label reference matrix; the target loss value is determined according to the first loss value and the second loss value.
在一些实施例中,第二确定模块405,可以用于:将所述第一损失值乘以第一权重值,得到第三损失值;将所述第二损失值乘以第二权重值,得到第四损失值,所述第二权重值小于所述第一权重值;根据所述第三损失值和所述第四损失值,确定目标损失值。In some embodiments, the second determining module 405 may be used to: multiply the first loss value by a first weight value to obtain a third loss value; and multiply the second loss value by a second weight value, Obtain a fourth loss value, where the second weight value is less than the first weight value; and determine a target loss value according to the third loss value and the fourth loss value.
在一些实施例中,第二确定模块405,可以用于:将所述目标关系依赖矩阵与预设值相加,得到第一矩阵;将所述二级标签预测矩阵点乘所述第一矩阵,得到目标矩阵。In some embodiments, the second determining module 405 may be used to: add the target relationship dependency matrix to a preset value to obtain a first matrix; and multiply the second-level label prediction matrix by the first matrix. , Get the target matrix.
在一些实施例中,第一确定模块404,可以用于:对所述一级标签预测矩阵进行整数化处理,以使所述一级标签预测矩阵中的各个元素由实数变为整数,得到一级标签整数矩阵,所述一级标签整数矩阵中的各个元素的值为0或1;将所述一级标签整数矩阵叉乘所述预设关系依赖矩阵,得到目标关系依赖矩阵。In some embodiments, the first determining module 404 may be used to: perform integer processing on the first-level label prediction matrix, so that each element in the first-level label prediction matrix is changed from a real number to an integer to obtain a The first-level label integer matrix, each element in the first-level label integer matrix has a value of 0 or 1, and the first-level label integer matrix is cross-multiplied by the preset relationship dependency matrix to obtain a target relationship dependency matrix.
在一些实施例中,第一获取模块401,可以用于:获取多条文本、各文本对应的一级标签和各文本对应的二级标签;对各文本进行分词处理,得到各文本对应的分词;确定所述各文本对应的分词对应的编码;根据各文本对应的分词对应的编码,确定分词矩阵;对所述各文本对应的一级标签进行独热编码处理,得到各文本对应的一级标签对应的编码;根据各文本对应的一级标签对应的编码,确定一级标签 基准矩阵;对所述各文本对应的二级标签进行独热编码处理,得到各文本对应的二级标签对应的编码;根据各文本对应的二级标签对应的编码,确定二级标签基准矩阵;根据所述分词矩阵、所述一级标签基准矩阵和所述二级标签基准矩阵,确定待训练数据。In some embodiments, the first obtaining module 401 may be used to: obtain multiple pieces of text, the first-level label corresponding to each text, and the second-level label corresponding to each text; perform word segmentation processing on each text to obtain the word segmentation corresponding to each text Determine the code corresponding to the word segmentation corresponding to each text; determine the word segmentation matrix according to the code corresponding to the word segmentation corresponding to each text; perform one-hot encoding processing on the first-level label corresponding to each text to obtain the first-level corresponding to each text The code corresponding to the label; determine the primary label reference matrix according to the code corresponding to the primary label corresponding to each text; perform one-hot encoding processing on the secondary label corresponding to each text to obtain the corresponding secondary label corresponding to each text Encoding; Determine the secondary label reference matrix according to the encoding corresponding to the secondary label corresponding to each text; Determine the data to be trained according to the word segmentation matrix, the primary label reference matrix and the secondary label reference matrix.
在一些实施例中,第一获取模块401,可以用于:根据所述各文本对应的分词,构建词典,所述词典包括多个分词及其对应的编码;根据所述各文本对应的分词和所述词典,确定各文本对应的分词对应的编码。In some embodiments, the first acquisition module 401 may be used to: construct a dictionary according to the word segmentation corresponding to each text, the dictionary including a plurality of word segmentation and their corresponding codes; according to the word segmentation corresponding to each text and The dictionary determines the code corresponding to the word segmentation corresponding to each text.
在一些实施例中,第一获取模块401,可以用于:获取多个一级标签;获取多个二级标签;确定各一级标签和各二级标签的层级关系;根据所述层级关系,建立预设关系依赖矩阵。In some embodiments, the first obtaining module 401 may be used to: obtain multiple primary tags; obtain multiple secondary tags; determine the hierarchical relationship between each primary tag and each secondary tag; according to the hierarchical relationship, Establish a default relationship dependency matrix.
请参阅图14,图14为本申请实施例提供的分类装置的结构示意图。该分类装置可以包括:第三获取模块501,预测模块502,第三确定模块503,化整模块504,第四确定模块505,第五确定模块506和第六确定模块507。Please refer to FIG. 14, which is a schematic structural diagram of a classification device provided by an embodiment of the application. The classification device may include: a third acquisition module 501, a prediction module 502, a third determination module 503, a rounding module 504, a fourth determination module 505, a fifth determination module 506, and a sixth determination module 507.
第三获取模块501,用于获取待分类文本;The third obtaining module 501 is configured to obtain the text to be classified;
预测模块502,用于将所述待分类文本输入训练后的模型中,得到一级标签概率矩阵和二级标签预测概率矩阵,所述一级标签概率矩阵中的每一元素对应一一级标签,所述一级标签概率矩阵中的各个元素均为实数,所述二级标签预测概率矩阵中的每一元素对应一二级标签,所述二级标签预测概率矩阵中的各个元素均为实数;The prediction module 502 is used to input the text to be classified into the trained model to obtain a first-level label probability matrix and a second-level label prediction probability matrix, each element in the first-level label probability matrix corresponds to a first-level label Each element in the primary label probability matrix is a real number, each element in the secondary label prediction probability matrix corresponds to a primary and secondary label, and each element in the secondary label prediction probability matrix is a real number ;
第三确定模块503,用于根据所述一级标签概率矩阵,确定所述待分类文本对应的一级标签,所述一级标签概率矩阵中值最大的元素对应的一级标签为所述待分类文本对应的一级标签;The third determining module 503 is configured to determine the primary label corresponding to the text to be classified according to the primary label probability matrix, and the primary label corresponding to the element with the largest value in the primary label probability matrix is the The first-level label corresponding to the classified text;
化整模块504,用于对所述一级标签概率矩阵进行整数化处理,以使所述一级标签概率矩阵中的各个元素由实数变为整数,得到一级标签整数化矩阵,所述一级标签整数化矩阵中的元素的值为0或1;The rounding module 504 is configured to perform integer processing on the first-level tag probability matrix, so that each element in the first-level tag probability matrix is changed from a real number to an integer to obtain the first-level tag integerization matrix. The value of the element in the level label integerization matrix is 0 or 1;
第四确定模块505,用于根据所述一级标签整数化矩阵和预设关系依赖矩阵,确定第一关系依赖矩阵;The fourth determining module 505 is configured to determine the first relationship dependence matrix according to the first-level label integerization matrix and the preset relationship dependence matrix;
第五确定模块506,用于根据所述第一关系依赖矩阵和所述二级标签预测概率矩阵,确定二级标签概率矩阵,所述二级标签概率矩阵中的每一元素对应一二级标签;The fifth determining module 506 is configured to determine a secondary label probability matrix according to the first relationship dependency matrix and the secondary label prediction probability matrix, and each element in the secondary label probability matrix corresponds to a primary and secondary label ;
第六确定模块507,用于根据二级标签概率矩阵,确定所述待分类文本对应的二级标签,所述二级标签概率矩阵中值最大的元素对应的二级标签为所述待分类文本对应的二级标签。The sixth determining module 507 is configured to determine the secondary label corresponding to the text to be classified according to the secondary label probability matrix, and the secondary label corresponding to the element with the largest value in the secondary label probability matrix is the text to be classified The corresponding secondary label.
本申请实施例提供一种计算机可读的存储介质,其上存储有计算机程序,当所述计算机程序在计算机上执行时,使得所述计算机执行如本实施例提供的模型构建方法或分类方法中的流程。The embodiment of the present application provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed on a computer, the computer is caused to execute the model construction method or the classification method provided in this embodiment Process.
本申请实施例还提供一种电子设备,包括存储器,处理器,所述存储器中存储有计算机程序,所述处理器通过调用所述存储器中存储的所述计算机程序,用于执行本实施例提供的模型构建方法或分类方法中的流程。An embodiment of the present application also provides an electronic device, including a memory, a processor, and a computer program stored in the memory. The processor is configured to execute the computer program stored in the memory by calling the computer program stored in the memory. The model building method or the process in the classification method.
例如,上述电子设备可以是诸如平板电脑或者智能手机等移动终端。请参阅图15,图15为本申请实施例提供的电子设备的第一种结构示意图。For example, the above-mentioned electronic device may be a mobile terminal such as a tablet computer or a smart phone. Please refer to FIG. 15. FIG. 15 is a schematic diagram of the first structure of an electronic device provided by an embodiment of this application.
该电子设备600可以包括存储器601、处理器602等部件。本领域技术人员可以理解,图15中示出的电子设备结构并不构成对电子设备的限定,可以包括比图示更多或更少的部件,或者组合某些部件,或者不同的部件布置。The electronic device 600 may include components such as a memory 601 and a processor 602. Those skilled in the art can understand that the structure of the electronic device shown in FIG. 15 does not constitute a limitation on the electronic device, and may include more or fewer components than shown in the figure, or a combination of certain components, or different component arrangements.
存储器601可用于存储应用程序和数据。存储器601存储的应用程序中包含有可执行代码。应用程序可以组成各种功能模块。处理器602通过运行存储在存储器601的应用程序,从而执行各种功能应用以及数据处理。The memory 601 can be used to store application programs and data. The application program stored in the memory 601 contains executable code. Application programs can be composed of various functional modules. The processor 602 executes various functional applications and data processing by running application programs stored in the memory 601.
处理器602是电子设备的控制中心,利用各种接口和线路连接整个电子设备的各个部分,通过运行或执行存储在存储器601内的应用程序,以及调用存储在存储器601内的数据,执行电子设备的各种功能和处理数据,从而对电子设备进行整体监控。The processor 602 is the control center of the electronic device. It uses various interfaces and lines to connect various parts of the entire electronic device, and executes the electronic device by running or executing the application program stored in the memory 601 and calling the data stored in the memory 601 The various functions and processing data of the electronic equipment can be used to monitor the electronic equipment as a whole.
在本实施例中,电子设备中的处理器602会按照如下的指令,将一个或一个以上的应用程序的进程对应的可执行代码加载到存储器601中,并由处理器601来运行存储在存储器601中的应用程序,从 而实现流程:In this embodiment, the processor 602 in the electronic device loads the executable code corresponding to the process of one or more application programs into the memory 601 according to the following instructions, and the processor 601 runs and stores the executable code in the memory 601 The application in 601, so as to realize the process:
获取待训练数据,所述待训练数据包括多条文本中各文本对应的分词对应的编码所组成的分词矩阵、各文本对应的一级标签对应的编码所组成的一级标签基准矩阵和各文本对应的二级标签对应的编码所组成的二级标签基准矩阵;Obtain the data to be trained. The data to be trained includes a word segmentation matrix composed of codes corresponding to word segmentation corresponding to each text in a plurality of texts, a first-level label reference matrix composed of codes corresponding to a first-level label corresponding to each text, and each text The reference matrix of the secondary label formed by the codes corresponding to the corresponding secondary label;
获取预设关系依赖矩阵,所述预设关系依赖矩阵用于表示一级标签和二级标签的层级关系;Acquiring a preset relationship dependency matrix, where the preset relationship dependency matrix is used to represent the hierarchical relationship between the primary label and the secondary label;
将所述待训练数据和所述预设关系依赖矩阵输入待训练模型中,以得到一级标签预测矩阵和二级标签预测矩阵;Inputting the to-be-trained data and the preset relationship dependency matrix into the to-be-trained model to obtain a primary label prediction matrix and a secondary label prediction matrix;
根据所述一级标签预测矩阵和所述预设关系依赖矩阵,确定目标关系依赖矩阵;Determine a target relationship dependence matrix according to the first-level label prediction matrix and the preset relationship dependence matrix;
根据所述一级标签预测矩阵、所述一级标签基准矩阵、目标矩阵和所述二级标签基准矩阵,确定目标损失值,所述目标矩阵根据所述二级标签预测矩阵和所述目标关系依赖矩阵确定;Determine a target loss value according to the primary label prediction matrix, the primary label reference matrix, the target matrix, and the secondary label reference matrix, and the target matrix is based on the secondary label prediction matrix and the target relationship Dependent matrix determination;
每当一批待训练数据训练完成后得到一目标损失值,每得到一目标损失值,将目标损失值回传到待训练模型中,以对待训练模型的参数进行调整,直至待训练模型收敛,确认模型训练结束,得到训练后的模型。Whenever a batch of training data is trained, a target loss value is obtained. For each target loss value obtained, the target loss value is returned to the model to be trained to adjust the parameters of the model to be trained until the model to be trained converges. Confirm that the model training is over and get the trained model.
在本实施例中,电子设备中的处理器602会按照如下的指令,将一个或一个以上的应用程序的进程对应的可执行代码加载到存储器601中,并由处理器601来运行存储在存储器601中的应用程序,从而实现流程:In this embodiment, the processor 602 in the electronic device loads the executable code corresponding to the process of one or more application programs into the memory 601 according to the following instructions, and the processor 601 runs and stores the executable code in the memory 601 The application in 601, so as to realize the process:
获取待分类文本;Obtain the text to be classified;
将所述待分类文本输入训练后的模型中,得到一级标签概率矩阵和二级标签预测概率矩阵,所述一级标签概率矩阵中的每一元素对应一一级标签,所述一级标签概率矩阵中的各个元素均为实数,所述二级标签预测概率矩阵中的每一元素对应一二级标签,所述二级标签预测概率矩阵中的各个元素均为实数;Input the text to be classified into the trained model to obtain a first-level label probability matrix and a second-level label prediction probability matrix. Each element in the first-level label probability matrix corresponds to a first-level label, and the first-level label Each element in the probability matrix is a real number, each element in the secondary label prediction probability matrix corresponds to a primary and secondary label, and each element in the secondary label prediction probability matrix is a real number;
根据所述一级标签概率矩阵,确定所述待分类文本对应的一级标签,所述一级标签概率矩阵中值最大的元素对应的一级标签为所述待分类文本对应的一级标签;Determine the primary label corresponding to the text to be classified according to the primary label probability matrix, and the primary label corresponding to the element with the largest value in the primary label probability matrix is the primary label corresponding to the text to be classified;
对所述一级标签概率矩阵进行整数化处理,以使所述一级标签概率矩阵中的各个元素由实数变为整数,得到一级标签整数化矩阵,所述一级标签整数化矩阵中的元素的值为0或1;Perform integerization processing on the first-level tag probability matrix, so that each element in the first-level tag probability matrix changes from a real number to an integer to obtain a first-level tag integerization matrix. The value of the element is 0 or 1;
根据所述一级标签整数化矩阵和预设关系依赖矩阵,确定第一关系依赖矩阵;Determine the first relationship dependence matrix according to the first-level label integerization matrix and the preset relationship dependence matrix;
根据所述第一关系依赖矩阵和所述二级标签预测概率矩阵,确定二级标签概率矩阵,所述二级标签概率矩阵中的每一元素对应一二级标签;Determining a secondary label probability matrix according to the first relationship dependency matrix and the secondary label prediction probability matrix, where each element in the secondary label probability matrix corresponds to a primary and secondary label;
根据二级标签概率矩阵,确定所述待分类文本对应的二级标签,所述二级标签概率矩阵中值最大的元素对应的二级标签为所述待分类文本对应的二级标签。According to the secondary label probability matrix, the secondary label corresponding to the text to be classified is determined, and the secondary label corresponding to the element with the largest value in the secondary label probability matrix is the secondary label corresponding to the text to be classified.
请参阅图16,图16为本申请实施例提供的电子设备的第二种结构示意图。Please refer to FIG. 16, which is a schematic diagram of a second structure of an electronic device provided by an embodiment of this application.
该电子设备600可以包括存储器601、处理器602、输入单元603、输出单元604、显示屏605等部件。The electronic device 600 may include components such as a memory 601, a processor 602, an input unit 603, an output unit 604, and a display screen 605.
存储器601可用于存储应用程序和数据。存储器601存储的应用程序中包含有可执行代码。应用程序可以组成各种功能模块。处理器602通过运行存储在存储601的应用程序,从而执行各种功能应用以及数据处理。The memory 601 can be used to store application programs and data. The application program stored in the memory 601 contains executable code. Application programs can be composed of various functional modules. The processor 602 executes various functional applications and data processing by running application programs stored in the storage 601.
处理器602是电子设备的控制中心,利用各种接口和线路连接整个电子设备的各个部分,通过运行或执行存储在存储器601内的应用程序,以及调用存储在存储器601内的数据,执行电子设备的各种功能和处理数据,从而对电子设备进行整体监控。The processor 602 is the control center of the electronic device. It uses various interfaces and lines to connect the various parts of the entire electronic device, and executes the electronic device by running or executing the application program stored in the memory 601 and calling the data stored in the memory 601 The various functions and processing data of the electronic equipment can be used to monitor the electronic equipment as a whole.
输入单元603可用于接收输入的数字、字符信息或用户特征信息(比如指纹),以及产生与用户设置以及功能控制有关的键盘、鼠标、操作杆、光学或者轨迹球信号输入。The input unit 603 can be used to receive inputted numbers, character information or user characteristic information (such as fingerprints), and generate keyboard, mouse, joystick, optical or trackball signal input related to user settings and function control.
输出单元604可用于显示由用户输入的信息或提供给用户的信息以及电子设备的各种图形用户接口,这些图形用户接口可以由图形、文本、图标、视频和其任意组合来构成。输出单元可包括显示面板。The output unit 604 may be used to display information input by the user or information provided to the user and various graphical user interfaces of the electronic device. These graphical user interfaces may be composed of graphics, text, icons, videos, and any combination thereof. The output unit may include a display panel.
显示屏605可以用于显示文字、图片等信息。The display screen 605 can be used to display information such as text and pictures.
在本实施例中,电子设备中的处理器602会按照如下的指令,将一个或一个以上的应用程序的进 程对应的可执行代码加载到存储器601中,并由处理器602来运行存储在存储器601中的应用程序,从而实现流程:In this embodiment, the processor 602 in the electronic device loads the executable code corresponding to the process of one or more application programs into the memory 601 according to the following instructions, and the processor 602 runs and stores the executable code in the memory 601 The application in 601, so as to realize the process:
获取待训练数据,所述待训练数据包括多条文本中各文本对应的分词对应的编码所组成的分词矩阵、各文本对应的一级标签对应的编码所组成的一级标签基准矩阵和各文本对应的二级标签对应的编码所组成的二级标签基准矩阵;Obtain the data to be trained. The data to be trained includes a word segmentation matrix composed of codes corresponding to word segmentation corresponding to each text in a plurality of texts, a first-level label reference matrix composed of codes corresponding to a first-level label corresponding to each text, and each text The reference matrix of the secondary label formed by the codes corresponding to the corresponding secondary label;
获取预设关系依赖矩阵,所述预设关系依赖矩阵用于表示一级标签和二级标签的层级关系;Acquiring a preset relationship dependency matrix, where the preset relationship dependency matrix is used to represent the hierarchical relationship between the primary label and the secondary label;
将所述待训练数据和所述预设关系依赖矩阵输入待训练模型中,以得到一级标签预测矩阵和二级标签预测矩阵;Inputting the to-be-trained data and the preset relationship dependency matrix into the to-be-trained model to obtain a primary label prediction matrix and a secondary label prediction matrix;
根据所述一级标签预测矩阵和所述预设关系依赖矩阵,确定目标关系依赖矩阵;Determine a target relationship dependence matrix according to the first-level label prediction matrix and the preset relationship dependence matrix;
根据所述一级标签预测矩阵、所述一级标签基准矩阵、目标矩阵和所述二级标签基准矩阵,确定目标损失值,所述目标矩阵根据所述二级标签预测矩阵和所述目标关系依赖矩阵确定;Determine a target loss value according to the primary label prediction matrix, the primary label reference matrix, the target matrix, and the secondary label reference matrix, and the target matrix is based on the secondary label prediction matrix and the target relationship Dependent matrix determination;
每当一批待训练数据训练完成后得到一目标损失值,每得到一目标损失值,将目标损失值回传到待训练模型中,以对待训练模型的参数进行调整,直至待训练模型收敛,确认模型训练结束,得到训练后的模型。Whenever a batch of training data is trained, a target loss value is obtained. For each target loss value obtained, the target loss value is returned to the model to be trained to adjust the parameters of the model to be trained until the model to be trained converges. Confirm that the model training is over and get the trained model.
在一些实施方式中,处理器602执行所述根据所述一级标签预测矩阵、所述一级标签基准矩阵、目标矩阵和所述二级标签基准矩阵,确定目标损失值,所述目标矩阵根据所述二级标签预测矩阵和所述目标关系依赖矩阵确定时,可以执行:根据所述一级标签预测矩阵和所述一级标签基准矩阵,确定第一损失值;根据所述二级标签预测矩阵和所述目标关系依赖矩阵,确定目标矩阵;根据所述目标矩阵和所述二级标签基准矩阵,确定第二损失值;根据所述第一损失值和所述第二损失值,确定目标损失值。In some implementation manners, the processor 602 executes the determination of a target loss value based on the primary label prediction matrix, the primary label reference matrix, the target matrix, and the secondary label reference matrix, and the target matrix is based on When the secondary label prediction matrix and the target relationship dependency matrix are determined, it may be executed: according to the primary label prediction matrix and the primary label reference matrix, the first loss value is determined; according to the secondary label prediction Determine the target matrix based on the matrix and the target relationship dependence matrix; determine the second loss value according to the target matrix and the secondary label reference matrix; determine the target according to the first loss value and the second loss value Loss value.
在一些实施方式中,处理器602执行所述根据所述第一损失值和所述第二损失值,确定目标损失值时,可以执行:将所述第一损失值乘以第一权重值,得到第三损失值;将所述第二损失值乘以第二权重值,得到第四损失值,所述第二权重值小于所述第一权重值;根据所述第三损失值和所述第四损失值,确定目标损失值。In some implementation manners, when the processor 602 executes the determination of the target loss value according to the first loss value and the second loss value, it may execute: multiply the first loss value by a first weight value, Obtain a third loss value; multiply the second loss value by a second weight value to obtain a fourth loss value, where the second weight value is less than the first weight value; according to the third loss value and the The fourth loss value determines the target loss value.
在一些实施方式中,处理器602执行所述根据所述二级标签预测矩阵和所述目标关系依赖矩阵,确定目标矩阵时,可以执行:将所述目标关系依赖矩阵与预设值相加,得到第一矩阵;将所述二级标签预测矩阵点乘所述第一矩阵,得到目标矩阵。In some embodiments, the processor 602 executes the prediction matrix based on the secondary label and the target relationship dependency matrix, and when determining the target matrix, it may execute: adding the target relationship dependency matrix to a preset value, Obtain a first matrix; multiply the first matrix by the second-level label prediction matrix to obtain a target matrix.
在一些实施方式中,所述一级标签预测矩阵中的各个元素均为实数,处理器602执行所述根据所述一级标签预测矩阵和所述预设关系依赖矩阵,确定目标关系依赖矩阵时,可以执行:对所述一级标签预测矩阵进行整数化处理,以使所述一级标签预测矩阵中的各个元素由实数变为整数,得到一级标签整数矩阵,所述一级标签整数矩阵中的各个元素的值为0或1;将所述一级标签整数矩阵叉乘所述预设关系依赖矩阵,得到目标关系依赖矩阵。In some implementation manners, each element in the primary label prediction matrix is a real number, and the processor 602 executes the determination of the target relationship dependence matrix according to the primary label prediction matrix and the preset relationship dependence matrix. , It may be executed: performing integerization processing on the first-level label prediction matrix, so that each element in the first-level label prediction matrix is changed from a real number to an integer to obtain a first-level label integer matrix, the first-level label integer matrix The value of each element in is 0 or 1; the first-level label integer matrix is cross-multiplied by the preset relationship dependence matrix to obtain the target relationship dependence matrix.
在一些实施方式中,处理器602执行所述获取待训练数据,所述待训练数据包括多条文本中各文本对应的分词对应的编码所组成的分词矩阵、各文本对应的一级标签对应的编码所组成的一级标签基准矩阵和各文本对应的二级标签对应的编码所组成的二级标签基准矩阵时,可以执行:获取多条文本、各文本对应的一级标签和各文本对应的二级标签;对各文本进行分词处理,得到各文本对应的分词;确定所述各文本对应的分词对应的编码;根据各文本对应的分词对应的编码,确定分词矩阵;对所述各文本对应的一级标签进行独热编码处理,得到各文本对应的一级标签对应的编码;根据各文本对应的一级标签对应的编码,确定一级标签基准矩阵;对所述各文本对应的二级标签进行独热编码处理,得到各文本对应的二级标签对应的编码;根据各文本对应的二级标签对应的编码,确定二级标签基准矩阵;根据所述分词矩阵、所述一级标签基准矩阵和所述二级标签基准矩阵,确定待训练数据。In some embodiments, the processor 602 executes the acquisition of data to be trained, and the data to be trained includes a word segmentation matrix composed of codes corresponding to word segmentation corresponding to each text in a plurality of texts, and a word segmentation matrix corresponding to a first-level label corresponding to each text. When the primary label reference matrix formed by codes and the secondary label reference matrix formed by the codes corresponding to the secondary labels corresponding to each text, you can execute: obtain multiple texts, the primary labels corresponding to each text, and the corresponding text Second-level tags; perform word segmentation processing on each text to obtain the word segmentation corresponding to each text; determine the code corresponding to the word segmentation corresponding to each text; determine the word segmentation matrix according to the code corresponding to the word segmentation corresponding to each text; correspond to each text One-hot encoding process is performed on the first-level tags of each text to obtain the codes corresponding to the first-level tags corresponding to each text; the first-level tag reference matrix is determined according to the codes corresponding to the first-level tags corresponding to each text; The tags are subjected to one-hot encoding processing to obtain the codes corresponding to the second-level tags of each text; determine the second-level tag reference matrix according to the codes corresponding to the second-level tags of each text; according to the word segmentation matrix and the first-level tag reference The matrix and the secondary label reference matrix determine the data to be trained.
在一些实施方式中,处理器602执行所述确定所述各文本对应的分词对应的编码时,可以执行:根据所述各文本对应的分词,构建词典,所述词典包括多个分词及其对应的编码;根据所述各文本对应的分词和所述词典,确定各文本对应的分词对应的编码。In some implementation manners, when the processor 602 executes the code corresponding to the word segmentation corresponding to each text, it may execute: construct a dictionary according to the word segmentation corresponding to each text, and the dictionary includes a plurality of word segmentation and their corresponding codes. The encoding; according to the word segmentation corresponding to each text and the dictionary, the encoding corresponding to the word segmentation corresponding to each text is determined.
在一些实施方式中,处理器602执行所述获取待训练数据之前,可以执行:获取多个一级标签;获 取多个二级标签;确定各一级标签和各二级标签的层级关系;根据所述层级关系,建立预设关系依赖矩阵。In some embodiments, before the processor 602 executes the acquisition of the data to be trained, it may execute: acquire multiple primary tags; acquire multiple secondary tags; determine the hierarchical relationship between each primary tag and each secondary tag; The hierarchical relationship establishes a preset relationship dependency matrix.
在本实施例中,电子设备中的处理器602会按照如下的指令,将一个或一个以上的应用程序的进程对应的可执行代码加载到存储器601中,并由处理器602来运行存储在存储器601中的应用程序,从而实现流程:In this embodiment, the processor 602 in the electronic device loads the executable code corresponding to the process of one or more application programs into the memory 601 according to the following instructions, and the processor 602 runs and stores the executable code in the memory 601 The application in 601, so as to realize the process:
获取待分类文本;Obtain the text to be classified;
将所述待分类文本输入训练后的模型中,得到一级标签概率矩阵和二级标签预测概率矩阵,所述一级标签概率矩阵中的每一元素对应一一级标签,所述一级标签概率矩阵中的各个元素均为实数,所述二级标签预测概率矩阵中的每一元素对应一二级标签,所述二级标签预测概率矩阵中的各个元素均为实数;Input the text to be classified into the trained model to obtain a first-level label probability matrix and a second-level label prediction probability matrix. Each element in the first-level label probability matrix corresponds to a first-level label, and the first-level label Each element in the probability matrix is a real number, each element in the secondary label prediction probability matrix corresponds to a primary and secondary label, and each element in the secondary label prediction probability matrix is a real number;
根据所述一级标签概率矩阵,确定所述待分类文本对应的一级标签,所述一级标签概率矩阵中值最大的元素对应的一级标签为所述待分类文本对应的一级标签;Determine the primary label corresponding to the text to be classified according to the primary label probability matrix, and the primary label corresponding to the element with the largest value in the primary label probability matrix is the primary label corresponding to the text to be classified;
对所述一级标签概率矩阵进行整数化处理,以使所述一级标签概率矩阵中的各个元素由实数变为整数,得到一级标签整数化矩阵,所述一级标签整数化矩阵中的元素的值为0或1;Perform integerization processing on the first-level tag probability matrix, so that each element in the first-level tag probability matrix changes from a real number to an integer to obtain a first-level tag integerization matrix. The value of the element is 0 or 1;
根据所述一级标签整数化矩阵和预设关系依赖矩阵,确定第一关系依赖矩阵;Determine the first relationship dependence matrix according to the first-level label integerization matrix and the preset relationship dependence matrix;
根据所述第一关系依赖矩阵和所述二级标签预测概率矩阵,确定二级标签概率矩阵,所述二级标签概率矩阵中的每一元素对应一二级标签;Determining a secondary label probability matrix according to the first relationship dependency matrix and the secondary label prediction probability matrix, where each element in the secondary label probability matrix corresponds to a primary and secondary label;
根据二级标签概率矩阵,确定所述待分类文本对应的二级标签,所述二级标签概率矩阵中值最大的元素对应的二级标签为所述待分类文本对应的二级标签。According to the secondary label probability matrix, the secondary label corresponding to the text to be classified is determined, and the secondary label corresponding to the element with the largest value in the secondary label probability matrix is the secondary label corresponding to the text to be classified.
在上述实施例中,对各个实施例的描述都各有侧重,某个实施例中没有详述的部分,可以参见上文针对模型构建方法/分类方法的详细描述,此处不再赘述。In the foregoing embodiments, the description of each embodiment has its own focus. For parts that are not described in detail in an embodiment, please refer to the detailed description of the model construction method/classification method above, which will not be repeated here.
本申请实施例提供的所述模型构建方法/分类方法装置与上文实施例中的模型构建方法/分类方法属于同一构思,在所述模型构建方法/分类方法装置上可以运行所述模型构建方法/分类方法实施例中提供的任一方法,其具体实现过程详见所述模型构建方法/分类方法实施例,此处不再赘述。The model construction method/classification method device provided by the embodiment of the application belongs to the same concept as the model construction method/classification method in the above embodiment, and the model construction method can be run on the model construction method/classification method device For any method provided in the embodiment of the classification method, for the specific implementation process, please refer to the embodiment of the model construction method/classification method, which will not be repeated here.
需要说明的是,对本申请实施例所述模型构建方法/分类方法而言,本领域普通技术人员可以理解实现本申请实施例所述模型构建方法/分类方法的全部或部分流程,是可以通过计算机程序来控制相关的硬件来完成,所述计算机程序可存储于一计算机可读取存储介质中,如存储在存储器中,并被至少一个处理器执行,在执行过程中可包括如所述模型构建方法/分类方法的实施例的流程。其中,所述的存储介质可为磁碟、光盘、只读存储器(ROM,Read Only Memory)、随机存取记忆体(RAM,Random Access Memory)等。It should be noted that for the model construction method/classification method described in the embodiment of this application, a person of ordinary skill in the art can understand that all or part of the process of realizing the model construction method/classification method described in the embodiment of this application can be achieved through a computer The computer program can be stored in a computer readable storage medium, such as stored in a memory, and executed by at least one processor. The execution process can include constructing the model as described above. The flow of the method/classification method of the embodiment. Wherein, the storage medium may be a magnetic disk, an optical disc, a read only memory (ROM, Read Only Memory), a random access memory (RAM, Random Access Memory), etc.
对本申请实施例的所述模型构建方法/分类方法装置而言,其各功能模块可以集成在一个处理芯片中,也可以是各个模块单独物理存在,也可以两个或两个以上模块集成在一个模块中。上述集成的模块既可以采用硬件的形式实现,也可以采用软件功能模块的形式实现。所述集成的模块如果以软件功能模块的形式实现并作为独立的产品销售或使用时,也可以存储在一个计算机可读取存储介质中,所述存储介质譬如为只读存储器,磁盘或光盘等。For the model construction method/classification method device of the embodiment of the present application, each functional module may be integrated in a processing chip, or each module may exist alone physically, or two or more modules may be integrated in one Module. The above-mentioned integrated modules can be implemented in the form of hardware or software function modules. If the integrated module is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a computer readable storage medium, such as a read-only memory, a magnetic disk or an optical disk, etc. .
以上对本申请实施例所提供的一种模型构建方法、分类方法、装置、存储介质以及电子设备进行了详细介绍,本文中应用了具体个例对本申请的原理及实施方式进行了阐述,以上实施例的说明只是用于帮助理解本申请的方法及其核心思想;同时,对于本领域的技术人员,依据本申请的思想,在具体实施方式及应用范围上均会有改变之处,综上所述,本说明书内容不应理解为对本申请的限制。The model construction method, classification method, device, storage medium, and electronic equipment provided in the embodiments of the application are described in detail above. Specific examples are used in this article to illustrate the principles and implementation of the application. The above embodiments The description is only used to help understand the method and core idea of this application; at the same time, for those skilled in the art, according to the idea of this application, there will be changes in the specific implementation and scope of application. In summary , The content of this manual should not be construed as a limitation on this application.

Claims (20)

  1. 一种模型构建方法,其中,包括:A model construction method, which includes:
    获取待训练数据,所述待训练数据包括多条文本中各文本对应的分词对应的编码所组成的分词矩阵、各文本对应的一级标签对应的编码所组成的一级标签基准矩阵和各文本对应的二级标签对应的编码所组成的二级标签基准矩阵;Obtain the data to be trained. The data to be trained includes a word segmentation matrix composed of codes corresponding to word segmentation corresponding to each text in a plurality of texts, a first-level label reference matrix composed of codes corresponding to a first-level label corresponding to each text, and each text The reference matrix of the secondary label formed by the codes corresponding to the corresponding secondary label;
    获取预设关系依赖矩阵,所述预设关系依赖矩阵用于表示一级标签和二级标签的层级关系;Acquiring a preset relationship dependency matrix, where the preset relationship dependency matrix is used to represent the hierarchical relationship between the primary label and the secondary label;
    将所述待训练数据和所述预设关系依赖矩阵输入待训练模型中,以得到一级标签预测矩阵和二级标签预测矩阵;Inputting the to-be-trained data and the preset relationship dependency matrix into the to-be-trained model to obtain a primary label prediction matrix and a secondary label prediction matrix;
    根据所述一级标签预测矩阵和所述预设关系依赖矩阵,确定目标关系依赖矩阵;Determine a target relationship dependence matrix according to the first-level label prediction matrix and the preset relationship dependence matrix;
    根据所述一级标签预测矩阵、所述一级标签基准矩阵、目标矩阵和所述二级标签基准矩阵,确定目标损失值,所述目标矩阵根据所述二级标签预测矩阵和所述目标关系依赖矩阵确定;Determine a target loss value according to the primary label prediction matrix, the primary label reference matrix, the target matrix, and the secondary label reference matrix, and the target matrix is based on the secondary label prediction matrix and the target relationship Dependent matrix determination;
    每当一批待训练数据训练完成后得到一目标损失值,每得到一目标损失值,将目标损失值回传到待训练模型中,以对待训练模型的参数进行调整,直至待训练模型收敛,确认模型训练结束,得到训练后的模型。Whenever a batch of training data is trained, a target loss value is obtained. For each target loss value obtained, the target loss value is returned to the model to be trained to adjust the parameters of the model to be trained until the model to be trained converges. Confirm that the model training is over and get the trained model.
  2. 根据权利要求1所述的模型构建方法,其中,所述根据所述一级标签预测矩阵、所述一级标签基准矩阵、目标矩阵和所述二级标签基准矩阵,确定目标损失值,所述目标矩阵根据所述二级标签预测矩阵和所述目标关系依赖矩阵确定,包括:The model construction method according to claim 1, wherein the target loss value is determined according to the primary label prediction matrix, the primary label reference matrix, the target matrix and the secondary label reference matrix, and The target matrix is determined according to the secondary label prediction matrix and the target relationship dependency matrix, and includes:
    根据所述一级标签预测矩阵和所述一级标签基准矩阵,确定第一损失值;Determine a first loss value according to the primary label prediction matrix and the primary label reference matrix;
    根据所述二级标签预测矩阵和所述目标关系依赖矩阵,确定目标矩阵;Determine a target matrix according to the secondary label prediction matrix and the target relationship dependency matrix;
    根据所述目标矩阵和所述二级标签基准矩阵,确定第二损失值;Determine a second loss value according to the target matrix and the secondary label reference matrix;
    根据所述第一损失值和所述第二损失值,确定目标损失值。According to the first loss value and the second loss value, a target loss value is determined.
  3. 根据权利要求2所述的模型构建方法,其中,所述根据所述第一损失值和所述第二损失值,确定目标损失值,包括:The model construction method according to claim 2, wherein the determining the target loss value according to the first loss value and the second loss value comprises:
    将所述第一损失值乘以第一权重值,得到第三损失值;Multiply the first loss value by the first weight value to obtain a third loss value;
    将所述第二损失值乘以第二权重值,得到第四损失值,所述第二权重值小于所述第一权重值;Multiplying the second loss value by a second weight value to obtain a fourth loss value, where the second weight value is smaller than the first weight value;
    根据所述第三损失值和所述第四损失值,确定目标损失值。According to the third loss value and the fourth loss value, a target loss value is determined.
  4. 根据权利要求2所述的模型构建方法,其中,所述根据所述二级标签预测矩阵和所述目标关系依赖矩阵,确定目标矩阵,包括:The model construction method according to claim 2, wherein the determining the target matrix according to the secondary label prediction matrix and the target relationship dependency matrix comprises:
    将所述目标关系依赖矩阵与预设值相加,得到第一矩阵;Adding the target relationship dependency matrix to a preset value to obtain a first matrix;
    将所述二级标签预测矩阵点乘所述第一矩阵,得到目标矩阵。Multiply the first matrix by the second-level label prediction matrix to obtain a target matrix.
  5. 根据权利要求1所述的模型构建方法,其中,所述一级标签预测矩阵中的各个元素均为实数,所述根据所述一级标签预测矩阵和所述预设关系依赖矩阵,确定目标关系依赖矩阵,包括:The model construction method according to claim 1, wherein each element in the first-level label prediction matrix is a real number, and the target relationship is determined according to the first-level label prediction matrix and the preset relationship dependency matrix The dependency matrix includes:
    对所述一级标签预测矩阵进行整数化处理,以使所述一级标签预测矩阵中的各个元素由实数变为整数,得到一级标签整数矩阵,所述一级标签整数矩阵中的各个元素的值为0或1;Perform integerization processing on the first-level label prediction matrix, so that each element in the first-level label prediction matrix is changed from a real number to an integer to obtain a first-level label integer matrix, and each element in the first-level label integer matrix The value is 0 or 1;
    将所述一级标签整数矩阵叉乘所述预设关系依赖矩阵,得到目标关系依赖矩阵。Multiplying the first-level label integer matrix by the preset relationship dependence matrix to obtain a target relationship dependence matrix.
  6. 根据权利要求1所述的模型构建方法,其中,所述获取待训练数据,所述待训练数据包括多条文本中各文本对应的分词对应的编码所组成的分词矩阵、各文本对应的一级标签对应的编码所组成的一级标签基准矩阵和各文本对应的二级标签对应的编码所组成的二级标签基准矩阵,包括:The model construction method according to claim 1, wherein the acquired data to be trained includes a word segmentation matrix composed of codes corresponding to word segmentation corresponding to each text in a plurality of texts, and a first level corresponding to each text The primary label reference matrix formed by the codes corresponding to the labels and the secondary label reference matrix formed by the codes corresponding to the secondary labels corresponding to each text include:
    获取多条文本、各文本对应的一级标签和各文本对应的二级标签;Obtain multiple pieces of text, the first-level label corresponding to each text, and the second-level label corresponding to each text;
    对各文本进行分词处理,得到各文本对应的分词;Perform word segmentation processing on each text to obtain the word segmentation corresponding to each text;
    确定所述各文本对应的分词对应的编码;Determine the code corresponding to the word segmentation corresponding to each text;
    根据各文本对应的分词对应的编码,确定分词矩阵;Determine the word segmentation matrix according to the code corresponding to the word segmentation corresponding to each text;
    对所述各文本对应的一级标签进行独热编码处理,得到各文本对应的一级标签对应的编码;Performing one-hot encoding processing on the first-level label corresponding to each text to obtain the code corresponding to the first-level label corresponding to each text;
    根据各文本对应的一级标签对应的编码,确定一级标签基准矩阵;Determine the first-level label reference matrix according to the code corresponding to the first-level label corresponding to each text;
    对所述各文本对应的二级标签进行独热编码处理,得到各文本对应的二级标签对应的编码;Performing one-hot encoding processing on the secondary label corresponding to each text to obtain the code corresponding to the secondary label corresponding to each text;
    根据各文本对应的二级标签对应的编码,确定二级标签基准矩阵;Determine the reference matrix of the secondary label according to the code corresponding to the secondary label corresponding to each text;
    根据所述分词矩阵、所述一级标签基准矩阵和所述二级标签基准矩阵,确定待训练数据。Determine the data to be trained according to the word segmentation matrix, the primary label reference matrix, and the secondary label reference matrix.
  7. 根据权利要求6所述的模型构建方法,其中,所述确定所述各文本对应的分词对应的编码,包括:The model construction method according to claim 6, wherein said determining the code corresponding to the word segmentation corresponding to each text comprises:
    根据所述各文本对应的分词,构建词典,所述词典包括多个分词及其对应的编码;Construct a dictionary according to the word segmentation corresponding to each text, the dictionary including a plurality of word segmentation and their corresponding codes;
    根据所述各文本对应的分词和所述词典,确定各文本对应的分词对应的编码。According to the word segmentation corresponding to each text and the dictionary, the code corresponding to the word segmentation corresponding to each text is determined.
  8. 根据权利要求1所述的模型构建方法,其中,在所述获取待训练数据之前,还包括:The model construction method according to claim 1, wherein before said obtaining the data to be trained, it further comprises:
    获取多个一级标签;Get multiple first-level labels;
    获取多个二级标签;Obtain multiple secondary labels;
    确定各一级标签和各二级标签的层级关系;Determine the hierarchical relationship between each primary label and each secondary label;
    根据所述层级关系,建立预设关系依赖矩阵。According to the hierarchical relationship, a preset relationship dependency matrix is established.
  9. 一种分类方法,其中,包括:A classification method, which includes:
    获取待分类文本;Obtain the text to be classified;
    将所述待分类文本输入训练后的模型中,得到一级标签概率矩阵和二级标签预测概率矩阵,所述一级标签概率矩阵中的每一元素对应一一级标签,所述一级标签概率矩阵中的各个元素均为实数,所述二级标签预测概率矩阵中的每一元素对应一二级标签,所述二级标签预测概率矩阵中的各个元素均为实数;Input the text to be classified into the trained model to obtain a first-level label probability matrix and a second-level label prediction probability matrix. Each element in the first-level label probability matrix corresponds to a first-level label, and the first-level label Each element in the probability matrix is a real number, each element in the secondary label prediction probability matrix corresponds to a primary and secondary label, and each element in the secondary label prediction probability matrix is a real number;
    根据所述一级标签概率矩阵,确定所述待分类文本对应的一级标签,所述一级标签概率矩阵中值最大的元素对应的一级标签为所述待分类文本对应的一级标签;Determine the primary label corresponding to the text to be classified according to the primary label probability matrix, and the primary label corresponding to the element with the largest value in the primary label probability matrix is the primary label corresponding to the text to be classified;
    对所述一级标签概率矩阵进行整数化处理,以使所述一级标签概率矩阵中的各个元素由实数变为整数,得到一级标签整数化矩阵,所述一级标签整数化矩阵中的元素的值为0或1;Perform integerization processing on the first-level tag probability matrix, so that each element in the first-level tag probability matrix changes from a real number to an integer to obtain a first-level tag integerization matrix. The value of the element is 0 or 1;
    根据所述一级标签整数化矩阵和预设关系依赖矩阵,确定第一关系依赖矩阵;Determine the first relationship dependence matrix according to the first-level label integerization matrix and the preset relationship dependence matrix;
    根据所述第一关系依赖矩阵和所述二级标签预测概率矩阵,确定二级标签概率矩阵,所述二级标签概率矩阵中的每一元素对应一二级标签;Determining a secondary label probability matrix according to the first relationship dependency matrix and the secondary label prediction probability matrix, where each element in the secondary label probability matrix corresponds to a primary and secondary label;
    根据所述二级标签概率矩阵,确定所述待分类文本对应的二级标签,所述二级标签概率矩阵中值最大的元素对应的二级标签为所述待分类文本对应的二级标签。According to the secondary label probability matrix, the secondary label corresponding to the text to be classified is determined, and the secondary label corresponding to the element with the largest value in the secondary label probability matrix is the secondary label corresponding to the text to be classified.
  10. 一种模型构建装置,其中,包括:A model building device, which includes:
    第一获取模块,用于获取待训练数据,所述待训练数据包括多条文本中各文本对应的分词对应的编码所组成的分词矩阵、各文本对应的一级标签对应的编码所组成的一级标签基准矩阵和各文本对应的二级标签对应的编码所组成的二级标签基准矩阵;The first acquisition module is used to acquire data to be trained. The data to be trained includes a word segmentation matrix composed of codes corresponding to word segmentation corresponding to each text in a plurality of texts, and a word segmentation matrix composed of codes corresponding to first-level tags corresponding to each text. A level-label reference matrix and a second-level label reference matrix composed of codes corresponding to the second-level labels corresponding to each text;
    第二获取模块,用于获取预设关系依赖矩阵,所述预设关系依赖矩阵用于表示一级标签和二级标签的层级关系;The second acquiring module is configured to acquire a preset relationship dependency matrix, where the preset relationship dependency matrix is used to represent the hierarchical relationship between the primary label and the secondary label;
    第一训练模块,用于将所述待训练数据和所述预设关系依赖矩阵输入待训练模型中,以得到一级标签预测矩阵和二级标签预测矩阵;The first training module is configured to input the data to be trained and the preset relationship dependency matrix into the model to be trained to obtain a primary label prediction matrix and a secondary label prediction matrix;
    第一确定模块,用于根据所述一级标签预测矩阵和所述预设关系依赖矩阵,确定目标关系依赖矩阵;A first determining module, configured to determine a target relationship dependence matrix according to the first-level label prediction matrix and the preset relationship dependence matrix;
    第二确定模块,用于根据所述一级标签预测矩阵、所述一级标签基准矩阵、目标矩阵和所述二级标签基准矩阵,确定目标损失值,所述目标矩阵根据所述二级标签预测矩阵和所述目标关系依赖矩阵确定;The second determining module is configured to determine a target loss value according to the primary label prediction matrix, the primary label reference matrix, the target matrix, and the secondary label reference matrix, and the target matrix is based on the secondary label The prediction matrix and the target relationship dependency matrix are determined;
    第二训练模块,用于每当一批待训练数据训练完成后得到一目标损失值,每得到一目标损失值,将目标损失值回传到待训练模型中,以对待训练模型的参数进行调整,直至待训练模型收敛,确认模型训练结束,得到训练后的模型。The second training module is used to obtain a target loss value after the training of a batch of training data is completed, and for each target loss value obtained, the target loss value is transmitted back to the model to be trained to adjust the parameters of the model to be trained , Until the model to be trained converges, confirm the end of the model training, and get the trained model.
  11. 一种分类装置,其中,包括:A classification device, which includes:
    第三获取模块,用于获取待分类文本;The third obtaining module is used to obtain the text to be classified;
    预测模块,用于将所述待分类文本输入训练后的模型中,得到一级标签概率矩阵和二级标签预测概率矩阵,所述一级标签概率矩阵中的每一元素对应一一级标签,所述一级标签概率矩阵中的各个元素均 为实数,所述二级标签预测概率矩阵中的每一元素对应一二级标签,所述二级标签预测概率矩阵中的各个元素均为实数;The prediction module is used to input the text to be classified into the trained model to obtain a first-level label probability matrix and a second-level label prediction probability matrix, each element in the first-level label probability matrix corresponds to a first-level label, Each element in the primary label probability matrix is a real number, each element in the secondary label prediction probability matrix corresponds to a primary and secondary label, and each element in the secondary label prediction probability matrix is a real number;
    第三确定模块,用于根据所述一级标签概率矩阵,确定所述待分类文本对应的一级标签,所述一级标签概率矩阵中值最大的元素对应的一级标签为所述待分类文本对应的一级标签;The third determining module is configured to determine the primary label corresponding to the text to be classified according to the primary label probability matrix, and the primary label corresponding to the element with the largest value in the primary label probability matrix is the to be classified The first level label corresponding to the text;
    化整模块,用于对所述一级标签概率矩阵进行整数化处理,以使所述一级标签概率矩阵中的各个元素由实数变为整数,得到一级标签整数化矩阵,所述一级标签整数化矩阵中的元素的值为0或1;The rounding module is used to perform integerization processing on the first-level tag probability matrix, so that each element in the first-level tag probability matrix is changed from a real number to an integer to obtain the first-level tag integerization matrix. The value of the element in the label integerization matrix is 0 or 1;
    第四确定模块,用于根据所述一级标签整数化矩阵和预设关系依赖矩阵,确定第一关系依赖矩阵;A fourth determining module, configured to determine a first relationship dependence matrix according to the first-level label integerization matrix and a preset relationship dependence matrix;
    第五确定模块,用于根据所述第一关系依赖矩阵和所述二级标签预测概率矩阵,确定二级标签概率矩阵,所述二级标签概率矩阵中的每一元素对应一二级标签;A fifth determining module, configured to determine a secondary label probability matrix according to the first relationship dependency matrix and the secondary label prediction probability matrix, and each element in the secondary label probability matrix corresponds to a primary and secondary label;
    第六确定模块,用于根据所述二级标签概率矩阵,确定所述待分类文本对应的二级标签,所述二级标签概率矩阵中值最大的元素对应的二级标签为所述待分类文本对应的二级标签。The sixth determining module is configured to determine the secondary label corresponding to the text to be classified according to the secondary label probability matrix, and the secondary label corresponding to the element with the largest value in the secondary label probability matrix is the to be classified The secondary label corresponding to the text.
  12. 一种存储介质,其中,所述存储介质中存储有计算机程序,当所述计算机程序在计算机上运行时,使得所述计算机执行权利要求1至8任一项所述的模型构建方法或权利要求9所述的分类方法。A storage medium, wherein a computer program is stored in the storage medium, and when the computer program is run on a computer, the computer is caused to execute the model construction method or claim of any one of claims 1 to 8 9 the classification method.
  13. 一种电子设备,其中,所述电子设备包括处理器和存储器,所述存储器中存储有计算机程序,所述处理器通过调用所述存储器中存储的所述计算机程序,用于执行:An electronic device, wherein the electronic device includes a processor and a memory, and a computer program is stored in the memory, and the processor is configured to execute:
    获取待训练数据,所述待训练数据包括多条文本中各文本对应的分词对应的编码所组成的分词矩阵、各文本对应的一级标签对应的编码所组成的一级标签基准矩阵和各文本对应的二级标签对应的编码所组成的二级标签基准矩阵;Obtain the data to be trained. The data to be trained includes a word segmentation matrix composed of codes corresponding to word segmentation corresponding to each text in a plurality of texts, a first-level label reference matrix composed of codes corresponding to a first-level label corresponding to each text, and each text The reference matrix of the secondary label formed by the codes corresponding to the corresponding secondary label;
    获取预设关系依赖矩阵,所述预设关系依赖矩阵用于表示一级标签和二级标签的层级关系;Acquiring a preset relationship dependency matrix, where the preset relationship dependency matrix is used to represent the hierarchical relationship between the primary label and the secondary label;
    将所述待训练数据和所述预设关系依赖矩阵输入待训练模型中,以得到一级标签预测矩阵和二级标签预测矩阵;Inputting the to-be-trained data and the preset relationship dependency matrix into the to-be-trained model to obtain a primary label prediction matrix and a secondary label prediction matrix;
    根据所述一级标签预测矩阵和所述预设关系依赖矩阵,确定目标关系依赖矩阵;Determine a target relationship dependence matrix according to the first-level label prediction matrix and the preset relationship dependence matrix;
    根据所述一级标签预测矩阵、所述一级标签基准矩阵、目标矩阵和所述二级标签基准矩阵,确定目标损失值,所述目标矩阵根据所述二级标签预测矩阵和所述目标关系依赖矩阵确定;Determine a target loss value according to the primary label prediction matrix, the primary label reference matrix, the target matrix, and the secondary label reference matrix, and the target matrix is based on the secondary label prediction matrix and the target relationship Dependent matrix determination;
    每当一批待训练数据训练完成后得到一目标损失值,每得到一目标损失值,将目标损失值回传到待训练模型中,以对待训练模型的参数进行调整,直至待训练模型收敛,确认模型训练结束,得到训练后的模型。Whenever a batch of training data is trained, a target loss value is obtained. For each target loss value obtained, the target loss value is returned to the model to be trained to adjust the parameters of the model to be trained until the model to be trained converges. Confirm that the model training is over and get the trained model.
  14. 根据权利要求13所述的电子设备,其中,所述处理器用于执行:The electronic device according to claim 13, wherein the processor is configured to execute:
    根据所述一级标签预测矩阵和所述一级标签基准矩阵,确定第一损失值;Determine a first loss value according to the primary label prediction matrix and the primary label reference matrix;
    根据所述二级标签预测矩阵和所述目标关系依赖矩阵,确定目标矩阵;Determine a target matrix according to the secondary label prediction matrix and the target relationship dependency matrix;
    根据所述目标矩阵和所述二级标签基准矩阵,确定第二损失值;Determine a second loss value according to the target matrix and the secondary label reference matrix;
    根据所述第一损失值和所述第二损失值,确定目标损失值。According to the first loss value and the second loss value, a target loss value is determined.
  15. 根据权利要求14所述的电子设备,其中,所述处理器用于执行:The electronic device according to claim 14, wherein the processor is configured to execute:
    将所述第一损失值乘以第一权重值,得到第三损失值;Multiply the first loss value by the first weight value to obtain a third loss value;
    将所述第二损失值乘以第二权重值,得到第四损失值,所述第二权重值小于所述第一权重值;Multiplying the second loss value by a second weight value to obtain a fourth loss value, where the second weight value is smaller than the first weight value;
    根据所述第三损失值和所述第四损失值,确定目标损失值。According to the third loss value and the fourth loss value, a target loss value is determined.
  16. 根据权利要求14所述的电子设备,其中,所述处理器用于执行:The electronic device according to claim 14, wherein the processor is configured to execute:
    将所述目标关系依赖矩阵与预设值相加,得到第一矩阵;Adding the target relationship dependency matrix to a preset value to obtain a first matrix;
    将所述二级标签预测矩阵点乘所述第一矩阵,得到目标矩阵。Multiply the first matrix by the second-level label prediction matrix to obtain a target matrix.
  17. 根据权利要求13所述的电子设备,其中,所述一级标签预测矩阵中的各个元素均为实数,所述处理器用于执行:The electronic device according to claim 13, wherein each element in the first-level label prediction matrix is a real number, and the processor is configured to execute:
    对所述一级标签预测矩阵进行整数化处理,以使所述一级标签预测矩阵中的各个元素由实数变为整数,得到一级标签整数矩阵,所述一级标签整数矩阵中的各个元素的值为0或1;Perform integerization processing on the first-level label prediction matrix, so that each element in the first-level label prediction matrix is changed from a real number to an integer to obtain a first-level label integer matrix, and each element in the first-level label integer matrix The value is 0 or 1;
    将所述一级标签整数矩阵叉乘所述预设关系依赖矩阵,得到目标关系依赖矩阵。Multiplying the first-level label integer matrix by the preset relationship dependence matrix to obtain a target relationship dependence matrix.
  18. 根据权利要求13所述的电子设备,其中,所述处理器用于执行:The electronic device according to claim 13, wherein the processor is configured to execute:
    获取多条文本、各文本对应的一级标签和各文本对应的二级标签;Obtain multiple pieces of text, the first-level label corresponding to each text, and the second-level label corresponding to each text;
    对各文本进行分词处理,得到各文本对应的分词;Perform word segmentation processing on each text to obtain the word segmentation corresponding to each text;
    确定所述各文本对应的分词对应的编码;Determine the code corresponding to the word segmentation corresponding to each text;
    根据各文本对应的分词对应的编码,确定分词矩阵;Determine the word segmentation matrix according to the code corresponding to the word segmentation corresponding to each text;
    对所述各文本对应的一级标签进行独热编码处理,得到各文本对应的一级标签对应的编码;Performing one-hot encoding processing on the first-level label corresponding to each text to obtain the code corresponding to the first-level label corresponding to each text;
    根据各文本对应的一级标签对应的编码,确定一级标签基准矩阵;Determine the first-level label reference matrix according to the code corresponding to the first-level label corresponding to each text;
    对所述各文本对应的二级标签进行独热编码处理,得到各文本对应的二级标签对应的编码;Performing one-hot encoding processing on the secondary label corresponding to each text to obtain the code corresponding to the secondary label corresponding to each text;
    根据各文本对应的二级标签对应的编码,确定二级标签基准矩阵;Determine the reference matrix of the secondary label according to the code corresponding to the secondary label corresponding to each text;
    根据所述分词矩阵、所述一级标签基准矩阵和所述二级标签基准矩阵,确定待训练数据。Determine the data to be trained according to the word segmentation matrix, the primary label reference matrix, and the secondary label reference matrix.
  19. 根据权利要求18所述的电子设备,其中,所述处理器用于执行:The electronic device according to claim 18, wherein the processor is configured to execute:
    根据所述各文本对应的分词,构建词典,所述词典包括多个分词及其对应的编码;Construct a dictionary according to the word segmentation corresponding to each text, the dictionary including a plurality of word segmentation and their corresponding codes;
    根据所述各文本对应的分词和所述词典,确定各文本对应的分词对应的编码。According to the word segmentation corresponding to each text and the dictionary, the code corresponding to the word segmentation corresponding to each text is determined.
  20. 一种电子设备,其中,所述电子设备包括处理器和存储器,所述存储器中存储有计算机程序,所述处理器通过调用所述存储器中存储的所述计算机程序,用于执行:An electronic device, wherein the electronic device includes a processor and a memory, and a computer program is stored in the memory, and the processor is configured to execute:
    获取待分类文本;Obtain the text to be classified;
    将所述待分类文本输入训练后的模型中,得到一级标签概率矩阵和二级标签预测概率矩阵,所述一级标签概率矩阵中的每一元素对应一一级标签,所述一级标签概率矩阵中的各个元素均为实数,所述二级标签预测概率矩阵中的每一元素对应一二级标签,所述二级标签预测概率矩阵中的各个元素均为实数;Input the text to be classified into the trained model to obtain a first-level label probability matrix and a second-level label prediction probability matrix. Each element in the first-level label probability matrix corresponds to a first-level label, and the first-level label Each element in the probability matrix is a real number, each element in the secondary label prediction probability matrix corresponds to a primary and secondary label, and each element in the secondary label prediction probability matrix is a real number;
    根据所述一级标签概率矩阵,确定所述待分类文本对应的一级标签,所述一级标签概率矩阵中值最大的元素对应的一级标签为所述待分类文本对应的一级标签;Determine the primary label corresponding to the text to be classified according to the primary label probability matrix, and the primary label corresponding to the element with the largest value in the primary label probability matrix is the primary label corresponding to the text to be classified;
    对所述一级标签概率矩阵进行整数化处理,以使所述一级标签概率矩阵中的各个元素由实数变为整数,得到一级标签整数化矩阵,所述一级标签整数化矩阵中的元素的值为0或1;Perform integerization processing on the first-level tag probability matrix, so that each element in the first-level tag probability matrix changes from a real number to an integer to obtain a first-level tag integerization matrix. The value of the element is 0 or 1;
    根据所述一级标签整数化矩阵和预设关系依赖矩阵,确定第一关系依赖矩阵;Determine the first relationship dependence matrix according to the first-level label integerization matrix and the preset relationship dependence matrix;
    根据所述第一关系依赖矩阵和所述二级标签预测概率矩阵,确定二级标签概率矩阵,所述二级标签概率矩阵中的每一元素对应一二级标签;Determining a secondary label probability matrix according to the first relationship dependency matrix and the secondary label prediction probability matrix, where each element in the secondary label probability matrix corresponds to a primary and secondary label;
    根据所述二级标签概率矩阵,确定所述待分类文本对应的二级标签,所述二级标签概率矩阵中值最大的元素对应的二级标签为所述待分类文本对应的二级标签。According to the secondary label probability matrix, the secondary label corresponding to the text to be classified is determined, and the secondary label corresponding to the element with the largest value in the secondary label probability matrix is the secondary label corresponding to the text to be classified.
PCT/CN2019/114473 2019-10-30 2019-10-30 Model construction method, classification method, apparatus, storage medium and electronic device WO2021081837A1 (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
PCT/CN2019/114473 WO2021081837A1 (en) 2019-10-30 2019-10-30 Model construction method, classification method, apparatus, storage medium and electronic device
CN201980098836.0A CN114175017A (en) 2019-10-30 2019-10-30 Model construction method, classification method, device, storage medium and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/CN2019/114473 WO2021081837A1 (en) 2019-10-30 2019-10-30 Model construction method, classification method, apparatus, storage medium and electronic device

Publications (1)

Publication Number Publication Date
WO2021081837A1 true WO2021081837A1 (en) 2021-05-06

Family

ID=75715698

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2019/114473 WO2021081837A1 (en) 2019-10-30 2019-10-30 Model construction method, classification method, apparatus, storage medium and electronic device

Country Status (2)

Country Link
CN (1) CN114175017A (en)
WO (1) WO2021081837A1 (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113361621A (en) * 2021-06-18 2021-09-07 北京百度网讯科技有限公司 Method and apparatus for training a model
CN115659058A (en) * 2022-12-30 2023-01-31 杭州远传新业科技股份有限公司 Method and device for generating questions

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20020143806A1 (en) * 2001-02-03 2002-10-03 Yong Bae Lee System and method for learning and classifying genre of document
CN101727500A (en) * 2010-01-15 2010-06-09 清华大学 Text classification method of Chinese web page based on steam clustering
WO2019024704A1 (en) * 2017-08-03 2019-02-07 阿里巴巴集团控股有限公司 Entity annotation method, intention recognition method and corresponding devices, and computer storage medium
CN110059181A (en) * 2019-03-18 2019-07-26 中国科学院自动化研究所 Short text stamp methods, system, device towards extensive classification system
CN110263854A (en) * 2019-06-20 2019-09-20 广州酷狗计算机科技有限公司 Live streaming label determines method, apparatus and storage medium
CN110276052A (en) * 2019-06-10 2019-09-24 北京科技大学 A kind of archaic Chinese automatic word segmentation and part-of-speech tagging integral method and device

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20020143806A1 (en) * 2001-02-03 2002-10-03 Yong Bae Lee System and method for learning and classifying genre of document
CN101727500A (en) * 2010-01-15 2010-06-09 清华大学 Text classification method of Chinese web page based on steam clustering
WO2019024704A1 (en) * 2017-08-03 2019-02-07 阿里巴巴集团控股有限公司 Entity annotation method, intention recognition method and corresponding devices, and computer storage medium
CN110059181A (en) * 2019-03-18 2019-07-26 中国科学院自动化研究所 Short text stamp methods, system, device towards extensive classification system
CN110276052A (en) * 2019-06-10 2019-09-24 北京科技大学 A kind of archaic Chinese automatic word segmentation and part-of-speech tagging integral method and device
CN110263854A (en) * 2019-06-20 2019-09-20 广州酷狗计算机科技有限公司 Live streaming label determines method, apparatus and storage medium

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113361621A (en) * 2021-06-18 2021-09-07 北京百度网讯科技有限公司 Method and apparatus for training a model
CN113361621B (en) * 2021-06-18 2023-12-15 北京百度网讯科技有限公司 Method and device for training model
CN115659058A (en) * 2022-12-30 2023-01-31 杭州远传新业科技股份有限公司 Method and device for generating questions

Also Published As

Publication number Publication date
CN114175017A (en) 2022-03-11

Similar Documents

Publication Publication Date Title
US20220245213A1 (en) Content recommendation method and apparatus, electronic device, and storage medium
CN109002488B (en) Recommendation model training method and device based on meta-path context
CN106776673B (en) Multimedia document summarization
CN107273438B (en) Recommendation method, device, equipment and storage medium
JP7431833B2 (en) Language sequence labeling methods, devices, programs and computing equipment
CN106776881A (en) A kind of realm information commending system and method based on microblog
US9378432B2 (en) Hierarchy similarity measure
CN110909182A (en) Multimedia resource searching method and device, computer equipment and storage medium
US20230386238A1 (en) Data processing method and apparatus, computer device, and storage medium
WO2021081837A1 (en) Model construction method, classification method, apparatus, storage medium and electronic device
CN112183881A (en) Public opinion event prediction method and device based on social network and storage medium
US10296635B2 (en) Auditing and augmenting user-generated tags for digital content
CN115048571A (en) Online education recommendation management system based on cloud platform
CN114036378A (en) Information pushing method and device, storage medium and electronic equipment
CN113158051B (en) Label sorting method based on information propagation and multilayer context information modeling
US20180090021A1 (en) Ranking courses for a presentation
US20180137587A1 (en) Contextual personalized list of recommended courses
CN114429384B (en) Intelligent product recommendation method and system based on e-commerce platform
CN113657116B (en) Social media popularity prediction method and device based on visual semantic relationship
KR102358195B1 (en) System for providing selected articles using linear regression
US20180137588A1 (en) Contextual personalized list of recommended courses
CN114493674A (en) Advertisement click rate prediction model and method
US10430431B2 (en) Recommending courses for an electronic presentation
CN117786234B (en) Multimode resource recommendation method based on two-stage comparison learning
CN117273003B (en) Text data processing method, model training method and named entity recognition method

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: 19950602

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: 19950602

Country of ref document: EP

Kind code of ref document: A1

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 181022)

122 Ep: pct application non-entry in european phase

Ref document number: 19950602

Country of ref document: EP

Kind code of ref document: A1