Views
No views yet
1from gensim.models import Word2Vec
2
3# URL of the model file on Hugging Face
4model_url = "https://huggingface.co/Hailay/Geez_word2vec_skipgram.model/resolve/main/Geez_word2vec_skipgram.model"
5
6# Load the trained Word2Vec model directly from the URL
7model = Word2Vec.load(model_url)
8
9# Get a vector for a word
10word_vector = model.wv['ሰብ']
11print(f"Vector for 'ሰብ': {word_vector}")
12
13# Find the most similar words
14similar_words = model.wv.most_similar('ሰብ')
15print(f"Words similar to 'ሰብ': {similar_words}")
16
17#Visualizing Word Vectors
18You can visualize the word vectors using t-SNE:
19import matplotlib.pyplot as plt
20from sklearn.manifold import TSNE
21import numpy as np
22
23# Words to visualize but you can change the words from the trained vocublary
24words = ['ሰብ', 'ዓለም', 'ሰላም', 'ሓይሊ','ጊዜ', 'ባህሪ']
25
26# Get the vectors for the words
27word_vectors = np.array([model.wv[word] for word in words])
28
29# Reduce dimensionality using t-SNE with a lower perplexity value
30perplexity_value = min(5, len(words) - 1)
31tsne = TSNE(n_components=2, perplexity=perplexity_value, random_state=0)
32word_vectors_2d = tsne.fit_transform(word_vectors)
33
34# Create a scatter plot
35plt.figure(figsize=(10, 6))
36plt.scatter(word_vectors_2d[:, 0], word_vectors_2d[:, 1], edgecolors='k', c='r')
37
38# Add annotations to the points
39for i, word in enumerate(words):
40 plt.annotate(word, xy=(word_vectors_2d[i, 0], word_vectors_2d[i, 1]), xytext=(5, 2),
41 textcoords='offset points', ha='right', va='bottom')
42
43plt.title('2D Visualization of Word2Vec Embeddings')
44plt.xlabel('TSNE Component 1')
45plt.ylabel('TSNE Component 2')
46plt.grid(True)
47plt.show()
48
49
50##Dataset Source
51
52The dataset for training this model contains text data in the Geez script of the Tigrinya language.
53It is a publicly available dataset as part of an NLP resource for low-resource languages for research and development.
54
55For more information about the TIGQA dataset, visit this link. https://zenodo.org/records/11423987 and from HornMT
56
57License
58This Word2Vec model and its associated files are released under the MIT License.