#!/usr/bin/env python # coding: utf-8 # In[1]: # Reveal.js from notebook.services.config import ConfigManager cm = ConfigManager() cm.update('livereveal', { 'theme': 'white', 'transition': 'none', 'controls': 'false', 'progress': 'true', }) # In[2]: get_ipython().run_cell_magic('capture', '', '%load_ext autoreload\n%autoreload 2\n# %cd ..\nimport sys\nsys.path.append("..")\nimport statnlpbook.util as util\nutil.execute_notebook(\'language_models.ipynb\')\n') # In[3]: get_ipython().run_cell_magic('html', '', '\n
\n') # In[4]: from IPython.display import Image import random # # Contextualised Word Representations # # # ## What makes a good word representation? ## # # 1. Representations are **distinct** # 2. **Similar** words have **similar** representations # ## What does this mean? ## # # # * "Yesterday I saw a bass ..." # In[5]: Image(url='../img/bass_1.jpg'+'?'+str(random.random()), width=300) # In[6]: Image(url='../img/bass_2.svg'+'?'+str(random.random()), width=100) # # Contextualised Representations # # # * Static embeddings (e.g., [word2vec](dl-representations_simple.ipynb)) have one representation per word *type*, regardless of context # # * Contextualised representations use the context surrounding the word *token* # # ## Contextualised Representations Example ## # # # * a) "Yesterday I saw a bass swimming in the lake" # In[7]: Image(url='../img/bass_1.jpg'+'?'+str(random.random()), width=300) # * b) "Yesterday I saw a bass in the music shop" # In[8]: Image(url='../img/bass_2.svg'+'?'+str(random.random()), width=100) # ## Contextualised Representations Example ## # # # * a) "Yesterday I saw a bass swimming in the lake". # * b) "Yesterday I saw a bass in the music shop". # In[9]: Image(url='../img/bass_visualisation.jpg'+'?'+str(random.random()), width=500) # ## What makes a good representation? ## # # 1. Representations are **distinct** # 2. **Similar** words have **similar** representations # Additional criterion: # # 3. Representations take **context** into account # ## How to train contextualised representations ## # # Basicallly like word2vec: predict a word from its context (or vice versa). # # Cannot just use lookup table (i.e., embedding matrix) any more. # # Train a network with the sequence as input! Does this remind you of anything? #