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:
- Returns:
A model using the DistMult scoring function.
- Return type:
- property predict: KgePredictEndpoints¶
Flat prediction endpoints, taking the scoring function as an explicit parameter.
- 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(...)orgds.kge.distmult(...).- node_embedding_property() str¶
Return the name of the node property storing embeddings in the graph.
- Return type:
- 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:
- 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_khighest 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_khighest scoring target nodes for each source node, with the score for the node pair.- Return type:
- 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:
- 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.predictprocedure. The scoring function (e.g.transeordistmult) and the per-relationship-type embedding are typically supplied by aSimpleRelEmbeddingModelcreated viagds.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.
transeordistmult.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:
- 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_khighest 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.
transeordistmult.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_khighest scoring target nodes for each source node, with the score for the node pair.- Return type:
- 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.
transeordistmult.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:
- class graphdatascience.procedure_surface.api.kge.kge_predict_endpoints.KgeMutateResult¶
- class graphdatascience.procedure_surface.api.kge.kge_predict_endpoints.KgeWriteResult¶