Instructions to use NORMA-DEV/Gliner_haystack with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- GLiNER
How to use NORMA-DEV/Gliner_haystack with GLiNER:
from gliner import GLiNER model = GLiNER.from_pretrained("NORMA-DEV/Gliner_haystack") text = "Cristiano Ronaldo dos Santos Aveiro was born on 5 February 1985 in Funchal, Madeira, Portugal." labels = ["person", "date", "location"] entities = model.predict_entities(text, labels) for entity in entities: print(entity["text"], "=>", entity["label"]) - Notebooks
- Google Colab
- Kaggle
Download handler.py from NORMA-DEV/Gliner_haystack: direct link, hf CLI and curl.
- Browser
- Download file 1.54 kB
-
https://huggingface.co/NORMA-DEV/Gliner_haystack/resolve/main/handler.py
- Command line
-
hf download hf://NORMA-DEV/Gliner_haystack/handler.py
-
curl -L -o handler.py https://huggingface.co/NORMA-DEV/Gliner_haystack/resolve/main/handler.py
1.54 kB
| from typing import Dict, List, Any | |
| from gliner import GLiNER | |
| class EndpointHandler: | |
| def __init__(self, path=""): | |
| # Initialize the GLiNER model | |
| self.model = GLiNER.from_pretrained("urchade/gliner_multi-v2.1") | |
| def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]: | |
| """ | |
| Args: | |
| data (Dict[str, Any]): The input data including: | |
| - "inputs": The text input from which to extract information. | |
| - "labels": The labels to predict entities for. | |
| Returns: | |
| List[Dict[str, Any]]: The extracted entities from the text, formatted as required. | |
| """ | |
| # Get inputs and labels | |
| inputs = data.get("inputs", "") | |
| labels = ["party", "document title"] | |
| # Predict entities using GLiNER | |
| entities = self.model.predict_entities(inputs, labels) | |
| # Initialize a dictionary to store organized entities | |
| organized_entities = {label: {"labels": [], "scores": []} for label in labels} | |
| for entity in entities: | |
| label = entity['label'] | |
| text = entity['text'] | |
| score = entity['score'] | |
| # Append text and score to the corresponding label | |
| organized_entities[label]["labels"].append(text) | |
| organized_entities[label]["scores"].append(score) | |
| # Store organized entities in document metadata | |
| doc.meta["entities"] = organized_entities | |
| return {"documents": documents} | |