Instructions to use arthrod/attempt_vanilla with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- GLiNER
How to use arthrod/attempt_vanilla with GLiNER:
from gliner import GLiNER model = GLiNER.from_pretrained("arthrod/attempt_vanilla") 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 data/process_nuner.py from arthrod/attempt_vanilla: direct link, hf CLI and curl.
- Browser
- Download file 1.7 kB
-
https://huggingface.co/arthrod/attempt_vanilla/resolve/main/data/process_nuner.py
- Command line
-
hf download hf://arthrod/attempt_vanilla/data/process_nuner.py
-
curl -L -o process_nuner.py https://huggingface.co/arthrod/attempt_vanilla/resolve/main/data/process_nuner.py
1.7 kB
| from datasets import load_dataset | |
| import re | |
| import ast | |
| import json | |
| from tqdm import tqdm | |
| def tokenize_text(text): | |
| """Tokenizes the input text into a list of tokens.""" | |
| return re.findall(r'\w+(?:[-_]\w+)*|\S', text) | |
| def process_entities(dataset): | |
| """Processes entities in the dataset to extract tokenized text and named entity spans.""" | |
| all_data = [] | |
| for el in tqdm(dataset["entity"]): | |
| try: | |
| tokenized_text = tokenize_text(el["input"]) | |
| parsed_output = ast.literal_eval(el["output"]) | |
| entity_texts, entity_types = zip(*[i.split(" <> ") for i in parsed_output]) | |
| entity_spans = [] | |
| for j, entity_text in enumerate(entity_texts): | |
| entity_tokens = tokenize_text(entity_text) | |
| matches = [] | |
| for i in range(len(tokenized_text) - len(entity_tokens) + 1): | |
| if " ".join(tokenized_text[i:i + len(entity_tokens)]).lower() == " ".join(entity_tokens).lower(): | |
| matches.append((i, i + len(entity_tokens) - 1, entity_types[j])) | |
| if matches: | |
| entity_spans.extend(matches) | |
| except Exception as e: | |
| continue | |
| all_data.append({"tokenized_text": tokenized_text, "ner": entity_spans}) | |
| return all_data | |
| def save_data_to_file(data, filepath): | |
| """Saves the processed data to a JSON file.""" | |
| with open(filepath, 'w') as f: | |
| json.dump(data, f) | |
| if __name__ == "__main__": | |
| dataset = load_dataset("numind/NuNER") | |
| processed_data = process_entities(dataset) | |
| save_data_to_file(processed_data, 'nuner_train.json') | |
| print("dataset size:", len(processed_data)) |