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

金钟街网站建设哪家好宁波专业定制网站建设

金钟街网站建设哪家好,宁波专业定制网站建设,上海鸿鹄设计公司,网建部是干什么的python-pytorch实现lstm模型预测文本输出0.1.00 数据参考效果分词到数组准备数数据查看频次获取vacab生成输入数据训练测试连续预测 有问题还需要完善 数据 一篇新闻#xff1a;https://news.sina.com.cn/c/2024-04-12/doc-inarqiev0222543.shtml 参考 https://blog.csdn.… python-pytorch实现lstm模型预测文本输出0.1.00 数据参考效果分词到数组准备数数据查看频次获取vacab生成输入数据训练测试连续预测 有问题还需要完善 数据 一篇新闻https://news.sina.com.cn/c/2024-04-12/doc-inarqiev0222543.shtml 参考 https://blog.csdn.net/qq_19530977/article/details/120936391 # https://blog.csdn.net/qq_19530977/article/details/120936391效果 布林肯国务卿 布林肯国务卿同王毅 布林肯国务卿同王毅主任 布林肯国务卿同王毅主任以及 布林肯国务卿同王毅主任以及其他 布林肯国务卿同王毅主任以及其他国家 布林肯国务卿同王毅主任以及其他国家敦促 布林肯国务卿同王毅主任以及其他国家敦促伊朗 布林肯国务卿同王毅主任以及其他国家敦促伊朗驻 布林肯国务卿同王毅主任以及其他国家敦促伊朗驻叙利亚 布林肯国务卿同王毅主任以及其他国家敦促伊朗驻叙利亚使馆 布林肯国务卿同王毅主任以及其他国家敦促伊朗驻叙利亚使馆的 布林肯国务卿同王毅主任以及其他国家敦促伊朗驻叙利亚使馆的安全 布林肯国务卿同王毅主任以及其他国家敦促伊朗驻叙利亚使馆的安全不容 布林肯国务卿同王毅主任以及其他国家敦促伊朗驻叙利亚使馆的安全不容侵犯 布林肯国务卿同王毅主任以及其他国家敦促伊朗驻叙利亚使馆的安全不容侵犯 布林肯国务卿同王毅主任以及其他国家敦促伊朗驻叙利亚使馆的安全不容侵犯布 布林肯国务卿同王毅主任以及其他国家敦促伊朗驻叙利亚使馆的安全不容侵犯布林肯 布林肯国务卿同王毅主任以及其他国家敦促伊朗驻叙利亚使馆的安全不容侵犯布林肯国务卿 布林肯国务卿同王毅主任以及其他国家敦促伊朗驻叙利亚使馆的安全不容侵犯布林肯国务卿同王毅 布林肯国务卿同王毅主任以及其他国家敦促伊朗驻叙利亚使馆的安全不容侵犯布林肯国务卿同王毅主任导入包 import torch import torch.nn as nn import torch.optim as optim import torch.utils.data as Data from torch.autograd import Variable import jieba 分词到数组 复制文章到txt文档 allarray[] with open(./howtousercbow/data/news.txt,encodingutf-8) as afterjieba:linesafterjieba.readlines()print(lines)for line in lines:resultlist(jieba.cut(line,False))for r in result:allarray.append(r.replace(\n,))allarray,len(allarray) 准备数数据 word2index{one:i for i,one in enumerate(allarray)} index2word{i:one for i,one in enumerate(allarray)} word2index[ ]len(allarray)-1 index2word[len(allarray)-1] word2index[ ]查看频次 from collections import Counter Counter(allarray)获取vacab vocab_size len(allarray) vocab_size生成输入数据 # 生成输入数据 batch_x [] batch_y [] window1 seq_lengthvocab_size for i in range(seq_length - window 1):x word2index[allarray[i]]if i window seq_length:y word2index[ ]else:y word2index[allarray[i 1]]batch_x.append([x])batch_y.append(y)# print(batch_x) # print() # print(batch_y) # print(45/0)# 训练数据 batch_x, batch_y Variable(torch.LongTensor(batch_x)), Variable(torch.LongTensor(batch_y))# 参数 # vocab_size len(letters) embedding_size 100 n_hidden 32 batch_size 10 num_classes vocab_sizedataset Data.TensorDataset(batch_x, batch_y) loader Data.DataLoader(dataset, batch_size, shuffleTrue)# 建立模型 class BiLSTM(nn.Module):def __init__(self):super(BiLSTM, self).__init__()self.word_vec nn.Embedding(vocab_size, embedding_size)# bidirectional双向LSTMself.bilstm nn.LSTM(embedding_size, n_hidden, 1, bidirectionalTrue)self.lstm nn.LSTM(2 * n_hidden, 2 * n_hidden, 1, bidirectionalFalse)self.fc nn.Linear(n_hidden * 2, num_classes)def forward(self, input):embedding_input self.word_vec(input) # print(embedding_input,embedding_input,embedding_input.size())# 调换第一维和第二维度embedding_input embedding_input.permute(1, 0, 2)bilstm_output, (h_n1, c_n1) self.bilstm(embedding_input)lstm_output, (h_n2, c_n2) self.lstm(bilstm_output)fc_out self.fc(lstm_output[-1])return fc_outmodel BiLSTM()训练 print(model) criterion nn.CrossEntropyLoss() optimizer optim.Adam(model.parameters(), lr0.001)# 训练 for epoch in range(300):cost 0for input_batch, target_batch in loader:pred model(input_batch) # print(pred,pred) # print(target_batch,target_batch)loss criterion(pred, target_batch)cost loss.item()optimizer.zero_grad()loss.backward()optimizer.step()print(Epoch: %d, loss: %.5f % (epoch, cost))测试 def test(str):test_text strtest_batch [word2index[str]] # print(test_batch)test_batch torch.LongTensor([test_batch]) # print(test_batch,test_batch) # print(test_batch)out model(test_batch)predict torch.max(out, 1)[1].item() # print(test_text,后一个字母为, index2word[predict])return index2word[predict] 连续预测 import time s布林肯 while True:fencijieba.cut(s,False)fenciListlist(fenci)sstest(fenciList[-1:][0])time.sleep(1)print(s)
http://www.zqtcl.cn/news/169757/

相关文章:

  • 新网网站空间做网站和app哪类商标
  • drupal网站建设数据库厦门市网站建设
  • 解释微信微网站室内设计效果图展板
  • 教做发绳的网站游戏网站建设需要多少钱
  • 那个网站可以做双色球号码对比的网站设计好学吗
  • 网站建设如何获取客户韩国建筑网站
  • 固始网站建设公司wordpress会员功能
  • 在哪找做调查赚钱的网站好自己做网站的成本
  • 网站开发职业xshuan主题wordpress
  • 网站代码框架建设网站需要学什么程序
  • 广州搜索seo网站优化企业邮箱密码忘了怎么重置密码
  • 重庆模板网站建设做新房网站怎么弄
  • 深圳做企业网站公司常用的网络营销方式
  • 建设网站公司怎么建站网站开发笔记
  • 网站网页建设论文惠州建设网站公司
  • 中介做网站的别打电话有没有教做健身餐的网站
  • 山东电力建设网站雷州市网站建设
  • 企业网站的意义公司网站建app
  • 网站设计模板免费国庆图片制作小程序
  • 包头焦点网站建设郑州包装设计公司
  • 建行官方网站首页做跨境电商亏死了
  • 河北智能网站建设平台卖链接的网站
  • 网站建设简单点的服装搭配网站建设策划书
  • 哪一个军事网站做的比较好今天第四针最新消息
  • 黄页网站推广app软件查企业公司用什么软件
  • 网站设计机构培训全自动网页制作系统源码
  • 外贸网站建设收益深圳建设厅官网
  • 跟网站开发有关的内容东莞市生态环境局
  • dw软件做的东西怎么在网站用网站备案抽查通过
  • 重庆建设集团网站首页wordpress主题inn