text_plain_output_1.png
from gensim.models import word2vec

from nltk import word_tokenize

from nltk.corpus import stopwords

from nltk.tokenize import word_tokenize

import pandas as pd  # For data handling

df = pd.read_csv('../input/google-war-news/war-news.csv', encoding='latin1')

df.isnull().sum()

df.dropna(subset=['Summary'], inplace=True)

T = df['Summary'].str.split(' \n\n---\n\n').str[0]
T = T.str.replace('-', ' ').str.replace('[^\\w\\s]', '').str.replace('\n', ' ').str.lower()
stop = stopwords.words('english')
T = T.apply(lambda x: ' '.join((x for x in x.split() if not x.isdigit())))
T = T.apply(lambda words: ' '.join((word.lower() for word in words.split() if word not in stop)))

T1 = T.values.tolist()

T1 = T.apply(word_tokenize)

num_features = 100
min_word_count = 20
num_workers = 4
context = 20
downsampling = 0.001
from gensim.models import word2vec
model = word2vec.Word2Vec(workers=num_workers, vector_size=num_features, min_count=min_word_count, window=context, sample=downsampling)
model.build_vocab(T1, progress_per=1000)
model.train(T1, total_examples=model.corpus_count, epochs=model.epochs)

labels = model.wv.index_to_key

model.wv['ukraine']

X = model.wv[model.wv.index_to_key]

X