一维卷积神经网络matlab,使用卷积神经网络对文本数据进行分类

本文档介绍了如何使用Matlab的一维卷积神经网络(1D CNN)对工厂报告的文本数据进行故障分类。首先加载预训练的fastText单词嵌入,接着处理和预览数据,然后定义1D CNN网络架构,并进行训练。最后,对新的故障报告进行预测。
摘要由CSDN通过智能技术生成

加载预训练的单词嵌入

加载预训练的 fastText 单词嵌入。此函数需要 Text Analytics Toolbox™ Model for fastText English 16 Billion Token Word Embedding 支持包。如果未安装此支持包,则函数会提供下载链接。

emb = fastTextWordEmbedding;

加载数据

根据 factoryReports.csv 中的数据创建一个表格文本数据存储。仅读取 "Description" 和 "Category" 列中的数据。

filenameTrain = "factoryReports.csv";

textName = "Description";

labelName = "Category";

ttdsTrain = tabularTextDatastore(filenameTrain,'SelectedVariableNames',[textName labelName]);

预览数据存储。

ttdsTrain.ReadSize = 8;

preview(ttdsTrain)

ans=8×2 table

Description Category

_______________________________________________________________________ ______________________

{'Items are occasionally getting stuck in the scanner spools.' } {'Mechanical Failure'}

{'Loud rattling and banging sounds are coming from assembler pistons.'} {'Mechanical Failure'}

{'There are cuts to the power when starting the plant.' } {'Electronic Failure'}

{'Fried capacitors in the assembler.' } {'Electronic Failure'}

{'Mixer tripped the fuses.' } {'Electronic Failure'}

{'Burst pipe in the constructing agent is spraying coolant.' } {'Leak' }

{'A fuse is blown in the mixer.' } {'Electronic Failure'}

{'Things continue to tumble off of the belt.' } {'Mechanical Failure'}

创建一个自定义变换函数,该函数将从数据存储中读取的数据转换为包含预测变量和响应的表。在示例末尾列出的 transformTextData 函数接受从 tabularTextDatastore 对象读取的数据,并返回包含预测变量和响应的表。预测变量是由单词嵌入 emb 给出的 1×sequenceLength×C 单词向量数组,其中 C 是嵌入维度。这些响应是 classNames 中的类的分类标签。

使用在示例末尾列出的 read

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值