Lecture Note: Unimodal Representation - Part 2 (Language)

11-777 Multimodal Machine Learning CMU Fall 2023
Instructor: Dr. Louis-Philippe Morency | Co-lecturer: Dr. Paul Pu Liang
Author: Yi-Jing Sie

Overview

This post is a continuation of Unimodal Representation – Part 1. While the previous post introduced common image representation techniques, this post explores word representation for language and then the evolution of language representation and language models.

Specifically, how individual words in a corpus are represented via the Skip-gram algorithm, how sequences of words are modeled with Recurrent Neural Networks (RNNs), and how the underlying syntax and language structure of a sentence are encoded.

Word Representations

The simplest way to represent a word is a one-hot encoding: a vector with a single $1$ at the word's index in dictionary and zeros everywhere else. This is easy to construct but carries no information about the word's meaning at all.

The distributional hypothesis offers a way to pass this limitation: it assumes a word's meaning can be approximated by the words surrounding it, so that words used in similar contexts will have similar meanings and be close in representation space too.

Co-occurrence Matrix

By building a co-occurrence matrix, where each row records how often that word appears with other words in the corpus, each row can then be treated as the coordinates of that word in a high-dimensional space, turning similarity into a geometric question. Vectors that are "close", measured either by Euclidean distance (after normalizing them to unit length) or by the angle between them, correspond to similar words.

Grid Image

Skip-gram Model

It's one of the two model architectures used in word2vec tool.
Instead of counting co-occurrences for words in the corpus directly, the skip-gram model trains a small network (linear-linear-softmax) that, given a target word, predicts the words surrounding it . This turns a sparse, high-dimensional one-hot vector into a compact, dense vector that actually reflects similarity. Two similar words like "walking" and "running," which share nothing when encoded as one-hot vectors, end up close together when encoded via word2vec.
This works because, while the model is learning word representations, it is also constructing a vector space where words are positioned according to their relationships. Both syntactic and semantic information are encoded in this space, allowing us to perform vector arithmetic on the learned representations.
However, they also encode gender-biases in the training data, such as gender stereotypes tied to specific occupations. For example:
representation(programmer) - representation(man) + representation(woman) is close to representation(homemaker) in the learned vector space.

Grid Image

After training is complete, we can use $W_1$ (shown in the figure above) to obtain word representations.

Recurrent Neural Networks (RNN)

Recurrent Neural Networks (RNNs) are designed to process sequential data, where the order of words is crucial for the tasks. RNNs maintain a hidden state that updates at every time step as it processes one word after another, letting information from earlier words influence how later words are interpreted.
This structure supports several kinds of predictions: a label at every position (such as part-of-speech tags or per-word sentiment), a single label for the whole sequence, or a prediction of the next word at each position.

Grid Image

Sequence Representation

The last hidden state of an RNN captures the accumulated context of the entire sequence and can be used as the representation for the input sequence.

Grid Image

Bidirectional RNN

To capture contextual information from both sides of a sequence, Bidirectional RNN architecture can be utilized. This approach processes the input sequence in both forward and backward directions to construct combined sequence representations.

Grid Image

Syntax & Language Structure

Moving beyond isolated words requires modeling the hierarchical structure of full sentences.

Phrase-Structure Grammar

By parsing a sentence based on grammar, the sentence can be modeled as a hierarchical tree, grouping words into progressively larger structural constituents.

  • The adjective "yellow" and noun "squash" are combined to create a noun phrase.
  • The verb "ate" and the noun phrase "yellow squash" are combined to create a larger verb phrase.
  • Finally, the noun "Alice" and the verb phrase "ate yellow squash" are combined to create a complete sentence.

Dependency Grammar

Instead of grouping phrases, this method maps direct, functional relationships between individual words. For example:

  • "Alice" is the subject of the action "ate"
  • "squash" is the object of the action "ate"
Grid Image

Challenges of Structural Ambiguity

However, human language inherently contains structural ambiguity where individual words can hold ambiguous, multiple syntactic roles depending on the context. Take, for instance, the sentence:

"Salesmen sold the dog biscuits."

A flat reading leaves room for two completely different interpretations:

  • Interpretation A (Compound Noun Phrase): The words "dog" and "biscuits" are joined as a single noun phrase. Here, "dog" acts as a modifier for "biscuits," meaning "The dog biscuits were sold by the salesmen".
  • Interpretation B (Separated Nouns): "The dog" and "biscuits" are treated as two entirely separate grammatical entities. In a dependency map, the verb "sold" points to "dog" as the recipient and "biscuits" as the object, meaning "Salesmen sold biscuits to the dog".

Tree-based RNNs

Tree-based RNNs can be employed to look beyond flat sequences of text, modeling the complex hierarchical structures of languages, which helps grasp the truly intended meaning.

Grid Image

Key Takeaways

Distributional Hypothesis for Word Representation

With distributional hypothesis, word representation can be transitioned from massive, sparse one-hot vectors to dense continuous vector spaces.


RNNs for Sequence Modeling

Recurrent Neural Networks (RNNs) process sequential data by maintaining a hidden state at each timestep, which acts as a built-in memory to retain information from previous inputs in sequential data.


Hierarchical Structure of Languages & Tree-based RNNs

Tree-based RNNs effectively capture the inherent hierarchical structure of natural language by processing tree-structured representations rather than treating sentences as flat sequences of words.