Skip to content

Commit

Permalink
get_dimension_stereotypes on removed community fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
aberanger committed Apr 24, 2024
1 parent 47e9c2b commit 9b0a68c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions sinr/graph_embeddings.py
Original file line number Diff line number Diff line change
Expand Up @@ -1235,15 +1235,18 @@ def get_obj_descriptors(self, obj, topk_dim=5, topk_val=-1):
def get_dimension_stereotypes(self, obj, topk=5):
"""Get the words with the highest values on dimension obj.
:param obj: id of a dimension, or label of a word (then turned into the id of its community)
:param obj: id of a word, or label of a word (then turned into the id of its community)
:type obj: int or str
:param topk: topk value to consider on the dimension (Default value = 5)
:type topk: int
:returns: the topk words that describe this dimension (highest values)
"""
index = self._get_index(obj)
return self.get_dimension_stereotypes_idx(self.get_community_membership(index), topk)
if self.community_membership[index] != -1:
return self.get_dimension_stereotypes_idx(self.get_community_membership(index), topk)
else:
raise DimensionFilteredException("'"+self.vocab[index] + "' (id "+str(index)+') is member of a community which got removed by filtering.')

def get_dimension_stereotypes_idx(self, idx, topk=5):
"""Get the indices of the words with the highest values on dimension obj.
Expand Down Expand Up @@ -1469,3 +1472,7 @@ def light_model_save(self):
f = open(self.name + "_light.pk", 'wb')
pk.dump(data,f)
f.close()

class DimensionFilteredException(Exception):
"""Exception raised when trying to access a dimension removed by filtering. """
pass

0 comments on commit 9b0a68c

Please sign in to comment.