门户网站cms网站幻灯通栏代码

diannao/2026/1/17 22:58:33/文章来源:
门户网站cms,网站幻灯通栏代码,儿童手工制作,淘宝建设网站的目的是什么文章目录1. 概述2. 数据3. 模型4. 训练5. 测试参考 基于深度学习的自然语言处理本文使用attention机制的模型#xff0c;将各种格式的日期转化成标准格式的日期 1. 概述 LSTM、GRU 减少了梯度消失的问题#xff0c;但是对于复杂依赖结构的长句子#xff0c;梯度消失仍然存… 文章目录1. 概述2. 数据3. 模型4. 训练5. 测试参考 基于深度学习的自然语言处理本文使用attention机制的模型将各种格式的日期转化成标准格式的日期 1. 概述 LSTM、GRU 减少了梯度消失的问题但是对于复杂依赖结构的长句子梯度消失仍然存在注意力机制能同时看见句子中的每个位置并赋予每个位置不同的权重注意力且可以并行计算 2. 数据 生成日期数据 from faker import Faker from babel.dates import format_date import random fake Faker() fake.seed(123) random.seed(321)# 各种日期格式 FORMATS [short,medium,long,full,full,full,full,full,full,full,full,full,full,d MMM YYY,d MMMM YYY,dd MMM YYY,d MMM, YYY,d MMMM, YYY,dd, MMM YYY,d MM YY,d MMMM YYY,MMMM d YYY,MMMM d, YYY,dd.MM.YY]生成日期数据随机格式X标准格式Y def load_date():# 加载一些日期数据dt fake.date_object() # 随机一个日期human_readable format_date(dt, formatrandom.choice(FORMATS),localeen_US)# 使用随机选取的格式生成日期human_readable human_readable.lower().replace(,,)machine_readable dt.isoformat() # 标准格式return human_readable, machine_readable, dttest_date load_date()输出 建立字典以及映射关系字符 idx from tqdm import tqdm # 显示进度条 def load_dateset(num_of_data):human_vocab set()machine_vocab set()dataset []Tx 30 # 日期最大长度for i in tqdm(range(num_of_data)):h, m, _ load_date()if h is not None:dataset.append((h, m))human_vocab.update(tuple(h))machine_vocab.update(tuple(m))human dict(zip(sorted(human_vocab)[unk, pad],list(range(len(human_vocab)2))))# x 字符idx 的映射inv_machine dict(enumerate(sorted(machine_vocab)))# idx y 字符machine {v : k for k, v in inv_machine.items()}# y 字符 idxreturn dataset, human, machine, inv_machinem 10000 # 样本个数 dataset, human_vocab, machine_vocab, inv_machine_vocab load_dateset(m)日期char序列转 ids 序列并且 pad / 截断 import numpy as np from keras.utils import to_categoricaldef string_to_int(string, length, vocab):string string.lower().replace(,,)if len(string) length: # 长了截断string string[:length]rep list(map(lambda x : vocab.get(x, unk), string))# 对string里每个char 使用 匿名函数 获取映射的id没有的话使用unk的idmap返回迭代器转成listif len(string) length:rep [vocab[pad]]*(length-len(string))# 长度不够加上 pad 的 idreturn rep # 返回 [ids,...]根据 ids 序列生成 one_hot 矩阵 def process_data(dataset, human_vocab, machine_vocab, Tx, Ty):X,Y zip(*dataset)print(处理前 X{}.format(X))print(处理前 Y{}.format(Y))X np.array([string_to_int(date, Tx, human_vocab) for date in X])Y [string_to_int(date, Ty, machine_vocab) for date in Y]print(处理后 X的shape{}.format(X.shape))print(处理后 Y: {}.format(Y))Xoh np.array(list(map(lambda x : to_categorical(x, num_classeslen(human_vocab)), X)))Yoh np.array(list(map(lambda x : to_categorical(x, num_classeslen(machine_vocab)), Y)))return X, np.array(Y), Xoh, Yoh Tx 30 # 输入长度 Ty 10 # 输出长度 X, Y, Xoh, Yoh process_data(dataset, human_vocab, machine_vocab, Tx, Ty)检查生成的 one_hot 编码矩阵维度 print(X.shape) print(Y.shape) print(Xoh.shape) print(Yoh.shape)输出 (10000, 30) (10000, 10) (10000, 30, 37) (10000, 10, 11)3. 模型 softmax 激活函数求注意力权重 from keras import backend as K def softmax(x, axis1):ndim K.ndim(x)if ndim 2:return K.softmax(x)elif ndim 2:e K.exp(x - K.max(x, axisaxis, keepdimsTrue))s K.sum(e, axisaxis, keepdimsTrue)return e/selse:raise ValueError(维度不对不能是1维)模型组件 from keras.layers import RepeatVector, LSTM, Concatenate, \Dense, Activation, Dot, Input, Bidirectionalrepeator RepeatVector(Tx) # 重复 Tx 次 # 重复器 # Input shape: # 2D tensor of shape (num_samples, features). # # Output shape: # 3D tensor of shape (num_samples, n, features). concator Concatenate(axis-1) # 拼接器 densor1 Dense(10, activationtanh) # FC densor2 Dense(1, activationrelu) # FC activator Activation(softmax, nameattention_weights) # 计算注意力权重 dotor Dot(axes1) # 加权模型 def one_step_attention(h, s_prev):s_prev repeator(s_prev) # 将前一个输出状态重复 Tx 次concat concator([h, s_prev]) # 与 全部句子状态 拼接e densor1(concat) # 经过 FCenergies densor2(e) # 经过FCalphas activator(energies) # 得到注意力权重context dotor([alphas, h]) # 跟原句子状态做attentionreturn context # 得到上下文向量后序输入到解码器# 解码器是一个单向LSTM n_h 32 n_s 64 post_activation_LSTM_cell LSTM(n_s, return_stateTrue) # 单向LSTM output_layer Dense(len(machine_vocab), activationsoftmax) # FC 输出预测值from keras.models import Model def model(Tx, Ty, n_h, n_s, human_vocab_size, machine_vocab_size):X Input(shape(Tx,human_vocab_size), nameinput_first)s0 Input(shape(n_s,),names0)c0 Input(shape(n_s,),namec0)s s0c c0outputs []h Bidirectional(LSTM(n_h, return_sequencesTrue))(X) # 编码器得到整个序列的状态for t in range(Ty): # 解码器 推理context one_step_attention(h, s) # attention 得到上下文向量s, _, c post_activation_LSTM_cell(context, initial_state[s,c])out output_layer(s) # FC 输出预测outputs.append(out)model Model(inputs[X,s0,c0], outputsoutputs)return modelmodel model(Tx,Ty,n_h,n_s,len(human_vocab), len(machine_vocab)) model.summary()from keras.utils import plot_model plot_model(model, to_filemodel.png,show_shapesTrue,rankdirTB)输出 Model: functional_1 __________________________________________________________________________________________________ Layer (type) Output Shape Param # Connected to input_first (InputLayer) [(None, 30, 37)] 0 __________________________________________________________________________________________________ s0 (InputLayer) [(None, 64)] 0 __________________________________________________________________________________________________ bidirectional (Bidirectional) (None, 30, 64) 17920 input_first[0][0] __________________________________________________________________________________________________ repeat_vector (RepeatVector) (None, 30, 64) 0 s0[0][0] lstm[0][0] lstm[1][0] lstm[2][0] lstm[3][0] lstm[4][0] lstm[5][0] lstm[6][0] lstm[7][0] lstm[8][0] __________________________________________________________________________________________________ concatenate (Concatenate) (None, 30, 128) 0 bidirectional[0][0] repeat_vector[0][0] bidirectional[0][0] repeat_vector[1][0] bidirectional[0][0] repeat_vector[2][0] bidirectional[0][0] repeat_vector[3][0] bidirectional[0][0] repeat_vector[4][0] bidirectional[0][0] repeat_vector[5][0] bidirectional[0][0] repeat_vector[6][0] bidirectional[0][0] repeat_vector[7][0] bidirectional[0][0] repeat_vector[8][0] bidirectional[0][0] repeat_vector[9][0] __________________________________________________________________________________________________ dense (Dense) (None, 30, 10) 1290 concatenate[0][0] concatenate[1][0] concatenate[2][0] concatenate[3][0] concatenate[4][0] concatenate[5][0] concatenate[6][0] concatenate[7][0] concatenate[8][0] concatenate[9][0] __________________________________________________________________________________________________ dense_1 (Dense) (None, 30, 1) 11 dense[0][0] dense[1][0] dense[2][0] dense[3][0] dense[4][0] dense[5][0] dense[6][0] dense[7][0] dense[8][0] dense[9][0] __________________________________________________________________________________________________ attention_weights (Activation) (None, 30, 1) 0 dense_1[0][0] dense_1[1][0] dense_1[2][0] dense_1[3][0] dense_1[4][0] dense_1[5][0] dense_1[6][0] dense_1[7][0] dense_1[8][0] dense_1[9][0] __________________________________________________________________________________________________ dot (Dot) (None, 1, 64) 0 attention_weights[0][0] bidirectional[0][0] attention_weights[1][0] bidirectional[0][0] attention_weights[2][0] bidirectional[0][0] attention_weights[3][0] bidirectional[0][0] attention_weights[4][0] bidirectional[0][0] attention_weights[5][0] bidirectional[0][0] attention_weights[6][0] bidirectional[0][0] attention_weights[7][0] bidirectional[0][0] attention_weights[8][0] bidirectional[0][0] attention_weights[9][0] bidirectional[0][0] __________________________________________________________________________________________________ c0 (InputLayer) [(None, 64)] 0 __________________________________________________________________________________________________ lstm (LSTM) [(None, 64), (None, 33024 dot[0][0] s0[0][0] c0[0][0] dot[1][0] lstm[0][0] lstm[0][2] dot[2][0] lstm[1][0] lstm[1][2] dot[3][0] lstm[2][0] lstm[2][2] dot[4][0] lstm[3][0] lstm[3][2] dot[5][0] lstm[4][0] lstm[4][2] dot[6][0] lstm[5][0] lstm[5][2] dot[7][0] lstm[6][0] lstm[6][2] dot[8][0] lstm[7][0] lstm[7][2] dot[9][0] lstm[8][0] lstm[8][2] __________________________________________________________________________________________________ dense_2 (Dense) (None, 11) 715 lstm[0][0] lstm[1][0] lstm[2][0] lstm[3][0] lstm[4][0] lstm[5][0] lstm[6][0] lstm[7][0] lstm[8][0] lstm[9][0] Total params: 52,960 Trainable params: 52,960 Non-trainable params: 0 ________________________________________________________________________________________________4. 训练 from keras.optimizers import Adam # 优化器 opt Adam(learning_rate0.005, decay0.01) # 配置模型 model.compile(optimizeropt, losscategorical_crossentropy,metrics[accuracy])# 初始化 解码器状态 s0 np.zeros((m, n_s)) c0 np.zeros((m, n_s)) outputs list(Yoh.swapaxes(0, 1)) # Yoh shape 10000*10*11调换0,1轴为10*10000*11 # outputs list长度 10 每个里面是array 10000*11history model.fit([Xoh, s0, c0], outputs,epochs10, batch_size128,validation_split0.1)绘制 loss 和 各位置的准确率 from matplotlib import pyplot as plt import pandas as pd his pd.DataFrame(history.history) print(his.columns) loss history.history[loss] val_loss history.history[val_loss]plt.plot(loss, labeltrain Loss) plt.plot(val_loss, labelvalid Loss) plt.title(Training and Validation Loss) plt.legend() plt.grid() plt.show()# 列 具体的名字根据运行次数会有变化 col_train_acc (dense_7_accuracy, dense_7_1_accuracy, dense_7_2_accuracy,dense_7_3_accuracy, dense_7_4_accuracy, dense_7_5_accuracy,dense_7_6_accuracy, dense_7_7_accuracy, dense_7_8_accuracy,dense_7_9_accuracy) col_test_acc (val_dense_7_accuracy, val_dense_7_1_accuracy,val_dense_7_2_accuracy, val_dense_7_3_accuracy,val_dense_7_4_accuracy, val_dense_7_5_accuracy,val_dense_7_6_accuracy, val_dense_7_7_accuracy,val_dense_7_8_accuracy, val_dense_7_9_accuracy) train_acc pd.DataFrame(history.history[c] for c in col_train_acc) test_acc pd.DataFrame(history.history[c] for c in col_test_acc)train_acc.plot() plt.title(Training Accuracy on pos) plt.legend() plt.grid() plt.show()test_acc.plot() plt.title(Validation Accuracy on pos) plt.legend() plt.grid() plt.show()5. 测试 s0 np.zeros((1, n_s)) c0 np.zeros((1, n_s)) test_data,_,_,_ load_dateset(10) for x,y in test_data:print(x y) for x,_ in test_data:source string_to_int(x, Tx, human_vocab)source np.array(list(map(lambda a : to_categorical(a, num_classeslen(human_vocab)), source)))source source[np.newaxis, :]pred model.predict([source, s0, c0])pred np.argmax(pred, axis-1)output [inv_machine_vocab[int(i)] for i in pred]print(source:,x)print(output:,.join(output))输出 18 april 2014 2014-04-18 saturday august 22 1998 1998-08-22 october 22 1995 1995-10-22 thursday february 29 1996 1996-02-29 wednesday october 17 1979 1979-10-17 7 12 73 1973-12-07 9/30/01 2001-09-30 22 may 2001 2001-05-22 7 march 1979 1979-03-07 19 feb 2013 2013-02-19预测10个错误了4个日期字符不完全正确 source: 18 april 2014 output: 2014-04-18 source: saturday august 22 1998 output: 1998-08-22 source: october 22 1995 output: 1995-12-22 # 错误 10 月 source: thursday february 29 1996 output: 1996-02-29 source: wednesday october 17 1979 output: 1979-10-17 source: 7 12 73 output: 1973-02-07 # 错误 12月 source: 9/30/01 output: 2001-05-00 # 错误 09-30 source: 22 may 2001 output: 2011-05-22 # 错误 2001 source: 7 march 1979 output: 1979-03-07 source: 19 feb 2013 output: 2013-02-19

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/diannao/90913.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

广汉市建设局网站赣榆区城乡建设局网站

1. 引言 对于ASP.NET Core应用程序来说,我们要记住非常重要的一点是:其本质上是一个独立的控制台应用,它并不是必需在IIS内部托管且并不需要IIS来启动运行(而这正是ASP.NET Core跨平台的基石)。ASP.NET Core应用程序拥…

唐山网站托管四川网站建设贴吧

Tip: 如果你在进行深度学习、自动驾驶、模型推理、微调或AI绘画出图等任务,并且需要GPU资源,可以考虑使用Compshare的GPU算力云平台。他们提供高性价比的4090 GPU,按时收费每卡2.6元,月卡只需要1.7元每小时,并附带200G…

特价做网站wordpress快速加载

每日推荐一篇专注于解决实际问题的外文,精准翻译并深入解读其要点,助力读者培养实际问题解决和代码动手的能力。 欢迎关注公众号(NLP Research),及时查看最新内容 原文标题:Building an Open Source Multi-Modal RAG System 原文地址:https://medium.com/nadsoft/buil…

网站开发遇到什么问题电商网站建设实训报告

还有不到十天,除夕就要到了。近几年春节假期中,有人第一次带着孩子直击海面冰风,坐船回老家;也有人选择“漫游”国内外,在旅行中迎接新春的朝气。合合信息旗下扫描全能王APP通过AI扫描技术,提供了一种全新的…

机器人网站建设如何对网站的文件和资源进行优化?

差分和前缀和都是算法里边比较重要的知识点,不过学习的难度并不高,这篇文章会讲解相关的内容。 1. 前缀和怎么玩 1)一维前缀和 在该数之前,包括该数的所有数之和,有点类似高中学的数列的前n项和Sn。 2)二维…

网站后台系统淘宝放单网站怎么做的

监控系统的多协议直播(RTSP RTMP HTTP Live Streaming) 转载于:https://www.cnblogs.com/cl1024cl/p/6204791.html

电子商务网站建设的工具建网站需要有啥能力

前言: 在上篇文章中,用Java语言创建的Spring Boot项目中,如何传递数组呢??-CSDN博客,我们了解到Spring Boot项目中如何传递数组,但是,对于同类型的List集合,我们又该如何…

海淀教育互动平台网站建设网站制作 南京

正整数的十进制转换二进制将一个十进制数除以二,得到的商再除以二,依此类推直到商等于一或零时为止,倒取除得的余数,即换算为二进制数的结果。只需记住要点:除二取余,倒序排列。由于计算机内部表示数的字节…

专业宁波seo排名如何优化

国学,一国所固有之学术也。国学和文学数学的意思不同,并非是国家之学或者治国之学。一般来说,国学是指以儒学为主体的中华传统文化与学术。国学是中国传统文化与学术,也包括了医学、戏剧、书画、星相、数术等等。广义上&#xff0…

泉州市建设工程交易网站hao123上网导航

当 AI 开发者社区配备 AI 基础设施开发平台工具时,它还能做什么? 答案是:过去半年,和鲸社区凭借在气象、医学、社科等垂直领域的长期积累以及多方伙伴的支持,联合举办了三场新书发布会——从 Python 到 R 语言 、从气…

做网站推广利润安康网站开发公司价格

Python2 还是 Python3 ? py2.7是2.x系列的最后一个版本,已经停止开发,不再增加新功能。2020年终止支持。 所有的最新的标准库的更新改进,只会在3.x的版本里出现。Python3.0在2008年就发布出来,而2.7作为2.X的最终版本并…

北京西站咨询服务电话怀化网页

2018武汉大学计算机考研复试经验贴武汉大学发布于2019年9月22日 12:25阅读数 18196初试唯一要讲的就是专业课问题,今年专业课改革,只考两门专业课。一门是数据结构,分值为90分,只有选择题和代码题,大概24个选择题&…

点餐网站模板郑州企业做网站

目录 1、简单的模版 2、简单的案例 2.1、python 执行.py 文件 2.2、调式多个文件 2.3、torchrun、deepspeed 调试 1、简单的模版 定义一个简单的模版如下: {// 使用 IntelliSense 了解相关属性。 // 悬停以查看现有属性的描述。// 欲了解更多信息,请访…

网站忧化教程网站制作价钱多少

扩展的视图类介绍 rest_framework提供了几种后端视图(对数据资源进行增删改查)处理流程的实现,如果需要编写的视图属于这几种,则视图可以通过继承相应的扩展类来复用代码,减少自己编写的代码量 官网:3 - Class based views - Django REST framework rest_framework.mixi…

做养生网站需要什么资质wordpress安装教程视频

表现: vscode 代码文件格式化之后,反而出现红色波浪线,提示 应该换行/缩进不正确 等等格式不规范之类的信息。 原因: 因为同时开启了两个格式化插件,且两者的规则有冲突。 就我自己的情况而言:格式化代…

网站空间和服务器的区别办公管理系统软件

制造企业设备管理和维护对于生产效率和成本控制至关重要。然而,传统的维护方法往往无法准确预测设备故障,导致生产中断和高额维修费用。为了应对这一挑战,越来越多的制造企业开始采用预测性维护技术。 预测性维护是通过传感器数据、机器学习和…

运用photoshop设计网站首页无锡网站建设开发

非常荣幸地通知您,华为认证HCIA-AI Solution V1.0(中文版)预计将于2024年4月30日正式对外发布。 为了帮助您做好学习、培训和考试计划,现进行预发布通知,请您关注。 01 发布概述 基于“平台生态”战略,围绕…

专门做特卖的网站下载手机微信

1、activemq.xml置文件新增如下内容 2、mqttx测试发送: 主题(配置的模糊匹配,为了并发):VirtualTopic/device/sendData/12312 3、mqtt接收的结果 4、程序处理 package comimport cn.hutool.core.date.DateUtil; imp…

怎么在网站里做关键词优化炫酷个人网站php源码

java -jar xxx.jar java -jar 是一个用于在命令行界面中执行 Java 可执行 JAR 文件的命令。它的语法如下&#xff1a; java -jar <JAR 文件路径> [参数]其中&#xff1a; java 是 Java 运行时环境的可执行文件。-jar 是一个选项&#xff0c;表示要执行的文件是一个 JA…