alea-institute commited on
Commit
aa44b09
·
verified ·
1 Parent(s): f5e95bf

Update README and config files - README.md

Browse files
Files changed (1) hide show
  1. README.md +289 -181
README.md CHANGED
@@ -1,199 +1,307 @@
1
  ---
 
 
2
  library_name: transformers
3
- tags: []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  ---
5
 
6
- # Model Card for Model ID
7
-
8
- <!-- Provide a quick summary of what the model is/does. -->
9
-
10
 
 
11
 
12
  ## Model Details
13
 
14
- ### Model Description
15
-
16
- <!-- Provide a longer summary of what this model is. -->
17
-
18
- This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
19
-
20
- - **Developed by:** [More Information Needed]
21
- - **Funded by [optional]:** [More Information Needed]
22
- - **Shared by [optional]:** [More Information Needed]
23
- - **Model type:** [More Information Needed]
24
- - **Language(s) (NLP):** [More Information Needed]
25
- - **License:** [More Information Needed]
26
- - **Finetuned from model [optional]:** [More Information Needed]
27
-
28
- ### Model Sources [optional]
29
-
30
- <!-- Provide the basic links for the model. -->
31
-
32
- - **Repository:** [More Information Needed]
33
- - **Paper [optional]:** [More Information Needed]
34
- - **Demo [optional]:** [More Information Needed]
35
-
36
- ## Uses
37
-
38
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
-
40
- ### Direct Use
41
-
42
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
43
-
44
- [More Information Needed]
45
-
46
- ### Downstream Use [optional]
47
-
48
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
49
-
50
- [More Information Needed]
51
-
52
- ### Out-of-Scope Use
53
-
54
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
55
-
56
- [More Information Needed]
57
-
58
- ## Bias, Risks, and Limitations
59
-
60
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
61
-
62
- [More Information Needed]
63
-
64
- ### Recommendations
65
-
66
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
67
-
68
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
69
-
70
- ## How to Get Started with the Model
71
-
72
- Use the code below to get started with the model.
73
-
74
- [More Information Needed]
75
-
76
- ## Training Details
77
-
78
- ### Training Data
79
-
80
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
81
-
82
- [More Information Needed]
83
-
84
- ### Training Procedure
85
-
86
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
87
-
88
- #### Preprocessing [optional]
89
-
90
- [More Information Needed]
91
-
92
-
93
- #### Training Hyperparameters
94
-
95
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
96
-
97
- #### Speeds, Sizes, Times [optional]
98
-
99
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
100
-
101
- [More Information Needed]
102
-
103
- ## Evaluation
104
-
105
- <!-- This section describes the evaluation protocols and provides the results. -->
106
-
107
- ### Testing Data, Factors & Metrics
108
-
109
- #### Testing Data
110
-
111
- <!-- This should link to a Dataset Card if possible. -->
112
-
113
- [More Information Needed]
114
-
115
- #### Factors
116
-
117
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
118
-
119
- [More Information Needed]
120
-
121
- #### Metrics
122
-
123
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
124
-
125
- [More Information Needed]
126
-
127
- ### Results
128
-
129
- [More Information Needed]
130
-
131
- #### Summary
132
-
133
-
134
-
135
- ## Model Examination [optional]
136
-
137
- <!-- Relevant interpretability work for the model goes here -->
138
-
139
- [More Information Needed]
140
-
141
- ## Environmental Impact
142
-
143
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
144
-
145
- Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
146
-
147
- - **Hardware Type:** [More Information Needed]
148
- - **Hours used:** [More Information Needed]
149
- - **Cloud Provider:** [More Information Needed]
150
- - **Compute Region:** [More Information Needed]
151
- - **Carbon Emitted:** [More Information Needed]
152
-
153
- ## Technical Specifications [optional]
154
-
155
- ### Model Architecture and Objective
156
-
157
- [More Information Needed]
158
-
159
- ### Compute Infrastructure
160
-
161
- [More Information Needed]
162
-
163
- #### Hardware
164
-
165
- [More Information Needed]
166
-
167
- #### Software
168
-
169
- [More Information Needed]
170
-
171
- ## Citation [optional]
172
-
173
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
174
-
175
- **BibTeX:**
176
-
177
- [More Information Needed]
178
-
179
- **APA:**
180
 
181
- [More Information Needed]
182
 
183
- ## Glossary [optional]
184
 
185
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
 
 
 
 
 
 
186
 
187
- [More Information Needed]
188
 
189
- ## More Information [optional]
 
 
190
 
191
- [More Information Needed]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192
 
193
- ## Model Card Authors [optional]
 
 
194
 
195
- [More Information Needed]
196
 
197
- ## Model Card Contact
 
 
 
 
198
 
199
- [More Information Needed]
 
1
  ---
2
+ language:
3
+ - en
4
  library_name: transformers
5
+ license: cc-by-4.0
6
+ tags:
7
+ - kl3m
8
+ - legal
9
+ - financial
10
+ - mlm
11
+ - roberta
12
+ - embedding
13
+ - uncased
14
+ pipeline_tag: fill-mask
15
+ tags_extended:
16
+ - feature-extraction
17
+ widget:
18
+ - text: "<|cls|> this credit agreement is made and entered into as of january 1, 2025, by and between acme corporation, a delaware <|mask|>, and first national bank, as lender. <|sep|>"
19
+ - example: "<|cls|> the<|mask|> agreement contains the entire understanding between <|sep|>"
20
+ - temperature: 0.7
21
+ - do_sample: true
22
+ date: '2025-01-15T00:00:00.000Z'
23
  ---
24
 
25
+ # kl3m-doc-micro-uncased-001
 
 
 
26
 
27
+ `kl3m-doc-micro-uncased-001` is a domain-specific masked language model (MLM) based on the DeBERTa-v2 architecture, specifically designed for legal and financial document analysis. With approximately 118M parameters, it provides a specialized model for NLP tasks in both fill-mask prediction and feature extraction for document embeddings. This uncased variant is particularly useful for case-insensitive applications, maintaining strong performance while disregarding capitalization differences.
28
 
29
  ## Model Details
30
 
31
+ - **Architecture**: DeBERTa-v2
32
+ - **Size**: 118M parameters
33
+ - **Hidden Size**: 512
34
+ - **Layers**: 16
35
+ - **Attention Heads**: 16
36
+ - **Intermediate Size**: 2048
37
+ - **Max Position Embeddings**: 512
38
+ - **Tokenizer**: [alea-institute/kl3m-004-128k-uncased](https://huggingface.co/alea-institute/kl3m-004-128k-uncased)
39
+ - **Vector Dimension**: 512 (hidden_size)
40
+ - **Pooling Strategy**: CLS token or mean pooling
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
 
42
+ ## Use Cases
43
 
44
+ This model is particularly useful for:
45
 
46
+ - Lightweight document classification in legal and financial domains
47
+ - Entity recognition for specialized terminology
48
+ - Understanding legal citations and references
49
+ - Filling in missing terms in legal documents
50
+ - Feature extraction for downstream legal analysis tasks
51
+ - Document similarity and retrieval tasks where capitalization is not significant
52
+ - Edge computing applications with limited resources
53
 
54
+ The uncased nature of this model makes it more efficient for scenarios where case distinctions are not important to the task, while its micro size makes it suitable for severely resource-constrained environments.
55
 
56
+ ## Standard Test Examples
57
+
58
+ Using our standardized test examples for comparing embedding models:
59
 
60
+ ### Fill-Mask Results
61
+
62
+ 1. **Contract Clause Heading**:
63
+ `"<|cls|> 8. representations and<|mask|>. each party hereby represents and warrants to the other party as of the date hereof as follows: <|sep|>"`
64
+
65
+ Top 5 predictions:
66
+ 1. warranties (0.8665)
67
+ 2. warrants (0.0857)
68
+ 3. warrant (0.0108)
69
+ 4. covenants (0.0079)
70
+ 5. agreements (0.0057)
71
+
72
+ 2. **Defined Term Example**:
73
+ `"<|cls|> \"effective<|mask|>\" means the date on which all conditions precedent set forth in article v are satisfied or waived by the administrative agent. <|sep|>"`
74
+
75
+ Top 5 predictions:
76
+ 1. date (0.9979)
77
+ 2. time (0.0011)
78
+ 3. day (0.0004)
79
+ 4. dates (0.0002)
80
+ 5. deadline (0.0001)
81
+
82
+ 3. **Regulation Example**:
83
+ `"<|cls|> all transactions shall comply with the requirements set forth in the truth in<|mask|> act and its implementing regulation z. <|sep|>"`
84
+
85
+ Top 5 predictions:
86
+ 1. the (0.4650)
87
+ 2. this (0.4385)
88
+ 3. such (0.0104)
89
+ 4. any (0.0050)
90
+ 5. an (0.0045)
91
+
92
+ ### Document Similarity Results
93
+
94
+ Using the standardized document examples for embeddings:
95
+
96
+ | Document Pair | Cosine Similarity (CLS token) | Cosine Similarity (Mean pooling) |
97
+ |---------------|-------------------------------|----------------------------------|
98
+ | Court Complaint vs. Consumer Terms | 0.607 | 0.723 |
99
+ | Court Complaint vs. Credit Agreement | 0.631 | 0.837 |
100
+ | Consumer Terms vs. Credit Agreement | 0.744 | 0.762 |
101
+
102
+ The micro-sized model shows strong document similarity performance despite its compact size, with mean pooling showing particularly good results for capturing similarity between related legal documents. The highest similarity with CLS tokens is between Consumer Terms and Credit Agreement (0.744), while with mean pooling, the highest similarity is between Court Complaint and Credit Agreement (0.837).
103
+
104
+ ## Usage
105
+
106
+ ### Masked Language Modeling
107
+
108
+ For masked language modeling tasks, you can use the simple pipeline API:
109
+
110
+ ```python
111
+ from transformers import pipeline
112
+
113
+ # Load the fill-mask pipeline with the model
114
+ fill_mask = pipeline('fill-mask', model="alea-institute/kl3m-doc-micro-uncased-001")
115
+
116
+ # Example: Contract clause heading
117
+ # Note the mask token placement - directly adjacent to "and" without space
118
+ text = "<|cls|> 8. representations and<|mask|>. each party hereby represents and warrants to the other party as of the date hereof as follows: <|sep|>"
119
+ results = fill_mask(text)
120
+
121
+ # Display predictions
122
+ print("Top predictions:")
123
+ for result in results:
124
+ print(f"- {result['token_str']} (score: {result['score']:.4f})")
125
+
126
+ # Output:
127
+ # Top predictions:
128
+ # - warranties (score: 0.8665)
129
+ # - warrants (score: 0.0857)
130
+ # - warrant (score: 0.0108)
131
+ # - covenants (score: 0.0079)
132
+ # - agreements (score: 0.0057)
133
+ ```
134
+
135
+ ### Feature Extraction for Embeddings
136
+
137
+ For document embeddings and similarity calculations, you can also use the pipeline API:
138
+
139
+ ```python
140
+ from transformers import pipeline
141
+ import numpy as np
142
+ from sklearn.metrics.pairwise import cosine_similarity
143
+
144
+ # Load the feature-extraction pipeline
145
+ extractor = pipeline('feature-extraction', model="alea-institute/kl3m-doc-micro-uncased-001", return_tensors=True)
146
+
147
+ # Example legal documents
148
+ texts = [
149
+ # Court Complaint
150
+ "<|cls|> in the united states district court for the eastern district of pennsylvania\n\njohn doe,\nplaintiff,\n\nvs.\n\nacme corporation,\ndefendant. <|sep|>",
151
+
152
+ # Consumer Terms
153
+ "<|cls|> terms and conditions\n\nlast updated: april 10, 2025\n\nthese terms and conditions govern your access to and use of the service. <|sep|>",
154
+
155
+ # Credit Agreement
156
+ "<|cls|> credit agreement\n\ndated as of april 10, 2025\n\namong\n\nacme borrower inc.,\nas the borrower,\n\nand bank of finance,\nas administrative agent. <|sep|>"
157
+ ]
158
+
159
+ # Strategy 1: CLS token embeddings
160
+ cls_embeddings = []
161
+ for text in texts:
162
+ features = extractor(text)
163
+ # Get the CLS token (first token) embedding
164
+ features_array = features[0].numpy() if hasattr(features[0], 'numpy') else features[0]
165
+ cls_embedding = features_array[0]
166
+ cls_embeddings.append(cls_embedding)
167
+
168
+ # Calculate similarity between documents using CLS tokens
169
+ cls_similarity = cosine_similarity(np.vstack(cls_embeddings))
170
+ print("\nDocument similarity (CLS token):")
171
+ print(np.round(cls_similarity, 3))
172
+ # Output:
173
+ # [[1. 0.607 0.631]
174
+ # [0.607 1. 0.744]
175
+ # [0.631 0.744 1. ]]
176
+
177
+ # Strategy 2: Mean pooling
178
+ mean_embeddings = []
179
+ for text in texts:
180
+ features = extractor(text)
181
+ # Average over all tokens
182
+ features_array = features[0].numpy() if hasattr(features[0], 'numpy') else features[0]
183
+ mean_embedding = np.mean(features_array, axis=0)
184
+ mean_embeddings.append(mean_embedding)
185
+
186
+ # Calculate similarity using mean pooling
187
+ mean_similarity = cosine_similarity(np.vstack(mean_embeddings))
188
+ print("\nDocument similarity (Mean pooling):")
189
+ print(np.round(mean_similarity, 3))
190
+ # Output:
191
+ # [[1. 0.723 0.837]
192
+ # [0.723 1. 0.762]
193
+ # [0.837 0.762 1. ]]
194
+
195
+ # Print pairwise similarities
196
+ doc_names = ["Court Complaint", "Consumer Terms", "Credit Agreement"]
197
+ print("\nPairwise similarities:")
198
+ for i in range(len(doc_names)):
199
+ for j in range(i+1, len(doc_names)):
200
+ print(f"{doc_names[i]} vs. {doc_names[j]}:")
201
+ print(f" - CLS token: {cls_similarity[i, j]:.4f}")
202
+ print(f" - Mean pooling: {mean_similarity[i, j]:.4f}")
203
+ # Output:
204
+ # Pairwise similarities:
205
+ # Court Complaint vs. Consumer Terms:
206
+ # - CLS token: 0.6073
207
+ # - Mean pooling: 0.7233
208
+ # Court Complaint vs. Credit Agreement:
209
+ # - CLS token: 0.6314
210
+ # - Mean pooling: 0.8370
211
+ # Consumer Terms vs. Credit Agreement:
212
+ # - CLS token: 0.7435
213
+ # - Mean pooling: 0.7620
214
+ ```
215
+
216
+ ## Training
217
+
218
+ The model was trained on a diverse corpus of legal and financial documents, ensuring high-quality performance in these domains. It leverages the KL3M tokenizer which provides 9-17% more efficient tokenization for domain-specific content than cl100k_base or the LLaMA/Mistral tokenizers.
219
+
220
+ Training included both masked language modeling (MLM) objectives and attention to dense document representation for retrieval and classification tasks. The model was trained on lowercase text to improve efficiency and reduce model size.
221
+
222
+ ## Intended Usage
223
+
224
+ This model is intended for both:
225
+
226
+ 1. **Masked Language Modeling**: Filling in missing words/terms in legal and financial documents
227
+ 2. **Document Embedding**: Generating fixed-length vector representations for document similarity and classification
228
+
229
+ It is particularly well-suited for resource-constrained environments and applications where case-sensitivity is not important.
230
+
231
+ ## Special Tokens
232
+
233
+ This model includes the following special tokens:
234
+
235
+ - CLS token: `<|cls|>` (ID: 5) - Used for the beginning of input text
236
+ - MASK token: `<|mask|>` (ID: 6) - Used to mark tokens for prediction
237
+ - SEP token: `<|sep|>` (ID: 4) - Used for the end of input text
238
+ - PAD token: `<|pad|>` (ID: 2) - Used for padding sequences to a uniform length
239
+ - BOS token: `<|start|>` (ID: 0) - Beginning of sequence
240
+ - EOS token: `<|end|>` (ID: 1) - End of sequence
241
+ - UNK token: `<|unk|>` (ID: 3) - Unknown token
242
+
243
+ Important usage notes:
244
+
245
+ When using the MASK token for predictions, be aware that this model uses a **space-prefixed BPE tokenizer**. The <|mask|> token should be placed IMMEDIATELY after the previous token with NO space, because most tokens in this tokenizer have an initial space encoded within them. For example: `"word<|mask|>"` rather than `"word <|mask|>"`.
246
+
247
+ This space-aware placement is crucial for getting accurate predictions.
248
+
249
+ ## Limitations
250
+
251
+ While extremely compact, this model has significant limitations:
252
+
253
+ - Limited parameter count (118M) means it captures less nuance than larger language models
254
+ - Uncased nature means it cannot distinguish between different capitalizations
255
+ - Primarily focused on English legal and financial texts
256
+ - Best suited for domain-specific rather than general-purpose tasks
257
+ - Maximum sequence length of 512 tokens may require chunking for lengthy documents
258
+ - Requires domain expertise to interpret results effectively
259
+
260
+ ## References
261
+
262
+ - [KL3M Tokenizers: A Family of Domain-Specific and Character-Level Tokenizers for Legal, Financial, and Preprocessing Applications](https://arxiv.org/abs/2503.17247)
263
+ - [The KL3M Data Project: Copyright-Clean Training Resources for Large Language Models](https://arxiv.org/abs/2504.07854)
264
+
265
+ ## Citation
266
+
267
+ If you use this model in your research, please cite:
268
+
269
+ ```bibtex
270
+ @misc{kl3m-doc-micro-uncased-001,
271
+ author = {ALEA Institute},
272
+ title = {kl3m-doc-micro-uncased-001: A Domain-Specific Uncased Language Model for Legal and Financial Text Analysis},
273
+ year = {2025},
274
+ publisher = {Hugging Face},
275
+ howpublished = {\url{https://huggingface.co/alea-institute/kl3m-doc-micro-uncased-001}}
276
+ }
277
+
278
+ @article{bommarito2025kl3m,
279
+ title={KL3M Tokenizers: A Family of Domain-Specific and Character-Level Tokenizers for Legal, Financial, and Preprocessing Applications},
280
+ author={Bommarito, Michael J and Katz, Daniel Martin and Bommarito, Jillian},
281
+ journal={arXiv preprint arXiv:2503.17247},
282
+ year={2025}
283
+ }
284
+
285
+ @misc{bommarito2025kl3mdata,
286
+ title={The KL3M Data Project: Copyright-Clean Training Resources for Large Language Models},
287
+ author={Bommarito II, Michael J. and Bommarito, Jillian and Katz, Daniel Martin},
288
+ year={2025},
289
+ eprint={2504.07854},
290
+ archivePrefix={arXiv},
291
+ primaryClass={cs.CL}
292
+ }
293
+ ```
294
 
295
+ ## License
296
+
297
+ This model is licensed under [CC-BY 4.0](https://creativecommons.org/licenses/by/4.0/).
298
 
299
+ ## Contact
300
 
301
+ The KL3M model family is maintained by the [ALEA Institute](https://aleainstitute.ai). For technical support, collaboration opportunities, or general inquiries:
302
+
303
+ - Email: [email protected]
304
+ - Website: https://aleainstitute.ai
305
+ - GitHub: https://github.com/alea-institute/kl3m-model-research
306
 
307
+ ![logo](https://aleainstitute.ai/images/alea-logo-ascii-1x1.png)