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

get_dimension_stereotypes on removed community fixed #82

Merged
merged 1 commit into from
May 15, 2024
Merged
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
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
Loading