Contextual Language Models

0.0(0)
Studied by 0 people
call kaiCall Kai
Locked
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/27

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 3:29 PM on 7/15/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

28 Terms

1
New cards

Polysemous Words

words with different meanings

2
New cards

Naive Polysemy Handling

● Perform word sense disambiguation on the entire corpus

● Create embeddings of the disambiguated words

3
New cards

Issues with Polysemy Naive Approach

● Error propagation (word sense disambiguation is hard)

● Requires labeled training data (unlike the embedding methods)

● The vocabulary size explodes

● We also need word sense information when using the embeddings

4
New cards

Machine Translation History

knowt flashcard image
5
New cards

Sequence to Sequence Learning

knowt flashcard image
6
New cards

RNN

Sequence to sequence learning with an RNN:

● At each time step t, the neural network A looks at some input xt

and outputs a value ht.

● Information from step t is passed to step t+1 in a loop.

● The number of iterations of the loop depend on the length of the sequence

● The loop notation can be unrolled into individual steps.

● The more iterations, the more likely the model will forget previously seen information

<p>Sequence to sequence learning with an RNN:</p><p>● At each time step t, the neural network A looks at some input xt</p><p>and outputs a value ht.</p><p>● Information from step t is passed to step t+1 in a loop.</p><p>● The number of iterations of the loop depend on the length of the sequence</p><p>● The loop notation can be unrolled into individual steps.</p><p>● The more iterations, the more likely the model will forget previously seen information</p><p></p>
7
New cards

RNN Architecture

knowt flashcard image
8
New cards

Long Short-Term Memory Networks (LSTM)

knowt flashcard image
9
New cards

Intermediate Context Vectors

knowt flashcard image
10
New cards

Sequence to sequence learning for translation

● Words in the input sentence are encoded as word embeddings

● Word embeddings are fed sequentially into a RNN / LSTM model

● In each step, the input is used to update an internal context vector

● A memory mechanism is used to keep track of relevant prior information

● The combination criteria for input, memory, and context vector are learned

● To generate the translation, the steps are “reversed” by a decoder

11
New cards

Sentence representations from translations

● The context vector that is passed from encoder to decoder lies in a latent space

● The context vector contains the semantic information of the input sentence

● A translation LSTM without a decoder is a sentence embedder

12
New cards

Embedding words Machine Translation

The context vector and memory in the final generation step retain the semantic information for the options of the next word

13
New cards

Cons of Memory

● Forgetting is still a problem, even for LSTMs

● We cannot “remember” the future...

● sentence ordering is flexible in many languages

14
New cards

Downsides of LSTMs / RNNs:

● Sentences are read sequentially

○ Good for dealing with varying sentence lengths

○ Bad for parallelization (for example in a GPU)

● Processing a sentence word by word without the ability of backtracking is different from natural human reading behavior

15
New cards

Attention

● We process all words of a sentence concurrently

(instead of sequentially)

● Instead of learning to remember, we learn how to pay attention to the parts of a sentence that are important to a given word

● This is called self-attention since we focus on other words in the same input sentence.

● Grounded in syntactic / semantic relations in natural language

16
New cards

Self-Attention

● All words in a sentence are encoded as vectors

● All words are fed into the model in parallel, each word in its own “lane”.

● For each word, the model learns weights that are used to determine how important other words in the sentence are.

17
New cards

Transformer Model

● Originally designed for machine translation

● Input: sentence in language A

● Output: sentence in language B

● Encoder:

○ Processes all words of the input sentence in parallel

○ Uses attention to determine word relations

○ Outputs one vector per input word

● Decoder:

○ Sequentially processes vectors created by encoder (similar to LSTM decoder) but has access to all vectors.

○ Predicts output words one at a time

<p>● Originally designed for machine translation</p><p>● Input: sentence in language A</p><p>● Output: sentence in language B</p><p>● Encoder:</p><p>○ Processes all words of the input sentence in parallel</p><p>○ Uses attention to determine word relations</p><p>○ Outputs one vector per input word</p><p>● Decoder:</p><p>○ Sequentially processes vectors created by encoder (similar to LSTM decoder) but has access to all vectors.</p><p>○ Predicts output words one at a time</p><p></p>
18
New cards

BERT Bidirectional Encoder Representations from Transformers

BERT is a contextual language model, based on transformers:

● It uses only encoders (12 transformer encoder layers)

● Bidirectional links connecting the “lanes” between layers

● Trained on ≈ 3.3 Billion words (Wikipedia & Google Books corpus)

● Created with transfer learning in mind:

○ Trained on 2 simple unsupervised tasks (for which lots of data is available)

○ Can be fine-tuned for numerous complex tasks (for which few labeled data are available)

● Due to the transformer’s attention mechanism, We get contextualization “for free”

<p>BERT is a contextual language model, based on transformers:</p><p>● It uses only encoders (12 transformer encoder layers)</p><p>● Bidirectional links connecting the “lanes” between layers</p><p>● Trained on ≈ 3.3 Billion words (Wikipedia &amp; Google Books corpus)</p><p>● Created with transfer learning in mind:</p><p>○ Trained on 2 simple unsupervised tasks (for which lots of data is available)</p><p>○ Can be fine-tuned for numerous complex tasks (for which few labeled data are available)</p><p>● Due to the transformer’s attention mechanism, We get contextualization “for free”</p><p></p>
19
New cards

BERT Training Tasks

● Masked language modeling (MLM)

○ This is the cloze task we already know:Random words in the input are replaced by a [MASK] token and the model is trained to predict them

○ Unlike word2vec, BERT uses the signal from all other words in the context simultaneously for this prediction (using attention to determine weights)

● Next sentence prediction (NSP)

○ Given a sentence, the model has to predict the next sentence.

○ Modeled as a classification problem: Given sentences A and B, does B follow A?

20
New cards

BERT Input Rep

BERT accepts input in a fixed-width window of at most 512 tokens:

● Input starts with a special [CLS] token

● Input may contain two separate sentences, which are separated by a [SEP] token.

● The second sentence is optional

21
New cards

BERT Training

knowt flashcard image
22
New cards

Contextualized Embeddings

feature vectors from any layer can be used as embeddings, depending on the task at hand!

BERT produces feature vectors for each token in each of its 12 transformer layers.

Due to the attention mechanism, they capture different aspects of the input tokens.

23
New cards

BERT Tasks via Transfer Learning

knowt flashcard image
24
New cards

Word piece Tokenization

Most language have millions of words

○ The English Wikipedia has ≈ 600,000 headwords alone...

○ ...but 1.3 million definitions

● Most words are very rare (recall Zipf’s law)

● Using a large vocabulary increases the size of the model

In practice, contextual language models use word piece tokenization:

● Think of it like morphological decomposition…

● ...but driven by statistics, not linguistic insight!

Keep this in mind when extracting word embeddings from BERT

25
New cards

GPT-2 (only decoder):

● Training objective: predict next word in the sentence

● Trained on "Common Crawl" (a massive dataset of web pages)and Book Corpus, a dataset of over 7,000 unpublished fiction books from various genres

● Learns only from context before

● Used for natural language generation tasks

● Generates contextual word and sentence representations

26
New cards

Transfer Learning

The idea:

1. Take a pre-trained model …

2. … and adapt its weights for a …

a. domain (e.g., biology, law)

b. or task (e.g., sentiment classification)

We do NOT train the model from scratch!

We learn on top of the existing weights from the pre-trained model (e.g., BERT)

27
New cards

Domain-adaptive pre-training

an unsupervised fine-tuning approach based on a masked language modeling task on text from a specific target domain

28
New cards

Task-specific fine-tuning

deals with adaptingan LM to a particular output label distribution

○ We need labeled data! But much lessthan when training the model from scratch!