Skip to content

results

results

Classes:

Name Description
RecordResult

Represents a NER result for a record in a dataset.

ExporterConfig
RecordResultExporter

Responsible for creating a representation of RecordResult that is exportable to

DatasetClassifyResults

Represents classification result on the dataset.

RecordResult(index, entities) dataclass

Represents a NER result for a record in a dataset.

Parameters:

Name Type Description Default
index int

index of the record in the original dataset

required
entities list[Prediction]

Dict representation of NERPrediction (NERPrediction.as_dict)

required
Source code in src/nemo_safe_synthesizer/pii_replacer/ner/report/results.py
def __init__(self, index: int, entities: list[Prediction]):
    self.index = index
    self.entities = entities

ExporterConfig(include_json_path=False, include_match=False) dataclass

Attributes:

Name Type Description
include_json_path bool

If set to True, the exported predictions will include "json_path" field for

include_match bool

If set to True, the exported prediction will contain text that got matched.

include_json_path = field(default=False) class-attribute instance-attribute

If set to True, the exported predictions will include "json_path" field for each entity.

include_match = field(default=False) class-attribute instance-attribute

If set to True, the exported prediction will contain text that got matched.

RecordResultExporter(config=None)

Responsible for creating a representation of RecordResult that is exportable to the outside.

Parameters:

Name Type Description Default
config Optional[ExporterConfig]

Configuration for how to export the predictions.

None
Source code in src/nemo_safe_synthesizer/pii_replacer/ner/report/results.py
def __init__(self, config: Optional[ExporterConfig] = None):
    if not config:
        config = ExporterConfig()

    self._keys_to_export = {name: name for name in self._pass_through_fields}

    if config.include_json_path:
        self._keys_to_export["json_path"] = "json_path"

    if config.include_match:
        self._keys_to_export["text"] = "match"

DatasetClassifyResults(results=None)

Represents classification result on the dataset.

For now this representation is using whatever is returned from the NER.predict() for simplicity and so we don't need to create a separate data structure (as there may be a lot of results).

Methods:

Name Description
jsonl

Serializes results into a JSONL-formatted string.

Source code in src/nemo_safe_synthesizer/pii_replacer/ner/report/results.py
def __init__(self, results: Optional[DatasetPredictions] = None):
    if not results:
        results = []

    self.results = results

jsonl(exporter_config=None)

Serializes results into a JSONL-formatted string.

Parameters:

Name Type Description Default
exporter_config Optional[ExporterConfig]

Config to use for the result exporter.

None

JSONL representation of results. Each line contains classification

Type Description
str

result for corresponding row in the input dataset.

Source code in src/nemo_safe_synthesizer/pii_replacer/ner/report/results.py
def jsonl(self, exporter_config: Optional[ExporterConfig] = None) -> str:
    """
    Serializes results into a JSONL-formatted string.

    Args:
        exporter_config: Config to use for the result exporter.

    Returns: JSONL representation of results. Each line contains classification
        result for corresponding row in the input dataset.
    """
    exporter = RecordResultExporter(exporter_config)
    return "\n".join(json.dumps(exporter.export(result)) for result in self.results)