Tag: machine learning

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

{ Add a Comment }

Emotion from the text (sadness , joy , fear , anger ) python Example

under editing

download the sample date:

Date and time: Sat Feb 22 04:14:23 +0000 2020

text: RT What a coincidence that Russia always happens to support whoever the Democrat party elites are trying to destroy at any given…

sadness: 0.15790210664272308

joy :0.20329616963863373

fear: 0.47116225957870483

anger: 0.2204379141330719

from nltk.tokenize import word_tokenize
import pandas as pd  
import matplotlib.pyplot as plt

I used Trump tweets :


{ Add a Comment }