Data Generation
Data generation module for creating SpaCy training datasets using LLMs.
This module provides functionality to generate annotated training data for SpaCy NER and text classification tasks using Large Language Models. The generated data is parsed and stored in SpaCy’s binary format.
- class spacylize.generator.TaskParser[source]
Bases:
ABCBase class for parsing LLM-generated annotations.
- class spacylize.generator.DocumentBuilder[source]
Bases:
ABCBase class for building SpaCy documents.
- class spacylize.generator.NERParser[source]
Bases:
TaskParserParser for NER inline annotations: [TEXT](LABEL)
- static parse(text)[source]
Parse NER annotations.
- Parameters:
text (str) – Annotated text with inline [entity_text](LABEL) markers.
- Returns:
- (clean_text, entities) where clean_text is the text without
annotation markers and entities is a list of (start, end, label) tuples representing entity spans.
- Return type:
tuple
- class spacylize.generator.NERDocumentBuilder[source]
Bases:
DocumentBuilderBuilds SpaCy docs with entity annotations.
- class spacylize.generator.TextCatParser[source]
Bases:
TaskParserParser for text classification annotations.
- static parse(text)[source]
Parse textcat annotation format.
- Expected format:
Text content
— LABEL: CATEGORY
- Parameters:
text (str) – Annotated text with delimiter and label.
- Returns:
- (clean_text, categories_dict) where categories_dict maps
category names to confidence scores.
- Return type:
tuple
- Raises:
ValueError – If the format is invalid.
- class spacylize.generator.TextCatDocumentBuilder[source]
Bases:
DocumentBuilderBuilds SpaCy docs with category annotations.
- class spacylize.generator.TaskHandler[source]
Bases:
objectRegistry for task-specific parsers and builders.
- class spacylize.generator.DataGenerator(llm_config_path, prompt_config_path, n_samples, output_path, task)[source]
Bases:
objectGenerator for creating SpaCy training data using LLMs.
- Parameters:
llm_config_path (Path)
prompt_config_path (Path)
- __init__(llm_config_path, prompt_config_path, n_samples, output_path, task)[source]
Initialize the DataGenerator.
- Parameters:
llm_config_path (Path) – Path to the LLM configuration YAML file.
prompt_config_path (Path) – Path to the prompt configuration YAML file.
n_samples – Number of training samples to generate.
output_path – Path where the generated .spacy file will be saved.
task – The SpaCy task type (e.g., ‘ner’, ‘textcat’).