0% found this document useful (0 votes)
19 views3 pages

Training Word2Vec with Gensim Insights

The report details the training of a Word2Vec model using the Gensim library to learn semantic relationships from a small dataset of 10 documents. The model utilized the skip-gram approach, with specific hyperparameters set for embedding dimensions, context window size, and training epochs. Challenges included visualization clarity and text pre-processing, which were addressed through adjustments in plot size and improved tokenization methods.

Uploaded by

James Toney
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)
19 views3 pages

Training Word2Vec with Gensim Insights

The report details the training of a Word2Vec model using the Gensim library to learn semantic relationships from a small dataset of 10 documents. The model utilized the skip-gram approach, with specific hyperparameters set for embedding dimensions, context window size, and training epochs. Challenges included visualization clarity and text pre-processing, which were addressed through adjustments in plot size and improved tokenization methods.

Uploaded by

James Toney
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

Name: Hassan Masood

Course: Natural Language Processing


Instructor: Dr. Usman Zia

Assignment 2 Report
Training a Dense Embedding Model

IGIS, NATIONAL UNIVERSITY OF SCIENCES AND TECHNOLOGY,


ISLAMABAD
A. Approach to Model Selection, Training, and Evaluation:

The goal of this project is to train a Word2Vec model to learn semantic relationships of words
basedo n embeddings. For this, Word2Vec model was taken via Gensim library.
Model Selection: Word2Vec model was used with the skip-gram, as skip-gram performs better
when working with a smaller dataset, which was the case with our dataset present in 10 documents
in “extracted_data_text” folder. Skip-gram was chosen over the continuous bag of word because
it has the capability to predict context from the word, which typically produces more useful
embeddings in tasks such as semantic similarity.
Training: Before the training, the text files were pre-processed to clean the text as well as perform
tokenization of the text, remove stopwords, and apply lemmatization. After pre-processing, the
Word2Vec model was trained. The hyperparameters that were used were:
 Embedding dimension: 30. Depicts that each word was represented by 30 values.
 Context window size: 5. This window captures the surrounding words of the target word.
 Min count: 2, Used to exclude words that appear less than twice.
 Number of epochs: 10. Represents the number of iterations.
Evaluation: After training the Word2Vec model, we performed an evaluation using TSNE (t-
distributed Stochastic Neighbor Embedding, a technique used for reducing the dimensions of data)
for dimensionality reduction to visualize the embeddings in two-dimensional space. At the end,
visualization was done for the top 50 words in the vocabulary.

B. Challenges Encountered and How They Were Addressed:

Issues in visualization: One of the foremost challenges encountered was to maintain clarity in the
scatter plot after applying TSNE. Initially, the word vectors were appearing to be quite congested
in that space, which made the visualization quite difficult. This was countered by increasing the
plot size, making the visualization much better.
Issues in Text Pre-Processing: Another challenges encountered was in the pre-processing steps.
While removing stopwords, caerain words were missed. Also, tokenization was not being done
correctly in the case of languages other than English, for which punkt_tab was used, which ensures
additional data for tokenization in other languages.

C. Observations from Embeddings:


Semantic Relationships: While the model successfully captured most of the semantic
relationships, (which was depicted by clustering contextually related words), the quality of some
of the relationships was not as strong or consistent as expected. Words that should be semantically
similar were often spaced farther apart in the embedding space, and clusters sometimes lacked
clear cohesion.

Common questions

Powered by AI

TSNE assists in analyzing the outcomes of word embeddings by reducing the high-dimensional data (word vectors) into a 2D space for visualization. This helps in visually assessing the proximity and clustering of words, thus indicating how well the semantic relationships are captured by the model .

The pre-processing techniques included cleaning the text, tokenization, removing stopwords, and applying lemmatization. Challenges encountered involved missing certain words during stopword removal and incorrect tokenization for languages other than English. Punkt_tab was used to ensure additional data for tokenization in non-English languages .

Hassan Masood observed that while the model captured most semantic relationships, the quality was inconsistent at times, with supposed semantically similar words spaced farther apart and clusters lacking cohesion. These discrepancies could arise from limitations in the training data, choice of hyperparameters, or inherent complexities in the language data that the model couldn't sufficiently capture .

The skip-gram model is significant in the context of semantic similarity because it predicts the context from a word, enhancing the creation of useful embeddings for semantic tasks. It is especially effective when dealing with smaller datasets, as it tends to maintain contextual relationships more effectively than the continuous bag of words approach .

Hassan Masood identified the challenge of maintaining clarity in the scatter plot after applying TSNE, as word vectors were appearing congested, compromising the visualization. To address this, the plot size was increased, which improved the clarity of the visualization .

Hassan Masood used the Word2Vec model with the skip-gram approach. This approach was chosen over the continuous bag of words because skip-gram is better at predicting context from words, which is particularly useful for smaller datasets. It tends to produce more useful embeddings for tasks involving semantic similarity .

In Hassan Masood’s project, the choice of hyperparameters such as embedding dimension, context window size, min count, and number of epochs play crucial roles in training the Word2Vec model. The embedding dimension (30) determines the size of the word vectors. The context window size (5) sets the surrounding words considered for predicting context. A min count of 2 filters out infrequent words, and the number of epochs (10) dictates how many times the model iterates over the dataset. These configurations help in managing computational efficiency and model specificity .

In Hassan Masood's NLP project, the skip-gram model is particularly suited for smaller datasets, such as the set used in his project which consisted of 10 documents. This is because the skip-gram approach is efficient at predicting context from words even with limited data, producing useful semantic embeddings .

The evaluation of the trained Word2Vec model was performed using TSNE (t-distributed Stochastic Neighbor Embedding) for dimensionality reduction. This was employed to visualize the embeddings in two-dimensional space, allowing for analysis of the proximity and clustering of words in the vocabulary .

To handle incorrectly tokenized non-English texts during the pre-processing stage, Hassan Masood used punkt_tab, which provides additional data for accurate tokenization across different languages .

You might also like