Regex Model¶
Contains class for regex data labeling model.
- class dataprofiler.labelers.regex_model.RegexModel(label_mapping=None, parameters=None)¶
Bases:
dataprofiler.labelers.base_model.BaseModel
Class for regex data labeling model.
Initialize Regex Model.
- Example regex_patterns:
- regex_patterns = {
- “LABEL_1”: [
“LABEL_1_pattern_1”, “LABEL_1_pattern_2”, …
], “LABEL_2”: [
“LABEL_2_pattern_1”, “LABEL_2_pattern_2”, …
}
- Example encapsulators:
- encapsulators = {
‘start’: r’(?<![w.$%-])’, ‘end’: r’(?:(?=(b|[ ]))|(?=[^w%$]([^w]|$))|$)’,
}
- Parameters
label_mapping (dict) – maps labels to their encoded integers
parameters (dict) –
Contains all the appropriate parameters for the model. Possible parameters are:
max_length, max_num_chars, dim_embed
- Returns
None
- reset_weights()¶
Reset weights.
- predict(data, batch_size=None, show_confidences=False, verbose=True)¶
Apply the regex patterns (within regex_model) to the input_string.
Create predictions for all matching patterns. Each pattern has an associated entity and the predictions of each character within the string are given a True or False identification for each entity. All characters not identified by ANY of the regex patterns in the pattern_dict are considered background characters, and are replaced with the default_label value.
- Parameters
data (iterator) – list of strings to predict upon
batch_size (N/A) – does not impact this model and should be fixed to not be required.
show_confidences – whether user wants prediction confidences
verbose (bool) – Flag to determine whether to print status or not
- Returns
char level predictions and confidences
- Return type
dict
- classmethod load_from_disk(dirpath)¶
Load whole model from disk with weights.
- Parameters
dirpath (str) – directory path where you want to load the model from
- Returns
None
- save_to_disk(dirpath)¶
Save whole model to disk with weights.
- Parameters
dirpath (str) – directory path where you want to save the model to
- Returns
None
- add_label(label, same_as=None)¶
Add a label to the data labeler.
- Parameters
label (str) – new label being added to the data labeler
same_as (str) – label to have the same encoding index as for multi-label to single encoding index.
- Returns
None
- classmethod get_class(class_name)¶
Get subclasses.
- get_parameters(param_list=None)¶
Return a dict of parameters from the model given a list.
- Parameters
param_list (list) – list of parameters to retrieve from the model.
- Returns
dict of parameters
- classmethod help()¶
Help describe alterable parameters.
- Returns
None
- property label_mapping¶
Return mapping of labels to their encoded values.
- property labels¶
Retrieve the label.
- Returns
list of labels
- property num_labels¶
Return max label mapping.
- requires_zero_mapping = False¶
- property reverse_label_mapping¶
Return reversed order of current labels.
Useful for when needed to extract Labels via indices.
- set_label_mapping(label_mapping)¶
Set the labels for the model.
- Parameters
label_mapping (Union[list, dict]) – label mapping of the model or list of labels to be converted into the label mapping
- Returns
None
- set_params(**kwargs)¶
Set the parameters if they exist given kwargs.