Home

Awesome

German Text Embedding Clustering Benchmark

Shortcut: Datasets - Results - Installation - Usage - Citation

Remarks

This repository contains code to evaluate language models for clustering word embeddings as used in neural topic modelling (see for example BERTopic) specifically for <b>German</b>. This work builds on Massive Text Embedding Benchmark (MTEB), which provides benchmark datasets and results for a wide range of tasks.

More specifically, this work contributes to mteb in the following ways:

:trophy: Note that you can contribute results to the MTEB leaderboard as our datasets are officially part of MTEB (apart from the Reddit datasets, see below)! You can either use this library or MTEB directly to produce results. If you run into any problems, please raise an issue. :trophy:

Datasets

Currently, we provide 4 datasets. The datasets are built similarly to the English clustering datasets in MTEB. Unfortunately, there are fewer datasets available for German and, therefore, we were not able to build as many datasets (e.g. Arxiv only contains very few German papers). However, we plan to add more datasets in the future.

NameHub URLDescription
BlurbsClusteringS2S<br>(data ref.)slvnwhrl/blurbs-clustering-s2sClustering of <b>book titles</b>: 17'726 unqiue samples, 28 splits with 177 to 16'425 samples and 4 to 93 unique classes (as represented by genres, e.g. fantasy). On average, a sample is 23.17 chars long. Splits are built similarly to MTEB's ArxivClusteringS2S (Paper).
BlurbsClusteringP2P<br>(data ref.)slvnwhrl/blurbs-clustering-p2pClustering of <b>book blurbs</b> (title + blurb): Clustering of book titles: 18'084 unqiue samples, 28 splits with 177 to 16'425 samples and 4 to 93 unique classes as represented by genres, e.g. fantasy. On average, a sample is 663.91 chars long. Splits are built similarly to MTEB's ArxivClusteringP2P (paper).
TenKGNADClusteringS2S<br>(data ref.)slvnwhrl/tenkgnad-clustering-s2sClustering of <b>news article titles</b>: 10'267 unique samples, 10 splits with 1'436 to 9'962 samples and 9 unique classes (as represented by, e.g. politics). On average, a sample is 50.97 chars long. Splits are built similarly to MTEB's TwentyNewsgroupsClustering (paper).
TenKGNADClusteringP2P<br>(data ref.)slvnwhrl-tenkgnad-clustering-p2pClustering of <b>news articles</b> (title + article body): 10'275 unique samples, 10 splits with 1'436 to 9'962 samples and 9 unique classes (as represented by, e.g. politics). On average, a sample is 2648.46 chars long. Splits are built similarly to MTEB's TwentyNewsgroupsClustering (paper).

Reddit datasets

We also include two Reddit datasets in the benchmark (similar to MTEB's RedditClustering and RedditClusteringP2P datasets). However, we only provide ids, and if you want to use these datasets, you need to download the data yourself (see Including the Reddit dataset for instructions). The datasets contain "hot" and "top" submissions to 80 popular German subreddits and were extracted using PRAW.

NameDescription
RedditClusteringS2SClustering of reddit submission titles: 40'181 unique samples, 10 splits with 9'288 to 26'221 samples and 10 to 50 unique classes (as represented by subbredits, e.g. r/Finanzen). On average, a sample is 52.16 chars long. Splits are built similarly to MTEB's RedditClustering (paper).
RedditClusteringP2PClustering of reddit submissions (title + body): 40'305 unique samples, 10 splits with 9'288 to 26'221 samples and 10 to 50 unique classes (as represented by subbredits, e.g. r/Finanzen). On average, a sample is 901.78 chars long. Splits are built similarly to MTEB's RedditClusteringP2P (paper).

Important: As of June 19, 2023 new Data API Terms become effective for Reddit. Most likely, it will not be allowed anymore to use Reddit data for such purposes (see especially "2.4 User Content" in the terms). Make sure you understand these terms and use Reddit data accordingly.

Results

All results show the V-measure (multiplied by 100 and rounded to two decimal points).

k-means (same as MTEB)

ModelBlurbsClusteringS2SBlurbsClusteringP2PTenKGNADClusteringS2STenKGNADClusteringP2PRedditClusteringS2SRedditClusteringP2PAVG
deepset/gbert-base11.2735.3624.2337.1628.5735.3028.66
deepset/gbert-large13.3439.3034.9741.6934.3544.6134.71
deepset/gelectra-base7.7410.064.119.026.597.737.54
deepset/gelectra-large7.5713.963.9111.497.5910.549.18
uklfr/gottbert-base8.3734.499.3433.6616.0719.4620.23
sentence-transformers/paraphrase-multilingual-MiniLM-L12-v214.3332.4622.2636.1333.3344.5930.52
sentence-transformers/paraphrase-multilingual-mpnet-base-v215.8134.3822.0035.9636.3948.4332.16
T-Systems-onsite/cross-en-de-roberta-sentence-transformer12.6930.8110.9423.5027.9833.0123.16
sentence-transformers/use-cmlm-multilingual15.2429.6325.6437.1033.6249.7031.82
sentence-transformers/sentence-t5-base11.5730.5918.1144.8831.9945.8030.49
sentence-transformers/sentence-t5-xxl15.9439.9119.6943.4338.5455.9035.57
xlm-roberta-large7.2929.846.1632.4610.1923.5018.24

additional clustering algorithms

In addition to k-means, we evaluate the following different clustering algorithms:

Inspired by BERTopic, we also evaluate PCA and UMAP as a "preprocessing" step.

If you want add/evaluate more algorithms, please have a look at FlexibleClusteringEvaluator.py on how to achieve that.

UMAP + {k-means, HDBSCAN, DBSTREAM}

For all results have a look at results/tecb-de-full-results.csv.

ModelAlgorithmBlurbsClusteringS2SBlurbsClusteringP2P10KGNADClusteringS2S10KGNADClusteringP2PRedditClusteringS2SRedditClusteringP2PAVG
deepset/gbert-basek-means<br> HDBSCAN<br> DBSTREAM12.81<br> 14.31<br> 12.7038.81<br> 22.83<br> 37.0629.31<br> 05.44<br> 28.9243.61<br> 32.45 <br> 42.7431.77<br> 17.21<br> 31.7046.06<br> 31.99<br> 44.8433.73<br> 20.71<br> 32.99
sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2k-means<br> HDBSCAN<br> DBSTREAM13.80<br> 20.00<br> 15.7734.16<br> 30.67<br> 32.4725.22<br> 24.90<br> 26.4443.75<br> 35.53<br> 41.3132.64<br> 32.23<br> 33.1447.46<br> 39.70<br> 46.4732.84<br> 30.51<br> 32.60

Installation

If you want to run the code from this repository (for creating the Reddit dataset or model evaluation), clone this repository and move to the downloaded folder

git clone https://github.com/ClimSocAna/tecb-de.git 

and create a new environment with the necessary packages

python -m venv tecb-de

source tecb-de/bin/activate # Linux, MacOS
venv\Scripts\activate.bat # Windows

pip install -r requirements.txt

Usage

Running the evaluation

Simply run python scripts/run_cteb_de.py. This will produce an results folder. You can modify the script to run the evaluation for models and clustering algorithms (and configuration) of your choosing.

Including the Reddit dataset

If you want to use the reddit dataset, you first have to download the data

# move to the reddit_data folder in tecb-de
# make sure you have PRAW and tdqm installed: pip install praw, pip install tqdm

# downloads the data and saves it to submissions.tsv
python download.py

Note that for this to work, you have to edit the reddit_data/praw.ini with your client data. You can find instructions here.

Then you can create the datasets

# creates the splits for both tasks (RedditClusteringS2S and ReddictClusteringP2P)
# and saves them in the reddit_data folder
python create_splits.py

Finally, you can can run the evaluation using the --include-reddit flag

# assuming your position is in the top-level folder
python scripts/run_cteb_de.py --reddit-flag

Adaptive pre-training

If you want to experiment with adaptive pre-training, you can have a look at scripts/run_fine_tuned_cteb_de.py. Basically, it allows you to train models using whole word masking (WWM) and TSDAE and to evaluate on a clustering algorithm during training.

Citation

If you make use of this work, please cite:

@inproceedings{wehrli-etal-2023-german,
    title = "{G}erman Text Embedding Clustering Benchmark",
    author = "Wehrli, Silvan  and
      Arnrich, Bert  and
      Irrgang, Christopher",
    editor = "Georges, Munir  and
      Herygers, Aaricia  and
      Friedrich, Annemarie  and
      Roth, Benjamin",
    booktitle = "Proceedings of the 19th Conference on Natural Language Processing (KONVENS 2023)",
    month = sep,
    year = "2023",
    address = "Ingolstadt, Germany",
    publisher = "Association for Computational Lingustics",
    url = "https://aclanthology.org/2023.konvens-main.20",
    pages = "187--201",
}