VictorMorand commited on
Commit
b7f4f63
·
verified ·
1 Parent(s): d599142

Update model to new HF format

Browse files
README.md CHANGED
@@ -17,9 +17,17 @@ paper: https://arxiv.org/abs/2510.19410
17
 
18
  # ToMMeR-pythia-2.8b_L5_R64
19
 
 
 
 
 
 
 
20
  ToMMeR is a lightweight probing model extracting emergent mention detection capabilities from early layers representations of any LLM backbone, achieving high Zero Shot recall across a wide set of 13 NER benchmarks.
21
 
22
- ## Checkpoint Details
 
 
23
 
24
  | Property | Value |
25
  |-----------|-------|
@@ -31,28 +39,69 @@ ToMMeR is a lightweight probing model extracting emergent mention detection capa
31
  # Usage
32
 
33
  ## Installation
34
-
35
- Our code can be installed with pip+git, Please visit the [repository](https://github.com/VictorMorand/llm2ner) for more details.
36
 
37
  ```bash
38
  pip install git+https://github.com/VictorMorand/llm2ner.git
39
  ```
40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  ## Fancy Outputs
42
 
 
 
43
  ```python
44
- import llm2ner
45
- from llm2ner import ToMMeR
46
 
47
- tommer = ToMMeR.from_pretrained("llm2ner/ToMMeR-pythia-2.8b_L5_R64")
48
  # load Backbone llm, optionnally cut the unused layer to save GPU space.
49
- llm = llm2ner.utils.load_llm( tommer.llm_name, cut_to_layer=tommer.layer,)
50
  tommer.to(llm.device)
51
 
52
  text = "Large language models are awesome. While trained on language modeling, they exhibit emergent Zero Shot abilities that make them suitable for a wide range of tasks, including Named Entity Recognition (NER). "
53
 
54
  #fancy interactive output
55
- outputs = llm2ner.plotting.demo_inference( text, tommer, llm,
56
  decoding_strategy="threshold", # or "greedy" for flat segmentation
57
  threshold=0.5, # default 50%
58
  show_attn=True,
@@ -89,7 +138,7 @@ outputs = llm2ner.plotting.demo_inference( text, tommer, llm,
89
  <span style="background: lightblue; top: 57px; height: 4px; left: -1px; width: calc(100% + 2px); position: absolute;">
90
  </span>
91
  </span>
92
- are awesome . While trained on
93
  <span style="font-weight: bold; display: inline-block; position: relative; height: 60px;">
94
  language
95
  <span style="background: lightblue; top: 40px; height: 4px; left: -1px; width: calc(100% + 2px); position: absolute;">
@@ -105,7 +154,7 @@ are awesome . While trained on
105
  <span style="background: lightblue; top: 40px; height: 4px; left: -1px; width: calc(100% + 2px); position: absolute;">
106
  </span>
107
  </span>
108
- , they exhibit
109
  <span style="font-weight: bold; display: inline-block; position: relative; height: 60px;">
110
  emergent
111
  <span style="background: lightblue; top: 40px; height: 4px; left: -1px; width: calc(100% + 2px); position: absolute;">
@@ -121,18 +170,18 @@ are awesome . While trained on
121
  <span style="background: lightblue; top: 40px; height: 4px; left: -1px; width: calc(100% + 2px); position: absolute;">
122
  </span>
123
  </span>
124
- that make them suitable for a wide range of
125
  <span style="font-weight: bold; display: inline-block; position: relative; height: 60px;">
126
  tasks
127
  <span style="background: lightblue; top: 40px; height: 4px; left: -1px; width: calc(100% + 2px); position: absolute;">
128
- </span>
129
  <span style="background: lightblue; top: 40px; height: 4px; border-top-left-radius: 3px; border-bottom-left-radius: 3px; left: -1px; width: calc(100% + 2px); position: absolute;">
130
  <span style="background: lightblue; z-index: 10; color: #000; top: -0.5em; padding: 2px 3px; position: absolute; font-size: 0.6em; font-weight: bold; line-height: 1; border-radius: 3px">
131
  PRED
132
  </span>
133
  </span>
134
  </span>
135
- , including
136
  <span style="font-weight: bold; display: inline-block; position: relative; height: 60px;">
137
  Named
138
  <span style="background: lightblue; top: 40px; height: 4px; left: -1px; width: calc(100% + 2px); position: absolute;">
@@ -145,7 +194,7 @@ that make them suitable for a wide range of
145
  </span>
146
  <span style="font-weight: bold; display: inline-block; position: relative; height: 60px;">
147
  Entity
148
-
149
  <span style="background: lightblue; top: 40px; height: 4px; left: -1px; width: calc(100% + 2px); position: absolute;">
150
  </span>
151
  </span>
@@ -154,7 +203,7 @@ that make them suitable for a wide range of
154
  <span style="background: lightblue; top: 40px; height: 4px; left: -1px; width: calc(100% + 2px); position: absolute;">
155
  </span>
156
  </span>
157
- (
158
  <span style="font-weight: bold; display: inline-block; position: relative; height: 60px;">
159
  NER
160
  <span style="background: lightblue; top: 40px; height: 4px; left: -1px; width: calc(100% + 2px); position: absolute;">
@@ -168,42 +217,6 @@ that make them suitable for a wide range of
168
  ) . </div></span>
169
  </div>
170
 
171
-
172
- ## Raw inference
173
- By default, ToMMeR outputs span probabilities, but we also propose built-in options for decoding entities.
174
-
175
- - Inputs:
176
- - tokens (batch, seq): tokens to process,
177
- - model: LLM to extract representation from.
178
- - Outputs: (batch, seq, seq) matrix (masked outside valid spans)
179
-
180
- ```python
181
-
182
- tommer = ToMMeR.from_pretrained("llm2ner/ToMMeR-pythia-2.8b_L5_R64")
183
- # load Backbone llm, optionnally cut the unused layer to save GPU space.
184
- llm = llm2ner.utils.load_llm( tommer.llm_name, cut_to_layer=tommer.layer,)
185
- tommer.to(llm.device)
186
-
187
- #### Raw Inference
188
- text = ["Large language models are awesome"]
189
- print(f"Input text: {text[0]}")
190
-
191
- #tokenize in shape (1, seq_len)
192
- tokens = model.tokenizer(text, return_tensors="pt")["input_ids"].to(device)
193
- # Output raw scores
194
- output = tommer.forward(tokens, model) # (batch_size, seq_len, seq_len)
195
- print(f"Raw Output shape: {output.shape}")
196
-
197
- #use given decoding strategy to infer entities
198
- entities = tommer.infer_entities(tokens=tokens, model=model, threshold=0.5, decoding_strategy="greedy")
199
- str_entities = [ model.tokenizer.decode(tokens[0,b:e+1]) for b, e in entities[0]]
200
- print(f"Predicted entities: {str_entities}")
201
-
202
- >>> Input text: Large language models are awesome
203
- >>> Raw Output shape: torch.Size([1, 6, 6])
204
- >>> Predicted entities: ['Large language models']
205
- ```
206
-
207
  Please visit the [repository](https://github.com/VictorMorand/llm2ner) for more details and a demo notebook.
208
 
209
  ## Evaluation Results
@@ -225,18 +238,17 @@ Please visit the [repository](https://github.com/VictorMorand/llm2ner) for more
225
  | Ontonotes | 0.2296 | 0.6734 | 0.3424 | 42193 |
226
  | Aggregated | 0.2121 | 0.8771 | 0.3415 | 353250 |
227
  | Mean | 0.2633 | 0.8198 | 0.3904 | 353250 |
228
-
229
  ## Citation
230
  If using this model or the approach, please cite the associated paper:
231
  ```
232
  @misc{morand2025tommerefficiententity,
233
- title={ToMMeR -- Efficient Entity Mention Detection from Large Language Models},
234
  author={Victor Morand and Nadi Tomeh and Josiane Mothe and Benjamin Piwowarski},
235
  year={2025},
236
  eprint={2510.19410},
237
  archivePrefix={arXiv},
238
  primaryClass={cs.CL},
239
- url={https://arxiv.org/abs/2510.19410},
240
  }
241
  ```
242
 
 
17
 
18
  # ToMMeR-pythia-2.8b_L5_R64
19
 
20
+
21
+ [![Paper](https://img.shields.io/badge/Paper-Arxiv-red)](https://arxiv.org/abs/2510.19410)
22
+ [![All Models](https://img.shields.io/badge/🤗%20Hugging%20Face%20Models-blue)](https://huggingface.co/llm2ner)
23
+ [![GitHub](https://img.shields.io/badge/GitHub-Code-blue)](https://github.com/VictorMorand/llm2ner)
24
+
25
+
26
  ToMMeR is a lightweight probing model extracting emergent mention detection capabilities from early layers representations of any LLM backbone, achieving high Zero Shot recall across a wide set of 13 NER benchmarks.
27
 
28
+ ## Model Details
29
+
30
+ This model can be plugged at layer 5 of `EleutherAI/pythia-2.8b`, with a computational overhead not greater than an additional attention head.
31
 
32
  | Property | Value |
33
  |-----------|-------|
 
39
  # Usage
40
 
41
  ## Installation
42
+ To use ToMMeR, you need to install its codebase first.
 
43
 
44
  ```bash
45
  pip install git+https://github.com/VictorMorand/llm2ner.git
46
  ```
47
 
48
+
49
+ ## Raw inference
50
+ By default, ToMMeR outputs span probabilities, but we also propose built-in options for decoding entities.
51
+
52
+ - Inputs:
53
+ - tokens (batch, seq): tokens to process,
54
+ - model: LLM to extract representation from.
55
+ - Outputs: (batch, seq, seq) matrix (masked outside valid spans)
56
+
57
+ ```python
58
+ from xpm_torch.huggingface import TorchHFHub
59
+ from llm2ner import ToMMeR, utils
60
+
61
+ tommer: ToMMeR = TorchHFHub.from_pretrained("llm2ner/ToMMeR-pythia-2.8b_L5_R64")
62
+ # load Backbone llm, optionnally cut the unused layer to save GPU space.
63
+ llm = utils.load_llm( tommer.llm_name, cut_to_layer=tommer.layer,)
64
+ tommer.to(llm.device)
65
+
66
+ #### Raw Inference
67
+ text = ["Large language models are awesome"]
68
+ print(f"Input text: {text[0]}")
69
+
70
+ #tokenize in shape (1, seq_len)
71
+ tokens = llm.tokenizer(text, return_tensors="pt")["input_ids"].to(llm.device)
72
+ # Output raw scores
73
+ output = tommer.forward(tokens, llm) # (batch_size, seq_len, seq_len)
74
+ print(f"Raw Output shape: {output.shape}")
75
+
76
+ #use given decoding strategy to infer entities
77
+ entities = tommer.infer_entities(tokens=tokens, model=llm, threshold=0.5, decoding_strategy="greedy")
78
+ str_entities = [ llm.tokenizer.decode(tokens[0,b:e+1]) for b, e in entities[0]]
79
+ print(f"Predicted entities: {str_entities}")
80
+
81
+ >>>INFO:root:Cut LlamaModel with 16 layers to 7 layers
82
+ >>> Input text: Large language models are awesome
83
+ >>> Raw Output shape: torch.Size([1, 6, 6])
84
+ >>> Predicted entities: ['Large language models']
85
+ ```
86
+
87
+
88
  ## Fancy Outputs
89
 
90
+ We also provide inference and plotting utils in `llm2ner.plotting`.
91
+
92
  ```python
93
+ from xpm_torch.huggingface import TorchHFHub
94
+ from llm2ner import ToMMeR, utils, plotting
95
 
96
+ tommer: ToMMeR = TorchHFHub.from_pretrained("llm2ner/ToMMeR-pythia-2.8b_L5_R64")
97
  # load Backbone llm, optionnally cut the unused layer to save GPU space.
98
+ llm = utils.load_llm( tommer.llm_name, cut_to_layer=tommer.layer,)
99
  tommer.to(llm.device)
100
 
101
  text = "Large language models are awesome. While trained on language modeling, they exhibit emergent Zero Shot abilities that make them suitable for a wide range of tasks, including Named Entity Recognition (NER). "
102
 
103
  #fancy interactive output
104
+ outputs = plotting.demo_inference( text, tommer, llm,
105
  decoding_strategy="threshold", # or "greedy" for flat segmentation
106
  threshold=0.5, # default 50%
107
  show_attn=True,
 
138
  <span style="background: lightblue; top: 57px; height: 4px; left: -1px; width: calc(100% + 2px); position: absolute;">
139
  </span>
140
  </span>
141
+ are awesome . While trained on
142
  <span style="font-weight: bold; display: inline-block; position: relative; height: 60px;">
143
  language
144
  <span style="background: lightblue; top: 40px; height: 4px; left: -1px; width: calc(100% + 2px); position: absolute;">
 
154
  <span style="background: lightblue; top: 40px; height: 4px; left: -1px; width: calc(100% + 2px); position: absolute;">
155
  </span>
156
  </span>
157
+ , they exhibit
158
  <span style="font-weight: bold; display: inline-block; position: relative; height: 60px;">
159
  emergent
160
  <span style="background: lightblue; top: 40px; height: 4px; left: -1px; width: calc(100% + 2px); position: absolute;">
 
170
  <span style="background: lightblue; top: 40px; height: 4px; left: -1px; width: calc(100% + 2px); position: absolute;">
171
  </span>
172
  </span>
173
+ that make them suitable for a wide range of
174
  <span style="font-weight: bold; display: inline-block; position: relative; height: 60px;">
175
  tasks
176
  <span style="background: lightblue; top: 40px; height: 4px; left: -1px; width: calc(100% + 2px); position: absolute;">
177
+ </span>
178
  <span style="background: lightblue; top: 40px; height: 4px; border-top-left-radius: 3px; border-bottom-left-radius: 3px; left: -1px; width: calc(100% + 2px); position: absolute;">
179
  <span style="background: lightblue; z-index: 10; color: #000; top: -0.5em; padding: 2px 3px; position: absolute; font-size: 0.6em; font-weight: bold; line-height: 1; border-radius: 3px">
180
  PRED
181
  </span>
182
  </span>
183
  </span>
184
+ , including
185
  <span style="font-weight: bold; display: inline-block; position: relative; height: 60px;">
186
  Named
187
  <span style="background: lightblue; top: 40px; height: 4px; left: -1px; width: calc(100% + 2px); position: absolute;">
 
194
  </span>
195
  <span style="font-weight: bold; display: inline-block; position: relative; height: 60px;">
196
  Entity
197
+
198
  <span style="background: lightblue; top: 40px; height: 4px; left: -1px; width: calc(100% + 2px); position: absolute;">
199
  </span>
200
  </span>
 
203
  <span style="background: lightblue; top: 40px; height: 4px; left: -1px; width: calc(100% + 2px); position: absolute;">
204
  </span>
205
  </span>
206
+ (
207
  <span style="font-weight: bold; display: inline-block; position: relative; height: 60px;">
208
  NER
209
  <span style="background: lightblue; top: 40px; height: 4px; left: -1px; width: calc(100% + 2px); position: absolute;">
 
217
  ) . </div></span>
218
  </div>
219
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
220
  Please visit the [repository](https://github.com/VictorMorand/llm2ner) for more details and a demo notebook.
221
 
222
  ## Evaluation Results
 
238
  | Ontonotes | 0.2296 | 0.6734 | 0.3424 | 42193 |
239
  | Aggregated | 0.2121 | 0.8771 | 0.3415 | 353250 |
240
  | Mean | 0.2633 | 0.8198 | 0.3904 | 353250 |
 
241
  ## Citation
242
  If using this model or the approach, please cite the associated paper:
243
  ```
244
  @misc{morand2025tommerefficiententity,
245
+ title={ToMMeR -- Efficient Entity Mention Detection from Large Language Models},
246
  author={Victor Morand and Nadi Tomeh and Josiane Mothe and Benjamin Piwowarski},
247
  year={2025},
248
  eprint={2510.19410},
249
  archivePrefix={arXiv},
250
  primaryClass={cs.CL},
251
+ url={https://arxiv.org/abs/2510.19410},
252
  }
253
  ```
254
 
definition.json DELETED
@@ -1 +0,0 @@
1
- {"objects": [{"id": 140521468942352, "module": "llm2ner.models.tommer", "type": "ToMMeR", "typename": "llm2ner.models.tommer.ToMMeR", "identifier": "8e3a62b0403a4172fcb037667ae94cd59bccde77e6f06ae1f0756664fd6a35db", "fields": {"llm_name": "EleutherAI/pythia-2.8b", "layer": 5, "rank": 64, "causal_mask": true, "sliding_window": 25, "use_cosine": true, "normalize_scores": ""}}, {"id": 140521600014832, "module": "llm2ner.xpmModel", "type": "xpmTorchHubModule.Loader", "typename": "llm2ner.xpmModel.xpmTorchHubModule.Loader", "identifier": "9f137eae73d32a9be6ff608a808bbe7cdc731525ff20a1095cdbdb68ff059e56", "fields": {"model": {"type": "python", "value": 140521468942352}, "parameters": {"type": "path.serialized", "value": "parameters", "is_folder": false}}}], "data": [{"type": "python", "value": 140521468942352}, [{"type": "python", "value": 140521600014832}]]}
 
 
experimaestro.json ADDED
@@ -0,0 +1 @@
 
 
1
+ [{"id": 5605317632, "module": "llm2ner.models.tommer", "type": "ToMMeR", "typename": "llm2ner.models.tommer.ToMMeR", "identifier": "c3bc1cd395a94210f0aac837c568ae710f731328e8711bcf00ea64fc43578279", "fields": {"llm_name": "EleutherAI/pythia-2.8b", "layer": 5, "rank": 64, "causal_mask": true, "sliding_window": 25, "use_cosine": true, "normalize_scores": ""}}, {"id": 5605317536, "module": "xpm_torch.module", "type": "SimpleModuleLoader", "typename": "xpm_torch.module.SimpleModuleLoader", "identifier": "821960ec1ccf4291eab475ab8e989519810584d3ce0982d1403bf8262eae5509", "fields": {"value": {"type": "python", "value": 5605317632}, "settings": null, "path": {"type": "path.serialized", "value": "model.safetensors", "is_folder": false}}}]
parameters → model.safetensors RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:35db9a84b09b1c9f5e5ee39cb23e215b6f580aa6a839adb1597c581b9bb4d0db
3
- size 1323770
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5d7ee3e91558d3fc68125685fdc23bb55df3adf76513ef59f7757b8756c63c4b
3
+ size 1321376