qbiocode.apps.quvine.api.sgns module#
SGNS embedding core: views -> walks -> corpus -> word2vec.
These functions are extracted verbatim from Pipeline._run_single_iteration
and its private helpers so that both the Hydra pipeline and the
quvine.embed() API share a single, behavior-preserving code path.
Reproducibility invariants that MUST be preserved (the cluster pipeline depends on them):
Per-root RNG seed:
cfg.experiment.base_seed + 10000 * it + idxwhereidxindexessorted(roots).Embedding row order is
list(graph.nodes)(neversorted).train_embeddingsreads the top-levelcfg.min_count.joblib
Parallel(backend='loky', batch_size=1, prefer='processes').
Note on the kinds argument: when a subset of walk kinds is requested, only
those walkers run, which changes the per-root RNG stream relative to a full
multi-kind run. Calling run_sgns with kinds=list(cfg.walks.kinds) (as
the pipeline does) reproduces the original behavior exactly.
Summary#
Functions:
Run walks over every root and compile a per-walk-kind token corpus. |
|
Build constrained views for a single root. |
|
Yield successive |
|
Build views + walks for a single root with deterministic seeding. |
|
Process a batch of roots inside a single worker process. |
|
One-shot SGNS embedding: |
|
Run every configured walk kind over each view for a single root. |
|
Train one SGNS (word2vec) embedding per walk kind. |
Reference#
- run_walks_for_root(cfg, graph, root, views, rng)[source]#
Run every configured walk kind over each view for a single root.
- process_root(cfg, graph, root, node2idx, it)[source]#
Build views + walks for a single root with deterministic seeding.
- process_root_chunk(cfg, graph, roots, node2idx, it)[source]#
Process a batch of roots inside a single worker process.
- build_corpora(cfg, graph, it=0, *, n_jobs=1, chunk_size=30)[source]#
Run walks over every root and compile a per-walk-kind token corpus.
Returns a dict
{walk_kind: corpus}where each corpus is a flat list of walks (each walk a list of node-id strings).- Return type:
Dict[str,List[List[str]]]
- train_embeddings(cfg, graph, all_corpora)[source]#
Train one SGNS (word2vec) embedding per walk kind. Rows in node order.
- run_sgns(cfg, graph, it=0, *, kinds=None, n_jobs=1, chunk_size=30)[source]#
One-shot SGNS embedding:
build_corpora->train_embeddings.- Parameters:
cfg – OmegaConf config (reads
walks.*,views.*,train.*,min_count,experiment.base_seed).graph (
Graph) – NetworkX graph.it (
int) – Iteration index used in the per-root seed.kinds (
Optional[List[str]]) – Walk kinds to compute.Noneusescfg.walks.kinds.n_jobs (
int) – joblib parallelism over roots.chunk_size (
int) – joblib parallelism over roots.
- Return type:
Dict[str,ndarray]- Returns:
{walk_kind: embedding}with each embedding(n_nodes, dim)inlist(graph.nodes)order.