Views
No views yet
meta-llama/Llama-3.2-1B, with a computational overhead not greater than an additional attention head.| Property | Value |
|---|---|
| Base LLM | meta-llama/Llama-3.2-1B |
| Layer | 3 |
| #Params | 264.2K |
pip install git+https://github.com/VictorMorand/llm2ner.git1from xpm_torch.huggingface import TorchHFHub
2from llm2ner import ToMMeR, utils
3
4tommer: ToMMeR = TorchHFHub.from_pretrained("llm2ner/ToMMeR-Llama-3.2-1B_L3_R64")
5# load Backbone llm, optionnally cut the unused layer to save GPU space.
6llm = utils.load_llm( tommer.llm_name, cut_to_layer=tommer.layer,)
7tommer.to(llm.device)
8
9#### Raw Inference
10text = ["Large language models are awesome"]
11print(f"Input text: {text[0]}")
12
13#tokenize in shape (1, seq_len)
14tokens = llm.tokenizer(text, return_tensors="pt")["input_ids"].to(llm.device)
15# Output raw scores
16output = tommer.forward(tokens, llm) # (batch_size, seq_len, seq_len)
17print(f"Raw Output shape: {output.shape}")
18
19#use given decoding strategy to infer entities
20entities = tommer.infer_entities(tokens=tokens, model=llm, threshold=0.5, decoding_strategy="greedy")
21str_entities = [ llm.tokenizer.decode(tokens[0,b:e+1]) for b, e in entities[0]]
22print(f"Predicted entities: {str_entities}")
23
24>>>INFO:root:Cut LlamaModel with 16 layers to 7 layers
25>>> Input text: Large language models are awesome
26>>> Raw Output shape: torch.Size([1, 6, 6])
27>>> Predicted entities: ['Large language models']llm2ner.plotting.1from xpm_torch.huggingface import TorchHFHub
2from llm2ner import ToMMeR, utils, plotting
3
4tommer: ToMMeR = TorchHFHub.from_pretrained("llm2ner/ToMMeR-Llama-3.2-1B_L3_R64")
5# load Backbone llm, optionnally cut the unused layer to save GPU space.
6llm = utils.load_llm( tommer.llm_name, cut_to_layer=tommer.layer,)
7tommer.to(llm.device)
8
9text = "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). "
10
11#fancy interactive output
12outputs = plotting.demo_inference( text, tommer, llm,
13 decoding_strategy="threshold", # or "greedy" for flat segmentation
14 threshold=0.5, # default 50%
15 show_attn=True,
16)| dataset | precision | recall | f1 | n_samples |
|---|---|---|---|---|
| MultiNERD | 0.1871 | 0.9906 | 0.3148 | 154144 |
| CoNLL 2003 | 0.2699 | 0.9659 | 0.4219 | 16493 |
| CrossNER_politics | 0.2852 | 0.9745 | 0.4413 | 1389 |
| CrossNER_AI | 0.3018 | 0.9717 | 0.4605 | 879 |
| CrossNER_literature | 0.3283 | 0.9594 | 0.4893 | 916 |
| CrossNER_science | 0.3251 | 0.9696 | 0.4869 | 1193 |
| CrossNER_music | 0.3584 | 0.9659 | 0.5228 | 945 |
| ncbi | 0.1082 | 0.9293 | 0.1939 | 3952 |
| FabNER | 0.2927 | 0.771 | 0.4243 | 13681 |
| WikiNeural | 0.1801 | 0.9894 | 0.3047 | 92672 |
| GENIA_NER | 0.223 | 0.9672 | 0.3624 | 16563 |
| ACE 2005 | 0.2659 | 0.4857 | 0.3437 | 8230 |
| Ontonotes | 0.2253 | 0.7601 | 0.3476 | 42193 |
| Aggregated | 0.2024 | 0.9392 | 0.333 | 353250 |
| Mean | 0.2578 | 0.9 | 0.3934 | 353250 |
@misc{morand2025tommerefficiententity,
title={ToMMeR -- Efficient Entity Mention Detection from Large Language Models},
author={Victor Morand and Nadi Tomeh and Josiane Mothe and Benjamin Piwowarski},
year={2025},
eprint={2510.19410},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2510.19410},
}