Distributed Representations of Words and Phrases and their Compositionality


Background Knowledge

  • Word Representations models

    A method of representing words numerically by mapping them into a high-dimensional vector space. It makes it possible to express similarities and relationships between words, and allows the meaning of words to be handled quantitatively.

  • Syntactic relationship and Semantic relationship:

  • n-gram: A sequence of n consecutive words or characters

Abstract


Motivation

  • The strength of the existing continuous Skip-gram model is that it is an efficient tool for learning high-quality distributed vector representations that capture syntactic and semantic relationships.
    • For example, word pairs such as “king”-“queen” and “man”-“woman” are learned so as to have similar relationships within the vector space.
  • However, it is difficult to capture idiomatic expressions or complex phrases.
    • As shown in the example presented in the abstract of this paper, a case where “Canada” and “Air” combine to form a new-meaning word “Air Canada” is not properly reflected can be an example.
  • In addition, it is difficult to capture the order of words.

Proposal:

  • Subsampling of frequently occurring words
    • Improves training speed
    • Enables learning more regularized word representations
  • Applying negative sampling instead of hierarchical softmax
    • Improves training speed
    • Obtains better vector representations for frequently occurring words

Introduction


Research Background

In NLP tasks, distributed word representations have been studied as an important technique for improving performance by grouping similar words. However, as explained in the abstract, there were several issues that needed to be resolved, so the authors sought to improve these through an approach that extends a word representation model called skip-gram.

Word representations using neural networks explicitly encode linguistic rules and patterns. The authors explain that many of these patterns can be expressed as linear translations; for example, vec(“Madrid”) - vec(“Spain”) + vec(“France”) is closer to vec(“Paris”) than to any other word vector.

💡

Can most linguistic rules and patterns be expressed as linear transformations?

  • However, subsequent research pointed out that for such linear transformations to work properly, one may need to exclude vec(“Madrid”) when finding the vector closest to the result of the computation in order to obtain the desired result.
    • Why? Because there are cases where the result of a simple linear transformation like the equation above is closer to vec(“Madrid”) than to vec(“Paris”). This is a situation that fails to properly reflect the actually intended relationship between words.
  • Along with this, it was pointed out that such linear vector transformations on words may be inconsistent and may originate from a reliance on biased information in the training data.
  • In addition, since words in word representations are mapped into a ‘high-dimensional’ space, it was also pointed out that explaining the relationships between word vectors solely through such linear transformations in a high-dimensional space is an oversimplification and fails to capture complex semantic representations and linguistic relationships.

Approaches: Modification of original Skip-gram model

  • Sub-sampling of frequent words
  • NEG as a simplified variant of Noise Contrastive Estimation(NCE)
  • Word based ⇒ Phrase based model
    • Identify large number of phrases with data-driven approach
    • One phrase = One token During training
    • Evaluate with a test set of analogical reasoning tasks containing both words & phrases

The Skip-gram Model


Figure

Architecture of the Skip-gram model

Architecture

1) word: Build a dictionary consisting of mapped vectors.

2) The input is the center word, and the output is the context word. Here, using a sliding window, when window size = \(c\), \(c\) words before and after the center word, a total of \(2c\) words, are learned and predicted as context words.

3) The dataset is composed of

\(x = w(t), Y = \{w(t-c), \cdots , w(t+c)\}\).

4) Each training sample becomes a classification task. (Because for a given x, it becomes a task of choosing the nearby word from among a very large number of words.)

Consider an example. In the sentence “The cat sat on the mat”, taking “sat” as the center word and letting c=2, the following training set can be built:

| X | Y | | — | — | | sat | The | | sat | cat | | sat | on | | sat | the |

Here, in the model architecture above, \(w(t)\) = “sat”, and each of the Y words enters the output.

The Objective of the original Skip-gram

The objective of the existing Skip-gram model is “to maximize the average log probability”:

\[\frac{1}{T}\sum_{t=1}^{T}\sum_{-c\leq j\leq c,\,j\neq 0}\log p(w_{t+j}\mid w_t)\]

Here, c is the window size

Here, \(p(w_{t+j}\vert w_t)\) is defined by the softmax function as follows:

\[p(w_O\vert w_I) = \frac{\exp\left(v'_{w_O}{}^{\top} v_{w_I}\right)}{\sum_{w=1}^{W} \exp\left(v'_{w}{}^{\top} v_{w_I}\right)}\]

\(v_w\) and \(v’_w\) are the “input” and “output” vector representations of \(w\), respectively, and \(W\) is the total number of words in the word vocabulary set. There is a problem that the probability value defined in this way incurs a large cost in gradient computation due to the very large \(W\). Therefore, the authors newly define the objective function using the Negative Sampling method, which is a simplification of NCE.

The New Objective of the Skip-gram

\[\log \sigma(v'_{w_O}{}^{\top} v_{w_I}) + \sum_{i=1}^{k} \mathbb{E}_{w_i \sim P_n(w)} \left[ \log \sigma(-v'_{w_i}{}^{\top} v_{w_I}) \right]\]

This objective function can be examined by classifying it into two terms: positive examples, which are words actually in the vocabulary, and negative examples, which are unrelated words outside the vocabulary.

\[\log \sigma(v'_{w_O}{}^{\top} v_{w_I})\]

First, this is the term for positive examples: the similarity of the two vectors, expressed by the dot product of vectors \(v’_{w_O}\) and \(v_{w_I}\), is converted into a probability value by taking \(\sigma\), and then the log is taken of it.

This becomes the value to be maximized.

\[\sum_{i=1}^{k} \mathbb{E}_{w_i \sim P_n(w)} \left[ \log \sigma(-{v'_{w_i}}^{\top} v_{w_I}) \right]\]

This is the term for negative examples: the similarity of the two vectors, expressed by the dot product of vectors \(-v’_{w_i}\) and \(v_{w_I}\), is converted into a probability value by taking \(\sigma\), the log is taken, and its expectation is summed over all negative samples.

  • \(k\) is the number of negative samples to sample, and \(w_i ~ P_n(w)\) denotes \(w_i\) sampled from the noise distribution \(P_n(w)\).

This becomes the value to be minimized.

Consider the vocabulary “The cat sat on the mat” used in the example above. In the first term, for example, training proceeds so that the vectors of the words “sat” and “cat” are positioned close to each other. On the other hand, in the second term, training proceeds so that the distance between the vectors of “sat” and an unrelated word such as “car” increases.

Here, the authors add that the model performed best when the noise distribution \(P_n(w)\) was set to the unigram distribution \(U(w)^{3 \over 4}\).

💡

Unigram

: One of the fundamental concepts used when analyzing text in natural language processing (NLP); a method of calculating the frequency or probability of words individually. It views a sentence as a sequence of words and assumes that each word occurs independently.

  • Unigram distribution

    : A distribution that calculates the probability of each word based on the frequency with which it appears within a corpus. For example, if the word “cat” appears 100 times within a corpus and the total number of words is 10,000, then the unigram probability of “cat” is

    \({100 \over 10000}=0.01\)

  • Used in negative sampling, basic forms of language models, etc.
  • Why multiply by the 3/4 power in Word2Vec? To lower the sampling probability of frequently occurring words.

Subsampling of Frequent Words

  • Words that occur very frequently, such as articles, be-verbs, or prepositions, carry little information yet appear often, which can slow down model training. In addition, they can interfere with learning words that are important but appear with low frequency.
  • To address this, the authors attempt to solve the problem by applying subsampling (ignoring some of them).
\[P(w_i) = 1 - \sqrt{\frac{t}{f(w_i)}}\]

\(t\) is a threshold; in the following equation, the probability of subsampling a word \(w_i\) is calculated according to the probability \(f(w_i)\) that the word \(w_i\) appears.

Empirical Results


Figure

  • The evaluation criteria consisted of training time and Syntactic, Semantic, and overall Total Accuracy.
  • As can be seen in the Table, NEG showed the highest accuracy, and it showed the best performance when combined with subsampling.
  • The NEG parameter \(k\) showed the best result when it was 15.
  • For high-frequency words, subsampling improved training speed by 2 to 10 times.
  • Evaluation method: Model performance was evaluated using analogical reasoning tasks.
    • e.g., relationships between word vectors were evaluated through analogy problems such as “Germany : Berlin :: France : ?”

Learning Phrases


This chapter explains a method of learning vector representations of phrases, going beyond word vectors. Since phrases take on a new meaning beyond a simple combination of the meanings of their component words, there is a problem that it is difficult to represent such phrases well with existing word embedding techniques alone. Therefore, the authors learn vector representations of phrases through the following process:

Once vector representation of phrases has been carried out through this process, model performance is again evaluated through analogical reasoning.

Figure

  • Without subsampling, NEG with k=15 showed the highest performance, but when subsampling was applied, the performance of Hierarchical Softmax improved significantly.
  • Subsequently, using Hierarchical Softmax on a dataset consisting of 33,000,000,000 words with dimensionality increased to 1000, the accuracy could be raised up to 72%.

💡

Bigram

: A case where two words appear consecutively in text. Generally used to analyze whether a combination of two words appears frequently and whether it is a meaningful combination.

  • Unlike Unigram, it can capture contextual relationships between words

    ⇒ enables more sophisticated language modeling

Additive Compositionality


This chapter explains the property, mentioned above, that the vector representations of words and phrases can be combined linearly. The authors show that simple vector addition can compose complex meanings.

Figure

  • As in the table, when Czech + currency were added, this vector was closest to the four words in the same row: “koruna”, “Czech crown”, “Polish zloty”, and “CTK”.

The authors explain that such operations are possible because the word vectors are linearly connected to the input of the softmax function, so the sum of vectors produces a result similar to the product of the context distributions of the two words.

This finding is significant in that complex semantic relationships in language can be reduced to simple vector operations, and it can be useful when vectorizing long texts.

💡

Analogical Reasoning vs. Additive Compositionality

  • Analogical Reasoning centers on the ability of ‘analogy’. For example, in relationships such as A → B, then C → D, it is a method of checking, through linear transformation of vectors, whether vec(“B”) - vec(“A”) + vec(“C”) is close to vec(“D”). It does not aim at composing ‘more’ complex meanings.
  • Additive Compositionality focuses on composing new meanings through operations between vectors. Composing complex meanings is the goal. For example, as in Table 5 above, the goal is to derive “koruna” through the vector addition of “Czech” + “currency”.

Comparison to Published Word Representations


Figure

  • Comparison of the authors’ enhanced Skip-gram with other existing word representation models.
  • The evaluation criterion is analogical reasoning.
  • On large-scale models, the performance of Skip-gram was the best by a large margin.
  • Relatively accurate inference was achieved even for rare words.
  • Even with larger datasets, it was more efficient in training than existing models.

Conclusion


Contributions

  • Model Accuracy & Training Speed:
    • improved model architecture
    • subsampling of the frequent words
    • Negative sampling algorithm
  • Phrase Representation:
    • phrase to a single token

Note

  • The choice of training algorithm and hyperparameters is task specific.
  • Crucial decisions that affect the performance of the model:
    • the choice of the model architecture
    • the size of the vectors
    • the subsampling rate
    • the size of the training window

Discussion


1. NEG and Hierarchical Softmax

  • Even though the method initially proposed in the paper is NEG, why was Hierarchical Softmax more effective for learning phrases?
    • NEG: Rather than directly calculating a word’s occurrence probability, it is more suitable for learning “relationships”. It has the advantage of greatly reducing the amount of computation, but it performs well on simpler computations (because it does not perform precise probability calculations), and learning may not be done well for words that appear with low frequency.
    • Hierarchical Softmax: Probability calculation is performed using a binary tree structure. Likewise, it is proposed as a method that can improve computational efficiency, and at the same time its probability calculation is more precise.

    ⇒ In the case of phrases, there exist words that do not appear frequently (e.g., Air Canada) and the computational complexity is a bit higher. Therefore, it is presumed that, even though NEG shows higher performance in general word representation, HS was able to show higher performance in phrase learning.

  • Why is Hierarchical Softmax specifically compared with NEG?
    • The original softmax function has low computational efficiency when dealing with large-scale vocabularies. Therefore, as methods that can improve computational efficiency over softmax, 1) NEG and 2) HS were proposed.
    • NEG and Hierarchical Softmax share the commonality that both are methods that improve upon the computational efficiency aspect compared to using the original softmax.

2. Figure Interpretation

  • Looking at Fig 2, the distance between country word vectors is closer than the distance between country-capital word vectors. Despite this, why can it be concluded that the capital word vector corresponding to a country word is located at the closest distance?

    Figure

    ⇒ This is understood as PCA being performed in a direction that clearly shows the country-capital projection relationship. In the actual 1000 dimensions, the country-capital distance would have been closer than the country-country distance.

    Also, since PCA performs dimensionality reduction in a direction that explains the data variance as much as possible, the contextual similarity between countries may have been taken into account.