"""

NOT SCALED 

Source code: https://github.com/kavgan/nlp-in-practice/tree/master/word2vec

Compile with Python 2.7

"""

#-------------------------------------------#
# Import dependencies                       #
#-------------------------------------------#

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import matplotlib.cm as cm
import time
import sys
import os
import re
import gensim
import logging
import warnings
import gensim.downloader as api
from multiprocessing import cpu_count

from gensim.models import Word2Vec
from gensim.models import KeyedVectors
from datetime import timedelta, datetime
from sklearn.cluster import MiniBatchKMeans, KMeans
from sklearn.datasets.samples_generator import make_blobs
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.decomposition import PCA
from sklearn.manifold import TSNE
from matplotlib import pyplot

#-------------------------------------------#
# Global variables                          #
#-------------------------------------------#

FILENAME = '../datasets/stop_cleaned_en_only_small_iranian.csv'
SCATTERPLOT_FIG = "../figures/word2vec{}.png"

#-------------------------------------------#
# Google pre-trained word2vec model         #
#-------------------------------------------#

# model = gensim.models.Word2Vec.load_word2vec_format('./model/GoogleNews-vectors-negative300.bin', binary=True) 

#-------------------------------------------#
# Regex tokeniser                           #
#-------------------------------------------#

regex_str = [
    r'<[^>]+>',                                                                             # HTML tags
    r'(?:@[\w_]+)',                                                                         # @-mentions
    r"(?:\#+[\w_]+[\w\'_\-]*[\w_]+)",                                                       # hash-tags
    r'http[s]?://(?:[a-z]|[0-9]|[$-_@.&amp;+]|[!*\(\),]|(?:%[0-9a-f][0-9a-f]))+',           # URLs
    r'(?:(?:\d+,?)+(?:\.?\d+)?)',                                                           # numbers
    r"(?:[a-z][a-z'\-_]+[a-z])",                                                            # words with - and '
    r'(?:[\w_]+)',                                                                          # other words
    r'(?:\S)'                                                                               # anything else
]

tokens_re = re.compile(r'('+'|'.join(regex_str)+')', re.VERBOSE | re.IGNORECASE)

#-------------------------------------------#
# Columns of CSV file                       #
#-------------------------------------------#

COLS = [
    'tweetid',
    'userid',
    'user_display_name',
    'user_screen_name',
    'user_reported_location',
    'user_profile_description',
    'user_profile_url',
    'follower_count',
    'following_count',
    'account_creation_date',
    'account_language',
    'tweet_language',
    'tweet_text',
    'tweet_time',
    'tweet_client_name',
    'in_reply_to_tweetid',
    'in_reply_to_userid',
    'quoted_tweet_tweetid',
    'is_retweet',
    'retweet_userid',
    'retweet_tweetid',
    'latitude',
    'longitude',
    'quote_count',
    'reply_count',
    'like_count',
    'retweet_count',
    'hashtags',
    'urls',
    'user_mentions',
    'poll_choices'
    ]

#-------------------------------------------#
# D-types                                   #
#-------------------------------------------#

thirtyone_d_types = {                                                                       # Version 1.0 datasets, i.e. 'ira' and 'iranian', have a tweet_language column and so have 31
    'tweetid':                  'str',                                                      # IDs are numeric in the unhashed datasets and alphanumeric in the hashed datasets
    'userid':                   'str',                                                      # IDs are numeric in the unhashed datasets and alphanumeric in the hashed datasets
    'user_display_name':        'str',
    'user_screen_name':         'str',
    'user_reported_location':   'str',
    'user_profile_description': 'str',
    'user_profile_url':         'str',
    'follower_count':           'str',
    'following_count':          'str',
    'account_creation_date':    'str',
    'account_language':         'str',
    'tweet_language':           'str',
    'tweet_text':               'str',
    'tweet_time':               'str',
    'tweet_client_name':        'str',
    'in_reply_to_tweetid':      'str',
    'in_reply_to_userid':       'str',
    'quoted_tweet_tweetid':     'str',
    'is_retweet':               'bool',
    'retweet_userid':           'str',
    'retweet_tweetid':          'str',
    'latitude':                 'str',                                                      # parse as string, for general purpose, and then check later if it is numeric
    'longitude':                'str',                                                      # parse as string, for general purpose, and then check later if it is numeric
    'quote_count':              'str',
    'reply_count':              'str',
    'like_count':               'str',
    'retweet_count':            'str',
    'hashtags':                 'str',
    'urls':                     'str',
    'user_mentions':            'str',
    'poll_choices':             'str'
}

thirty_d_types = {                                                                          # Version 1.1 datasets do not have a tweet_language column and so have only 30 columns
    'tweetid':                  'str',                                                      # IDs are numeric in the unhashed datasets and alphanumeric in the hashed datasets
    'userid':                   'str',                                                      # IDs are numeric in the unhashed datasets and alphanumeric in the hashed datasets
    'user_display_name':        'str',
    'user_screen_name':         'str',
    'user_reported_location':   'str',
    'user_profile_description': 'str',
    'user_profile_url':         'str',
    'follower_count':           'str',
    'following_count':          'str',
    'account_creation_date':    'str',
    'account_language':         'str',
    'tweet_text':               'str',
    'tweet_time':               'str',
    'tweet_client_name':        'str',
    'in_reply_to_tweetid':      'str',
    'in_reply_to_userid':       'str',
    'quoted_tweet_tweetid':     'str',
    'is_retweet':               'bool',
    'retweet_userid':           'str',
    'retweet_tweetid':          'str',
    'latitude':                 'str',                                                      # parse as string, for general purpose, and then check later if it is numeric
    'longitude':                'str',                                                      # parse as string, for general purpose, and then check later if it is numeric
    'quote_count':              'str',
    'reply_count':              'str',
    'like_count':               'str',
    'retweet_count':            'str',
    'hashtags':                 'str',
    'urls':                     'str',
    'user_mentions':            'str',
    'poll_choices':             'str'
}

dates_to_parse = [                                                                          # column(s) that needs to be converted to datetime dtype
    'account_creation_date',
    'tweet_time'
    ]

#-------------------------------------------#
# Functions                                 #
#-------------------------------------------#

def read_in_cleaned_data(dataset):


    tweets_df = pd.read_csv(dataset, 
                            header=0, 
                            dtype=thirtyone_d_types, 
                            parse_dates=dates_to_parse,                                     # parse tweet_time as datetime dtype
                            keep_default_na=False)                                          # do not parse rows with default NaN values
    # tweets_df[tweets_df.isnull().any(axis=1)]                                               # check for null values in any rows (in this case, no empty tweets should be kept)
    # tweets_df.drop(tweets_df[tweets_df.isnull().any(axis=1)].index,inplace=True)            # drop rows with null values
    num_tweets = len(tweets_df)

    print("Reading in",num_tweets,"tweets at: ",str(datetime.now()))
    
    print("Finished reading in",num_tweets,"tweets at: ",str(datetime.now()))
    # print(tweets_df.dtypes)
    return tweets_df

def return_text(df):
    tokenised_tweets = []
    num_tweets = len(df)
    # print(df.head())
    for i in range(num_tweets):
        tweet = (df['tweet_text'].iloc[i]).lower()
        tweet = re.findall(tokens_re, tweet)
        tokenised_tweets.append(tweet)
    # print(tokenised_tweets)
    return tokenised_tweets

def find_optimal_clusters(data, max_k):
    iters = range(2, max_k+1, 2)
    
    sse = []
    for k in iters:
        sse.append(MiniBatchKMeans(n_clusters=k, init_size=1024, batch_size=2048, random_state=20).fit(data).inertia_)
        print('Fit {} clusters'.format(k))
        
    f, ax = plt.subplots(1, 1)
    ax.plot(iters, sse, marker='o')
    ax.set_xlabel('Cluster Centers')
    ax.set_xticks(iters)
    ax.set_xticklabels(iters)
    ax.set_ylabel('SSE')
    ax.set_title('SSE by Cluster Center Plot')
    f.savefig('SSE.png')

    
def get_top_keywords(data, clusters, labels, n_terms):
    df = pd.DataFrame(data.todense()).groupby(clusters).mean()
    
    for i,r in df.iterrows():
        print('\nCluster {}'.format(i+1))
        print(','.join([labels[t] for t in np.argsort(r)[-n_terms:]]))


#-------------------------------------------#
# Main                                      #
#-------------------------------------------#

def main(): 
    tokenised_tweets = return_text(read_in_cleaned_data(FILENAME))

    # train model
    model = Word2Vec(  
                       size=100,
                       window=5, 
                       min_count=5,
                       workers=cpu_count(),
                       sg=1                                                                 # CBOW (0) or skip gram (1)
                       )
    model.build_vocab(tokenised_tweets)
    total_examples = model.corpus_count
    my_dict = dict({})
    for idx, key in enumerate(model.wv.vocab):
        my_dict[key] = model.wv[key]
        print(my_dict[key])
        print(key)

    # print(total_examples)
    # print(model['trump'])
    for word in words:
        wv = KeyedVectors(model, mmap='r')
        vector = model.wv[word]
        print(vector)
    w = ["china"]
    print(model.most_similar(positive=w, topn=6))

    # model.save('newmodel')
    # model = Word2Vec.load('newmodel')

    # Update the model with new data.
    model.build_vocab(data_part2, update=True)
    model.train(data_part2, total_examples=model.corpus_count, epochs=model.iter)
    print(model.most_similar('america'))


    logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO)

    # Load the models
    word2vec_model300 = KeyedVectors.load_word2vec_format('../models/GoogleNews-vectors-negative300.bin', binary=True, limit=50000)

    # Get word embeddings
    # print(word2vec_model300.most_similar('trump'))

    

# train model
    my_model = Word2Vec(  
                       size=150,
                       window=5, 
                       min_count=1,
                       workers=3,
                       sg=1                                                                 # CBOW (0) or skip gram (1)
                       )
    my_model.build_vocab(tokenised_tweets)
    total_examples = my_model.corpus_count
    my_model.build_vocab([list(word2vec_model300.vocab.keys())], update=True)
    my_model.train(tokenised_tweets, total_examples=total_examples, epochs=my_model.iter)

    # fit a 2d PCA model to the vectors
    X = my_model[word2vec_model300.wv.vocab]
    pca = PCA(n_components=2)
    result = pca.fit_transform(X)
    # create a scatter plot of the projection
    pyplot.scatter(
                   result[:, 0], 
                   result[:, 1], 
                   marker='.',
                   alpha=0.5,
                   )
    # words = list(word2vec_model300.wv.vocab)
    # for i, word in enumerate(words):
    #     pyplot.annotate(word, xy=(result[i, 0], result[i, 1]))
    counter = 0
    SCATTERPLOT_FIG = "../figures/word2vec{}.png"
    while os.path.isfile(SCATTERPLOT_FIG.format(counter)):
        counter += 1
    SCATTERPLOT_FIG = SCATTERPLOT_FIG.format(counter)
    pyplot.savefig(SCATTERPLOT_FIG)


#-------------------------------------------#
# Call Main()                               #
#-------------------------------------------#

if __name__ == "__main__":
    with warnings.catch_warnings():
        warnings.simplefilter("error")
        #warnings.simplefilter("ignore")
    main()
"""

NOT SCALED 

Source code: https://github.com/kavgan/nlp-in-practice/tree/master/word2vec

Compile with Python 2.7

"""

#-------------------------------------------#
# Import dependencies                       #
#-------------------------------------------#

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import matplotlib.cm as cm
import time
import sys
import os
import re
import gensim
import logging
import warnings
import gensim.downloader as api
from multiprocessing import cpu_count

from gensim.models import Word2Vec
from gensim.models import KeyedVectors
from datetime import timedelta, datetime
from sklearn.cluster import MiniBatchKMeans, KMeans
from sklearn.datasets.samples_generator import make_blobs
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.decomposition import PCA
from sklearn.manifold import TSNE
from matplotlib import pyplot

#-------------------------------------------#
# Global variables                          #
#-------------------------------------------#

FILENAME = '../datasets/stop_cleaned_en_only_small_iranian.csv'
SCATTERPLOT_FIG = "../figures/word2vec{}.png"

#-------------------------------------------#
# Google pre-trained word2vec model         #
#-------------------------------------------#

# model = gensim.models.Word2Vec.load_word2vec_format('./model/GoogleNews-vectors-negative300.bin', binary=True) 

#-------------------------------------------#
# Regex tokeniser                           #
#-------------------------------------------#

regex_str = [
    r'<[^>]+>',                                                                             # HTML tags
    r'(?:@[\w_]+)',                                                                         # @-mentions
    r"(?:\#+[\w_]+[\w\'_\-]*[\w_]+)",                                                       # hash-tags
    r'http[s]?://(?:[a-z]|[0-9]|[$-_@.&amp;+]|[!*\(\),]|(?:%[0-9a-f][0-9a-f]))+',           # URLs
    r'(?:(?:\d+,?)+(?:\.?\d+)?)',                                                           # numbers
    r"(?:[a-z][a-z'\-_]+[a-z])",                                                            # words with - and '
    r'(?:[\w_]+)',                                                                          # other words
    r'(?:\S)'                                                                               # anything else
]

tokens_re = re.compile(r'('+'|'.join(regex_str)+')', re.VERBOSE | re.IGNORECASE)

#-------------------------------------------#
# Columns of CSV file                       #
#-------------------------------------------#

COLS = [
    'tweetid',
    'userid',
    'user_display_name',
    'user_screen_name',
    'user_reported_location',
    'user_profile_description',
    'user_profile_url',
    'follower_count',
    'following_count',
    'account_creation_date',
    'account_language',
    'tweet_language',
    'tweet_text',
    'tweet_time',
    'tweet_client_name',
    'in_reply_to_tweetid',
    'in_reply_to_userid',
    'quoted_tweet_tweetid',
    'is_retweet',
    'retweet_userid',
    'retweet_tweetid',
    'latitude',
    'longitude',
    'quote_count',
    'reply_count',
    'like_count',
    'retweet_count',
    'hashtags',
    'urls',
    'user_mentions',
    'poll_choices'
    ]

#-------------------------------------------#
# D-types                                   #
#-------------------------------------------#

thirtyone_d_types = {                                                                       # Version 1.0 datasets, i.e. 'ira' and 'iranian', have a tweet_language column and so have 31
    'tweetid':                  'str',                                                      # IDs are numeric in the unhashed datasets and alphanumeric in the hashed datasets
    'userid':                   'str',                                                      # IDs are numeric in the unhashed datasets and alphanumeric in the hashed datasets
    'user_display_name':        'str',
    'user_screen_name':         'str',
    'user_reported_location':   'str',
    'user_profile_description': 'str',
    'user_profile_url':         'str',
    'follower_count':           'str',
    'following_count':          'str',
    'account_creation_date':    'str',
    'account_language':         'str',
    'tweet_language':           'str',
    'tweet_text':               'str',
    'tweet_time':               'str',
    'tweet_client_name':        'str',
    'in_reply_to_tweetid':      'str',
    'in_reply_to_userid':       'str',
    'quoted_tweet_tweetid':     'str',
    'is_retweet':               'bool',
    'retweet_userid':           'str',
    'retweet_tweetid':          'str',
    'latitude':                 'str',                                                      # parse as string, for general purpose, and then check later if it is numeric
    'longitude':                'str',                                                      # parse as string, for general purpose, and then check later if it is numeric
    'quote_count':              'str',
    'reply_count':              'str',
    'like_count':               'str',
    'retweet_count':            'str',
    'hashtags':                 'str',
    'urls':                     'str',
    'user_mentions':            'str',
    'poll_choices':             'str'
}

thirty_d_types = {                                                                          # Version 1.1 datasets do not have a tweet_language column and so have only 30 columns
    'tweetid':                  'str',                                                      # IDs are numeric in the unhashed datasets and alphanumeric in the hashed datasets
    'userid':                   'str',                                                      # IDs are numeric in the unhashed datasets and alphanumeric in the hashed datasets
    'user_display_name':        'str',
    'user_screen_name':         'str',
    'user_reported_location':   'str',
    'user_profile_description': 'str',
    'user_profile_url':         'str',
    'follower_count':           'str',
    'following_count':          'str',
    'account_creation_date':    'str',
    'account_language':         'str',
    'tweet_text':               'str',
    'tweet_time':               'str',
    'tweet_client_name':        'str',
    'in_reply_to_tweetid':      'str',
    'in_reply_to_userid':       'str',
    'quoted_tweet_tweetid':     'str',
    'is_retweet':               'bool',
    'retweet_userid':           'str',
    'retweet_tweetid':          'str',
    'latitude':                 'str',                                                      # parse as string, for general purpose, and then check later if it is numeric
    'longitude':                'str',                                                      # parse as string, for general purpose, and then check later if it is numeric
    'quote_count':              'str',
    'reply_count':              'str',
    'like_count':               'str',
    'retweet_count':            'str',
    'hashtags':                 'str',
    'urls':                     'str',
    'user_mentions':            'str',
    'poll_choices':             'str'
}

dates_to_parse = [                                                                          # column(s) that needs to be converted to datetime dtype
    'account_creation_date',
    'tweet_time'
    ]

#-------------------------------------------#
# Functions                                 #
#-------------------------------------------#

def read_in_cleaned_data(dataset):


    tweets_df = pd.read_csv(dataset, 
                            header=0, 
                            dtype=thirtyone_d_types, 
                            parse_dates=dates_to_parse,                                     # parse tweet_time as datetime dtype
                            keep_default_na=False)                                          # do not parse rows with default NaN values
    # tweets_df[tweets_df.isnull().any(axis=1)]                                               # check for null values in any rows (in this case, no empty tweets should be kept)
    # tweets_df.drop(tweets_df[tweets_df.isnull().any(axis=1)].index,inplace=True)            # drop rows with null values
    num_tweets = len(tweets_df)

    print("Reading in",num_tweets,"tweets at: ",str(datetime.now()))
    
    print("Finished reading in",num_tweets,"tweets at: ",str(datetime.now()))
    # print(tweets_df.dtypes)
    return tweets_df

def return_text(df):
    tokenised_tweets = []
    num_tweets = len(df)
    # print(df.head())
    for i in range(num_tweets):
        tweet = (df['tweet_text'].iloc[i]).lower()
        tweet = re.findall(tokens_re, tweet)
        tokenised_tweets.append(tweet)
    # print(tokenised_tweets)
    return tokenised_tweets

def find_optimal_clusters(data, max_k):
    iters = range(2, max_k+1, 2)
    
    sse = []
    for k in iters:
        sse.append(MiniBatchKMeans(n_clusters=k, init_size=1024, batch_size=2048, random_state=20).fit(data).inertia_)
        print('Fit {} clusters'.format(k))
        
    f, ax = plt.subplots(1, 1)
    ax.plot(iters, sse, marker='o')
    ax.set_xlabel('Cluster Centers')
    ax.set_xticks(iters)
    ax.set_xticklabels(iters)
    ax.set_ylabel('SSE')
    ax.set_title('SSE by Cluster Center Plot')
    f.savefig('SSE.png')

    
def get_top_keywords(data, clusters, labels, n_terms):
    df = pd.DataFrame(data.todense()).groupby(clusters).mean()
    
    for i,r in df.iterrows():
        print('\nCluster {}'.format(i+1))
        print(','.join([labels[t] for t in np.argsort(r)[-n_terms:]]))


#-------------------------------------------#
# Main                                      #
#-------------------------------------------#

def main(): 
    tokenised_tweets = return_text(read_in_cleaned_data(FILENAME))

    # train model
    model = Word2Vec(  
                       size=100,
                       window=5, 
                       min_count=5,
                       workers=cpu_count(),
                       sg=1                                                                 # CBOW (0) or skip gram (1)
                       )
    model.build_vocab(tokenised_tweets)
    total_examples = model.corpus_count
    my_dict = dict({})
    for idx, key in enumerate(model.wv.vocab):
        my_dict[key] = model.wv[key]
        print(my_dict[key])
        print(key)

    # print(total_examples)
    # print(model['trump'])
    for word in words:
        wv = KeyedVectors(model, mmap='r')
        vector = model.wv[word]
        print(vector)
    w = ["china"]
    print(model.most_similar(positive=w, topn=6))

    # model.save('newmodel')
    # model = Word2Vec.load('newmodel')

    # Update the model with new data.
    model.build_vocab(data_part2, update=True)
    model.train(data_part2, total_examples=model.corpus_count, epochs=model.iter)
    print(model.most_similar('america'))


    logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO)

    # Load the models
    word2vec_model300 = KeyedVectors.load_word2vec_format('../models/GoogleNews-vectors-negative300.bin', binary=True, limit=50000)

    # Get word embeddings
    # print(word2vec_model300.most_similar('trump'))

    

# train model
    my_model = Word2Vec(  
                       size=150,
                       window=5, 
                       min_count=1,
                       workers=3,
                       sg=1                                                                 # CBOW (0) or skip gram (1)
                       )
    my_model.build_vocab(tokenised_tweets)
    total_examples = my_model.corpus_count
    my_model.build_vocab([list(word2vec_model300.vocab.keys())], update=True)
    my_model.train(tokenised_tweets, total_examples=total_examples, epochs=my_model.iter)

    # fit a 2d PCA model to the vectors
    X = my_model[word2vec_model300.wv.vocab]
    pca = PCA(n_components=2)
    result = pca.fit_transform(X)
    # create a scatter plot of the projection
    pyplot.scatter(
                   result[:, 0], 
                   result[:, 1], 
                   marker='.',
                   alpha=0.5,
                   )
    # words = list(word2vec_model300.wv.vocab)
    # for i, word in enumerate(words):
    #     pyplot.annotate(word, xy=(result[i, 0], result[i, 1]))
    counter = 0
    SCATTERPLOT_FIG = "../figures/word2vec{}.png"
    while os.path.isfile(SCATTERPLOT_FIG.format(counter)):
        counter += 1
    SCATTERPLOT_FIG = SCATTERPLOT_FIG.format(counter)
    pyplot.savefig(SCATTERPLOT_FIG)


#-------------------------------------------#
# Call Main()                               #
#-------------------------------------------#

if __name__ == "__main__":
    with warnings.catch_warnings():
        warnings.simplefilter("error")
        #warnings.simplefilter("ignore")
    main()
NOT SCALED   Source code: https://github.com/kavgan/nlp-in-practice/tree/master/word2vec  Compile with Python 2.7 #-------------------------------------------# # Import dependencies                       # #-------------------------------------------# #-------------------------------------------# # Global variables                          # #-------------------------------------------# #-------------------------------------------# # Google pre-trained word2vec model         # #-------------------------------------------# # model = gensim.models.Word2Vec.load_word2vec_format('./model/GoogleNews-vectors-negative300.bin', binary=True) #-------------------------------------------# # Regex tokeniser                           # #-------------------------------------------# # HTML tags # @-mentions #+[\w_]+[\w\'_\-]*[\w_]+)",                                                       # hash-tags # URLs # numbers # words with - and ' # other words # anything else #-------------------------------------------# # Columns of CSV file                       # #-------------------------------------------# #-------------------------------------------# # D-types                                   # #-------------------------------------------# # Version 1.0 datasets, i.e. 'ira' and 'iranian', have a tweet_language column and so have 31 # IDs are numeric in the unhashed datasets and alphanumeric in the hashed datasets # IDs are numeric in the unhashed datasets and alphanumeric in the hashed datasets # parse as string, for general purpose, and then check later if it is numeric # parse as string, for general purpose, and then check later if it is numeric # Version 1.1 datasets do not have a tweet_language column and so have only 30 columns # IDs are numeric in the unhashed datasets and alphanumeric in the hashed datasets # IDs are numeric in the unhashed datasets and alphanumeric in the hashed datasets # parse as string, for general purpose, and then check later if it is numeric # parse as string, for general purpose, and then check later if it is numeric # column(s) that needs to be converted to datetime dtype #-------------------------------------------# # Functions                                 # #-------------------------------------------# # parse tweet_time as datetime dtype # do not parse rows with default NaN values # tweets_df[tweets_df.isnull().any(axis=1)]                                               # check for null values in any rows (in this case, no empty tweets should be kept) # tweets_df.drop(tweets_df[tweets_df.isnull().any(axis=1)].index,inplace=True)            # drop rows with null values # print(tweets_df.dtypes) # print(df.head()) # print(tokenised_tweets) #-------------------------------------------# # Main                                      # #-------------------------------------------# # train model # CBOW (0) or skip gram (1) # print(total_examples) # print(model['trump']) # model.save('newmodel') # model = Word2Vec.load('newmodel') # Update the model with new data. # Load the models # Get word embeddings # print(word2vec_model300.most_similar('trump')) # train model # CBOW (0) or skip gram (1) # fit a 2d PCA model to the vectors # create a scatter plot of the projection # words = list(word2vec_model300.wv.vocab) # for i, word in enumerate(words): #     pyplot.annotate(word, xy=(result[i, 0], result[i, 1])) #-------------------------------------------# # Call Main()                               # #-------------------------------------------# #warnings.simplefilter("ignore")