English
Joelito commited on
Commit
9a969c0
1 Parent(s): b65d239

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +182 -0
README.md ADDED
@@ -0,0 +1,182 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: cc
3
+ language:
4
+ - en
5
+
6
+ datasets:
7
+ - MultiLegalPile
8
+ - LEXTREME
9
+ - LEXGLUE
10
+ ---
11
+ # Model Card for joelito/legal-english-longformer-base
12
+
13
+ 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)), a multilingual dataset from various legal sources covering 24 languages.
14
+
15
+ ## Model Details
16
+
17
+ ### Model Description
18
+
19
+ - **Developed by:** Joel Niklaus: [huggingface](https://huggingface.co/joelito); [email](mailto:joel.niklaus.2@bfh.ch)
20
+ - **Model type:** Transformer-based language model (Longformer)
21
+ - **Language(s) (NLP):** en
22
+ - **License:** CC BY-SA
23
+
24
+ ## Uses
25
+
26
+ ### Direct Use and Downstream Use
27
+
28
+ 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.
29
+
30
+ 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.
31
+
32
+ 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.
33
+
34
+ ### Out-of-Scope Use
35
+
36
+ For tasks such as text generation you should look at model like GPT2.
37
+
38
+ 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.
39
+
40
+ ## Bias, Risks, and Limitations
41
+
42
+ 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.
43
+
44
+ ### Recommendations
45
+
46
+ Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model.
47
+
48
+ ## How to Get Started with the Model
49
+
50
+ 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).
51
+
52
+ ## Training Details
53
+
54
+ 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)).
55
+
56
+ Our pretraining procedure includes the following key steps:
57
+
58
+ (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.
59
+
60
+ (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.
61
+
62
+ (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).
63
+
64
+ (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.
65
+
66
+ (e) Mixed Cased Models: Our models cover both upper- and lowercase letters, similar to recently developed large PLMs.
67
+
68
+ (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.
69
+
70
+ ### Training Data
71
+
72
+ 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)).
73
+
74
+ #### Preprocessing
75
+
76
+ For further details see [Niklaus et al. 2023](https://arxiv.org/abs/2306.02069?utm_source=tldrai)
77
+
78
+ #### Training Hyperparameters
79
+
80
+ - batche size: 512 samples
81
+ - Number of steps: 1M/500K for the base/large model
82
+ - Warm-up steps for the first 5\% of the total training steps
83
+ - Learning rate: (linearly increasing up to) $1e\!-\!4$
84
+ - Word masking: increased 20/30\% masking rate for base/large models respectively
85
+
86
+ ## Evaluation
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-english-longformer-base')
97
+ print(model)
98
+
99
+ LongformerModel(
100
+ (embeddings): LongformerEmbeddings(
101
+ (word_embeddings): Embedding(128000, 768, padding_idx=0)
102
+ (position_embeddings): Embedding(4098, 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): LongformerEncoder(
108
+ (layer): ModuleList(
109
+ (0-11): 12 x LongformerLayer(
110
+ (attention): LongformerAttention(
111
+ (self): LongformerSelfAttention(
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
+ (query_global): Linear(in_features=768, out_features=768, bias=True)
116
+ (key_global): Linear(in_features=768, out_features=768, bias=True)
117
+ (value_global): Linear(in_features=768, out_features=768, bias=True)
118
+ )
119
+ (output): LongformerSelfOutput(
120
+ (dense): Linear(in_features=768, out_features=768, bias=True)
121
+ (LayerNorm): LayerNorm((768,), eps=1e-05, elementwise_affine=True)
122
+ (dropout): Dropout(p=0.1, inplace=False)
123
+ )
124
+ )
125
+ (intermediate): LongformerIntermediate(
126
+ (dense): Linear(in_features=768, out_features=3072, bias=True)
127
+ (intermediate_act_fn): GELUActivation()
128
+ )
129
+ (output): LongformerOutput(
130
+ (dense): Linear(in_features=3072, out_features=768, bias=True)
131
+ (LayerNorm): LayerNorm((768,), eps=1e-05, elementwise_affine=True)
132
+ (dropout): Dropout(p=0.1, inplace=False)
133
+ )
134
+ )
135
+ )
136
+ )
137
+ (pooler): LongformerPooler(
138
+ (dense): Linear(in_features=768, out_features=768, bias=True)
139
+ (activation): Tanh()
140
+ )
141
+ )
142
+
143
+ ```
144
+
145
+ ### Compute Infrastructure
146
+
147
+ Google TPU.
148
+
149
+ #### Hardware
150
+
151
+ Google TPU v3-8
152
+
153
+ #### Software
154
+
155
+ pytorch, transformers.
156
+
157
+ ## Citation [optional]
158
+
159
+ ```
160
+
161
+ @article{Niklaus2023MultiLegalPileA6,
162
+ title={MultiLegalPile: A 689GB Multilingual Legal Corpus},
163
+ author={Joel Niklaus and Veton Matoshi and Matthias Sturmer and Ilias Chalkidis and Daniel E. Ho},
164
+ journal={ArXiv},
165
+ year={2023},
166
+ volume={abs/2306.02069}
167
+ }
168
+
169
+ ```
170
+
171
+ ## Model Card Authors
172
+
173
+ Joel Niklaus: [huggingface](https://huggingface.co/joelito); [email](mailto:joel.niklaus.2@bfh.ch)
174
+
175
+ Veton Matoshi: [huggingface](https://huggingface.co/kapllan); [email](mailto:msv3@bfh.ch)
176
+
177
+ ## Model Card Contact
178
+
179
+ Joel Niklaus: [huggingface](https://huggingface.co/joelito); [email](mailto:joel.niklaus.2@bfh.ch)
180
+
181
+ Veton Matoshi: [huggingface](https://huggingface.co/kapllan); [email](mailto:msv3@bfh.ch)
182
+