# LegalBert-pt

## Introduction

LegalBert-pt is a language model for the legal domain in the Portuguese language. The model was pre-trained to acquire specialization for the domain, and later it could be adjusted for use in specific tasks. Two versions of the model were created: one as a complement to the BERTimbau model, and the other from scratch. The effectiveness of the model based on BERTimbau was evident when analyzing the perplexity measure of the models. Experiments were also carried out in the tasks of identifying legal entities and classifying legal petitions. The results show that the use of specific language models outperforms those obtained using the generic language model in all tasks, suggesting that the specialization of the language model for the legal domain is an important factor for improving the accuracy of learning algorithms.

## Available models
|Model|Initial model|#Layers|#Params|
|-|-|-|-|
|LegalBert-pt SC| |12|110M|
|LegalBert-pt FP| neuralmind/bert-base-portuguese-cased	| 12 | 110M |

## Dataset

To pretrain various versions of the LegalBert-pt language model, we collected a total of 1.5 million legal documents in Portuguese from ten Brazilian courts. These documents consisted of four types: initial petitions, petitions, decisions, and sentences. Table shows the distribution of these documents.

The data were obtained from the Codex system of the Brazilian National Council of Justice (CNJ), which maintains the largest and most diverse set of legal texts in Brazilian Portuguese. As part of an agreement established with the researchers who authored this article, the CNJ provided these data for our research.

|Data source|Number of documents|%|
|-|-|-|
|Court of Justice of the State of Ceará|80,504|5.37\%|
|Court of Justice of the State of Piauí|90,514|6.03|
|Court of Justice of the State of Rio de Janeiro|33,320|2.22|
|Court of Justice of the State of Rondônia|971,615|64.77|
|Federal Regional Court of the 3rd Region|70,196|4.68|
|Federal Regional Court of the 5th Region|6,767|0.45|
|Regional Labor Court of the 9th Region|16,133|1.08|
|Regional Labor Court of the 11th Region|5,351|0.36|
|Regional Labor Court of the 13th Region|155,567|10.37|
|Regional Labor Court of the 23th Region|70,033|4.67|
|Total|1,500,000|100.00\% |

## Usage

```python
from transformers import AutoTokenizer  # Or BertTokenizer
from transformers import AutoModelForPreTraining  # Or BertForPreTraining for loading pretraining heads
from transformers import AutoModel  # or BertModel, for BERT without pretraining heads
  
model = AutoModelForPreTraining.from_pretrained('raquelsilveira/legalbertpt_fp')
tokenizer = AutoTokenizer.from_pretrained('raquelsilveira/legalbertpt_fp')
```
{"license": "openrail"}
transformers pytorch bert fill-mask license:openrail autotrain_compatible endpoints_compatible region:us
TAGS
#transformers #pytorch #bert #fill-mask #license-openrail #autotrain_compatible #endpoints_compatible #region-us 

LegalBert-pt
============


Introduction
------------


LegalBert-pt is a language model for the legal domain in the Portuguese language. The model was pre-trained to acquire specialization for the domain, and later it could be adjusted for use in specific tasks. Two versions of the model were created: one as a complement to the BERTimbau model, and the other from scratch. The effectiveness of the model based on BERTimbau was evident when analyzing the perplexity measure of the models. Experiments were also carried out in the tasks of identifying legal entities and classifying legal petitions. The results show that the use of specific language models outperforms those obtained using the generic language model in all tasks, suggesting that the specialization of the language model for the legal domain is an important factor for improving the accuracy of learning algorithms.


Available models
----------------



Dataset
-------


To pretrain various versions of the LegalBert-pt language model, we collected a total of 1.5 million legal documents in Portuguese from ten Brazilian courts. These documents consisted of four types: initial petitions, petitions, decisions, and sentences. Table shows the distribution of these documents.


The data were obtained from the Codex system of the Brazilian National Council of Justice (CNJ), which maintains the largest and most diverse set of legal texts in Brazilian Portuguese. As part of an agreement established with the researchers who authored this article, the CNJ provided these data for our research.


Data source: Court of Justice of the State of Ceará, Number of documents: 80,504, %: 5.37%
Data source: Court of Justice of the State of Piauí, Number of documents: 90,514, %: 6.03
Data source: Court of Justice of the State of Rio de Janeiro, Number of documents: 33,320, %: 2.22
Data source: Court of Justice of the State of Rondônia, Number of documents: 971,615, %: 64.77
Data source: Federal Regional Court of the 3rd Region, Number of documents: 70,196, %: 4.68
Data source: Federal Regional Court of the 5th Region, Number of documents: 6,767, %: 0.45
Data source: Regional Labor Court of the 9th Region, Number of documents: 16,133, %: 1.08
Data source: Regional Labor Court of the 11th Region, Number of documents: 5,351, %: 0.36
Data source: Regional Labor Court of the 13th Region, Number of documents: 155,567, %: 10.37
Data source: Regional Labor Court of the 23th Region, Number of documents: 70,033, %: 4.67
Data source: Total, Number of documents: 1,500,000, %: 100.00%


Usage
-----



TAGS
#transformers #pytorch #bert #fill-mask #license-openrail #autotrain_compatible #endpoints_compatible #region-us 
