Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

52 loading vectors such as w2v or spine ones #57

Merged
merged 5 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions sinr/graph_embeddings.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,37 @@ def __init__(self, name, n_jobs=-1, n_neighbors=20):
self.n_jobs = n_jobs
self.n_neighbors = n_neighbors
self.labels = False

@classmethod
def load_from_w2v(cls, w2v_path, name, n_jobs=-1, n_neighbors=20):
"""
Initializing a SINrVectors object using a file at the word2vec format
:param w2v_path: path of the file at word2vec format which contains vectors
:type w2v_path: str
:param name: name of the model, useful to save it
:type name: str
"""
file = open(w2v_path)
i = 0
vocabulary= []
vectors = []
for line in file:
line = line.strip()
line = line.split(" ")
word = line[0].strip()
vector = [[i,col, float(x)] for col, x in enumerate(line[1:]) if x != 0]
vectors.extend(vector)
vocabulary.append(word)
i+=1
file.close()

model = cls(name, n_jobs=n_jobs, n_neighbors=n_neighbors)
model.set_vocabulary(vocabulary)
rows, cols, vals = zip(*vectors)
matrix = csr_matrix((vals, (rows, cols)))
model.set_vectors(matrix)

return model

def get_communities_as_labels_sets(self):
"""Get partition of communities as a list of sets each containing the label associates to the node in the community.
Expand Down
3 changes: 1 addition & 2 deletions sinr/text/exceptions_for_categorization.txt
Original file line number Diff line number Diff line change
Expand Up @@ -726,5 +726,4 @@ run
fly
drive
walk
ride

ride
3 changes: 1 addition & 2 deletions sinr/text/exceptions_for_evaluation.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3011,5 +3011,4 @@ run
fly
drive
walk
ride

ride