The Reformer

Siraj Raval · Beginner ·📐 ML Fundamentals ·6y ago

Key Takeaways

The Reformer architecture, released by Google, improves the efficiency of natural language processing using reversible layers and locality sensitive hashing, allowing for processing of text sequences up to 1 million words long with reduced memory footprint. The video covers the basics of LLMs, including Word2Vec, FastText, and the Transformer architecture, as well as the Reformer's unique features and applications.

Full Transcript

hey nice computer oh thanks I bought 40 GPUs to do some text processing hmm well now you just need one hello world it's Suraj and Google just released a new language model called the reformer that's able to process text sequences that are up to 1 million words long using only one accelerator and 16 gigs of memory what that means for you is that it's now easier than ever before to build a surprisingly impressive app or project that can generate text classify text categorize text or summarize text with a low cost computer in this episode I'll help you understand what makes the reformer architecture unique compared to its predecessors and will repurpose Google's simple Python demo to ingest an entire biology textbook and help us answer questions we have about its topics automatically to truly understand the Reformers architecture we've got to wind the clock back to seven years ago it was 2013 the year the movie sharknado was released it's so bad that it's good up until that point the field of natural language processing consisted of rule-based & heuristic techniques that worked well enough but when a model called word Tyvek was released that year it changed how developers thought about natural language processing more Tyvek was a neural network that was able to literally turn words into vectors aka numerical representations and this numerical format allowed us to apply mathematical operations to these words to compute results we could say create an expression using vectors like King - man plus woman and it would output Yas Queen without the Yas yeah we could visualize these vectors and see how similar words cluster together or use them to help make other types of models more robust this technique was a new lens with which to see the world of data this way of learning representations rather than applying rules to raw text then in 2015 a model called fast text extended the word Tyvek model by treating each word vector as the sum of a series of character level vectors doing cell allowed us to present rare words words that didn't show up that often in the training data more robustly since characters are often shared between words two years later in 2017 Google release in architecture called the transformer in a paper titled attention is all you need in the paper Google showed how they achieved state-of-the-art results in automatic language translation using a concept called an attention mechanism this attention mechanism allowed their model to not just ingest all the input data during the training process but instead pay attention to the most relevant parts of the input the parts that matter most to make the most accurate predictions this in turn helped reduce the amount of training time necessary by a large margin so by early 2018 there were some powerful open source models available for anyone to use on their own text processing projects but to get really great results you still needed lots of computing power and lots and lots and lots of data that is until Google released Bert or bi-directional encoder representations from transformers they modified the original transformer architecture to take the full context of a word into account when learning from it Bert's bi-directional nature learned a words context from both ends of a sentence ie bi-directionally they trained Bert on an absolutely massive amount of text data including all of Wikipedia and 800 million words from books and then open sourced it for anyone to use as a starting point for their own project that moment the release of Bert might just have been the most significant contribution to the field of natural language processing of all time similar to how convolutional networks changed computer vision forever in 2012 achieving state of the art accuracy during the image net competition because Bert was already trained on so much text data developers could leverage its knowledge to quickly and easily train NLP apps for a huge range of tasks without requiring huge data sets tasks like question answering machine translation text summarization sentiment analysis text cat zatia dialogue systems and common-sense reasoning all became very accessible to build and if you didn't want to use Bert you could just use the slew of Bert variations that were released by other companies throughout the rest of the year like Ernie Elmo I love these Sesame Street naming conventions roberta excel ned GPT to transformer x and my personal favorite bio bert bio Bert was Bert retrained on biomedical domain knowledge from experts and its variations included an automatic diagnostic app just give it your symptoms and it will tell you a preliminary diagnosis including possible treatment options so now it's 2020 and google has released the reformer architecture they've re-engineered the transformer architecture to be much more efficient in terms of speed and storage or in more computer science e terms its space and time complexity are much better to do this they used two techniques locality-sensitive hashing and reversible layers let's dive into why they used both of them let's say we have a sequence of words in the form of a book and we want to learn from it we wouldn't want to use a feed-forward neural network since they aren't meant for sequential data where all the inputs are related in some way we'd want to use a recurrent Network but while recurrent Nets are great they're sequential processing nature is not well-suited for the parallel processing nature of GPUs and TP use we could maybe use convolutional networks instead but they tend to get computationally expensive for long sequences sorry yawn let's just discard recurrence and convolutions entirely maybe all you really need is attention if we're reading a mystery novel and we're trying to remember the most relevant characters we pay attention to certain words more than others namely character names this internal mechanism we have allows us to interpret text data faster since we focus on the most relevant parts we can mathematically represent this as an attention mechanism think of it as a vector of importance weights in order to predict a given element like a word in a sentence we estimate you an attention vector how much it's correlated with or attends to other elements then we take the sum of their values weighing them by the attention vector as a proper prediction of the target attention can be thought of as a clever matrix math trick that makes training time faster but the attention mechanism used by the transformer architecture took way too many words into account when trying to understand the relationships between them and thus the memory footprint reflected that so in the reformer paper they use a hash function to match similar input vectors together a hash function takes a group of characters also called keys as input and map's each of them to a smaller length ID called a hash value the hash represents the original inputs too many words might impose big watch me hash it I like to hash it I like to hash it so when feeding the network input text each vector from layer 1 represents a given word the hash function will then give similar vectors the same hash value and once these hashes are given the input sequence is reordered to bring together similar vectors based on their hash and chunked to enable parallel processing it's only then that we apply attention to these much smaller chunks which makes the training process much faster they call this technique locality sensitive hashing because sensitivity is so 20/20 more seriously in their own words a hashing scheme that assigns each vector X to a hash H of X is called locality sensitive if nearby vectors get the same hash with high probability and distant ones do not okay so that was a first solution the other one was an idea introduced in 2017 called reversible layers the way neural networks are trained is by using a technique called back propagation which LaRon Sanderson made an excellent video on it's basically a way of propagating the lessons learned during the training process to the entire network this process however requires storing what are called activations in so the more activations the higher the memory footprint activations help a network learn the optimal function from the data to make predictions instead of storing all the activations in memory the reformer recomputes the input of each layer on demand during the backpropagation process two sets of activations are kept for each layer one captures changes to the first layer and the other captures the last layer thus using subtraction the network is able to recompute the necessary input values during back propagation without having to store it all in memory SiC right but what better way to understand the reformer and by playing with the code ourselves let's take a look at our text generation collab demo first we'll need to install jax for hardware acceleration and tensorflow for deep learning then we'll load a biology textbook from the Gutenberg library into it instead of the example they used okay boomer then we tokenize it using the sentence piece processor function in order to prevent overfitting we'll add random padding to each token so the model does not just memorize the data set completely it'll be able to add some novelty to its generated predictions clearly in this example there are a lot of hyper parameters that we can configure here and no doubt the values of what these numbers should be will sprout multiple papers this year then we can use the Trax library which they decided to wrap this model into to setup a trainer object once trained we can sample from it giving it a seed sentence and it'll fill in the rest I'm pretty excited to see what NLP researchers come up with this year the primitives have been defined attention mechanisms sequence learning and gradient based optimization now the next phase is to tune and dial up these models a millionfold to produce amazing results the winner of last week's coding challenge is bintang a swamp bintang submitted this aircraft design repository which isn't exactly a healthcare app but it's still cool so good job in tang i've got links to some great learning resources for you in the video description so hit that subscribe button like the video and happy learning

Original Description

Google just released a new Neural Network architecture called "The Reformer" that helps make the state of the art in Natural Language Processing available to people with a smaller budget. They introduced two key ideas here, "reversible layers" and "locality sensitive hashing". Both of these concept build on about a decade of research in neural networks applied to NLP, so to truly understand the Reformer, we've got to understand the timeline of deep learning based NLP. In this episode, I'll take you on a journey through the advances that lead up to the Reformer, what the relevant applications of it are, and how you can get started building your own text application with it today in a few lines of Python code. All the code I demonstrate in this video is from various developers across GitHub, I do not claim any of it as my own, I am using them as examples to enable more people outside of Academia to understand modern NLP. Enjoy! TWITTER: https://bit.ly/2OHYLbB WEBSITE: https://bit.ly/2OoVPQF INSTAGRAM: https://bit.ly/312pLUb FACEBOOK: https://bit.ly/2OqOhx1 Please subscribe for more educational videos! It would mean so much to me. Google's Reformer Code (Text Generation): https://colab.research.google.com/github/google/trax/blob/master/trax/models/reformer/text_generation.ipynb Bintang's winning code (forked, yes, but thanks for bringing this to our attention, cool repo!) : https://github.com/baswam95/SUAVE Are you a total beginner to machine learning? Watch this: https://www.youtube.com/watch?v=Cr6VqTRO1v0 Learn Python: https://www.youtube.com/watch?v=T5pRlIbr6gg Free Natural Language Processing Curriculum: https://www.youtube.com/watch?v=GazFsfcijXQ Natural Language Processing: https://www.youtube.com/watch?v=bDxFvr1gpSU Sentdex has some great playlists on NLP: https://www.youtube.com/watch?v=FLZvOKSCkxY Google's Initial Reformer Blog Post https://ai.googleblog.com/2020/01/reformer-efficient-transformer.html Word2Vec Explained: https://www.youtube.com/wat
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Siraj Raval · Siraj Raval · 0 of 60

← Previous Next →
1 What is Bitcoin?
What is Bitcoin?
Siraj Raval
2 5 Ways to Use Bitcoin
5 Ways to Use Bitcoin
Siraj Raval
3 BTC Fever - Siraj [Music Video]
BTC Fever - Siraj [Music Video]
Siraj Raval
4 5 Reasons to Build Decentralized Apps
5 Reasons to Build Decentralized Apps
Siraj Raval
5 The Interplanetary File System
The Interplanetary File System
Siraj Raval
6 How to Build a Dapp in 3 min
How to Build a Dapp in 3 min
Siraj Raval
7 Life Before Smartphones
Life Before Smartphones
Siraj Raval
8 4 Ways to Use Smart Contracts
4 Ways to Use Smart Contracts
Siraj Raval
9 3 Dapps You HAVE to See
3 Dapps You HAVE to See
Siraj Raval
10 Char's Life as a BitTorrent Engineer
Char's Life as a BitTorrent Engineer
Siraj Raval
11 4 Reasons AlphaGo is a Huge Deal
4 Reasons AlphaGo is a Huge Deal
Siraj Raval
12 Build a Neural Net in 4 Minutes
Build a Neural Net in 4 Minutes
Siraj Raval
13 Sentiment Analysis in 4 Minutes
Sentiment Analysis in 4 Minutes
Siraj Raval
14 The Hackathon Life
The Hackathon Life
Siraj Raval
15 Your First ML App - Machine Learning for Hackers #1
Your First ML App - Machine Learning for Hackers #1
Siraj Raval
16 Build an AI Composer - Machine Learning for Hackers #2
Build an AI Composer - Machine Learning for Hackers #2
Siraj Raval
17 Build a Game AI - Machine Learning for Hackers #3
Build a Game AI - Machine Learning for Hackers #3
Siraj Raval
18 Build a Movie Recommender - Machine Learning for Hackers #4
Build a Movie Recommender - Machine Learning for Hackers #4
Siraj Raval
19 Build an AI Artist - Machine Learning for Hackers #5
Build an AI Artist - Machine Learning for Hackers #5
Siraj Raval
20 Build a Chatbot - ML for Hackers #6
Build a Chatbot - ML for Hackers #6
Siraj Raval
21 Build an AI Reader - Machine Learning for Hackers #7
Build an AI Reader - Machine Learning for Hackers #7
Siraj Raval
22 Build an AI Writer - Machine Learning for Hackers #8
Build an AI Writer - Machine Learning for Hackers #8
Siraj Raval
23 Build a Chatbot w/ an API - ML for Hackers #9
Build a Chatbot w/ an API - ML for Hackers #9
Siraj Raval
24 One-Shot Learning - Fresh Machine Learning #1
One-Shot Learning - Fresh Machine Learning #1
Siraj Raval
25 Generative Adversarial Nets - Fresh Machine Learning #2
Generative Adversarial Nets - Fresh Machine Learning #2
Siraj Raval
26 Tone Analysis - Fresh Machine Learning #3
Tone Analysis - Fresh Machine Learning #3
Siraj Raval
27 Generate Rap Lyrics - Fresh Machine Learning #4
Generate Rap Lyrics - Fresh Machine Learning #4
Siraj Raval
28 Build an Autoencoder in 5 Min - Fresh Machine Learning #5
Build an Autoencoder in 5 Min - Fresh Machine Learning #5
Siraj Raval
29 Build a Self Driving Car in 5 Min - Fresh Machine Learning #6
Build a Self Driving Car in 5 Min - Fresh Machine Learning #6
Siraj Raval
30 Build an Antivirus in 5 Min - Fresh Machine Learning #7
Build an Antivirus in 5 Min - Fresh Machine Learning #7
Siraj Raval
31 TensorFlow in 5 Minutes (tutorial)
TensorFlow in 5 Minutes (tutorial)
Siraj Raval
32 Build a Recurrent Neural Net in 5 Min
Build a Recurrent Neural Net in 5 Min
Siraj Raval
33 Build a Simulation in 5 Min
Build a Simulation in 5 Min
Siraj Raval
34 Build a TensorFlow Image Classifier in 5 Min
Build a TensorFlow Image Classifier in 5 Min
Siraj Raval
35 Tensorboard Explained in 5 Min
Tensorboard Explained in 5 Min
Siraj Raval
36 Generate Music in TensorFlow
Generate Music in TensorFlow
Siraj Raval
37 Build a Game Bot (LIVE)
Build a Game Bot (LIVE)
Siraj Raval
38 Deep Learning Frameworks Compared
Deep Learning Frameworks Compared
Siraj Raval
39 Introduction - Learn Python for Data Science #1
Introduction - Learn Python for Data Science #1
Siraj Raval
40 Build a Neural Network (LIVE)
Build a Neural Network (LIVE)
Siraj Raval
41 Twitter Sentiment Analysis - Learn Python for Data Science #2
Twitter Sentiment Analysis - Learn Python for Data Science #2
Siraj Raval
42 Recommendation Systems - Learn Python for Data Science #3
Recommendation Systems - Learn Python for Data Science #3
Siraj Raval
43 Predicting Stock Prices - Learn Python for Data Science #4
Predicting Stock Prices - Learn Python for Data Science #4
Siraj Raval
44 Pong Neural Network (LIVE)
Pong Neural Network (LIVE)
Siraj Raval
45 Deep Dream in TensorFlow - Learn Python for Data Science #5
Deep Dream in TensorFlow - Learn Python for Data Science #5
Siraj Raval
46 Visualizing Data with D3.js (LIVE)
Visualizing Data with D3.js (LIVE)
Siraj Raval
47 Genetic Algorithms - Learn Python for Data Science #6
Genetic Algorithms - Learn Python for Data Science #6
Siraj Raval
48 Enter Siraj [Music Video]
Enter Siraj [Music Video]
Siraj Raval
49 Build a Web Scraper (LIVE)
Build a Web Scraper (LIVE)
Siraj Raval
50 Why is P vs NP Important?
Why is P vs NP Important?
Siraj Raval
51 How to Make a Neural Network (LIVE)
How to Make a Neural Network (LIVE)
Siraj Raval
52 How to Make an Amazing Tensorflow Chatbot Easily
How to Make an Amazing Tensorflow Chatbot Easily
Siraj Raval
53 How to Make an Amazing Video Game Bot Easily
How to Make an Amazing Video Game Bot Easily
Siraj Raval
54 How to Make a Tensorflow Neural Network (LIVE)
How to Make a Tensorflow Neural Network (LIVE)
Siraj Raval
55 How to Make a Simple Tensorflow Speech Recognizer
How to Make a Simple Tensorflow Speech Recognizer
Siraj Raval
56 Joel Shor - Really Quick Questions with an Awesome Google Engineer
Joel Shor - Really Quick Questions with an Awesome Google Engineer
Siraj Raval
57 How to Make a Path Planning Algorithm Easily (LIVE)
How to Make a Path Planning Algorithm Easily (LIVE)
Siraj Raval
58 The Best Way to Prepare a Dataset Easily
The Best Way to Prepare a Dataset Easily
Siraj Raval
59 Catherine Olsson - Really Quick Questions with an OpenAI Engineer
Catherine Olsson - Really Quick Questions with an OpenAI Engineer
Siraj Raval
60 How to Make a Tic Tac Toe Neural Network Easily (LIVE)
How to Make a Tic Tac Toe Neural Network Easily (LIVE)
Siraj Raval

The Reformer architecture improves the efficiency of natural language processing using reversible layers and locality sensitive hashing. This video covers the basics of LLMs and the Reformer's unique features, and provides a practical example of how to implement the Reformer using JAX and TensorFlow.

Key Takeaways
  1. Install JAX for hardware acceleration
  2. Install TensorFlow for deep learning
  3. Load a biology textbook from the Gutenberg library
  4. Tokenize input using the sentence piece processor function
  5. Add random padding to prevent overfitting
  6. Implement reversible layers and locality sensitive hashing
  7. Fine-tune the Reformer model for a specific task
💡 The Reformer architecture's use of reversible layers and locality sensitive hashing allows for efficient processing of long text sequences with reduced memory footprint, making it a promising approach for natural language processing tasks.

Related Reads

📰
Making fundamentals and advanced concepts very clear
Improve your fundamentals and advanced concepts in OOPS, DBMS, OS, and CN with recommended sources for interview preparation
Reddit r/learnprogramming
📰
The N+1 Query Problem in Java: Why Loading One Record Triggers 100 Queries
Learn to solve the N+1 query problem in Java using Spring Data JPA and Hibernate to improve performance
Medium · Programming
📰
Never Regress: Putting a Model in Your Query Optimizer Without Letting It Wreck the Plan
Learn how to integrate a model into your query optimizer without compromising the plan, using a Rust SDK that corrects row-count estimates
Dev.to · AI Explore
📰
The PRNG draw-tape: eager versus lazy
Learn about the PRNG draw-tape and the difference between eager and lazy approaches in generating random numbers for reproducibility
Dev.to · Ernesto Herrera Salinas
Up next
Arrays vs Lists: What AI Actually Prefers | Common Tech Interview Questions
SCALER
Watch →