NER4Legal_SRB is a fine-tuned Named Entity Recognition (NER) model designed for processing Serbian legal documents. This model was created as part of the conference paper "Named Entity Recognition for Serbian Legal Documents: Design, Methodology and Dataset Development", accepted for publication at the 15th International Conference on Information Society and Technology, Kopaonik, Serbia, March 9-12, 2025. The model aims to automate tasks involving legal documents, such as document archiving, search, and retrieval. It leverages the classla/bcms-bertic pre-trained BERT model, carefully adapted to the specific task of identifying and classifying a predefined set of word entities in Serbian legal texts. Model can be run on both CPU and GPU. Provided model was trained on all data from NER4Legal_SRB dataset described in the reference paper.
Abstract
Recent advancements in the field of natural language processing (NLP) and especially large language models (LLMs) and their numerous applications have brought research attention to the design of different document processing tools and enhancements in the process of document archiving, search, and retrieval. The domain of official legal documents is especially interesting due to the vast amount of data generated daily, as well as the significant community of interested practitioners (lawyers, law offices, administrative workers, state institutions, and citizens). Providing efficient ways for automation of everyday work involving legal documents is therefore expected to have significant impact in different fields.
In this work, we present one LLM-based solution for Named Entity Recognition (NER) in the case of legal documents written in Serbian language. It leverages the pre-trained bidirectional encoder representations from transformers (BERT), carefully adapted to the specific task of identifying and classifying specific data points from textual content. Besides novel dataset development for Serbian language (involving public court rulings), presented system design and applied methodology, the paper also discusses achieved performance metrics and their implications for objective assessment of the proposed solution. Performed cross-validation tests on the created manually labeled dataset with a mean F1 score of 0.96 and additional results on the examples of intentionally modified text inputs confirm applicability of the proposed system design and robustness of the developed NER solution.
Base Model
The model is fine-tuned from the classla/bcms-bertic base model, which is a pre-trained BERT model designed for the BCMS (Bosnian, Croatian, Montenegrin, Serbian) languages.
Dataset
This model was fine-tuned on a manually labeled dataset of Serbian legal documents, including public court rulings. The dataset was specifically developed for this task to enable precise identification and classification of entities in Serbian legal texts.
Performance Metrics
The model achieved a mean F1 score of 0.96 during cross-validation tests on the labeled dataset, demonstrating robust performance and applicability to real-world scenarios. For detailed information about performed model evaluation and reported results please consult the original conference paper.
1from transformers import AutoModelForTokenClassification, AutoTokenizer
2import torch
34# Load the model and tokenizer5device = torch.device("cuda"if torch.cuda.is_available()else"cpu")6tokenizer = AutoTokenizer.from_pretrained("kalusev/NER4Legal_SRB", use_auth_token=True)7model = AutoModelForTokenClassification.from_pretrained("kalusev/NER4Legal_SRB", use_auth_token=True).to(device)89# Define the label mapping (id_to_label)10id_to_label ={110:'O',121:'B-COURT',132:'B-DATE',143:'B-DECISION',154:'B-LAW',165:'B-MONEY',176:'B-OFFICIAL GAZZETE',187:'B-PERSON',198:'B-REFERENCE',209:'I-COURT',2110:'I-LAW',2211:'I-MONEY',2312:'I-OFFICIAL GAZZETE',2413:'I-PERSON',2514:'I-REFERENCE'26}2728# NER with GPU/CPU fallback29defperform_ner(text):30"""
31 Perform Named Entity Recognition on a single text with GPU memory fallback.
32 Args:
33 text (str): Input text.
34 Returns:
35 list: List of tokens and predicted labels.
36 """37try:38# Tokenize the input text39 inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True).to(device)40# Get predictions from the model41with torch.no_grad():42 outputs = model(**inputs)43 logits = outputs.logits
44 predictions = torch.argmax(logits, dim=2).squeeze().tolist()4546except RuntimeError as e:47if"CUDA out of memory"instr(e):48print("Switching to CPU due to memory constraints.")49 inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)50with torch.no_grad():51 outputs = model.cpu()(**inputs)# Run model on CPU52 logits = outputs.logits
53 predictions = torch.argmax(logits, dim=2).squeeze().tolist()54else:55raise e # Re-raise other exceptions5657 tokens = tokenizer.convert_ids_to_tokens(inputs["input_ids"].squeeze())58 labels =[id_to_label[pred]for pred in predictions]5960# Filter out special tokens61 results =[62(token, label)63for token, label inzip(tokens, labels)64if token notin tokenizer.all_special_tokens
65]66return results
6768# Example usage69text ="""Rešenjem Apelacionog suda u Novom Sadu, Gž1. 1901/10 od 12.05.2010. godine žalba tuženog je usvojena, a presuda Opštinskog suda u Novom Sadu, P. 5734/04 od 29.01.2009. godine, ukinuta i predmet upućen ovom sudu na ponovno suđenje."""7071# Perform NER72results = perform_ner(text)7374# Print tokens and labels as a formatted table75print("Token | Predicted Label")76print("----------------------------------------")77for token, label in results:78print(f"{token:<17} | {label}")79
SRB4Legal_NER performance in presence of noisy inputs
If you would like to use this software, please consider citing the following publication:
Kalušev, V., Brkljač, B. (2026). Named Entity Recognition for Serbian Legal Documents: Design, Methodology and Dataset Development. In: Transformative Technologies Shaping a Smarter Society. ICIST 2025. Lecture Notes in Networks and Systems, vol 1621. Springer, Cham. https://doi.org/10.1007/978-3-032-04890-5_30
@inproceedings{KalusevNER2025,
author = {Kalu{\v{s}ev, Vladimir and Brklja{\v{c}}, Branko},
booktitle = {Transformative Technologies Shaping a Smarter Society. ICIST 2025. Lecture Notes in Networks and Systems, vol 1621. Springer},
doi = {https://doi.org/10.1007/978-3-032-04890-5_30},
month = mar,
pages = {403--420},
title = {Named entity recognition for Serbian legal documents: {D}esign, methodology and dataset development},
year = {2026}
}
@misc{kalušev2025namedentityrecognitionserbian,
title={Named entity recognition for Serbian legal documents: Design, methodology and dataset development},
author={Vladimir Kalušev and Branko Brkljač},
year={2025},
eprint={2502.10582},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2502.10582},
}