Holy Quran Word Clouds by word2vec algorithm, python example

شارك هذه المقالة مع أصدقائك!

طريقة رسم الكلمات المتشابهه من القران الكريم على شكل word cloud باستخدام الفكتور مودلword2vec لحساب الكلمات المتشابهة، يمكنك تحميل المودل واتباع خطوات البرنامج للحصول على نفس النتائج.

Download the model:

from gensim.models import KeyedVectors
from bidi.algorithm import get_display
import arabic_reshaper
import numpy as np
import matplotlib.pyplot as plt
from wordcloud import WordCloud
from typing import List, Dict
# function to plot the word cloud 
def plot_word_cloud(word_list: List[str], word_frequency: Dict[str, float]):
    full_string = ' '.join(word_list)
    reshaped_text = arabic_reshaper.reshape(full_string)
    translated_text = get_display(reshaped_text)   
    # Build the Arabic word cloud
    wordc = WordCloud(font_path='tahoma',background_color='white', width=800, height=300).generate(translated_text)
    wordc.fit_words(word_frequency)
        
    # Draw the word cloud
    plt.imshow(wordc)
    plt.axis("off")
    plt.tight_layout(pad = 0)
    
    plt.show()
# load the model
model = KeyedVectors.load('model/quran_w7_m15.bin') 
print("Model loaded")

#check the model size
print ('Number of all words: ', len(model.wv.vocab))
# Enter the word you want to search
Word_to_plot = 'النهار' 

#result size 
retsize = 200
  
temp_tuple = model.most_similar(positive=[Word_to_plot], negative=[], topn = retsize)

similar_words=[i[0] for i in temp_tuple]
        
word_frequency = {}
for word_tuple in temp_tuple:
    reshaped_word = arabic_reshaper.reshape(word_tuple[0])
    key = get_display(reshaped_word)
    word_frequency[key] = word_tuple[1]     
    
 
plot_word_cloud(similar_words, word_frequency)

Result:

# Enter the word you want to search
Word_to_plot = 'كريم' 

#result size 
retsize = 200
# Enter the word you want to search
Word_to_plot = 'النار' 

#result size 
retsize = 200

‫0 تعليق

اترك تعليقاً