liveBook · Manning

Negative sampling

As explained in Knowledge Graphs and LLMs in Action

Negative sampling is a training technique that selects unobserved or candidate relationships as negative examples instead of evaluating every possible relationship.

Negative sampling makes graph link-prediction training practical by evaluating sampled false relationships instead of every possible node pair. It addresses both the computational cost of dense pairwise comparison and the severe class imbalance created by sparse graphs. section 11.4.1

A typical negative-sampling loss pipeline:

  • Score observed edges with a decoder and convert scores into probabilities with a sigmoid function. section 11.4.1
  • Sample candidate false relationships from a negative-example distribution rather than enumerating all nonedges. section 11.4.1
  • Combine positive and negative cross-entropy terms, using a balancing parameter to control the influence of negatives. section 11.4.1

Biomedical knowledge graph

For the fact “aspirin treats headache,” training rewards a high decoder score for the observed relationship while penalizing sampled alternatives such as “COX-2 treats headache.” section 11.4.1

How Knowledge Graphs and LLMs in Action covers it

How deep it goes
Explains sampled negatives, sigmoid scoring, cross-entropy terms, sampling distributions, and balancing weights without deriving their optimization.
Examples
Uses a biomedical knowledge-graph fact about aspirin treating headache and a sampled COX-2 alternative.
What it assumes
Assumes graph nodes, relationships, embeddings, and decoder scores while defining the main loss-function components.
What you can do after
Evaluate link-prediction losses that score observed edges and sampled false relationships with tunable negative weighting.
How it connects
Connects negative sampling to graph embeddings, knowledge graphs, decoders, sigmoid functions, cross-entropy loss, and link prediction.

Also explained in

Compare how 2 books explain negative sampling →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Knowledge Graphs and LLMs in Action. The section links point to the parts of the book it draws on.