Interpreting Word Embeddings with Eigenvector Analysis
Anonymous Author(s)
AfﬁliationAddress email
Abstract
Dense word vectors have proven their values in many downstream NLP tasks overthe past few years.
However, the dimensions of such embeddings are not easilyinterpretable.
Out of the d -dimensions in a word vector, we would not be able tounderstand
what high or low values mean.
Previous approaches addressing thisissue have mainly focused on either training sparse/non-negative constrained wordembeddings, or post-processing standard pre-trained word embeddings.
On theother hand, we analyze conventional word embeddings trained with Singular Value
Decomposition, and reveal similar interpretability.
We use a novel eigenvectoranalysis method inspired from Random Matrix Theory and show that semantically coherent groups not only form in the row space, but also the column space.
This allows us to view individual word vector dimensions as human-interpretablesemantic features.
Introduction
Understanding words has a fundamental impact on many natural language processing tasks, and hasbeen modeled with the Distributional Hypothesis [1].
Dense d -dimensional vector representationsof words created from this model are often referred to as word embeddings , and have successfullycaptured similarities between words, such as word2vec and GloVe [2, 3].
They have also been appliedto downstream NLP tasks as word representation features, ranging from sentiment analysis to machinetranslation [4, 5].
Despite their widespread popularity in usage, the dimensions of these word vectors are difﬁcult tointerpret [6].
Consider w president =
3 ] as the 3-dimensional vector of “president” fromword2vec .
In this 3-dimensional space (or the row space), semantically similar words like “minister”and “president” are closely located.
However, it is unclear what the dimensions represent, as we do notknow the meaning of the 2.4 in w president .
It is difﬁcult to answer questions like ‘ what is the meaningof high and low values in the columns of W ’ and ‘ how can we interpret the dimensions of wordvectors ’.
To address this problem, previous literature focused on the column space by either trainingword embeddings with sparse and non-negative constraints [7–9], or post-processing pre-trainedword embeddings [6, 10, 11].
We instead investigate this problem from a random matrix perspective.
In our work, we analyze the eigenvectors of word embeddings obtained with truncated Singular
Value Decomposition (SVD) [12, 13] of the Positive Pointwise Mutual Information (PPMI) matrix[14].
Moreover, we compare this analysis with the row and column space analysis of Skip Gram
Negative Sampling (SGNS) , a model used to train word2vec [15].
From the works of [16] provingthat both SVD and SGNS factorizes and approximates the same matrix, we hypothesize that a studyof the principal eigenvectors of the PPMI matrix reﬂects the information contained in SGNS.
Contributions: Without requiring any constraints or post-processing, we show that the dimensionsof word vectors can be interpreted as semantic features.
In doing so, we also introduce novel wordembedding analysis methods inspired by the literature of eigenvector analysis techniques from
Random Matrix Theory.
Related Work
Recently, there have been several works that have shown similar results in semantic grouping amongthe column values.
Several of these algorithms proposed to train non-negative sparse interpretableword vectors [7–9, 17].
Furthermore, [6] also proposed methods to post-process pre-trained word vectors with non-negativityand sparsity constraints.
However, their vectors were optionally binarized, which is difﬁcult tointerpret intensity than real-values.
[10] has proposed to overcome these limitations by simplytraining a rotation matrix to transform pre-trained word2vec and GloVe , without being sparse orbinary.
Finally, [11] post-trained the pre-trained word embeddings with k -sparse autoencoders withsimilar constraints to [6].
While these methods were able to successfully achieve interpretability in the column space evaluatedwith word intrusion detection tests, they either enforced sparsity and non-negativity constraints, orrequired extensive
post-processing.
Furthermore, they focused less on the analysis and discussion onthe actual meanings of the columns despite their pursuit of interpretable dimensions.
Hence, in ourwork, we put more emphasis on such implications with conventional algorithms without any extraconstraints or post-processing steps.
Methodology3.1 Notations
We deﬁne the Positive Pointwise Mutual Information (PPMI) matrix as M PPMI , the set of uniquewords as vocabulary V , and word embedding matrices created from SVD and SGNS as W SVD and
W SGNS .
The k -th largest eigenvalue and corresponding eigenvector of M PPMI are denoted as λ k andu k ∈ R | V | , and the k -th column of W SGNS as v k ∈ R | V | .
The word vectors are denoted w SVD word or w SVD word ,but when context is clear or does not matter, we simply use w word .
Note that we often use the term"eigen" when and "singular" interchangeably because M PPMI is deﬁned as a square matrix.
3.2 Positive Pointwise Mutual Information (PPMI) Matrix
Each entry of a co-occurrence matrix M represents the co-occurrence counts of words w i and c j in alldocuments in the corpus.
However, raw co-occurrence counts have been known to underperform thanother transformed variants [16].
Pointwise Mutual Information (PMI)
[14] instead transforms matrixby measuring the log ratio between the joint probability of w and c when assuming independence ofthe two and not.
[Equation]
The problem of this association measure is when dealing with never observed pairs which result in
PMI ( w , c ) = log0.
To cope with such, Positive Pointwise Mutual Information has been used to mapall negative values to 0 from the intuition that positive associations are often more informative indownstream NLP tasks [16].
[Equation]
3.3 Truncated Singular Value Decomposition (SVD)
Truncated SVD (we will further refer this as simply SVD), which is equivalent to maximum variance
Principal Component Analysis (PCA) and has been popularized by Latent Semantic Analysis (LSA)[13], factorizes the PPMI matrix as M PPMI
= U · S · V T and truncates to d dimensions.
Followingthe works of [18], the word embedding matrix is taken as W = U d , instead of the more “standard"eigenvalue weighting W = U
d · S .
We discuss the effect of this in Section 6.2.
[Equation]
3.4 Skip-Gram with Negative Sampling (SGNS)
Unlike PPMI and SVD which gives exact solutions, the word2vec Skip-Gram model, proposed by[2], trains two randomly initialized word embedding matrices W and C with a neural network.
P ( C j | W i ) =
Softmax ( W i · C j ) , where Softmax ( W i · C j ) =
e W i · C j ∑ k e W i · C k
The intuition is to basically maximize the dot product between "similar" word and context pairs, andminimize the dot product between wrong pairs.
The Softmax function is simply a generalized versionof the logistic function to multi-class scenario.
However, the normalization constant which computesthe exponentials of all context words, is very computationally expensive when the vocabulary size islarge.
Hence, [15] proposed Skip Gram with Negative Sampling (SGNS) to simplify the objectiveusing negative sampling.
3.5 Eigenvector Analysis Methods
We borrow intuitions from the Random Matrix Theory literature to analyze eigenvectors of M PPMI .
We analyze the distributions of eigenvectors, calculate the Inverse Participation Ratios (IPR) toquantify the ratio of signiﬁcant elements and measure structural sparsity, and qualitatively interpretthe signiﬁcant elements.
Distribution of Eigenvector: The empirical distribution of eigenvector elements u k is comparedwith a Normal distribution N ( µ u k , σ 2 u k ) to measure normality of the eigenvectors.
[19] have shownthat eigenvectors deviating from Gaussian contain genuine correlation between stocks, while alsorevealing a global bias that represented newsbreaks inﬂuencing all stocks.
We search for similarpatterns in Section 5.1.
Inverse Participation Ratio: The Inverse Participation Ratio (IPR) of u k , denoted as I k , quantiﬁesthe inverse ratio of signiﬁcant elements in the eigenvector u k [19–21].
[Equation]
where u ki is the i -th element of u k .
The intuition of IPR can be illustrated with two extreme cases.
First, if all elements of u k have same values 1 / (cid:112) | V | , then I k is simply 1 / | V | , with reciprocal 1 / I kbeing | V | .
This means that all | V | elements contribute similarly.
On the other hand, a one-hot vectorwith only one element as one, and the rest as zero, u k will have an IPR value of one (also same forreciprocal).
Hence, the reciprocal, 1 / I k , measures the ratio of signiﬁcant participants in u k .
In short,the larger the I k , the smaller the ratio of participation, and the sparser the vector, in turn, reﬂectingstructural sparsity of u k .
Furthermore, as 1 / I k ∈ [ 1 , | V | ] , dividing this reciprocal with | V | will yieldthe sparsity of a given vector u k ∈ R | V | .
Visualization of Top Eigenvector elements: As u k , v k ∈ R | V | , we can map each index of the vectorsto a word in the vocabulary V .
Hence, we investigate the dimensions and their indices (or words )with the largest absolute values and search for semantic coherence.
Similar approaches with ﬁnancialdata have shown to group stocks from same industries or nearby regions [19], and with genetic data,revealed important co-evolving genes in gene co-expression networks [20].
Experimental Setup
4.1 Training
English Wikipedia We use the English Wikipedia dump 1 cleaned by adapting Matt Mahoney’s Perlscript 2 , which has also been used by [2].
Removing most of the noisy non-alphanumerics, such as
XML tags, the dataset size effectively reduced from approximately 66GB to 25GB, containing around3.4B tokens.
The vocabulary size is approximately 346K as we only consider words with at least 100occurrences.
At the bottom of http://mattmahoney.net/dc/textdata.html
[Figure]
SGNS and SVD
We adapt the code from the hyperwords 3 released by [18] to train both W SVD and
W SGNS .
For W SGNS , we set negative sampling as 5.
For both, we set a context window size of 2(taking 5 words as context) and embedding dimension d = 500.
Results
5.1 Distribution of Eigenvector Elements
From Figure 1, we can see that eigenvectors corresponding to the larger eigenvalues such as u 1 or u 2clearly deviate from a Gaussian distribution, and so do u 100 and u 500 , but less.
This shows us that theeigenvectors are not random and contain meaningful correlations.
It is expected to see such patternbecause these vectors are the principal eigenvectors.
On a more interesting note, u 1 not only signiﬁcantly deviates from a normal distribution, but also hasonly non-zero negative values as its elements, and no other eigenvectors have shown this behavior.
This suggests that this particular eigenvector could represent a common bias that affects all “words",as it captured the effect of news outbreaks for stock prices in [19].
We revisit the interpretation ofthis observation in Section 6.1.
5.2 Inverse Participation Ratio
Figure 2 illustrates the IPR of u k plotted against the corresponding eigenvalue λ k , and vice versa forv k .
From the plot, we can clearly see that the eigenvectors of W SVD have approximately 10x higher
IPR values than those of W SGNS , meaning that the vectors are much sparser for W SVD .
From Figure 2a, we can see that the largest eigenvector has the smallest IPR of 0 . 000006, and thereciprocal 1 / I k divided by | V | , yields 48%, while the same for the largest I k gave around 4.7%.
Themean value of 1 / I k divided by | V | , across all eigenvectors was 27.5% indicating that there exists
[Figure]
uu
[Equation]
uuuulastly molly determinants shyam famille jays outset sally biochemical sanjeev vrier strikeouts ostensibly toby intrinsic meera autour halladay curiously maggie qualitative anupama naissance hitters actuality valentine elucidated deepa rique buehrle crucially jenny analytical rajkumar diteur batters theirs tracy psychological manju octobre pitching importantly lucy unger uday chambre phillies thankfully carrie ehrlich chitra lettre rbis regrettably elliot quantitative vinod campagne astros ironically susie integrative archana jeune diamondbacks aforementioned laurie extrinsic bhanu jours homers paradoxically cooper nagel santosh septembre hitless oftentimes jill methodologies rajesh enfance orioles doubtless kitty exogenous ashok plon podsednik unsurprisingly charlie underneath munna affaire baserunners connelly shirley translational suman cembre hitter merrick hannah kuhn komal royaume sox invariably annie functional subhash propos
pettitte dunning elaine schweitzer usha juin vizquel
Transition
First Names
Science
Indian Names
French
Baseball some sparse structure within the eigenvectors of W SVD .
On the other hand, Figure 2b shows thatmean for v k was around 36%, meaning that column vectors of W SGNS are generally denser and lessstructured.
Such discrepancy in structural sparsity motivates us to analyze the eigenvectors of W SVDin depth.
Analysis and Discussion
6.1 Column Space Analysis
Based on the results of previous sections, we further examine the top elements of the eigenvectors bysorting their absolute values in decreasing order.
Table 1 shows interesting results as the signiﬁcantdimensions or their corresponding “words" of each eigenvector, in general, form semantically orsyntactically coherent groups.
For instance, u 14 groups French words together and u 121 showsbaseball related words.
Some words from u 121 initially seem irrelevant to baseball.
However,“buehrle” is a baseball player, “rbis” stand for “Run Batted Ins”, and “astros” is a baseball team name uuuuuustani bandeira famille seon bucharest jays kne concei vrier hyeon lcescu strikeouts vukovi
nio autour seung ional halladay kovi jardim naissance seong ntul hitters vuk velho rique hwang napoca buehrle kova visconde diteur choi editura batters popovi pessoa octobre sik iancu pitching inovi domingos chambre kyung romanian phillies uro pinheiro lettre kwang mihai rbis mileti branco campagne jeong institutul astros novakovi ncio jeune yeong tilor diamondbacks anovi trindade jours taek traian homers ﬁlipovi carmo septembre gyeong ianu hitless petrovi cio enfance seok pentru orioles radi ssimo plon choe tefan podsednik evi penha affaire ryong muzeul baserunners knez paulo cembre hee gheorghe hitter martinovi cavalo royaume gwang bucuresti sox vuka marinho propos cheol biserica pettitte veljko neves juin myeong craiova vizquel
Slavic
Brazillian
French
Korean Names
Romanian
Baseball
[Table]
located vueling garabed itch near tuiﬂy hagopian negros connecting eurowings activist sulu situated tunisair
[Table]
from Houston.
Meanwhile, the words grouped in u 1 , the largest eigenvector, could explain the biaswe mentioned in Section 5.1.
The signiﬁcant participants tend to be strong transition words that areused often for dramatic effects, such as “importantly" or “crucially".
Evidently, these words increasethe intensity of the context.
Moreover, while it was originally hypothesized that the largest principal eigenvectors would capturesome semantic relationship, the 121th vector u 121 show surprisingly focused and narrow semanticgrouping related to baseball.
Further investigation reveals that u 121 has one of the highest IPR values,hence being one of the most sparse vectors.
We verify similar trends in other eigenvectors with high
IPR values as shown in Table 2.
An interesting pattern arises here, in which the sparser eigenvectorstend to capture more distinct and rare features such as foreign names or languages, or topics likebaseball.
Furthermore, we compare the column space analysis on W SVD and W SGNS .
Consider the word vectorw airport for the word “airport.”
We choose the salient dimensions, which are the largest elements,of w airport , and investigate the signiﬁcant elements of those chosen dimensions (columns).
Table3 shows that the columns from W SVD display semantic coherence while those from W SGNS seemrandom.
u 53 groups words that are related to the location of the airports.
For example, one could
[Figure]
where the rows are embedding dimensions.
It is clear that W SVD shows similar representations.
say “Trindade station connects with the airport.”
Similarly, u 337 groups famous airline companiestogether, while “ﬁumicino” is a famous airport in Italy.
6.2 Word Embedding Dimensions as Interpretable Features
Sections 5.1 and 5.2 revealed that the eigenvectors contain genuine correlation and structure in thecolumn space.
We further show in Section 6.1 that semantically coherent words form groups ofsigniﬁcant participants in each eigenvector.
Now we can answer the questions we asked earlier.
What is the meaning of high and low values in the columns of W?
If word vector w from W SVDhas a high absolute value in column k , it means that the word is relevant to the semantic group formedin u k .
For example, the words from Figure 3a have highest values in column k
= 121, in which u 121represents a semantic group related to baseball, as shown in Table 1.
How can we interpret the dimensions of word vectors ?
The answer to this question follows naturally.
As the salient dimensions represent relevant semantic groups, we can view the dimensions of was semantic features.
This view is in line with the Topic Modeling literature, in which words anddocuments are clustered into distinct latent topics.
Hence, we can also see the word embeddingdimensions as latent topics that can be interpretable.
It can be easily seen from Figure 3b that similar words do not show any interpretable similarity intheir W SGNS representations, despite being nearest neighbors in the row space.
On the other hand, itis very clear from Figure 3a that similar words have similar representations, or feature vectors.
Wethus empirically verify that the dimensions of the row vectors can be viewed as semantic or syntacticfeatures.
Finally, the structural sparsity discovered with the IPR is further conﬁrmed by contrasting
Figures 3a and 3b.
It is clearly visible that the the vectors from SVD are much sparser than from
SGNS.
Effect of Eigenvalue Weighting:
As mentioned in Section 3, weighting with the eigenvaluesessentially scales each feature column by the corresponding eigenvalues.
Such process can be viewedas simply incorporating a prior, and does not hurt the interpretability.
However, as [18] showed thateigenvalue weighting decreases the performance of downstream NLP tasks, we can assume that either the prior is wrong, or too strong.
In fact, in many cases, the largest eigenvalues are often order ofmagnitude larger than others, which can explain why not weighting the word embeddings with theircorresponding eigenvalues would work better.
Conclusion
In this work we analyzed the eigenvectors or the column space, of the word embeddings obtainedfrom the Singular Value Decomposition of PPMI matrix.
We revealed that the signiﬁcant participantsof the eigenvectors form semantically coherent groups, allowing us to view each word vector asan interpretable feature vector composed of semantic groups.
These results can be very useful inerror analysis in downstream NLP tasks, or cherry-picking useful feature dimensions to easily createcompressed and efﬁcient task-speciﬁc embeddings.
Future work will proceed in this direction onapplying interpretability to practical usage