Instructions to use Siddharth63/gliner2-small with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- GLiNER2
How to use Siddharth63/gliner2-small with GLiNER2:
from gliner2 import AutoExtractor extractor = AutoExtractor.from_pretrained("Siddharth63/gliner2-small") # Extract entities text = "Apple CEO Tim Cook announced iPhone 15 in Cupertino yesterday." result = extractor.extract_entities(text, ["company", "person", "product", "location"]) print(result) - Notebooks
- Google Colab
- Kaggle
Download span_runtime.py from Siddharth63/gliner2-small: direct link, hf CLI and curl.
- Browser
- Download file 1.46 kB
-
https://huggingface.co/Siddharth63/gliner2-small/resolve/main/span_runtime.py
- Command line
-
hf download hf://Siddharth63/gliner2-small/span_runtime.py
-
curl -L -o span_runtime.py https://huggingface.co/Siddharth63/gliner2-small/resolve/main/span_runtime.py
1.46 kB
| """Keep offsets relative to original text with GLiNER2's span architecture.""" | |
| import copy | |
| class OriginalTextCollator: | |
| def __init__(self, processor): | |
| self.processor = processor | |
| def __call__(self, batch): | |
| self.processor.change_mode(False) | |
| transformed = [] | |
| for text, schema in batch: | |
| if not text: | |
| raise ValueError('empty_text_requires_an_explicit_empty_result') | |
| if hasattr(schema, 'build'): | |
| schema = schema.build() | |
| transformed.append(self.processor._transform_record( | |
| {'text': text, 'schema': copy.deepcopy(schema)}, max_len=None)) | |
| return self.processor._pad_batch(transformed) | |
| def preserve_original_text(model): | |
| """Install before using batch_extract/extract with max_len=None. | |
| Native GLiNER2 2.0.0's generic collator appends a period to unpunctuated | |
| inputs. This collator keeps both the encoder input and span offsets faithful | |
| to the supplied text. Long-input chunking must happen before this call. | |
| """ | |
| if getattr(model, 'architecture', 'span') != 'span': | |
| raise ValueError('this_runtime_adapter_is_for_span_checkpoints') | |
| if getattr(model.config, 'source_word_splitter', None) == 'fine-source-v1': | |
| from fine_span_tokenizer import fine_words | |
| model.processor.word_splitter = fine_words | |
| model._inference_collator = OriginalTextCollator(model.processor) | |
| return model | |