langtest.augmentation.base.TemplaticAugment#
- class TemplaticAugment(templates: str | List[str], task: TaskManager, generate_templates=False, show_templates=False)#
Bases:
BaseAugmentaion
This class is used for templatic augmentation. It is a subclass of the BaseAugmentation class.
- __templates#
A string or a list of strings or samples that represents the templates for the augmentation.
- __task#
The task for which the augmentation is being performed.
- __generate_templates#
if set to True, generates sample templates from the given ones.
- __show_templates#
if set to True, displays the used templates.
- __init__(self, templates
Union[str, List[str]], task: str): Initializes the TemplaticAugment class.
- fix(self, training_data
str, output_path: str, *args, **kwargs): Performs the templatic augmentation and exports the results to a specified path.
- __init__(templates: str | List[str], task: TaskManager, generate_templates=False, show_templates=False) None #
This constructor for the TemplaticAugment class.
- Parameters:
templates (Union[str, List[str]]) – The templates to be used for the augmentation.
task (str) – The task for which the augmentation is being performed.
generate_templates (bool, optional) – if set to True, generates sample templates from the given ones.
show_templates (bool, optional) – if set to True, displays the used templates.
Methods
__init__
(templates, task[, ...])This constructor for the TemplaticAugment class.
This method is used to add spaces around punctuation in a string.
extract_variable_names
(f_string)This method is used to extract the variable names from the templates.
fix
(training_data, output_path[, max_num, ...])This method is used to perform the templatic augmentation.
new_sample
(template)This method is used to generate a new sample from a template.
search_sample_results
(samples)This method is used to search the results of the samples for the entities in the templates.
str_to_sample
(template)This method is used to convert a template string to a Sample object.
Attributes
Task getter
Templates getter
- static add_spaces_around_punctuation(text: str)#
This method is used to add spaces around punctuation in a string.
- Parameters:
text (str) – The string to which spaces are to be added.
- Returns:
The string with spaces added around punctuation.
- Return type:
str
- static extract_variable_names(f_string: str) List[str] #
This method is used to extract the variable names from the templates.
- Parameters:
f_string (str) – The template string.
- Returns:
A list of variable names.
- Return type:
List[str]
- fix(training_data: Dict[str, Any], output_path: str, max_num: int | None = None, append_original: bool = False, *args, **kwargs) bool #
This method is used to perform the templatic augmentation.
It takes the input data, performs the augmentation and then saves the augmented data to the output path.
- Parameters:
training_data (dict) – A dictionary containing the input data for augmentation.
output_path (str) – The path where the augmented data will be saved.
max_num (int) – Maximum number of new samples to generate
append_original (bool, optional) – If set to True, appends the original data to the augmented data. Defaults to False.
*args – Variable length argument list.
**kwargs – Arbitrary keyword arguments.
- Returns:
Returns True upon successful completion of the method.
- Return type:
bool
- new_sample(template: Sample)#
This method is used to generate a new sample from a template.
- Parameters:
template (Sample) – The template from which the new sample is to be generated.
- Returns:
The new sample generated from the template.
- Return type:
Sample
- static search_sample_results(samples: List[Sample]) Dict[str, List[NERPrediction | SequenceLabel]] #
This method is used to search the results of the samples for the entities in the templates.
- Parameters:
samples (List[Sample]) – The samples for which the results are to be searched.
- Returns:
A dictionary containing the search results.
- Return type:
Dict[str, List[Union[NERPrediction, SequenceLabel]]]
- str_to_sample(template: str)#
This method is used to convert a template string to a Sample object.
- Parameters:
template (str) – The template string to be converted.
- Returns:
The Sample object generated from the template string.
- Return type:
Sample
- property task#
Task getter
- property templates#
Templates getter