graphvite.graph

Graph module of GraphVite

class graphvite.graph.Graph(index_type=dtype.uint32)

Normal graphs without attributes.

Parameters

index_type (dtype) – type of node indexes

Instantiations:
  • index_type: dtype.uint32

load(*args, **kwargs)

Load a graph from an edge-list file. Store the graph in an adjacency list.

This function has 2 overloads

load(file_name, as_undirected=True, normalization=False, delimiters=' \t\r\n', comment='#')
load(edge_list, as_undirected=True, normalization=False)
Parameters
  • file_name (str) – file name

  • edge_list (list of (str, str, float)) – edge list

  • as_undirected (bool, optional) – symmetrize the graph or not

  • normalization (bool, optional) – normalize the adjacency matrix or not

  • delimiters (str, optional) – string of delimiter characters

  • comment (str, optional) – prefix of comment strings

save(file_name, weighted=True, anonymous=False)

Save the graph in edge-list format.

Parameters
  • file_name (str) – file name

  • weighted (bool, optional) – save edge weights or not

  • anonymous (bool, optional) – save node names or not

property id2name

Map of node index to name.

property name2id

Map of node name to index.

class graphvite.graph.WordGraph(index_type=dtype.uint32)

Normal graphs of word co-occurrences.

Parameters

index_type (dtype) – type of node indexes

Instantiations:
  • index_type: dtype.uint32

load(file_name, window=5, min_count=5, normalization=False, delimiters=' \t\r\n', comment='#')

Load a word graph from a corpus file. Store the graph in an adjacency list.

Parameters
  • file_name (str) – file name

  • window (int, optional) – word pairs with distance <= window are counted as edges

  • min_count (int, optional) – words with occurrence <= min_count are discarded

  • normalization (bool, optional) – normalize the adjacency matrix or not

  • delimiters (str, optional) – string of delimiter characters

  • comment (str, optional) – prefix of comment strings

class graphvite.graph.KnowledgeGraph(index_type=dtype.uint32)

Knowledge graphs.

Parameters

index_type (dtype) – type of node indexes

Instantiations:
  • index_type: dtype.uint32

load(*args, **kwargs)

Load a knowledge graph from a triplet-list file. Store the graph in an adjacency list.

This function has 2 overloads

load(file_name, normalization=False, delimiters=' \t\r\n', comment='#')
load(triplet_list, normalization=False)
Parameters
  • file_name (str) – file name

  • triplet_list (list of (str, str, str)) – triplet list

  • normalization (bool, optional) – normalize the adjacency matrix or not

  • delimiters (str, optional) – string of delimiter characters

  • comment (str, optional) – prefix of comment strings

save(file_name, anonymous=False)

Save the graph in triplet-list format.

Parameters
  • file_name (str) – file name

  • anonymous (bool, optional) – save entity / relation names or not

property entity2id

Map of entity name to index.

property id2entity

Map of entity index to name.

property id2relation

Map of relation index to name.

property relation2id

Map of relation name to index.

class graphvite.graph.KNNGraph(index_type=dtype.uint32, device_ids=[], num_thread_per_worker=auto)

K-nearest neighbor graphs.

Parameters
  • index_type (dtype, optional) – type of node indexes

  • device_ids (list of int, optional) – GPU ids, [] for auto

  • num_thread_per_worker (int, optional) – number of CPU thread per GPU

Instantiations:
  • index_type: dtype.uint32

load(*arg, **kwargs)

Build a KNN graph from a vector list. Store the graph in an adjacency list.

This function has 2 overloads

load(vector_file, num_neighbor=200, perplexity=30, vector_normalization=True, delimiters=' \t\r\n', comment='#')
load(vectors, num_neighbor=200, perplexity=30, vector_normalization=True)
Parameters
  • file_name (str) – file name

  • vectors (2D array_like) – vector list

  • num_neighbor (int, optional) – number of neighbors for each node

  • perplexity (int, optional) – perplexity for the neighborhood of each node

  • vector_normalization (bool, optional) – normalize the input vectors or not

  • delimiters (str, optional) – string of delimiter characters

  • comment (str, optional) – prefix of comment strings