citation-topics · Sample board · GitHub
How the topics are made: the Leiden algorithm
citation-topics finds the topics of any list of works from their citations alone, with no list of fields decided in advance. This page explains, as simply as possible, how a computer finds them and how each work gets its topic. The numbers come from the largest list it has been run on: the 1.87 million papers of INSPIRE-HEP, grouped into 304 topics (inspireauth10, which the package reproduces exactly); the last sections say what the package does with a list of any size and how to see the result.
1. Papers that cite each other form a topic
Draw every paper as a dot and every citation as a line between two dots (it does not matter who cites whom). The whole of INSPIRE gives 1.87 million dots and 44.3 million lines. Papers on the same subject cite each other much more than they cite papers on other subjects, so the drawing has dense groups with only a few lines between them. A topic is one of those dense groups.
With twelve dots the groups can be seen by eye. With 1.87 million they cannot, so the computer needs a score that says how good a split into groups is, and a fast way to find a split with a high score. The Leiden algorithm (Traag, Waltman & van Eck 2019) does both.
2. The score: more links inside than chance would give
Counting the links inside the groups is not enough: putting every paper in one single group would keep every link inside. The score therefore compares the links inside each group with the number of links the group would have by chance, if the same papers, each with the same number of citations, were wired at random. A good topic has many more links inside than chance gives. This score is the modularity of Newman (2006).
Chance gives more links between papers that have many links. A paper with k links meets a group whose papers have K links in all about k × K / (2m) times at random, where m is the number of links in the whole network. So, for one paper, the gain of joining a topic is:
gain = (its links to the topic) − γ × k × K / (2m)
The number γ is the resolution (Reichardt & Bornholdt 2006). It decides how large the topics are: with a large γ the "chance" term weighs more, big groups stop paying off, and the network splits into more, smaller topics. On INSPIRE-HEP the default γ = 16 gives 304 topics of typically a few thousand papers; γ = 4 gives only 69 topics, and γ = 32, 623. A list of a few thousand works needs a much smaller γ: the sample board uses γ = 1 for 1,967 works and gets 11 topics.
3. How Leiden searches
Trying every possible split is impossible, so Leiden improves a split step by step:
- Move. Start with every paper alone. Visit the papers one by one and move each to the neighbouring group where its gain is largest (or leave it where it is). Repeat until no move helps.
- Refine. Check that every group is really held together by its own links; a group that is two separate pieces is split. This step is what Leiden adds to the older Louvain algorithm, which could leave such broken groups (Traag, Waltman & van Eck 2019).
- Merge. Replace each group by one big dot (its inside links become a loop on the dot, its outside links become thick lines) and go back to step 1 with these dots, so that whole groups can move together.
The three steps are repeated until the score stops rising. In the end every paper has exactly one topic: the group where, given all the other papers, it adds most to the score. That is its main topic.
4. An example: why Geant4 is not in the LHC topic
The Geant4 simulation toolkit paper (2003) is the most cited paper of the network, with 20,392 citation links. 3,919 of them go to papers of the topic LHC experiments and the Higgs discovery, but only 1,348 to the topic Geant4 and detector simulation. Still, Leiden puts it in the second one. The gain explains why:
| Topic | Geant4's links there | All links of the topic's papers | Expected by chance (γ = 16) | Gain |
|---|---|---|---|---|
| Geant4 and detector simulation | 1,348 | 117,958 | 434 | +914 |
| LHC experiments and the Higgs discovery | 3,919 | 1,097,765 | 4,038 | −119 |
| Silicon trackers and LHC detector upgrades | 360 | 179,020 | 659 | −299 |
- The LHC topic is huge: its papers carry about 1.1 million links, nine times those of the simulation topic. Almost every LHC paper cites Geant4, the way it cites the Review of Particle Physics, so 3,919 links is just what chance gives to a paper with 20,392 links.
- The detector-simulation papers cite Geant4 three times more than chance, and cite each other around it: they are about Geant4. That excess is what makes a topic, and the topic is built around this paper.
- The resolution matters. With γ = 1 the expected numbers are 16 times smaller (27, 252 and 41 links) and, if the topics stayed the same, the LHC topic would give a gain of 3,667 against 1,321, and Geant4 would join the LHC topic. At the default resolution, the fine subject wins over the big field.
citation-topics also gives each work a second and third topic: the other topics with most links, scored as their links divided by the links to the main topic (at most 1). That score counts raw links, with no correction for chance, so a widely used tool such as Geant4 gets a second topic with score 1 (the LHC topic), while Leiden's gain for it is about zero.
5. What citation-topics does exactly
- Network (
citation-topics run): every work of the list is a dot; a line for each reference to another work of the list, each pair counted once. References to works outside the list and self-citations are dropped and counted. - Topics: Leiden with the score above (igraph), γ =
--resolution(16 by default), repeated until the score stops rising (at most--passes, 20). Groups under--min-sizeworks (100) join the topic they share most links with. Works with no citation link to another work of the list get no topic. - Areas: Leiden again (leidenalg), on the network of the topics (each topic a dot), with
γ =
--area-resolution(0.3); the best of--area-seedsruns (50). - Stability: Leiden visits the works in a random order (
--seed). Run a few seeds and keep the most typical one:citation-topics agreementgives the NMI and ARI between runs and names the medoid. - Names: never made by the package.
describewrites what each topic is about (distinctive terms, journals, categories, most cited works), and a person or Claude'stopic-namerskill writes the names from it. - Code:
src/citation_topics/(cluster.pyruns Leiden). The same approach, direct citations clustered with Leiden (Waltman & van Eck 2012), is the one CWTS at Leiden University used to build the clusters behind the OpenAlex topics (OpenAlex, “Topics”; van Eck & Waltman 2024), but nothing here is taken from OpenAlex or any other classification.
6. Seeing the topics: the network of works
When the list has at most 10,000 works (--network-max), the board has a Network tab that draws
every work with a citation link as a dot and every citation link as a line, with each topic as its own cluster,
labelled with its name. The positions are made in two steps, so that each cluster really is one topic:
- Each topic becomes a disc whose area is proportional to its works. The discs are placed by the links between topics (topics that cite each other more sit closer; Fruchterman–Reingold layout of the graph of topics) and then pushed apart until none overlap.
- Inside each disc, the topic's works are placed by the links among them (Fruchterman–Reingold again), so that works that cite each other sit together.
Dots are coloured by area and sized by citations. Clicking a work leaves only its own citation links, in one colour to the works it cites
and in another to the works citing it, and the works at their other end, with its first author beside it and its title, authors, year, citations, topic and
link in a box below the graph. The same positions go into works_vosviewer.json
(citation-topics export OUT --works INPUT), a VOSviewer file with one item
per work, its topic as the cluster (named), its citations and year, and its link. VOSviewer Online opens such a
file from a public address: https://app.vosviewer.com/?json= followed by the file's URL. The sample
board's file opens with
this link.
In VOSviewer the clusters can be recomputed and the works re-laid with its own method (VOS mapping and
clustering); the file keeps the topics of citation-topics until that is done.
References
- V. A. Traag, L. Waltman, N. J. van Eck, "From Louvain to Leiden: guaranteeing well-connected communities", Scientific Reports 9, 5233 (2019). doi:10.1038/s41598-019-41695-z
- L. Waltman, N. J. van Eck, "A new methodology for constructing a publication-level classification system of science", JASIST 63, 2378 (2012). doi:10.1002/asi.22748
- OpenAlex, “Topics”, OpenAlex help center (official documentation of the OpenAlex topic classification, developed with CWTS at Leiden University). help.openalex.org/hc/en-us/articles/24736129405719-Topics
- N. J. van Eck, L. Waltman, “An open approach for classifying research publications”, Leiden Madtrics, CWTS, 24 January 2024. leidenmadtrics.nl; data: N. J. van Eck, “Classification of research publications based on data from OpenAlex”, Zenodo (2024), doi:10.5281/zenodo.10560276
- J. Reichardt, S. Bornholdt, "Statistical mechanics of community detection", Phys. Rev. E 74, 016110 (2006). doi:10.1103/PhysRevE.74.016110
- N. J. van Eck, L. Waltman, "Software survey: VOSviewer, a computer program for bibliometric mapping", Scientometrics 84, 523 (2010). doi:10.1007/s11192-009-0146-3; VOSviewer Online: app.vosviewer.com
- M. E. J. Newman, "Modularity and community structure in networks", PNAS 103, 8577 (2006). doi:10.1073/pnas.0601602103