Graph Metrics API

Graph-specific metrics.

Contains: - compute_validation_metrics: Triplet-based validation metrics for hyperbolic embeddings - GraphEmbeddingDataset: Container for hyperbolic graph embeddings

GraphEmbeddingDataset dataclass

Container for a set of hyperbolic graph embeddings.

from_dataframe(frame, *, embedding_prefix=STAGE4_EMBEDDING_PREFIX, code_column='code', level_column='level') classmethod

Build a dataset from a parquet dataframe.

compute_validation_metrics(emb, anchors, positives, negatives, c=1.0, top_k=1, *, as_tensors=False)

Compute validation metrics for hyperbolic embeddings.

Distances are computed in float64 on the CPU (see _anchor_distances). Like every distance formula here, sqrt(c) * acosh(-_L) is only correct for c = 1.

Parameters:

Name Type Description Default
emb Tensor

Embeddings tensor of shape (N, embedding_dim+1).

required
anchors Tensor

Anchor indices, shape (batch_size,).

required
positives Tensor

Positive indices, shape (batch_size,).

required
negatives Tensor

Negative indices, shape (batch_size, k_negatives).

required
c float

Curvature parameter (default: 1.0).

1.0
top_k int

Number of top negatives to consider for auxiliary accuracy.

1
as_tensors bool

Return torch scalars instead of Python floats (for Lightning logging).

False

Returns:

Type Description
Union[Dict[str, float], Dict[str, Tensor]]

Mapping of metric names to values: float32 tensors on emb's device, or floats.