mirror of
https://github.com/labmlai/annotated_deep_learning_paper_implementations.git
synced 2025-08-06 15:22:21 +08:00
188 lines
9.1 KiB
HTML
188 lines
9.1 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
|
<meta name="description" content="This is a collection of PyTorch implementations/tutorials of transformers and related techniques."/>
|
|
|
|
<meta name="twitter:card" content="summary"/>
|
|
<meta name="twitter:image:src" content="https://avatars1.githubusercontent.com/u/64068543?s=400&v=4"/>
|
|
<meta name="twitter:title" content="Transformers"/>
|
|
<meta name="twitter:description" content="This is a collection of PyTorch implementations/tutorials of transformers and related techniques."/>
|
|
<meta name="twitter:site" content="@labmlai"/>
|
|
<meta name="twitter:creator" content="@labmlai"/>
|
|
|
|
<meta property="og:url" content="https://nn.labml.ai/transformers/index.html"/>
|
|
<meta property="og:title" content="Transformers"/>
|
|
<meta property="og:image" content="https://avatars1.githubusercontent.com/u/64068543?s=400&v=4"/>
|
|
<meta property="og:site_name" content="LabML Neural Networks"/>
|
|
<meta property="og:type" content="object"/>
|
|
<meta property="og:title" content="Transformers"/>
|
|
<meta property="og:description" content="This is a collection of PyTorch implementations/tutorials of transformers and related techniques."/>
|
|
|
|
<title>Transformers</title>
|
|
<link rel="shortcut icon" href="/icon.png"/>
|
|
<link rel="stylesheet" href="../pylit.css">
|
|
<link rel="canonical" href="https://nn.labml.ai/transformers/index.html"/>
|
|
<!-- Global site tag (gtag.js) - Google Analytics -->
|
|
<script async src="https://www.googletagmanager.com/gtag/js?id=G-4V3HC8HBLH"></script>
|
|
<script>
|
|
window.dataLayer = window.dataLayer || [];
|
|
|
|
function gtag() {
|
|
dataLayer.push(arguments);
|
|
}
|
|
|
|
gtag('js', new Date());
|
|
|
|
gtag('config', 'G-4V3HC8HBLH');
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<div id='container'>
|
|
<div id="background"></div>
|
|
<div class='section'>
|
|
<div class='docs'>
|
|
<p>
|
|
<a class="parent" href="/">home</a>
|
|
<a class="parent" href="index.html">transformers</a>
|
|
</p>
|
|
<p>
|
|
|
|
<a href="https://github.com/lab-ml/labml_nn/tree/master/labml_nn/transformers/__init__.py">
|
|
<img alt="Github"
|
|
src="https://img.shields.io/github/stars/lab-ml/nn?style=social"
|
|
style="max-width:100%;"/></a>
|
|
<a href="https://twitter.com/labmlai"
|
|
rel="nofollow">
|
|
<img alt="Twitter"
|
|
src="https://img.shields.io/twitter/follow/labmlai?style=social"
|
|
style="max-width:100%;"/></a>
|
|
</p>
|
|
</div>
|
|
</div>
|
|
<div class='section' id='section-0'>
|
|
<div class='docs doc-strings'>
|
|
<div class='section-link'>
|
|
<a href='#section-0'>#</a>
|
|
</div>
|
|
<h1>Transformers</h1>
|
|
<p>This module contains <a href="https://pytorch.org/">PyTorch</a>
|
|
implementations and explanations of original transformer
|
|
from paper <a href="https://arxiv.org/abs/1706.03762">Attention Is All You Need</a>,
|
|
and derivatives and enhancements of it.</p>
|
|
<ul>
|
|
<li><a href="mha.html">Multi-head attention</a></li>
|
|
<li><a href="models.html">Transformer Encoder and Decoder Models</a></li>
|
|
<li><a href="positional_encoding.html">Fixed positional encoding</a></li>
|
|
</ul>
|
|
<h2><a href="xl/index.html">Transformer XL</a></h2>
|
|
<p>This implements Transformer XL model using
|
|
<a href="xl/relative_mha.html">relative multi-head attention</a></p>
|
|
<h2><a href="compressive/index.html">Compressive Transformer</a></h2>
|
|
<p>This is an implementation of compressive transformer
|
|
that extends upon <a href="xl/index.html">Transformer XL</a> by compressing
|
|
oldest memories to give a longer attention span.</p>
|
|
<h2><a href="gpt/index.html">GPT Architecture</a></h2>
|
|
<p>This is an implementation of GPT-2 architecture.</p>
|
|
<h2><a href="glu_variants/simple.html">GLU Variants</a></h2>
|
|
<p>This is an implementation of the paper
|
|
<a href="https://arxiv.org/abs/2002.05202">GLU Variants Improve Transformer</a>.</p>
|
|
<h2><a href="knn/index.html">kNN-LM</a></h2>
|
|
<p>This is an implementation of the paper
|
|
<a href="https://arxiv.org/abs/1911.00172">Generalization through Memorization: Nearest Neighbor Language Models</a>.</p>
|
|
<h2><a href="feedback/index.html">Feedback Transformer</a></h2>
|
|
<p>This is an implementation of the paper
|
|
<a href="https://arxiv.org/abs/2002.09402">Accessing Higher-level Representations in Sequential Transformers with Feedback Memory</a>.</p>
|
|
<h2><a href="switch/index.html">Switch Transformer</a></h2>
|
|
<p>This is a miniature implementation of the paper
|
|
<a href="https://arxiv.org/abs/2101.03961">Switch Transformers: Scaling to Trillion Parameter Models with Simple and Efficient Sparsity</a>.
|
|
Our implementation only has a few million parameters and doesn’t do model parallel distributed training.
|
|
It does single GPU training but we implement the concept of switching as described in the paper.</p>
|
|
<h2><a href="fast_weights/index.html">Fast Weights Transformer</a></h2>
|
|
<p>This is an implementation of the paper
|
|
<a href="https://arxiv.org/abs/2102.11174">Linear Transformers Are Secretly Fast Weight Memory Systems in PyTorch</a>.</p>
|
|
<h2><a href="fnet/index.html">FNet: Mixing Tokens with Fourier Transforms</a></h2>
|
|
<p>This is an implementation of the paper
|
|
<a href="https://arxiv.org/abs/2105.03824">FNet: Mixing Tokens with Fourier Transforms</a>.</p>
|
|
<h2><a href="aft/index.html">Attention Free Transformer</a></h2>
|
|
<p>This is an implementation of the paper
|
|
<a href="https://papers.labml.ai/paper/2105.14103">An Attention Free Transformer</a>.</p>
|
|
<h2><a href="mlm/index.html">Masked Language Model</a></h2>
|
|
<p>This is an implementation of Masked Language Model used for pre-training in paper
|
|
<a href="https://arxiv.org/abs/1810.04805">BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding</a>.</p>
|
|
<h2><a href="mlp_mixer/index.html">MLP-Mixer: An all-MLP Architecture for Vision</a></h2>
|
|
<p>This is an implementation of the paper
|
|
<a href="https://papers.labml.ai/paper/2105.01601">MLP-Mixer: An all-MLP Architecture for Vision</a>.</p>
|
|
<h2><a href="gmlp/index.html">Pay Attention to MLPs (gMLP)</a></h2>
|
|
<p>This is an implementation of the paper
|
|
<a href="https://papers.labml.ai/paper/2105.08050">Pay Attention to MLPs</a>.</p>
|
|
</div>
|
|
<div class='code'>
|
|
<div class="highlight"><pre><span class="lineno">87</span><span></span><span class="kn">from</span> <span class="nn">.configs</span> <span class="kn">import</span> <span class="n">TransformerConfigs</span>
|
|
<span class="lineno">88</span><span class="kn">from</span> <span class="nn">.models</span> <span class="kn">import</span> <span class="n">TransformerLayer</span><span class="p">,</span> <span class="n">Encoder</span><span class="p">,</span> <span class="n">Decoder</span><span class="p">,</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">EncoderDecoder</span>
|
|
<span class="lineno">89</span><span class="kn">from</span> <span class="nn">.mha</span> <span class="kn">import</span> <span class="n">MultiHeadAttention</span>
|
|
<span class="lineno">90</span><span class="kn">from</span> <span class="nn">labml_nn.transformers.xl.relative_mha</span> <span class="kn">import</span> <span class="n">RelativeMultiHeadAttention</span></pre></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js?config=TeX-AMS_HTML">
|
|
</script>
|
|
<!-- MathJax configuration -->
|
|
<script type="text/x-mathjax-config">
|
|
MathJax.Hub.Config({
|
|
tex2jax: {
|
|
inlineMath: [ ['$','$'] ],
|
|
displayMath: [ ['$$','$$'] ],
|
|
processEscapes: true,
|
|
processEnvironments: true
|
|
},
|
|
// Center justify equations in code and markdown cells. Elsewhere
|
|
// we use CSS to left justify single line equations in code cells.
|
|
displayAlign: 'center',
|
|
"HTML-CSS": { fonts: ["TeX"] }
|
|
});
|
|
</script>
|
|
<script>
|
|
function handleImages() {
|
|
var images = document.querySelectorAll('p>img')
|
|
|
|
console.log(images);
|
|
for (var i = 0; i < images.length; ++i) {
|
|
handleImage(images[i])
|
|
}
|
|
}
|
|
|
|
function handleImage(img) {
|
|
img.parentElement.style.textAlign = 'center'
|
|
|
|
var modal = document.createElement('div')
|
|
modal.id = 'modal'
|
|
|
|
var modalContent = document.createElement('div')
|
|
modal.appendChild(modalContent)
|
|
|
|
var modalImage = document.createElement('img')
|
|
modalContent.appendChild(modalImage)
|
|
|
|
var span = document.createElement('span')
|
|
span.classList.add('close')
|
|
span.textContent = 'x'
|
|
modal.appendChild(span)
|
|
|
|
img.onclick = function () {
|
|
console.log('clicked')
|
|
document.body.appendChild(modal)
|
|
modalImage.src = img.src
|
|
}
|
|
|
|
span.onclick = function () {
|
|
document.body.removeChild(modal)
|
|
}
|
|
}
|
|
|
|
handleImages()
|
|
</script>
|
|
</body>
|
|
</html> |