svercoutere commited on
Commit
2f0f7fd
·
0 Parent(s):

Duplicate from svercoutere/longformer-classifier-refinement-abb

Browse files
.gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: transformers
3
+ tags:
4
+ - transformers
5
+ - pytorch
6
+ - bert
7
+ - legal-domain
8
+ - entity-classification
9
+ - sequence-classification
10
+ - NER
11
+ - longformer
12
+ - token-classification
13
+ - label-studio
14
+ - english
15
+ - fine-tuned
16
+ ---
17
+
18
+ # Model Card for Model ID
19
+
20
+ <!-- Provide a quick summary of what the model is/does. -->
21
+
22
+
23
+ # Legal-BERT Base Entity Classifier
24
+
25
+ ## Overview
26
+ A fine-tuned Longformer-based model for classifying legal entities (such as locations and dates) within the context of legal decision texts.
27
+ The model is based on `allenai/longformer` and is trained to predict the type of a marked entity span, given its context, using special entity markers `[E] ... [/E]`.
28
+
29
+ ## Model Details
30
+ - **Model Name:** longformer-classifier-refinement-abb
31
+ - **Architecture:** Longformer (allenai/longformer)
32
+ - **Task:** Entity Classification (NER-style, entity-in-context classification)
33
+ - **Framework:** PyTorch, Hugging Face Transformers
34
+ - **Author:** S. Vercoutere
35
+
36
+ ## Intended Use
37
+ - **Purpose:** Automatic classification of legal entities (e.g., location, date) in municipal or governmental decision documents.
38
+ - **Not Intended For:** General-purpose NER, non-legal domains, or tasks outside entity classification.
39
+
40
+ ## Training Data
41
+ - **Source:** Annotated legal decision texts from Ghent/Freiburg/Bamberg.
42
+ - **Entity Types:**
43
+ - Locations: `impact_location`, `context_location`
44
+ - Dates: `publication_date`, `session_date`, `entry_date`, `expiry_date`, `legal_date`, `context_date`, `validity_period`, `context_period`
45
+ - **Preprocessing:**
46
+ - XML-like tags in text, with entities wrapped in `<entity_type>...</entity_type>`.
47
+ - For training, one entity per sample is marked with `[E] ... [/E]` in context.
48
+ - Dataset balanced to max 5000 samples per label.
49
+
50
+ ## Training Procedure
51
+ - **Model:** `nlpaueb/legal-bert-base-uncased`
52
+ - **Tokenization:** Hugging Face AutoTokenizer, with `[E]` and `[/E]` as additional special tokens.
53
+ - **Max Sequence Length:** 2048 (trained)
54
+ - **Batch Size:** 4
55
+ - **Optimizer:** AdamW
56
+ - **Learning Rate:** 2e-5
57
+ - **Epochs:** 10
58
+ - **Mixed Precision:** Yes (AMP)
59
+ - **Validation Split:** 20%
60
+ - **Evaluation Metrics:** Accuracy, F1, confusion matrix
61
+
62
+ ## Evaluation
63
+
64
+ **Validation Accuracy:** 0.8454 (on held-out validation set)
65
+
66
+ **Detailed Entity-Level Evaluation:**
67
+
68
+ | Entity Label | Precision | Recall | F1-score | Support |
69
+ | ---------------- | --------- | ------ | ---------- | ------- |
70
+ | context_date | 0.9272 | 0.9405 | 0.9338 | 975 |
71
+ | context_location | 0.9671 | 0.9751 | 0.9711 | 843 |
72
+ | context_period | 0.9744 | 0.8321 | 0.8976 | 137 |
73
+ | entry_date | 0.9528 | 0.9587 | 0.9557 | 484 |
74
+ | expiry_date | 0.8980 | 0.9496 | 0.9231 | 139 |
75
+ | impact_location | 0.9501 | 0.9559 | 0.9530 | 997 |
76
+ | legal_date | 1.0000 | 0.9926 | 0.9963 | 943 |
77
+ | publication_date | 0.9501 | 0.9870 | 0.9682 | 386 |
78
+ | session_date | 0.9597 | 0.9597 | 0.9597 | 347 |
79
+ | validity_period | 0.9932 | 0.9379 | 0.9648 | 467 |
80
+ | **accuracy** | | | **0.9601** | 5718 |
81
+ | **macro avg** | 0.9572 | 0.9489 | 0.9523 | 5718 |
82
+ | **weighted avg** | 0.9606 | 0.9601 | 0.9601 | 5718 |
83
+
84
+
85
+ ## Usage Example
86
+ ```python
87
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
88
+ import torch
89
+
90
+ tokenizer = AutoTokenizer.from_pretrained("svercoutere/longformer-classifier-refinement-abb")
91
+ model = AutoModelForSequenceClassification.from_pretrained("svercoutere/longformer-classifier-refinement-abb")
92
+
93
+ def classify_entity(entity_text, context_text):
94
+ marked_text = context_text.replace(entity_text, f"[E] {entity_text} [/E]", 1)
95
+ inputs = tokenizer(marked_text, return_tensors="pt", truncation=True, max_length=2048, padding="max_length")
96
+ with torch.no_grad():
97
+ outputs = model(**inputs)
98
+ pred = torch.argmax(outputs.logits, dim=-1).item()
99
+ return pred # Map to label using label_encoder.classes_
100
+ ```
101
+
102
+ ## Limitations & Bias
103
+ - The model is trained on legal texts from specific municipalities and may not generalize to other domains or languages.
104
+ - Only entity types present in the training data are supported.
105
+ - The model expects entities to be marked with `[E] ... [/E]` in the input.
106
+
107
+ ## Citation
108
+ If you use this model, please cite:
109
+
110
+ ```
111
+ @misc{longformer-classifier-refinement-abb,
112
+ author = {S. Vercoutere},
113
+ title = {Longformer Entity Refinement},
114
+ year = {2026},
115
+ howpublished = {\url{https://huggingface.co/svercoutere/longformer-classifier-refinement-abb}}
116
+ }
117
+ ```
118
+
added_tokens.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "[/E]": 50266,
3
+ "[E]": 50265
4
+ }
config.json ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "LongformerForSequenceClassification"
4
+ ],
5
+ "attention_mode": "longformer",
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "attention_window": [
8
+ 512,
9
+ 512,
10
+ 512,
11
+ 512,
12
+ 512,
13
+ 512,
14
+ 512,
15
+ 512,
16
+ 512,
17
+ 512,
18
+ 512,
19
+ 512
20
+ ],
21
+ "bos_token_id": 0,
22
+ "dtype": "float32",
23
+ "eos_token_id": 2,
24
+ "gradient_checkpointing": false,
25
+ "hidden_act": "gelu",
26
+ "hidden_dropout_prob": 0.1,
27
+ "hidden_size": 768,
28
+ "id2label": {
29
+ "0": "LABEL_0",
30
+ "1": "LABEL_1",
31
+ "2": "LABEL_2",
32
+ "3": "LABEL_3",
33
+ "4": "LABEL_4",
34
+ "5": "LABEL_5",
35
+ "6": "LABEL_6",
36
+ "7": "LABEL_7",
37
+ "8": "LABEL_8",
38
+ "9": "LABEL_9"
39
+ },
40
+ "ignore_attention_mask": false,
41
+ "initializer_range": 0.02,
42
+ "intermediate_size": 3072,
43
+ "label2id": {
44
+ "LABEL_0": 0,
45
+ "LABEL_1": 1,
46
+ "LABEL_2": 2,
47
+ "LABEL_3": 3,
48
+ "LABEL_4": 4,
49
+ "LABEL_5": 5,
50
+ "LABEL_6": 6,
51
+ "LABEL_7": 7,
52
+ "LABEL_8": 8,
53
+ "LABEL_9": 9
54
+ },
55
+ "layer_norm_eps": 1e-05,
56
+ "max_position_embeddings": 4098,
57
+ "model_type": "longformer",
58
+ "num_attention_heads": 12,
59
+ "num_hidden_layers": 12,
60
+ "onnx_export": false,
61
+ "pad_token_id": 1,
62
+ "problem_type": "single_label_classification",
63
+ "sep_token_id": 2,
64
+ "transformers_version": "4.57.3",
65
+ "type_vocab_size": 1,
66
+ "vocab_size": 50267
67
+ }
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6cfe293229aee94941ece63f93e9b032d48504bc149cef2d0e66994e80afb260
3
+ size 594708936
special_tokens_map.json ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "additional_special_tokens": [
3
+ {
4
+ "content": "[E]",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false
9
+ },
10
+ {
11
+ "content": "[/E]",
12
+ "lstrip": false,
13
+ "normalized": false,
14
+ "rstrip": false,
15
+ "single_word": false
16
+ }
17
+ ],
18
+ "bos_token": "<s>",
19
+ "cls_token": "<s>",
20
+ "eos_token": "</s>",
21
+ "mask_token": {
22
+ "content": "<mask>",
23
+ "lstrip": true,
24
+ "normalized": false,
25
+ "rstrip": false,
26
+ "single_word": false
27
+ },
28
+ "pad_token": "<pad>",
29
+ "sep_token": "</s>",
30
+ "unk_token": "<unk>"
31
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "added_tokens_decoder": {
4
+ "0": {
5
+ "content": "<s>",
6
+ "lstrip": false,
7
+ "normalized": true,
8
+ "rstrip": false,
9
+ "single_word": false,
10
+ "special": true
11
+ },
12
+ "1": {
13
+ "content": "<pad>",
14
+ "lstrip": false,
15
+ "normalized": true,
16
+ "rstrip": false,
17
+ "single_word": false,
18
+ "special": true
19
+ },
20
+ "2": {
21
+ "content": "</s>",
22
+ "lstrip": false,
23
+ "normalized": true,
24
+ "rstrip": false,
25
+ "single_word": false,
26
+ "special": true
27
+ },
28
+ "3": {
29
+ "content": "<unk>",
30
+ "lstrip": false,
31
+ "normalized": true,
32
+ "rstrip": false,
33
+ "single_word": false,
34
+ "special": true
35
+ },
36
+ "50264": {
37
+ "content": "<mask>",
38
+ "lstrip": true,
39
+ "normalized": false,
40
+ "rstrip": false,
41
+ "single_word": false,
42
+ "special": true
43
+ },
44
+ "50265": {
45
+ "content": "[E]",
46
+ "lstrip": false,
47
+ "normalized": false,
48
+ "rstrip": false,
49
+ "single_word": false,
50
+ "special": true
51
+ },
52
+ "50266": {
53
+ "content": "[/E]",
54
+ "lstrip": false,
55
+ "normalized": false,
56
+ "rstrip": false,
57
+ "single_word": false,
58
+ "special": true
59
+ }
60
+ },
61
+ "additional_special_tokens": [
62
+ "[E]",
63
+ "[/E]"
64
+ ],
65
+ "bos_token": "<s>",
66
+ "clean_up_tokenization_spaces": false,
67
+ "cls_token": "<s>",
68
+ "eos_token": "</s>",
69
+ "errors": "replace",
70
+ "extra_special_tokens": {},
71
+ "mask_token": "<mask>",
72
+ "model_max_length": 1000000000000000019884624838656,
73
+ "pad_token": "<pad>",
74
+ "sep_token": "</s>",
75
+ "tokenizer_class": "LongformerTokenizer",
76
+ "trim_offsets": true,
77
+ "unk_token": "<unk>"
78
+ }
vocab.json ADDED
The diff for this file is too large to render. See raw diff