kapllan commited on
Commit
2e67c46
1 Parent(s): 47048d0

Added a model card

Browse files
Files changed (1) hide show
  1. README.md +178 -0
README.md ADDED
@@ -0,0 +1,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: cc
3
+ ---
4
+
5
+ # Model Card for joelito/legal-swiss-roberta-base
6
+
7
+ <!-- Provide a quick summary of what the model is/does. -->
8
+
9
+ This model is a multilingual model pretrained on legal data. It is based on XLM-R ([base](https://huggingface.co/xlm-roberta-base) and [large](https://huggingface.co/xlm-roberta-large)). For pretraining we used [Multi Legal Pile](https://huggingface.co/datasets/joelito/Multi_Legal_Pile) ([Niklaus et al. 2023](https://arxiv.org/abs/2306.02069?utm_source=tldrai)), a multilingual dataset from various legal sources covering 24 languages.
10
+
11
+ ## Model Details
12
+
13
+ ### Model Description
14
+
15
+ - **Developed by:** Joel Niklaus: [huggingface](https://huggingface.co/joelito); [email](mailto:joel.niklaus.2@bfh.ch)
16
+ - **Model type:** Transformer-based language model (RoBERTa)
17
+ - **Language(s) (NLP):** bg, cs, da, de, el, en, es, et, fi, fr, ga, hr, hu, it, lt, lv, mt, nl, pl, pt, ro, sk, sl, sv
18
+ - **License:** CC BY-SA
19
+
20
+ ## Uses
21
+
22
+ <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
23
+
24
+ ### Direct Use and Downstream Use
25
+
26
+ You can utilize the raw model for masked language modeling since we did not perform next sentence prediction. However, its main purpose is to be fine-tuned for downstream tasks.
27
+
28
+ It's important to note that this model is primarily designed for fine-tuning on tasks that rely on the entire sentence, potentially with masked elements, to make decisions. Examples of such tasks include sequence classification, token classification, or question answering. For text generation tasks, models like GPT-2 are more suitable.
29
+
30
+ Additionally, the model is specifically trained on legal data, aiming to deliver strong performance in that domain. Its performance may vary when applied to non-legal data.
31
+
32
+ ### Out-of-Scope Use
33
+
34
+ For tasks such as text generation you should look at model like GPT2.
35
+
36
+ The model should not be used to intentionally create hostile or alienating environments for people. The model was not trained to be factual or true representations of people or events, and therefore using the models to generate such content is out-of-scope for the abilities of this model.
37
+
38
+ ## Bias, Risks, and Limitations
39
+
40
+ Significant research has explored bias and fairness issues with language models (see, e.g., [Sheng et al. (2021)](https://aclanthology.org/2021.acl-long.330.pdf) and [Bender et al. (2021)](https://dl.acm.org/doi/pdf/10.1145/3442188.3445922)). Predictions generated by the model may include disturbing and harmful stereotypes across protected classes; identity characteristics; and sensitive, social, and occupational groups.
41
+
42
+ ### Recommendations
43
+
44
+ Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model.
45
+
46
+ ## How to Get Started with the Model
47
+
48
+ See [huggingface tutorials](https://huggingface.co/learn/nlp-course/chapter7/1?fw=pt). For masked word prediction see [this tutorial](https://huggingface.co/tasks/fill-mask).
49
+
50
+ ## Training Details
51
+
52
+ This model was pretrained on [Multi Legal Pile](https://huggingface.co/datasets/joelito/Multi_Legal_Pile) ([Niklaus et al. 2023](https://arxiv.org/abs/2306.02069?utm_source=tldrai)).
53
+
54
+ Our pretraining procedure includes the following key steps:
55
+
56
+ (a) Warm-starting: We initialize our models from the original XLM-R checkpoints ([base](https://huggingface.co/xlm-roberta-base) and [large](https://huggingface.co/xlm-roberta-large)) of [Conneau et al. (2019)](https://proceedings.neurips.cc/paper/2019/file/c04c19c2c2474dbf5f7ac4372c5b9af1-Paper.pdf) to benefit from a well-trained base.
57
+
58
+ (b) Tokenization: We train a new tokenizer of 128K BPEs to cover legal language better. However, we reuse the original XLM-R embeddings for lexically overlapping tokens and use random embeddings for the rest.
59
+
60
+ (c) Pretraining: We continue pretraining on Multi Legal Pile with batches of 512 samples for an additional 1M/500K steps for the base/large model. We use warm-up steps, a linearly increasing learning rate, and cosine decay scheduling. During the warm-up phase, only the embeddings are updated, and a higher masking rate and percentage of predictions based on masked tokens are used compared to [Devlin et al. (2019)](https://aclanthology.org/N19-1423).
61
+
62
+ (d) Sentence Sampling: We employ a sentence sampler with exponential smoothing to handle disparate token proportions across cantons and languages, preserving per-canton and language capacity.
63
+
64
+ (e) Mixed Cased Models: Our models cover both upper- and lowercase letters, similar to recently developed large PLMs.
65
+
66
+ (f) Long Context Training: To account for long contexts in legal documents, we train the base-size multilingual model on long contexts with windowed attention. This variant, named Legal-Swiss-LF-base, uses a 15% masking probability, increased learning rate, and similar settings to small-context models.
67
+
68
+ ### Training Data
69
+
70
+ This model was pretrained on [Multi Legal Pile](https://huggingface.co/datasets/joelito/Multi_Legal_Pile) ([Niklaus et al. 2023](https://arxiv.org/abs/2306.02069?utm_source=tldrai)).
71
+
72
+ #### Preprocessing
73
+
74
+ For further details see [Niklaus et al. 2023](https://arxiv.org/abs/2306.02069?utm_source=tldrai)
75
+
76
+ #### Training Hyperparameters
77
+
78
+ - batche size: 512 samples
79
+ - Number of steps: 1M/500K for the base/large model
80
+ - Warm-up steps for the first 5\% of the total training steps
81
+ - Learning rate: (linearly increasing up to) $1e\!-\!4$
82
+ - Word masking: increased 20/30\% masking rate for base/large models respectively
83
+
84
+ ## Evaluation
85
+
86
+ For further insights into the evaluation, we refer to the [trainer state](https://huggingface.co/joelito/legal-swiss-roberta-base/blob/main/last-checkpoint/trainer_state.json). Additional information is available in the [tensorboard](https://huggingface.co/joelito/legal-swiss-roberta-base/tensorboard).
87
+
88
+ For performance on downstream tasks, such as [LEXTREME](https://huggingface.co/datasets/joelito/lextreme) ([Niklaus et al. 2023](https://arxiv.org/abs/2301.13126)) or [LEXGLUE](https://huggingface.co/datasets/lex_glue) ([Chalkidis et al. 2021](https://arxiv.org/abs/2110.00976)), we refer to the results presented in Niklaus et al. (2023) [1](https://arxiv.org/abs/2306.02069), [2](https://arxiv.org/abs/2306.09237).
89
+
90
+ ### Model Architecture and Objective
91
+
92
+ It is a RoBERTa-based model. Run the following code to view the architecture:
93
+
94
+ ```
95
+ from transformers import AutoModel
96
+ model = AutoModel.from_pretrained('joelito/legal-swiss-roberta-base')
97
+ print(model)
98
+
99
+ RobertaModel(
100
+ (embeddings): RobertaEmbeddings(
101
+ (word_embeddings): Embedding(128000, 768, padding_idx=0)
102
+ (position_embeddings): Embedding(514, 768, padding_idx=0)
103
+ (token_type_embeddings): Embedding(1, 768)
104
+ (LayerNorm): LayerNorm((768,), eps=1e-05, elementwise_affine=True)
105
+ (dropout): Dropout(p=0.1, inplace=False)
106
+ )
107
+ (encoder): RobertaEncoder(
108
+ (layer): ModuleList(
109
+ (0-11): 12 x RobertaLayer(
110
+ (attention): RobertaAttention(
111
+ (self): RobertaSelfAttention(
112
+ (query): Linear(in_features=768, out_features=768, bias=True)
113
+ (key): Linear(in_features=768, out_features=768, bias=True)
114
+ (value): Linear(in_features=768, out_features=768, bias=True)
115
+ (dropout): Dropout(p=0.1, inplace=False)
116
+ )
117
+ (output): RobertaSelfOutput(
118
+ (dense): Linear(in_features=768, out_features=768, bias=True)
119
+ (LayerNorm): LayerNorm((768,), eps=1e-05, elementwise_affine=True)
120
+ (dropout): Dropout(p=0.1, inplace=False)
121
+ )
122
+ )
123
+ (intermediate): RobertaIntermediate(
124
+ (dense): Linear(in_features=768, out_features=3072, bias=True)
125
+ (intermediate_act_fn): GELUActivation()
126
+ )
127
+ (output): RobertaOutput(
128
+ (dense): Linear(in_features=3072, out_features=768, bias=True)
129
+ (LayerNorm): LayerNorm((768,), eps=1e-05, elementwise_affine=True)
130
+ (dropout): Dropout(p=0.1, inplace=False)
131
+ )
132
+ )
133
+ )
134
+ )
135
+ (pooler): RobertaPooler(
136
+ (dense): Linear(in_features=768, out_features=768, bias=True)
137
+ (activation): Tanh()
138
+ )
139
+ )
140
+ ```
141
+
142
+ ### Compute Infrastructure
143
+
144
+ Google TPU.
145
+
146
+ #### Hardware
147
+
148
+ Google TPU v3-8
149
+
150
+ #### Software
151
+
152
+ pytorch, transformers.
153
+
154
+ ## Citation [optional]
155
+
156
+ ```
157
+
158
+ @article{Niklaus2023MultiLegalPileA6,
159
+ title={MultiLegalPile: A 689GB Multilingual Legal Corpus},
160
+ author={Joel Niklaus and Veton Matoshi and Matthias Sturmer and Ilias Chalkidis and Daniel E. Ho},
161
+ journal={ArXiv},
162
+ year={2023},
163
+ volume={abs/2306.02069}
164
+ }
165
+
166
+ ```
167
+
168
+ ## Model Card Authors
169
+
170
+ Joel Niklaus: [huggingface](https://huggingface.co/joelito); [email](mailto:joel.niklaus.2@bfh.ch)
171
+
172
+ Veton Matoshi: [huggingface](https://huggingface.co/kapllan); [email](mailto:msv3@bfh.ch)
173
+
174
+ ## Model Card Contact
175
+
176
+ Joel Niklaus: [huggingface](https://huggingface.co/joelito); [email](mailto:joel.niklaus.2@bfh.ch)
177
+
178
+ Veton Matoshi: [huggingface](https://huggingface.co/kapllan); [email](mailto:msv3@bfh.ch)