Home

Awesome

LEXTREME: A Multi-Lingual Benchmark Dataset for Legal Language Understanding

Lately, propelled by the phenomenal advances around the transformer architecture, the legal NLP field has enjoyed spectacular growth. To measure progress, well curated and challenging benchmarks are crucial. However, most benchmarks are English only and in legal NLP specifically there is no multilingual benchmark available yet. Additionally, many benchmarks are saturated, with the best models clearly outperforming the best humans and achieving near perfect scores. We survey the legal NLP literature and select 11 datasets covering 24 languages, creating LEXTREME. To provide a fair comparison, we propose two aggregate scores, one based on the datasets and one on the languages. The best baseline ( XLM-R large) achieves both a dataset aggregate score a language aggregate score of 61.3. This indicates that LEXTREME is still very challenging and leaves ample room for improvement. To make it easy for researchers and practitioners to use, we release LEXTREME on huggingface together with all the code required to evaluate models and a public Weights and Biases project with all the runs.

Leaderboard

LEXTREME Scores

The final LEXTREME score is computed using the harmonic mean of the dataset and the language aggregate score, thus weighing datasets and languages equally, promoting model fairness and robustness following Shavrina and Malykh (2021) and Chalkidis et al,.

We evaluated multilingual models as well as monolingual models. The multilingual models are the following:

ModelSourceParametersVocabulary SizePretraining SpecsPretraining CorporaPretraining Languages
MiniLMWang et al. (2020)118M250K1M steps / BS 2562.5TB CC100100
DistilBertSanh (2019)135M120KBS up to 4000Wikipedia104
mDeberta-v3He et al. (2020, 2021)278M128K500K steps / BS 81922.5TB CC100100
XLM-R baseConneau et al. (2020)278M250K1.5M steps / BS 81922.5TB CC100100
XLM-R largeConneau et al. (2020)560M250K1.5M steps / BS 81922.5TB CC100100
Legal-XLM-R-baseNiklaus et al. 2023184M128K1M steps / BS 512689GB MLP24
Legal-XLM-R-largeNiklaus et al. 2023435M128K500K steps / BS 512689GB MLP24
Legal-XLM-LF-baseNiklaus et al. 2023208M128K50K steps / BS 512689GB MLP24
Legal-mono-R-baseNiklaus et al. 2023111M32K200K steps / BS 512689GB MLP1
Legal-mono-R-largeNiklaus et al. 2023337M32K500K steps / BS 512689GB MLP1

In the following, we will provide the results on the basis of the multilingual models.

Dataset aggregate scores for multilingual models. The best scores are in bold.

We compute the dataset aggregate score by taking the successive harmonic mean of (1.) the languages inside the configurations (e.g., de,fr,it within SJP), (2.) the configurations inside the datasets (e.g., OTS-UL, OTS-CT within OTS), and (3.) the datasets inside LEXTREME (BCD, GAM, etc.).

ModelBCDGAMGLCSJPOTSC19MEUGLNLNRLNBMAPAgg.
MiniLM53.073.342.167.744.15.029.774.084.593.657.856.8
DistilBERT54.569.562.866.856.125.936.471.085.389.660.861.7
mDeBERTa-v360.271.352.269.166.529.737.473.385.194.867.264.3
XLM-R-base63.572.057.469.367.826.433.374.685.894.162.064.2
XLM-R-large58.773.157.469.075.029.042.274.185.095.368.066.1
Legal-XLM-R-base62.572.468.970.270.830.738.673.684.194.169.266.8
Legal-XLM-R-large63.373.959.370.174.934.639.773.183.994.667.366.8
Legal-XLM-LF-base72.474.670.272.969.826.333.172.184.793.366.266.9

Language aggregate scores for multilingual models. The best scores are in bold.

We compute the language aggregate score by taking the successive harmonic mean of (1.) the configurations inside the datasets, (2.) the datasets for the given language (e.g., MAP and MEU for lv), and (3.) the languages inside LEXTREME ( bg,cs, etc.).

ModelbgcsdadeelenesetfifrgahrhuitltlvmtnlplptroskslsvAgg.
MiniLM52.748.642.854.650.334.340.146.342.239.042.829.729.640.544.240.840.829.522.761.659.644.330.043.440.5
DistilBERT54.248.646.060.158.848.050.048.849.647.951.435.931.250.151.941.544.434.634.563.263.851.336.250.146.7
mDeBERTa-v354.151.351.763.657.750.753.350.854.649.254.937.437.555.153.947.052.542.141.065.765.355.437.556.150.5
XLM-R-base56.448.348.360.657.650.147.246.748.649.450.133.632.853.450.044.143.835.241.366.163.745.333.750.047.1
XLM-R-large59.956.056.365.460.856.256.656.556.951.455.442.538.158.558.149.953.939.546.468.666.857.942.459.153.7
Legal-XLM-R-base55.658.850.463.663.766.856.357.052.650.156.638.756.556.157.249.156.041.643.968.266.155.638.654.953.5
Legal-XLM-R-large57.855.650.465.760.769.355.754.556.653.357.239.739.158.160.648.457.239.445.567.365.549.339.756.453.6
Legal-XLM-LF-base54.449.348.164.060.552.849.252.248.248.555.433.034.754.654.845.252.540.140.668.364.148.433.051.348.9
NativeLegalBERT-----53.146.9------45.3------59.0---51.1
NativeBERT54.857.351.263.062.352.042.647.252.449.450.1-37.447.1---37.040.566.563.144.8-55.150.2
Legal-mono-R-base55.949.551.561.361.350.552.153.553.651.152.244.154.151.855.550.059.154.334.467.161.548.853.45853.5

Dataset Summary

LEXTREME consist of three classification task types:

The dataset consists of 11 diverse multilingual legal NLU (natural language understanding) datasets. Six datasets have one single configuration and five datasets have two or three configurations. This leads to a total of 18 tasks (8 SLTC, 5 MLTC and 5 NER).

We use the existing train, validation, and test splits if present. In the other cases we split the data ourselves (80% train, 10% validation and test each).

Supported Tasks

For a detailed description of each task and dataset, see Niklaus et al. (2023). Datasets are abbreviated by three capital letters. Configurations of datasets, in case they exist, are indicated by an additional letter separated by a hyphen.

TaskTypeTrain / Dev / Test ExamplesTrain / Dev / Test Labels
BCD-J (brazilian_court_decisions_judgment)SLTC (Judgment Prediction)3234 / 404 / 4053 / 3 / 3
BCD-U (brazilian_court_decisions_unan)SLTC (Judgment Prediction)1715 / 211 / 2042 / 2 / 2
GAM (german_argument_mining)SLTC (Argument Mining)19271 / 2726 / 30784 / 4 / 4
GLC-V (greek_legal_code_volume)SLTC (Topic Classification)28536 / 9511 / 951647 / 47 / 47
GLC-C (greek_legal_code_chapter)SLTC (Topic Classification)28536 / 9511 / 9516386 / 377 / 374
GLC-S (greek_legal_code_subject)SLTC (Topic Classification)28536 / 9511 / 95162143 / 1679 / 1685
SJP (swiss_judgment_prediction)SLTC (Judgment Prediction)59709 / 8208 / 173572 / 2 / 2
OTS-UL (online_terms_of_service_unfairness_levels)SLTC (Unfairness Classification)2074 / 191 / 4173 / 3 / 3
OTS-CT (online_terms_of_service_clause_topics)MLTC (Unfairness Classification)19942 / 1690 / 42979 / 8 / 9
C19 (covid19_emergency_event)MLTC (Event Classification)3312 / 418 / 4188 / 8 / 8
MEU-1 (multi_eurlex_level_1)MLTC (Topic Classification)817239 / 112500 / 11500021 / 21 / 21
MEU-2 (multi_eurlex_level_2)MLTC (Topic Classification)817239 / 112500 / 115000127 / 126 / 127
MEU-3 (multi_eurlex_level_3)MLTC (Topic Classification)817239 / 112500 / 115000500 / 454 / 465
GLN (greek_legal_ner)NER17699 / 4909 / 401717 / 17 / 17
LNR (legalnero)NER7552 / 966 / 90711 / 9 / 11
LNB (lener_br)NER7828 / 1177 / 139013 / 13 / 13
MAP-C (mapa_coarse)NER27823 / 3354 / 1059013 / 11 / 11
MAP-F (mapa_fine)NER27823 / 3354 / 1059044 / 26 / 34

Setup

It works best with python 3.9 and torch==1.10.0+cu113. Otherwise, we experienced problems with fp16 training and evaluation.

# install torch like this to avoid fp16 problems
pip install torch==1.11.0+cu113 -f https://download.pytorch.org/whl/torch_stable.html
pip install -r requirements.txt

In case you get the error AttributeError: module 'distutils' has no attribute 'version' (https://github.com/pytorch/pytorch/issues/69894) Run

pip install setuptools==59.5.0

In order to log the training results, we used Weights & Biases. When running the script below, you will be asked if you want to use Weights & Biases or not. In case you want to use Weights & Biases too, you should log in to your Weights & Biases account beforehand, by typing the following command in the terminal:

wandb login {WANDB_API_KEY}

You can find WANDB_API_KEY in your profile setting on Weights & Biases after signing up or login.

Frequently Asked Questions (FAQ)

Where are the datasets?

We provide access to LEXTREME at https://huggingface.co/datasets/joelito/lextreme.

For example, to load the swiss_judgment_prediction (Niklaus et al. 2021) dataset, you first simply install the datasets' python library and then make the following call:


from datasets import load_dataset

dataset = load_dataset("joelito/lextreme", "swiss_judgment_prediction")

How to run experiments?

It is possible to reproduce the results of the paper by running the finetuning for each dataset separately. Alternatively, you can run main.py which, in a nutshell, will generate bash scripts for each dataset with the necessary hyperparameters and run them on every available GPU in your system (if available).

The following command will make sure that you run most experiments as described in the paper:

python main.py

It allows a certain degree of customizability by specifying the following arguments:

short argument namefull argument namedescriptiondefault value
-as--accumulation_stepsDefine the number of accumulation_steps.Generated automatically depending on the batch size and the size of the pretrained model
-bz--batch_sizeDefine the batch size.Generated automatically depending on the size of the pretrained model
-gn--gpu_numberDefine which GPU you would like to use. If you want to specify multiple GPUs, seperate the integers by a comma.Available GPUs are detected automatically. If no GPU is available, the CPU is used instead.
-gm--gpu_memoryDefine how much memory your GPUs have. Depending on that the batch size will be calculated automatically. In case the batch size is too big, you can change it manually with -bz.11
-hier--hierarchicalDefine whether you want to use a hierarchical model or not. Caution: this will not work for every task.Defined automatically depending on the dataset
-lang--languageDefine if you want to filter the training dataset by language.all_all_all; only important for multlingual datasets; per default the entire dataset is used
-lc--lower_caseDefine if lower case or not.False
-lmt50Define which kind of language model you would like to use; you can choose between small,base and large language models or all of them.all_all_all = all pretrained language models as decribed in the paper
-los--list_of_seedsDefine the number of training epochs.Three seeds (1,2,3) are used
-lr--learning_rateDefine the learning rate.1e-05
-nte--num_train_epochsDefine the number of training epochs.50
-rmo--running_modeDefine whether you want to run the finetungin on all available training data or just a small portion for testing purposes.default = the entire dataset will be used for finetuning. The other option is experimental which will only take a small fraction of the dataset for experimental purposes.
-t--taskChoose a specific task or all of them.all. The other options are: brazilian_court_decisions_judgment, brazilian_court_decisions_unanimity, covid19_emergency_event, german_argument_mining, greek_legal_code_chapter_level, greek_legal_code_subject_level, greek_legal_code_volume_level, greek_legal_ner, legalnero, lener_br, mapa_ner_coarse_grained, mapa_ner_fine_grained, multi_eurlex_level_1, multi_eurlex_level_2, multi_eurlex_level_3, online_terms_of_service_unfairness_category, online_terms_of_service_unfairness_level, swiss_judgment_prediction
-dmo--download_modeChoose if you want to redownload the datasets or use load them from cache.force_redownload. The other options are reuse_dataset_if_exists, reuse_cache_if_exists. For more information, visit: https://huggingface.co/docs/datasets/v1.4.1/loading_datasets.html.
-od--output_dirSpecify the output directory for the logs.Generated automatically with a time stamp.
-rev-revisionThe specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a git-based system for storing models and other artifacts on huggingface.co, so revision can be any identifier allowed by git.main

For example, if you want to finetune on swiss_judgment_prediction with the seeds [1,2,3], 10 epochs, and all pretrained language models as described in the paper, you can type the following:

python main.py --task swiss_judgment_prediction --list_of_seeds 1,2,3 --num_train_epochs 10

Temporary bash files will be created and saved in the folder temporary_scripts and they will be run immediately. These bash files will be overwritten the next time you run main.py.

If you want to finetune only on, let's say, xlm-roberta-large, you can type the following command.

python main.py --task swiss_judgment_prediction --list_of_seeds 1,2,3 --num_train_epochs 10 --language_model_type xlm-roberta-large

If, additionally, you don't want to make use of a hierarchical model (swiss_judgment_prediction makes use of hierarchical models due to the length of the input documents), you type the following.

python main.py --task swiss_judgment_prediction --list_of_seeds 1,2,3 --num_train_epochs 10 --language_model_type xlm-roberta-large --hierarchical False

Not all tasks support the use of hierarchical types. For example, the code for the named entity recognition tasks has not been optimized to make use of both the non-hierarchical and the hierarchical variants. Therefore, setting -hierarchical to True will cause an error.

How to do hyperparameter search

In case you want to perform hyperparameter search this is possible via the argument do_hyperparameter_search. The values for metric_for_best_model (and accordingly for greater_is_better, see the huggingface documentation) will stay the same, i.e., the hyperparameters will be searched by searching for the lowest evaluation loss. In the following, we provide the command for hyperparameter search for the finetuning task german_argument_mining with the model distilbert-base-multilingual-cased.

python main.py -gn 1 -gm 80 --task german_argument_mining --do_hyperparameter_search True -lmt distilbert-base-multilingual-cased -ld hyperparameter_tuning

Automatically, you will create a new project in wandb which is the same as the name of the logging directory, in the case above hyperparameter_tuning. The runs in wandb will be named according to this pattern: finetuning task

If you want to change the value for metric_for_best_model, add it to the bash command like this:

python main.py -gn 1 -gm 80 --task german_argument_mining --do_hyperparameter_search True -lmt distilbert-base-multilingual-cased -ld hyperparameter_tuning --metric_for_best_model macro-f1

Automatically, greater_is_better will change to true.

You can choose between three types of search methods, i.e., grid, random, bayes (see the wandb documentation). Per default, you will use grid. You can change this by passing search_type_method to the command, like this:

python main.py -gn 1 -gm 80 --task german_argument_mining --do_hyperparameter_search True -lmt distilbert-base-multilingual-cased -ld hyperparameter_tuning --metric_for_best_model macro-f1 --search_type_method bayes

The hyperparamters to search for will be loaded from the json file hyperparameter_search_config.json .

Note that when using the search type method grid you will not be able to use learning rate as an hyperparamter to tune; wandb would through this error: "Invalid sweep config: Parameter learning_rate is a disallowed type with grid search. Grid search requires all parameters to be categorical, constant, int_uniform, or q_uniform. Specification of probabilities for categorical parameters is disallowed in grid search". Therefore, if grid is chosen, the values for learning_rate in hyperparameter_search_config.json are ignored; instead the default learning rate (1e-5) or the one that you specify will be taken.

How can I contribute a dataset to LEXTREME?

If you want to extend the benchmark with your own datasets, you can do so by following the following instructions. Once these steps are finished, make a merge request, and we merge the changes into the main branch.

Add a new dataset

Make your dataset available on hugginface
  1. Make sure your dataset is available on the huggingface hub and has a train, validation and test split.
  2. Make sure that the structure of your dataset is in compliance with the other datasets of LEXTREME.
  3. Create a pull request to the lextreme repository by adding the following to the LEXTREME.py file:
    • Create a dict _{YOUR_DATASET_NAME} (similar to _BRAZILIAN_COURT_DECISIONS_JUDGMENT) containing all the necessary information about your dataset (task_type, input_col, label_col, etc.)
    • Add your dataset to the BUILDER*CONFIGS list: LextremeConfig(name="{your_dataset_name}", \*\**{YOUR_DATASET_NAME})
    • Test that it works correctly by loading your subset with load_dataset("lextreme", "{your_dataset_name}") and inspecting a few examples.

GitHub

The following instructions will suffice only if

  1. Navigate to the folder utils and open the file meta_infos.json.
  2. The file contains several fields with important information about each dataset and finetuning task. Some of this information is essential to run the code. The fields are:

Add a new model

Navigate to the utils folder and open the file meta_infos.json. The key field 'language_models' contains all the language models available for use. If your language model is a general-purpose one, proceed to the key field 'general'. If it is a language model pre-trained on legal data, navigate to the key field 'legal'. Next, specify the language(s) on which your model has been trained, such as 'en', 'de', 'multilingual', etc. Finally, determine the category of your model, i.e., whether it is 'small', 'base', or 'large'. Insert the Hugging Face name of your model into the appropriate field. Remember to save the changes to the JSON file.

References

Please cite the following preprint:

@misc{niklaus2023lextreme,
    title={LEXTREME: A Multi-Lingual and Multi-Task Benchmark for the Legal Domain},
    author={Joel Niklaus and Veton Matoshi and Pooja Rani and Andrea Galassi and Matthias Stürmer and Ilias Chalkidis},
    year={2023},
    eprint={2301.13126},
    archivePrefix={arXiv},
    primaryClass={cs.CL}
}