Knowledge Graph Embedding Endpoints

class graphdatascience.procedure_surface.api.kge.kge_endpoints.KgeEndpoints

Endpoints for knowledge-graph-embedding relationship prediction.

distmult(G: Graph, node_embedding_property: str, relationship_type_embeddings: dict[str, list[float]]) → SimpleRelEmbeddingModel

Create a DistMult relationship-embedding model over the given graph.

Parameters:
  • G (Graph) – Graph object to use.

  • node_embedding_property (str) – The name of the node property storing the embeddings in the graph.

  • relationship_type_embeddings (dict[str, list[float]]) – A map from relationship type to its embedding vector.

Returns:

A model using the DistMult scoring function.

Return type:

SimpleRelEmbeddingModel

property predict: KgePredictEndpoints

Flat prediction endpoints, taking the scoring function as an explicit parameter.

transe(G: Graph, node_embedding_property: str, relationship_type_embeddings: dict[str, list[float]]) → SimpleRelEmbeddingModel

Create a TransE relationship-embedding model over the given graph.

Parameters:
  • G (Graph) – Graph object to use.

  • node_embedding_property (str) – The name of the node property storing the embeddings in the graph.

  • relationship_type_embeddings (dict[str, list[float]]) – A map from relationship type to its embedding vector.

Returns:

A model using the TransE scoring function.

Return type:

SimpleRelEmbeddingModel

class graphdatascience.procedure_surface.api.kge.simple_rel_embedding_model.SimpleRelEmbeddingModel

A client-side model for computing and ranking pairwise scores between nodes according to a knowledge-graph-embedding scoring function (e.g. TransE or DistMult).

It can also produce new relationships based on these rankings. Instances are not stored in the model catalog; construct them via gds.kge.transe(...) or gds.kge.distmult(...).

graph() → Graph

Return the graph the model is based on.

Return type:

Graph

node_embedding_property() → str

Return the name of the node property storing embeddings in the graph.

Return type:

str

predict_mutate(source_node_filter: int | list[int] | str, target_node_filter: int | list[int] | str, relationship_type: str, top_k: int, mutate_relationship_type: str, mutate_property: str, *, relationship_types: list[str] = ['*'], concurrency: int | None = None, job_id: str | None = None, log_progress: bool = True) → KgeMutateResult

Compute relationships and add them to the in-memory graph under a new relationship type.

Parameters:
  • source_node_filter (int | list[int] | str) – The specification of source nodes to consider.

  • target_node_filter (int | list[int] | str) – The specification of target nodes to consider.

  • relationship_type (str) – The relationship type whose embedding will be used in the computation.

  • top_k (int) – How many relationships to add for each source node.

  • mutate_relationship_type (str) – The relationship type for the predicted relationships.

  • mutate_property (str) – The property on the new relationships storing the prediction score.

  • relationship_types (list[str]) – Filter the graph using the given relationship types.

  • concurrency (int | None) – Number of concurrent threads to use.

  • job_id (str | None) – Identifier for the computation.

  • log_progress (bool) – Display progress logging.

Returns:

Metadata about the performed computation and mutation.

Return type:

KgeMutateResult

predict_stream(source_node_filter: int | list[int] | str, target_node_filter: int | list[int] | str, relationship_type: str, top_k: int, *, relationship_types: list[str] = ['*'], concurrency: int | None = None, job_id: str | None = None, log_progress: bool = True) → DataFrame

Compute and stream the top_k highest scoring target nodes for each source node.

Parameters:
  • source_node_filter (int | list[int] | str) – The specification of source nodes to consider.

  • target_node_filter (int | list[int] | str) – The specification of target nodes to consider.

  • relationship_type (str) – The relationship type whose embedding will be used in the computation.

  • top_k (int) – How many target nodes to return for each source node.

  • relationship_types (list[str]) – Filter the graph using the given relationship types.

  • concurrency (int | None) – Number of concurrent threads to use.

  • job_id (str | None) – Identifier for the computation.

  • log_progress (bool) – Display progress logging.

Returns:

The top_k highest scoring target nodes for each source node, with the score for the node pair.

Return type:

pandas.DataFrame

predict_write(source_node_filter: int | list[int] | str, target_node_filter: int | list[int] | str, relationship_type: str, top_k: int, write_relationship_type: str, write_property: str, *, relationship_types: list[str] = ['*'], concurrency: int | None = None, write_concurrency: int | None = None, job_id: str | None = None, log_progress: bool = True) → KgeWriteResult

Compute relationships and write them back to the database under a new relationship type.

Parameters:
  • source_node_filter (int | list[int] | str) – The specification of source nodes to consider.

  • target_node_filter (int | list[int] | str) – The specification of target nodes to consider.

  • relationship_type (str) – The relationship type whose embedding will be used in the computation.

  • top_k (int) – How many relationships to add for each source node.

  • write_relationship_type (str) – The relationship type for the predicted relationships.

  • write_property (str) – The property on the new relationships storing the prediction score.

  • relationship_types (list[str]) – Filter the graph using the given relationship types.

  • concurrency (int | None) – Number of concurrent threads to use.

  • write_concurrency (int | None) – Number of concurrent threads used for writing.

  • job_id (str | None) – Identifier for the computation.

  • log_progress (bool) – Display progress logging.

Returns:

Metadata about the performed computation and write-back.

Return type:

KgeWriteResult

relationship_type_embeddings() → dict[str, list[float]]

Return the relationship type embeddings of the model.

Return type:

dict[str, list[float]]

scoring_function() → str

Return the name of the scoring function the model uses.

Return type:

str

class graphdatascience.procedure_surface.api.kge.kge_predict_endpoints.KgePredictEndpoints

Endpoints for predicting relationships with a knowledge-graph-embedding scoring function.

Mirrors the gds.ml.kge.predict procedure. The scoring function (e.g. transe or distmult) and the per-relationship-type embedding are typically supplied by a SimpleRelEmbeddingModel created via gds.kge.transe(...) / gds.kge.distmult(...).

abstract mutate(G: Graph, *, node_embedding_property: str, relationship_type_embedding: list[float], scoring_function: str, top_k: int, mutate_relationship_type: str, mutate_property: str = 'score', source_node_filter: int | list[int] | str | None = None, target_node_filter: int | list[int] | str | None = None, relationship_types: list[str] = ['*'], concurrency: int | None = None, job_id: str | None = None, log_progress: bool = True, sudo: bool = False, username: str | None = None) → KgeMutateResult

Compute relationships and add them to the in-memory graph under a new relationship type.

Parameters:
  • G (Graph) – Graph object to use.

  • node_embedding_property (str) – The name of the node property storing the embeddings in the graph.

  • relationship_type_embedding (list[float]) – The embedding vector of the relationship type used in the computation.

  • scoring_function (str) – The scoring function to use, e.g. transe or distmult.

  • top_k (int) – How many relationships to add for each source node.

  • mutate_relationship_type (str) – The relationship type for the predicted relationships.

  • mutate_property (str) – The property on the new relationships storing the prediction score.

  • source_node_filter (int | list[int] | str | None) – The specification of source nodes to consider.

  • target_node_filter (int | list[int] | str | None) – The specification of target nodes to consider.

  • relationship_types (list[str]) – Filter the graph using the given relationship types.

  • concurrency (int | None) – Number of concurrent threads to use.

  • job_id (str | None) – Identifier for the computation.

  • log_progress (bool) – Display progress logging.

  • sudo (bool) – Disable the memory guard.

  • username (str | None) – As an administrator, impersonate a different user for accessing their graphs.

Returns:

Metadata about the performed computation and mutation.

Return type:

KgeMutateResult

abstract stream(G: Graph, *, node_embedding_property: str, relationship_type_embedding: list[float], scoring_function: str, top_k: int, source_node_filter: int | list[int] | str | None = None, target_node_filter: int | list[int] | str | None = None, relationship_types: list[str] = ['*'], concurrency: int | None = None, job_id: str | None = None, log_progress: bool = True, sudo: bool = False, username: str | None = None) → DataFrame

Compute and stream the top_k highest scoring target nodes for each source node.

Parameters:
  • G (Graph) – Graph object to use.

  • node_embedding_property (str) – The name of the node property storing the embeddings in the graph.

  • relationship_type_embedding (list[float]) – The embedding vector of the relationship type used in the computation.

  • scoring_function (str) – The scoring function to use, e.g. transe or distmult.

  • top_k (int) – How many target nodes to return for each source node.

  • source_node_filter (int | list[int] | str | None) – The specification of source nodes to consider.

  • target_node_filter (int | list[int] | str | None) – The specification of target nodes to consider.

  • relationship_types (list[str]) – Filter the graph using the given relationship types.

  • concurrency (int | None) – Number of concurrent threads to use.

  • job_id (str | None) – Identifier for the computation.

  • log_progress (bool) – Display progress logging.

  • sudo (bool) – Disable the memory guard.

  • username (str | None) – As an administrator, impersonate a different user for accessing their graphs.

Returns:

The top_k highest scoring target nodes for each source node, with the score for the node pair.

Return type:

pandas.DataFrame

abstract write(G: Graph, *, node_embedding_property: str, relationship_type_embedding: list[float], scoring_function: str, top_k: int, write_relationship_type: str, write_property: str = 'score', source_node_filter: int | list[int] | str | None = None, target_node_filter: int | list[int] | str | None = None, relationship_types: list[str] = ['*'], concurrency: int | None = None, write_concurrency: int | None = None, job_id: str | None = None, log_progress: bool = True, sudo: bool = False, username: str | None = None) → KgeWriteResult

Compute relationships and write them back to the database under a new relationship type.

Parameters:
  • G (Graph) – Graph object to use.

  • node_embedding_property (str) – The name of the node property storing the embeddings in the graph.

  • relationship_type_embedding (list[float]) – The embedding vector of the relationship type used in the computation.

  • scoring_function (str) – The scoring function to use, e.g. transe or distmult.

  • top_k (int) – How many relationships to add for each source node.

  • write_relationship_type (str) – The relationship type for the predicted relationships.

  • write_property (str) – The property on the new relationships storing the prediction score.

  • source_node_filter (int | list[int] | str | None) – The specification of source nodes to consider.

  • target_node_filter (int | list[int] | str | None) – The specification of target nodes to consider.

  • relationship_types (list[str]) – Filter the graph using the given relationship types.

  • concurrency (int | None) – Number of concurrent threads to use.

  • write_concurrency (int | None) – Number of concurrent threads used for writing.

  • job_id (str | None) – Identifier for the computation.

  • log_progress (bool) – Display progress logging.

  • sudo (bool) – Disable the memory guard.

  • username (str | None) – As an administrator, impersonate a different user for accessing their graphs.

Returns:

Metadata about the performed computation and write-back.

Return type:

KgeWriteResult

class graphdatascience.procedure_surface.api.kge.kge_predict_endpoints.KgeMutateResult
class graphdatascience.procedure_surface.api.kge.kge_predict_endpoints.KgeWriteResult
graphdatascience.procedure_surface.api.kge.kge_predict_endpoints.NodeFilter

alias of int | list[int] | str