0% found this document useful (0 votes)
14 views5 pages

Word Vectorization Assignment Guide

The document provides instructions for an assignment on training word vectors using singular value decomposition and skip-gram models with negative sampling. It describes implementing the models in Python using PyTorch, training them on a provided news corpus, using the word vectors for a downstream classification task, and analyzing the results.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views5 pages

Word Vectorization Assignment Guide

The document provides instructions for an assignment on training word vectors using singular value decomposition and skip-gram models with negative sampling. It describes implementing the models in Python using PyTorch, training them on a provided news corpus, using the word vectors for a downstream classification task, and analyzing the results.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Assignment 3: Word Vectorization

Course: Introduction to Natural Language Processing

Deadline: 25 March | 23:59

General Instructions
1. The assignment must be implemented in Python.

2. The assignment must be done using PyTorch. Usage of other frame-


works will not be accepted.

3. Submitted assignment must be your original work. Please do not copy


any part from any source including your friends, seniors, and/or the
internet. If any such attempt is caught, then serious actions including
an F grade in the course is possible.

4. A single .zip file needs to be uploaded to the Moodle Course Portal.

5. Your grade will depend on the correctness of answers and output. In


addition, due consideration will be given to the clarity and details of
your answers and the legibility and structure of your code.

6. Please start early since no extension to the announced deadline would


be possible.

1 About
Many NLP systems employ modern distributional semantic algorithms, known
as word embedding algorithms, to generate meaningful numerical represen-
tations for words. These algorithms aim to create embeddings where words
with similar meanings are represented closely in a mathematical space. Word

1
embeddings fall into two main categories: frequency-based and prediction-
based. Frequency-based embeddings utilize various vectorization methods
such as Count Vector, TF-IDF Vector, and Cooccurrence Matrix with a fixed
context window. Prediction-based embeddings, exemplified by Word2vec,
utilize models like Continuous Bag of Words (CBOW) and Skip-Gram (SG).
However, the computational complexity of Word2vec’s training algorithm can
be high due to gradient calculations over the entire vocabulary. To tackle
this challenge, variants such as Hierarchical Softmax output, Negative Sam-
pling, and Subsampling of frequent words have been proposed. This task
involves implementing a frequency-based modeling approach like Singular
Value Decomposition (SVD) and comparing it with embeddings obtained
using a Word2vec variant like Skip Gram with Negative Sampling. The
analysis will focus on discerning differences in the quality of embeddings pro-
duced. While "word vectors" and "word embeddings" are used interchange-
ably, "embedding" specifically denotes encoding a word’s meaning into a
lower-dimensional space.

2 Training Word Vectors


2.1 Singular Value Decomposition
Implement a word embedding model and train word vectors by first building
a Co-occurrence Matrix followed by the application of SVD. [15 Marks]

2.2 Skip Gram


Implement the word2vec model and train word vectors using the Skip Gram
model with Negative Sampling. [15 Marks]

3 Corpus
Please train your model on the given csv files link here: Link to the cor-
pus(News Classification Dataset)
Note that you have to only use the Description column of the [Link]
for training your word vectors. You have to use the label/index column for
the downstream classification task.

2
4 Downstream Task
After successfully creating word vectors using the above two methods, eval-
uate your word vectors by using them for the downstream classification task
in the News Classification Dataset provided above. You are free to use any
kind of RNN for the downstream task, but use the same RNN and RNN
hyperparameters across vectorization methods for the downstream task. [10
+ 10 Marks]

5 Analysis
Compare and analyze which of the two word vectorizing methods performs
better by using performance metrics such as accuracy, F1 score, precision,
recall, and the confusion matrix on both the train and test sets. Write a
detailed report on why one technique might perform better than the other.
Also, include the possible shortcomings of both techniques (SVD and Word2Vec).
[10 Marks]

Hyperparameter tuning
Experiment with at least three different context window sizes. Explain why
you chose those context window sizes. Report performance metrics for all
three context window configurations. Mention which configuration performs
the best and write about the possible reasons for it. [20 Marks]

Submission Format
Zip the following files into one archive and submit it through the Moodle
course portal. The filename should be <roll number>_assignment3.zip,
for example, 2021114017_assignment3.zip.

• Source Code

– [Link]: Train the word embeddings using SVD method and save
the word vectors.

3
– [Link]: Train the word embeddings using Skip gram method
(with negative sampling) and save the word vectors.

– [Link]: Train any RNN on the classification


task using the SVD word vectors.

– [Link]: Train any RNN on the classifi-


cation task using the Skip-Gram word vectors.

• Pretrained Models

– [Link]: Saved word vectors for the entire vocab-


ulary trained using SVD.

– [Link]: Saved word vectors for the entire


vocabulary trained using Skip-gram (using negative sampling).

– [Link]: Saved model for the classifica-


tion task trained using SVD word embeddings.

– [Link]: Saved model for the clas-


sification task trained using Skip-gram word embeddings.

• Report (PDF)

– Hyperparameters used to train the model(s).


– Corresponding graphs and evaluation metrics
– Your analysis of the results.

• README

– Instructions on how to execute the file, load the pretrained model,


implementation assumptions etc.

Ensure that all necessary files are included in the zip archive. There
should be, at least, four files in total.

4
Grading
Evaluation will be individual and based on your viva, report, and code review.
During your evaluation, you will be expected to walk us through your code
and explain your results. You will be graded based on the correctness of your
code, accuracy of your results, and the quality of the code.

Implementation: 50 marks
Hyperparameter Tuning Report: 20 marks
Analysis: 10 marks
Viva during Evaluation: 20 marks

Resources
1. Efficient Estimation of Word Representations in Vector Space

2. Distributed Representations of Words and Phrases and their Composi-


tionality

3. Stanford lecture notes - SVD and word2vec

4. A simple, intuitive explanation of word2vec, with Negative Sampling


included

5. Skip Gram with Negative Sampling

6. word2vec Explained: Deriving Mikolov et al.’s Negative-Sampling Word-


Embedding Method 5. On word embeddings in general

7. You can also refer to other resources, including lecture slides!

Common questions

Powered by AI

Hyperparameter tuning can significantly affect the quality of word embeddings by modifying parameters such as context window size, learning rate, and negative sample number. These parameters influence how the model learns associations between words. Proper tuning ensures that the model adequately captures meaningful word relationships and accurately reflects semantic and syntactic nuances of the training data, thus impacting the downstream task performance. It can shift the balance from underfitting to overfitting, finding the sweet spot for optimal performance .

The performance of word vectorization techniques in downstream classification tasks can depend on how well the embeddings capture semantic and syntactic relationships within the data. Prediction-based methods like Skip-Gram with Negative Sampling might perform better due to their ability to learn context more effectively, which can enhance the understanding of word usage nuances. Furthermore, if the classification task depends heavily on capturing such nuances, prediction-based embeddings may offer superior performance over frequency-based methods like SVD, which might be limited by their reliance on word co-occurrence data alone .

SVD can be computationally expensive, especially with large vocabularies, as it involves factorizing potentially very large matrices. It is also sensitive to the choice of dimensions retained during decomposition, which affects the quality of the embeddings. Additionally, frequency-based methods like SVD may not capture semantic relationships between words as effectively as prediction-based methods. They are less flexible in capturing nuanced contextual usage of words compared to models like Word2Vec .

A detailed report should consider both quantitative metrics such as accuracy, F1 score, precision, recall, and confusion matrix results, as well as qualitative evaluations of semantic meaning captured by the embeddings. Additionally, it should discuss computational efficiency, scalability, and potential biases present in each method. The report should also include an evaluation of how each method handles various NLP tasks and discuss the strengths and limitations encountered, including scenarios where one method may be favored over the other due to task-specific considerations or data characteristics .

Frequency-based methods, such as those using Singular Value Decomposition (SVD), typically involve building and decomposing a large Co-occurrence Matrix, which can be computationally intensive due to matrix factorization. Prediction-based methods like Word2Vec's Skip-Gram model involve predicting the context words given a target word and usually require multiple passes over the data and gradient calculations, which can be complex especially for large vocabularies. However, enhancements like Negative Sampling and Hierarchical Softmax help reduce the computational load .

Negative Sampling enhances the efficiency of the Skip-Gram model by reducing the computational burden associated with updating all weight parameters for every context word prediction. Instead, it updates a limited number of 'negative' samples, or words not in the correct context, thereby decreasing the number of calculations needed for backpropagation. This focuses the learning process on distinguishing correct contexts more effectively and efficiently with significantly less computational overhead than the full softmax method .

The Co-occurrence Matrix method creates embeddings by counting how often words appear together within a specified window and then applying Singular Value Decomposition (SVD) to reduce dimensionality. Skip-Gram with Negative Sampling, on the other hand, is a prediction-based model that generates embeddings by training a model to predict context words from a target word, selectively updating negative samples to ensure efficiency. This approach tends to capture more semantic nuances due to its predictive nature .

The choice of context window size significantly affects the quality and nature of learned word embeddings. A smaller context window may capture more syntactic information whereas a larger window might capture more semantic relationships. The context window size affects both frequency-based methods (like SVD) and prediction-based methods (like Word2Vec) by influencing the number of context words considered around target words during training, impacting the embeddings' ability to generalize well across different tasks .

RNNs are employed in evaluating word vectors because they are adept at processing and learning from sequences. They help determine how well word embeddings encapsulate the semantic meaning of sequences by assessing how effectively they can be used for text classification tasks. By maintaining information across various sequence lengths, RNNs can evaluate the embeddings' ability to convey contextual relationships comprehensively, which contributes to understanding the practical utility of the embeddings in real-world applications .

Training word embeddings using SVD requires constructing a Co-occurrence Matrix from the dataset, which is then factorized into separate matrices whose product approximates the original matrix. This step can be computationally heavy due to matrix operations, especially for large datasets. Skip-Gram with Negative Sampling primarily focuses on optimizing predictions around target-context word pairs and requires less memory, although still demanding significant computational resources for gradient descent. The latter is more adaptable to online processing compared to SVD, which is more batch-oriented .

You might also like