Skip to content

Commit

Permalink
Add Playground for michael
Browse files Browse the repository at this point in the history
  • Loading branch information
mkali-personal committed Aug 31, 2021
1 parent 9474fc5 commit b592e2c
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
33 changes: 33 additions & 0 deletions CodeName.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from gensim import models
import random
from operator import itemgetter
# %%

class CodeName:
def __init__(self):
self.model = models.KeyedVectors.load_word2vec_format(r'DataFiles/GoogleNews-vectors-negative300.bin',
binary=True)
self.n = len(self.model.index_to_key)
self.board_size = 25

self.board_words_indices = None
self.board = None

# self.pick_words()

def pick_words(self):
# Randomize words and create an attribute of board with word-vectors pairs
# self.board_words_indices = random.sample(range(int(self.n / 1000), int(self.n / 2)), self.board_size)
# words = self.model.index_to_key[self.board_words_indices]
words = ['cloak', 'kiss', 'flood', 'mail', 'skates', 'paper', 'frog', 'skyscrapper', 'moon', 'egypt', 'teacher',
'avalance', 'newton', 'violet', 'drill', 'fever', 'ninja', 'jupyter', 'ski', 'attic', 'beach', 'lock',
'earth', 'park', 'gymnast']

vectors = self.model.vectors[self.board_words_indices]

zipped = zip(words, vectors)
self.board = dict(zipped)

# %%

c = CodeName()
43 changes: 43 additions & 0 deletions playground.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

from gensim import models
from pyvis.network import Network
import networkx as nx

# %%

w = models.KeyedVectors.load_word2vec_format(
'DataFiles/GoogleNews-vectors-negative300.bin', binary=True)

# %%
a = w.most_similar(w.get_vector('king') + w.get_vector('woman') -w.get_vector('man'))
print(a)

# %%
board_words = ['king', 'queen', 'teenage', 'tomato', 'parrot', 'london', 'spiderman']
n = len(board_words)
board_vecs = w[board_words]


# %%
nx_graph = nx.Graph()
nx_graph.add_nodes_from(board_words)
for i in range(n):
for j in range(i+1, n):
nx_graph.add_edge(board_words[i], board_words[j], weight=100 * (1-w.similarity(board_words[i], board_words[j])))


# %%
# nx_graph = nx.cycle_graph(10)
# nx_graph.nodes[1]['title'] = 'Number 1'
# nx_graph.nodes[1]['group'] = 1
# nx_graph.nodes[3]['title'] = 'I belong to a different group!'
# nx_graph.nodes[3]['group'] = 10
# nx_graph.add_node(20, size=20, title='couple', group=2)
# nx_graph.add_node(21, size=15, title='couple', group=2)
#
# nx_graph.add_node(25, size=25, label='lonely', title='lonely node', group=3)
nt = Network('500px', '500px')
# populates the nodes and edges data structures
nt.from_nx(nx_graph)
nt.show_buttons(filter_=['physics'])
nt.show('nx.html')

0 comments on commit b592e2c

Please sign in to comment.