Your node2vec vectors cluster friend groups, but you need bridge accounts to look alike — what do you change?
answer
- the sampler picks the similarity, not the loss
- two kinds of similar: same group, same job
- one knob pushes walks outward, one keeps them home
- in-out parameter above one stays local
- local walks survey the neighbourhood shape
basics
~20 sRaise node2vec's in-out parameter q above one. Walks then stay in the source's immediate neighbourhood instead of wandering outward, so vectors encode structural role rather than community membership, and two brokers in unrelated groups land near each other.
solid answer
~50 sThe sampler decides which notion of similarity you get, so change `q`, not the objective. With `q < 1` the walk is pushed away from the previous node's neighbourhood — a depth-first-like drift that keeps sweeping through one community, so co-occurrence encodes homophily and a university social graph comes out clustered into friend groups. With `q > 1` the walk keeps doubling back into the source's own neighbourhood — a breadth-first-like sample of the local structure — so a node's context summarises its immediate surroundings and two accounts that both sit between dense clusters look alike even if they share no neighbours. The return parameter `p` is a separate knob: a large `p` discourages stepping straight back to where you came from, a small `p` keeps the walk hovering. Then validate: take accounts you already know are brokers and check whether they are now mutual nearest neighbours.
go deeper
Know that node2vec has two walk-bias knobs, p and q, and that they change which nodes end up near each other rather than changing the training loss.
Explain the transition weights concretely: back to the previous node gets weight 1/p, a shared neighbour gets 1, a two-hop candidate gets 1/q, and describe the resulting breadth-first versus depth-first behaviour.
Show you would verify the regime empirically with a labelled probe set and downstream scores, and that you know embedding proximity stops implying graph proximity once the walks go local.
Own the framing question before any tuning: decide whether the product needs community similarity or role similarity, since one embedding cannot serve both and the choice quietly determines what every downstream consumer means by similar.
## Two similarities, one embedding Ask what it means for two nodes to be similar and you get two defensible answers. - **Homophily / community**: two nodes are similar if they sit in the same densely connected region. Two students in the same dorm friend group. - **Structural equivalence / role**: two nodes are similar if they occupy the same *kind* of position, regardless of where. Two students who each sit between two otherwise disconnected friend groups — brokers, bridges, hubs — even if they have never met and share no friends at all. A single embedding cannot maximise both. node2vec's contribution is that the *sampler* — not the objective — chooses between them, through two parameters on a second-order walk. ## The bias, precisely The walk is standing at node `v`, having arrived from `t`. Each candidate next node `x` gets an unnormalised weight: - `1/p` if `x` is `t` — stepping straight back; - `1` if `x` is a neighbour of `t` as well as of `v` — staying inside the shared local structure; - `1/q` if `x` is two hops from `t` — moving outward into new territory. **`q` is the in-out parameter.** `q < 1` inflates `1/q`, upweighting the outward step: walks behave depth-first, drifting far from the start, sweeping long stretches of one region. **`q > 1` deflates it**, so walks stay inside the source's own neighbourhood, behaving breadth-first and repeatedly sampling the same local surroundings. **`p` is the return parameter.** Small `p` inflates `1/p` and encourages immediate backtracking, producing very local, redundant walks. Large `p` discourages returning to the previous node and keeps the walk exploring. ## Why local walks give you roles When `q > 1`, a node's context window is dominated by a repeated micro-survey of its own neighbourhood. What the vector ends up encoding is the *shape* of that neighbourhood — how many distinct clusters touch it, how dense they are, how quickly the walk gets trapped. Two broker accounts in a university social network, one bridging the chess club and the rowing team, another bridging two unrelated dorms, produce similar local micro-surveys: a walk starting at either keeps oscillating between two dense regions. Their vectors converge even though the walks never overlap on a single shared node. When `q < 1`, the walk instead escapes and roams one community, so the context of a chess-club member is other chess-club members, and the embedding recovers friend groups. That is the regime that produced the complaint in the question. ## The counter-intuitive consequence Under `q > 1`, embedding proximity no longer implies graph proximity. Two nodes that are twenty hops apart can be nearest neighbours in vector space, and two adjacent nodes — say a broker and one of the ordinary members it connects to — can be far apart. If a downstream system was built assuming near-in-vector-space means near-in-graph (a recommendation that suggests people you might actually know, for instance), it will start returning strangers who happen to share a role. Decide which similarity the *product* needs before you tune. ## How to verify you got the regime you asked for Do not trust the parameter setting; measure it. - **Labelled probe set.** Take a handful of nodes you already know are brokers or hubs and check whether they became mutual nearest neighbours. Do the same for a known tight community and check that its members did *not*. - **Correlate with a structural statistic.** If the embedding encodes role, nearest neighbours should share degree and clustering-coefficient magnitude while sitting in different components of the community structure. - **Downstream task.** The honest test is whether the classifier that consumes the vectors improved on the task you care about; role embeddings often help fraud and anomaly work and hurt friend recommendation. ## Costs and cautions The second-order bias is not free. Because the transition depends on the previous node, the sampler must consider, at each step, whether each candidate is the predecessor or a neighbour of the predecessor — so either you check neighbour membership online or you precompute per-edge transition distributions, whose memory grows with the sum over edges of the endpoint degrees. On a hub-heavy graph that precomputation can dwarf the embedding table itself. Also, `p` and `q` are not a small correction; they change what the model means. Tuning them by downstream validation score alone, without an interpretation of which similarity you want, tends to produce an embedding nobody can explain when it later misbehaves. Finally, note the limiting case: uniform DeepWalk walks are the `p = q = 1` setting, which sits between the two regimes and commits to neither.
- What does the return parameter p do that the in-out parameter q does not?`p` governs only the immediate step back to the node you just left. A small `p` makes the walk hover on the same edge, producing very redundant, tightly local context; a large `p` forbids backtracking and pushes the walk to keep moving. `q` instead decides, among the non-return options, whether to stay inside the previous node's neighbourhood or move two hops out. They interact — a large `p` with a large `q` explores locally without stalling.
- How would you check which regime you actually landed in, rather than trusting the setting?Use a labelled probe set. Take nodes you already know are brokers and check whether they became mutual nearest neighbours; take a known tight community and check that its members did not collapse together. Correlate nearest-neighbour pairs with degree and clustering coefficient. Finally, judge by the downstream task — role-flavoured vectors usually help anomaly work and hurt friend recommendation.
- What does the second-order bias cost you compared with uniform walks?Every step depends on the previous node, so the sampler must know whether each candidate is the predecessor or one of its neighbours. You either test that membership online per step or precompute a transition distribution per directed edge, whose memory grows with the sum of endpoint degrees. On hub-heavy graphs that table can be larger than the embeddings you are trying to learn.
Exploring a city on foot: if you keep walking outward you learn which district you are in; if you keep circling one block you learn what kind of corner you are standing on, and every similar corner in the city starts to feel the same.
saying these in an interview costs you the question
- Says q below one gives structural roles - the direction is inverted
- Thinks p and q change the training objective rather than the sampler
- Assumes nodes similar in role must be close in the graph
- Treats p and q as ordinary hyperparameters to grid-search blindly
- Claims one embedding can capture community and role at once