Path: blob/master/second_edition/chapter11_part03_transformer.ipynb
713 views
Kernel: Python 3
This is a companion notebook for the book Deep Learning with Python, Second Edition. For readability, it only contains runnable code blocks and section titles, and omits everything else in the book: text paragraphs, figures, and pseudocode.
If you want to be able to follow what's going on, I recommend reading the notebook side by side with your copy of the book.
This notebook was generated for TensorFlow 2.6.
The Transformer architecture
Understanding self-attention
Generalized self-attention: the query-key-value model
Multi-head attention
The Transformer encoder
Getting the data
In [0]:
Preparing the data
In [0]:
Vectorizing the data
In [0]:
Transformer encoder implemented as a subclassed Layer
In [0]:
Using the Transformer encoder for text classification
In [0]:
Training and evaluating the Transformer encoder based model
In [0]:
Using positional encoding to re-inject order information
Implementing positional embedding as a subclassed layer
In [0]:
Putting it all together: A text-classification Transformer
Combining the Transformer encoder with positional embedding
In [0]: