Skip to content

Commit

Permalink
Renames hypernym pair to relations everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
jayantj committed Nov 13, 2017
1 parent 001ec76 commit 9446a05
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions gensim/models/poincare.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,16 @@ def _load_relations(self):
node_relations = defaultdict(set) # Mapping from node index to its related node indices

logger.info("Loading relations from train data..")
for hypernym_pair in self.train_data:
if len(hypernym_pair) != 2:
raise ValueError('Relation pair "%s" should have exactly two items' % str(hypernym_pair))
for item in hypernym_pair:
for relation in self.train_data:
if len(relation) != 2:
raise ValueError('Relation pair "%s" should have exactly two items' % repr(relation))
for item in relation:
if item in vocab:
vocab[item].count += 1
else:
vocab[item] = Vocab(count=1, index=len(index2word))
index2word.append(item)
node_1, node_2 = hypernym_pair
node_1, node_2 = relation
node_1_index, node_2_index = vocab[node_1].index, vocab[node_2].index
node_relations[node_1_index].add(node_2_index)
relation = (node_1_index, node_2_index)
Expand Down Expand Up @@ -602,7 +602,7 @@ def __init__(self, vectors_u, vectors_v, indices_u, indices_v):
Vectors of all nodes `u` in the batch.
Expected shape (batch_size, dim).
vectors_v : numpy.array
Vectors of all hypernym nodes `v` and negatively sampled nodes `v'`,
Vectors of all positively related nodes `v` and negatively sampled nodes `v'`,
for each node `u` in the batch.
Expected shape (1 + neg_size, dim, batch_size).
indices_u : list
Expand Down Expand Up @@ -758,19 +758,19 @@ def poincare_dist(vector_1, vector_2):


class PoincareRelations(object):
"""Class to stream hypernym relations for `PoincareModel` from a tsv-like file."""
"""Class to stream relations for `PoincareModel` from a tsv-like file."""

def __init__(self, file_path, encoding='utf8', delimiter='\t'):
"""Initialize instance from file containing one hypernym pair per line.
"""Initialize instance from file containing a pair of nodes (a relation) per line.
Parameters
----------
file_path : str
Path to file containing one hypernym pair per line, separated by `delimiter`.
Path to file containing a pair of nodes (a relation) per line, separated by `delimiter`.
encoding : str, optional
Character encoding of the input file.
delimiter : str, optional
Delimiter character for each hypernym pair.
Delimiter character for each relation.
"""

Expand All @@ -784,7 +784,7 @@ def __iter__(self):
Yields
-------
2-tuple (unicode, unicode)
Hypernym relation from input file.
Relation from input file.
"""
if sys.version_info[0] < 3:
Expand Down

0 comments on commit 9446a05

Please sign in to comment.