Recurrent model 2020 06 RNN 3 LSTM LSTMLong

  • Slides: 19
Download presentation
Recurrent model 李文涛 2020. 06

Recurrent model 李文涛 2020. 06

RNN 3

RNN 3

LSTM • LSTM(Long short-term memory, 长短期记忆) • Memory Cell: 存储长期记忆 • 三重门:gate unit 控制信息流动

LSTM • LSTM(Long short-term memory, 长短期记忆) • Memory Cell: 存储长期记忆 • 三重门:gate unit 控制信息流动 • 遗忘门 forget gate • 输入门 input gate • 输出门 output gate 5

推荐资料 1. 《深度学习》(花书)第十章 2. 李宏毅老师《机器学习》课程 P 20 -21 Recurrent Neural Network (B站:https: //www. bili.

推荐资料 1. 《深度学习》(花书)第十章 2. 李宏毅老师《机器学习》课程 P 20 -21 Recurrent Neural Network (B站:https: //www. bili. com/video/BV 1 JE 411 g 7 XF) 11

Framework RNN Based Fusion Prediction Loss FC … RNNs … … 历史数据 环境数据 12

Framework RNN Based Fusion Prediction Loss FC … RNNs … … 历史数据 环境数据 12

Pytorch • Pytorch 主要特点 • Tensor(张量),可以利用 GPU 对张量计算进行加速 • Autograd 系统,计算梯度很方便 • 安装和使用 Pytorch

Pytorch • Pytorch 主要特点 • Tensor(张量),可以利用 GPU 对张量计算进行加速 • Autograd 系统,计算梯度很方便 • 安装和使用 Pytorch • 官网:https: //pytorch. org/ • 60分钟入门教程: https: //pytorch. org/tutorials/beginner/deep_learning_60 min_blitz. html 13

模型训练 —— 数据准备 • Tensor 和设备的绑定 • x = torch. tensor([1, 2, 3]) •

模型训练 —— 数据准备 • Tensor 和设备的绑定 • x = torch. tensor([1, 2, 3]) • x = x. to(device=‘cuda: 0’) • CUDA是一种由NVIDIA推出的基于GPU的通用并行计算架构 • 构建 Dataset 和 Data. Loader • dataset = Tensor. Dataset(x_train, y_train) • data_loader = Data. Loader(dataset=dataset, shuffle=True, batch_size=16) • 或者定义自己的 Dataset 和 Data. Loader 17

模型训练-训练过程 opt = optim. Adam(model. parameters(), lr=learning_rate) # 优化器 for epoch in range(300): #

模型训练-训练过程 opt = optim. Adam(model. parameters(), lr=learning_rate) # 优化器 for epoch in range(300): # 训练轮数 for data in dataloader: x, y = data # 从数据集中取出的一个batch with torch. set_grad_enabled(True): # 训练期间设置为True pred_y = model(x) loss = loss_func(y, y_pred) opt. zero_grad() loss. backward() # 计算梯度 opt. step() # 更新模型的参数 18