Package: pyeurovoc
IMPORTANT NOTE!This repository is not compatible yet with the latest version of thetransformerslibrary. You need to install a version < 4.11.0.
We recommend and tested withtransformers==4.10.3.We are currently working to migrate the models to the latest version oftransformers.EuroVoc-BERTPyEuroVoc is a tool for legal document classification withEuroVocdescriptors. It supports 22 languages: Bulgarian (bg), Czech (cs), Danish (da), German (de), Greek (el), English (en), Spanish (es), Estonian (et), Finnish (fi), French (fr), Hungarian (hu), Italian (it), Lithuanian (lt), Latvian (lv), Maltese (mt), Dutch (nl), Polish (pl), Portuguese (pt), Romanian (ro), Slovak (sk), Slovenian (sl), Sweedish (sv).The tool uses BERT at its core. The list of BERT variant for each language can be foundhere. The performance of each model is outlined in ourpaper.InstallationMake sure you have Python3 installed and a suitable package for PyTorch. Then, installpyeurovocwith pip:pip install pyeurovocUsageImport theEuroVocBERTclass frompyeurovoc. Instantiate the class with the desired langauge (default is "en") and then simply pass a document text to the model.frompyeurovocimportEuroVocBERTmodel=EuroVocBERT(lang="en")prediction=model("Commission Decision on a modification of the system of aid applied in Italy in respect of shipbuilding")The prediction of the model is a dictionary that contains the predicted ID descriptors as keys together with their confidence score as values.{'1519':0.9990228414535522,'889':0.9199628829956055,'155':0.8993383646011353,'5541':0.6949614882469177,'365':0.03358528017997742,'431':0.03317515179514885}The number of most probable labels returned by the model is controlled by thenum_labelsparameter (default is 6).prediction=model("Commission Decision on a modification of the system of aid applied in Italy in respect of shipbuilding",num_labels=4)Which outputs:{'1519':0.9990228414535522,'889':0.9199628829956055,'155':0.8993383646011353,'5541':0.6949614882469177}Training your own modelsDownload DatasetFirstly, you need to download the datasets. Use thedownload_datasets.shscript in data to do that../download_datasets.shPreprocessOnce the datasets has finished downloading, you need to preprocess them using thepreprocess.pyscript. It takes as input the model per language configuration file and the path to the dataset.python preprocess.py --config [model_config] --data_path [dataset_path]TrainTraining is done using thetrain.pyscript. It will automatically load the preprocessed files created by the previous step, and will save the best model for each split at the path given by the-save_pathargument. To view the full list of available arguments, runpython train.py --help.python train.py --config [model_config] --data_path [dataset_path] 
                --epochs [n_epochs] --batch_size [batch_size] 
                --max_grad_norm [max_grad_norm]
                --device [device]
                --save_path [model_save_path]
                --logging_step [logging_step]
                --verbose [verbose]EvaluateTo evaluate the performance of each model on a split, run theevaluate.pyscript. As in the case of training, it provides several arguments that can be visualized withpython evaluate.py --help.python evaluate.py --config [model_config] --mt_labels [mt_labels_path] --data_path [dataset_path]
                   --models_path [models_ckpt_path] 
                   --batch_size [batch_size]
                   --device [device]
                   --output_path [results_output_path]
                   --loggin_step [logging_step]
                   --verbose [verbose]AcknowledgmentsThis research was supported by the EC grant no. INEA/CEF/ICT/A2017/1565710 for the Action no. 2017-EU-IA-0136 entitled “Multilingual Resources for CEF.AT in the legal domain” (MARCELL).CreditsPlease consider citing the followingpaperas a thank you to the authors of the PyEuroVoc:Avram, Andrei-Marius, Vasile Pais, and Dan Tufis. "PyEuroVoc: A Tool for Multilingual Legal Document Classification with EuroVoc Descriptors." arXiv preprint arXiv:2108.01139 (2021).or in .bibtex format:@article{avram2021pyeurovoc,
  title={PyEuroVoc: A Tool for Multilingual Legal Document Classification with EuroVoc Descriptors},
  author={Avram, Andrei-Marius and Pais, Vasile and Tufis, Dan},
  journal={arXiv preprint arXiv:2108.01139},
  year={2021}
}