import matplotlib.pyplot as plt
from bidi.algorithm import get_display
import arabic_reshaper
import numpy as np
# plot function
def plotnow(words):
word_vectors = np.vstack([model[w] for w in words])
word_vectors.shape
from sklearn.decomposition import PCA
twodim = PCA().fit_transform(word_vectors)[:,:2]
twodim.shape
fig, ax = plt.subplots(1, figsize=(10, 6))
fig.suptitle('Arabic Example Of Labelled Scatterpoints')
# Plot the scatter points
ax.scatter(twodim[:,0], twodim[:,1],
color="red", # Color of the dots
s=100, # Size of the dots
alpha=0.5, # Alpha of the dots
linewidths=1) # Size of edge around the dots
for word, (x_pos,y_pos) in zip(words, twodim):
xword = arabic_reshaper.reshape(word) # support arabic letters
artext = get_display(xword)
ax.annotate(artext, # The label for point
xy=(x_pos, y_pos), # Position of the corresponding point
xytext=(7, 0), # Offset text by 7 points to the right
textcoords='offset points', # tell it to use offset points
ha='left', # Horizontally aligned to the left
va='center') # Vertical alignment is centered
# Show the plot
plt.show()
from gensim.models import word2vec
sentences = [
'تفتح التجارب الأولية لفحص جديد لفيروس كورونا الطريق أمام إمكانية تشخيص الفيروس خلال ثوان بدلا من ساعات.',
'وأظهرت الأبحاث أن الفحص عن طريق التنفس، وهو أسلوب طور في مقاطعة ويلز، قد يكون قادرا عن التمييز بين فيروس كورونا وأي عدوى صدرية أخرى في الحال تقريبا.',
'وجاء نشر البحث في دورية ذا لانسيت بعد إجراء تجارب في ألمانيا واسكتلندا.',
'وقال المطورون (إيمسبيكس دياغنوستيكس) إن أجهزة الفحص قد تكون جاهزة للاستعمال خلال ستة شهور، إذا حصلوا على التمويل اللازم.'
]
for i, sentence in enumerate(sentences):
tokenized= []
for word in sentence.split(' '):
word = word.split('.')[0]
word = word.lower()
tokenized.append(word)
sentences[i] = tokenized
model = word2vec.Word2Vec(sentences, workers = 1, size = 200, min_count = 1, window = 2, sg = 0)
listofwords = model.wv.vocab.keys()
plotnow(listofwords)
To get similar words in Arabic classic , Arabic modern standard and Arabic dialects, you can use this link: