Fork me on GitHub
摘要: 代码来源:https://github.com/graykode/nlp-tutorial/blob/master/5-1.Transformer/Transformer-Torch.py 一些基础变量和参数: import numpy as np import torch import torch 阅读全文
posted @ 2020-07-20 16:38 西西嘛呦 阅读(1256) 评论(0) 推荐(0)
摘要: 1、https://zhuanlan.zhihu.com/p/107889011 2、https://zhuanlan.zhihu.com/p/107891957 3、https://zhuanlan.zhihu.com/p/109003287 阅读全文
posted @ 2020-07-20 11:09 西西嘛呦 阅读(1389) 评论(0) 推荐(0)
摘要: 首先是注意力公式: 其计算图: 代码: def attention(query, key, value, mask=None, dropout=None): # query, key, value的形状类似于(30, 8, 10, 64), (30, 8, 11, 64), #(30, 8, 11, 阅读全文
posted @ 2020-07-20 10:50 西西嘛呦 阅读(6452) 评论(3) 推荐(0)
摘要: class PositionalEncoding(nn.Module): "Implement the PE function." def __init__(self, d_model, dropout, max_len=5000): #d_model=512,dropout=0.1, #max_l 阅读全文
posted @ 2020-07-20 10:23 西西嘛呦 阅读(3961) 评论(0) 推荐(0)
摘要: 直接看代码: import torch import torch.nn as nn embedding=nn.Embedding(10,3) input=torch.LongTensor([[1,2,4,5],[4,3,2,9]]) embedding(input) tensor([[[ 0.805 阅读全文
posted @ 2020-07-20 10:13 西西嘛呦 阅读(3343) 评论(0) 推荐(0)