Harvard NLP The Annotated Transformer 学习

版权声明:王家林大咖2018年新书《SPARK大数据商业实战三部曲》清华大学出版,微信公众号:从零起步学习人工智能 https://blog.csdn.net/duan_zhihua/article/details/87426913

Harvard NLP The Annotated Transformer  复现Google公司的Transformer论文

“Attention is All You Need” 的Transformer 在过去的一年里一直在很多人的脑海中出现。Transformer在机器翻译质量上有重大改进,它还为许多其他NLP任务提供了一种新的体系结构。论文本身写得很清楚,但传统的看法是论文很难准确的去实现。在这篇文章中,Harvard NLP的原作者在2018年初以逐行实现的形式呈现了论文的“注释”版本,总共有400行代码,可以在4个GPU上每秒处理27000个标识。您首先需要安装PyTorch,notebook可以在Github或谷歌Colab(免费提供GPU)上使用。注意,这仅仅是研究人员和感兴趣的开发人员的起点。这里的代码主要基于Harvard NLP的OpenNMT包。对于模型的其他完整服务实现,请查看tensor2tensor(tensorflow)和Socketeye(mxnet)。 
原作者:Alexander Rush (@harvardnlp or [email protected]), with help from Vincent Nguyen and Guillaume Klein 

预备工作:

# !pip install http://download.pytorch.org/whl/cu80/torch-0.3.0.post4-cp36-cp36m-linux_x86_64.whl numpy matplotlib spacy torchtext seaborn 
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
import math, copy, time
from torch.autograd import Variable
import matplotlib.pyplot as plt
import seaborn
seaborn.set_context(context="talk")
%matplotlib inline

猜你喜欢

转载自blog.csdn.net/duan_zhihua/article/details/87426913