TermXtract
TermXtract is a Python library for automatic term extraction (ATE): finding the domain-specific terms in a collection of documents. It offers a range of classic unsupervised scoring methods (TF-IDF, C-Value, Weirdness, RAKE, topic models, …) and supervised methods that learn from labelled examples (Roger, and transformer-based token classification).
Every method takes either a plain list of strings or a Teanga Corpus, and returns the same ATEResults object.
📖 Documentation: https://teanga.io/TermXtract/
📝 Changelog: CHANGELOG.md. TermXtract follows Semantic Versioning; before 1.0, minor releases may contain breaking changes.
Installation
TermXtract needs Python 3.10 or later. Install it from PyPI:
pip install termxtract
or install the development version, with the changes since the last release, from GitHub:
pip install git+https://github.com/TeangaNLP/TermXtract.git
The transformer-based token-classification and embedrank extractors need PyTorch and Hugging Face Transformers, which are large, so they are an optional extra. Install them with:
pip install "termxtract[transformers]"
The llm method talks to a large language model through the OpenAI API or a compatible local server, such as Ollama; install its client with pip install "termxtract[llm]". All other methods work with the base install.
Quickstart
Unsupervised extraction
from termxtract import TermExtractor
corpus = [
"Machine learning is a field of artificial intelligence.",
"Deep learning is a subfield of machine learning.",
"Natural language processing applies machine learning to text.",
]
extractor = TermExtractor(method="cvalue", n=2) # consider unigrams and bigrams
results = extractor.extract(corpus)
for doc in results.terms:
print(doc["doc_id"], [(t["term"], round(t["score"], 2)) for t in doc["terms"][:3]])
# doc_0 [('machine learning', 3.21), ('artificial intelligence', 1.07), ('learning', 0.28)]
# ...
Each document's terms are ranked from highest to lowest score. Pass threshold=... to keep only terms scoring at or above a minimum. Candidates that start or end with a stopword, such as is a or of machine, are dropped by default; pass stopwords=None to keep them, or a list of words to use your own stopwords.
Methods that need a reference corpus
weirdness, domainpertinence and relevance compare the target corpus against a general-language reference corpus, or a list of reference corpora:
reference = [
"The weather was pleasant and people walked in the park.",
"She bought bread and milk at the shop on the corner.",
]
extractor = TermExtractor(method="weirdness", reference_corpus=reference, n=2)
results = extractor.extract(corpus)
Supervised extraction
Supervised methods are trained from a dictionary of candidate terms labelled 1 (term) or 0 (not a term). Roger ranks multi-word candidates, so it needs multi-word examples of both:
from termxtract import SupervisedTermExtractor
labels = {
"machine learning": 1,
"deep learning": 1,
"natural language processing": 1,
"is a": 0,
"applies machine": 0,
}
extractor = SupervisedTermExtractor(method="roger", n=3)
results = extractor.extract(corpus, labels)
extract trains on a corpus and extracts terms from the same corpus. To train on one corpus and extract terms from another, use extractor.fit(train_corpus, labels).predict(test_corpus). For a Teanga corpus with gold terms in a terms layer, such as those of termxtract.datasets, leave out labels to train on them.
Using a Teanga corpus
Any extractor also accepts a Teanga Corpus with a words span layer:
from teanga import Corpus
corpus = Corpus()
corpus.add_layer_meta("text")
corpus.add_layer_meta("words", layer_type="span", base="text")
doc = corpus.add_doc("Deep learning is a subfield of machine learning.")
doc.words = [(0, 4), (5, 13), (14, 16), (17, 18), (19, 27), (28, 30), (31, 38), (39, 47)]
results = TermExtractor(method="basic", n=2).extract(corpus)
Words are read from the words layer or, if there is none, from a tokens layer, as written by Teanga's CoNLL-U reader and spaCy service. If the corpus has part-of-speech tags, pos_pattern="noun_phrase" keeps only noun phrases, and if it has lemmas, lemma_layer="lemma" counts cell and cells as one term (see the TF-IDF tutorial).
Methods
TermXtract has 21 unsupervised methods, from TF-IDF, C-value and weirdness to TextRank, YAKE! and MDERank, and four supervised ones: Roger, a feature-based classifier, token classification with a fine-tuned transformer, and in-context learning with a large language model. Any ranking can be re-ranked by related seed terms, and training data can be extended with synthetic sentences. See the methods for the full list and their parameters, and the tutorials for how to use them.
Benchmarks
BENCHMARKS.md scores every method on three English datasets and on Hindi, Slovenian and Irish ones, and compares them with published results. In short:
- With labelled training data, token classification and in-context learning with a large language model are far ahead of the other methods. Token classification has F1 of 58 to 68 on every dataset with training data, against at most 43 for any unsupervised method, and in-context learning is close behind everywhere but on Hindi. With only a few labelled sentences, in-context learning is best.
- Without training data, the methods that compare the corpus with a general-language reference corpus (weirdness, domain pertinence and relevance) rank terms best on five of the nine test sets, followed by the t-score, MDERank and TF-IDF.
See Which method should I use? for more.
Development
See Development for how to run the tests and checks, and how to make a release.
License
TermXtract is licensed under the Apache License 2.0, the same license as Teanga.
Metadata
Release files for termxtract 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| termxtract-0.2.0.tar.gz | 194.3 kB | With provenance | Details for termxtract-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| termxtract-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for termxtract-0.2.0-py3-none-any.whl |
Total release size: 428.1 kB
Release files / termxtract-0.2.0.tar.gz
| Download URL | termxtract-0.2.0.tar.gz |
|---|---|
| Size | 194.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
28d975986c68e8f21231fac77b5a5a0fa1416377258155db7bda53786ee003cc
|
|
BLAKE2b-256 checksum How to use checksums |
60e4279f615c2f2089a487a257e1cf359d6e3588b0a268d2b00c47a09e5a90da
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.
Transparency logRelease files / termxtract-0.2.0-py3-none-any.whl
| Download URL | termxtract-0.2.0-py3-none-any.whl |
|---|---|
| Size | 233.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
03d05a22d528e0afe87ed7c11a19d5506b999f3be181c3d0aa1ebcbbcf7e91fa
|
|
BLAKE2b-256 checksum How to use checksums |
aafb8a78f7b6b41fdc4a2310246d4bf35a43b3250788fdac488b68d8c57b1159
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.
Transparency logSecurity for termxtract 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for termxtract-0.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.