当前位置: 首页 > news >正文

html5网站和传统网站的优点wap网站 劣势

html5网站和传统网站的优点,wap网站 劣势,做网站线上线下价格混乱,建设微网站多少钱系列文章目录 1. 文本分类与词嵌入表示#xff0c;mlp来处理分类问题 2. RNN、LSTM、GRU三种方式处理文本分类问题 3. 评论情绪分类 还是得开个坑#xff0c;最近搞论文#xff0c;使用lstm做的ssd的cache prefetching#xff0c;意味着我不能再划水了。 文章目录 系列文章…系列文章目录 1. 文本分类与词嵌入表示mlp来处理分类问题 2. RNN、LSTM、GRU三种方式处理文本分类问题 3. 评论情绪分类 还是得开个坑最近搞论文使用lstm做的ssd的cache prefetching意味着我不能再划水了。 文章目录 系列文章目录[1. 文本分类与词嵌入表示mlp来处理分类问题](https://blog.csdn.net/weixin_40293999/article/details/132864421) 2. RNN、LSTM、GRU三种方式处理文本分类问题 3. 评论情绪分类 还是得开个坑最近搞论文使用lstm做的ssd的cache prefetching意味着我不能再划水了。 1. 文本数据表示法与词嵌入1.1 文本是什么如何表示1.2 文本的词嵌入表示处理流程1.3 代码展示分词过程1.4 词嵌入表示 2.简单文本分类 1. 文本数据表示法与词嵌入 torch 是做张量计算的框架张量只能存储数字类型的值因此无论啥样的文本中文、英文都不能直接用张量表示这就引出了文本数据的表示问题如何表示文本数据 1.1 文本是什么如何表示 文本是常用的序列化数据类型之一。文本数据可以看作是一 个字符序列或词的序列。对大多数问题我们都将文本看作 词序列。 深度学习序列模型如RNN及其变体能够较好的对序列化 数据建模。 深度学习序列模型如RNN及其变体可以解决类似以下领 域中的问题自然语言理解、文献分类、情感分类、问答系统等。 深度学习模型并不能理解文本因此需要将文本转换为数值 的表示形式。 将文本转换为数值表示形式的过程称为向量化过程可以用 不同的方式来完成 词嵌入是单词的一种数值化表示方式一般情况下会将一个单词映射到一个高维的向量中词向量 来代表这个单词 ‘机器学习’表示为 [1, 2, 3] ‘深度学习’表示为 [1, 3, 3] ‘日月光华’表示为 [9, 9, 6] 对于词向量我们可以使用余弦相似度在计算机中来判断 单词之间的距离。 词嵌入用密集的分布式向量来表示每个单词。词向量表示方式依赖于单词的使用习惯这就使得具有相似使用方式的单词具有相似的表示形式。 Glove算法是对word2vec方法的拓展并且更为有效。 1.2 文本的词嵌入表示处理流程 每个较小的文本单元称为token将文本分解成token的过程称为分词tokenization。在 Python中有很多强大的库可以用来进行分词. one-hot独热编码和词嵌入是将token映射到向量最流行的两种方法。 1.3 代码展示分词过程 import torch import numpy as np import string s Life is not easy for any of us.We must work,and above all we must believe in ourselves.We must believe that each one of us is able to do some thing well.And that we must work until we succeed.string.punctuation!#$%\()*,-./:;?[\\]^_{|}~for c in string.punctuation:s s.replace(c, ).lower()去掉标点符号 slife is not easy for any of us we must work and above all we must believe in ourselves we must believe that each one of us is able to do some thing well and that we must work until we succeed ’ s.split()[life,is,not,easy,for,any,of,us,we,must,work,and,above,all,we,must,believe,in,ourselves,we,must,believe,that,each,one,of,us,is,able,to,do,some,thing,well,and,that,we,must,work,until,we,succeed]分词方式三:n-gram 向量化one-hot emdeding import numpy as np np.unique(s.split())array([‘able’, ‘above’, ‘all’, ‘and’, ‘any’, ‘believe’, ‘do’, ‘each’, ‘easy’, ‘for’, ‘in’, ‘is’, ‘life’, ‘must’, ‘not’, ‘of’, ‘one’, ‘ourselves’, ‘some’, ‘succeed’, ‘that’, ‘thing’, ‘to’, ‘until’, ‘us’, ‘we’, ‘well’, ‘work’], dtype‘U9’) vocab dict((word,index) for index, word in enumerate(np.unique(s.split()))) vocab 建立映射关系{‘able’: 0, ‘above’: 1, ‘all’: 2, ‘and’: 3, ‘any’: 4, ‘believe’: 5, ‘do’: 6, ‘each’: 7, ‘easy’: 8, ‘for’: 9, ‘in’: 10, ‘is’: 11, ‘life’: 12, ‘must’: 13, ‘not’: 14, ‘of’: 15, ‘one’: 16, ‘ourselves’: 17, ‘some’: 18, ‘succeed’: 19, ‘that’: 20, ‘thing’: 21, ‘to’: 22, ‘until’: 23, ‘us’: 24, ‘we’: 25, ‘well’: 26, ‘work’: 27} 这是one-hot的表示方法 for index, i in enumerate(s):b[index,i] 1 b[0:5]array([[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0.,0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0.,0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0.,0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],[0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0.,0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],[0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0.,0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]])1.4 词嵌入表示 import torch em torch.nn.Embedding(len(vocab), 20) s_em em(torch.LongTensor(s)) s_em.shape torch.Size([42, 20])2.简单文本分类 这里要说明一下torch1.8 gpu 和 torchtext 0.90 版本这俩个要匹配否则安装torchtext的时候会吧torch uninstall 再install特别麻烦。 对应关系 refhttps://pypi.org/project/torchtext/0.14.0/ 可以看到2.0的torch还没有对应的torchtext import torch import torchtext from torchtext import data import numpy as np import torch.nn as nn import torch.nn.functional as F from torchtext.vocab import GloVe from torchtext.datasets import IMDB用的是这个数据集 IMDBhttp://ai.stanford.edu/~amaas/data/sentiment/ 是影评包括三个标签正向、负向和未知。 TORCHTEXT.DATASETS, 所有数据集都是子类 torch.data.Dataset, 她们继承自torch.utils.data.Dataset,并且具有split和iters实现的方法 切分数据集 TEXT torchtext.legacy.data.Field(lowerTrue, fix_length200,batch_firstTrue) LABEL torchtext.legacy.data.Field(sequentialFalse) # make splits for data train,test torchtext.legacy.datasets.IMDB.splits(TEXT,LABEL)构建词嵌入 最多容量10000个词最小的频率是出现10次。 # 构建词表 vocab 构建train训练集的 top 10000个单词做训练 vectors用来提供预训练模型 TEXT.build_vocab(train, max_size 10000,min_freq10, vectorsNone) LABEL.build_vocab(train)查看频率 TEXT.vocab.freqs一共10002行数据因为0是unknown 1是padding。 超过10000的词都标记为unknown train_iter, test_iter torchtext.legacy.data.BucketIterator.splits((train,test),batch_size16)创建模型 class Net(nn.Module):def __init__(self):super().__init__()self.em nn.Embedding(len(TEXT.vocab.stoi),100) # batch*200--batch*200*100self.fc1 nn.Linear(200*100,1024)self.fc2 nn.Linear(1024,3)def forward(self,x):x self.em(x)x x.view(x.size(0), -1)x self.fc1(x)x F.relu(x)x self.fc2(x)return x model Net() model损失函数 loss_fn nn.CrossEntropyLoss() optimizer torch.optim.Adam(model.parameters(),lr0.001)训练过程这个代码是固定的和我其它的文章里面也有很多 def fit(epoch, model, trainloader, testloader):correct 0total 0running_loss 0model.train()for b in trainloader:x, y b.text, b.labelif torch.cuda.is_available():x, y b.text.to(cuda), b.label.to(cuda)y_pred model(x)loss loss_fn(y_pred, y)optimizer.zero_grad()loss.backward()optimizer.step()with torch.no_grad():y_pred torch.argmax(y_pred, dim1)correct (y_pred y).sum().item()total y.size(0)running_loss loss.item() # exp_lr_scheduler.step()epoch_loss running_loss / len(trainloader.dataset)epoch_acc correct / totaltest_correct 0test_total 0test_running_loss 0 model.eval()with torch.no_grad():for b in testloader:x, y b.text, b.labelif torch.cuda.is_available():x, y x.to(cuda), y.to(cuda)y_pred model(x)loss loss_fn(y_pred, y)y_pred torch.argmax(y_pred, dim1)test_correct (y_pred y).sum().item()test_total y.size(0)test_running_loss loss.item()epoch_test_loss test_running_loss / len(testloader.dataset)epoch_test_acc test_correct / test_totalprint(epoch: , epoch, loss , round(epoch_loss, 3),accuracy:, round(epoch_acc, 3),test_loss , round(epoch_test_loss, 3),test_accuracy:, round(epoch_test_acc, 3))return epoch_loss, epoch_acc, epoch_test_loss, epoch_test_acc训练 epochs 10 train_loss [] train_acc [] test_loss [] test_acc []for epoch in range(epochs):epoch_loss, epoch_acc, epoch_test_loss, epoch_test_acc fit(epoch,model,train_iter,test_iter)train_loss.append(epoch_loss)train_acc.append(epoch_acc)test_loss.append(epoch_test_loss)test_acc.append(epoch_test_acc)结果输出 epoch: 0 loss 0.046 accuracy: 0.55 test_loss 0.041 test_accuracy: 0.618 epoch: 1 loss 0.026 accuracy: 0.809 test_loss 0.046 test_accuracy: 0.69 epoch: 2 loss 0.009 accuracy: 0.945 test_loss 0.053 test_accuracy: 0.721 epoch: 3 loss 0.004 accuracy: 0.975 test_loss 0.068 test_accuracy: 0.729 epoch: 4 loss 0.002 accuracy: 0.985 test_loss 0.115 test_accuracy: 0.708 epoch: 5 loss 0.002 accuracy: 0.989 test_loss 0.098 test_accuracy: 0.737 epoch: 6 loss 0.002 accuracy: 0.991 test_loss 0.096 test_accuracy: 0.744 epoch: 7 loss 0.001 accuracy: 0.996 test_loss 0.108 test_accuracy: 0.742 epoch: 8 loss 0.001 accuracy: 0.994 test_loss 0.12 test_accuracy: 0.744 epoch: 9 loss 0.001 accuracy: 0.994 test_loss 0.128 test_accuracy: 0.74
http://www.eeditor.cn/news/123920/

相关文章:

  • 百度权重网站无锡app制作
  • 网站建设概况云计算网站建设
  • 佛山营销型网站建设公司厦门网络推广培训
  • 济南高新区 网站制作亚洲成成品网站源码
  • 深圳免费网站制作哪个好家政网站建设方案分析
  • 网站内容页显示不出来的网站建设的感想
  • 西安高端网站制作xampp做的网站能搜索吗
  • 即墨网站建设在哪西安有关做网站的公司有哪些
  • 五和网站建设海南网页设计
  • 网站公司怎么做推广方案个人备案 什么网站
  • 网站 医院信息化建设简约的网站设计
  • 阿里巴巴怎样做网站网站备案经验
  • 网站建设要注意百度竞价包年推广是怎么回事
  • app开发和网站开发哪个好企业信息管理系统的发展历程
  • wui网站建设做移动网站优化快速排名软件
  • 网站集约建设后网站域名规范抖音代运营有风险吗
  • 微官网和微网站首页推广一个app的费用
  • 品牌和网站建设网站的建设与维护实践报告
  • 想给公司做个网站怎么做的济南外贸网站
  • 广东外贸网站推广公司杭州富阳网站建设
  • 汕头网页设计网站方案淘宝网站怎么做会话保持的
  • 手机微信网站怎么做常德营销型网站建设
  • 西安网站建设定wordpress还是hexo
  • 杭州品牌网站开发网站手机访问 动易
  • 网上提交报名表系统的网站建设百度网站架构
  • 十堰市建设网站的公司用什么制作网站
  • 网站推广预期达到的目标建筑企业和建设企业区别
  • 新零售型网站开发邯郸网站建设服务报价
  • 产品网站开发服务价格低性能好的手机
  • 株洲专业做网站设计的搜素引擎排名优化