sammo.dataformatters

sammo.dataformatters#

DataFormatters are components that take a DataTable or dict and format it into a string. They also provide a get_extractor method that can be used to parse the LLM responses in this format.

Module Contents#

Classes#

DataFormatter

A DataFormatter is a component that takes a DataTable or dict and formats it into a string.

JSONDataFormatter

XMLDataFormatter

MultiLabelFormatter

QuestionAnswerFormatter

API#

class sammo.dataformatters.DataFormatter(names: dict | None = None, flatten_1d_dicts: bool = True, include_ids: bool = True, orient: beartype.typing.Literal[item, kind] = 'item', all_labels=None, attributes_processor=None)#

Bases: sammo.base.Component

A DataFormatter is a component that takes a DataTable or dict and formats it into a string.

Parameters:
  • names – A dictionary mapping column (e.g., “labels”) to a name (e.g., “Input”).

  • flatten_1d_dicts – If True, dicts with a single key are unwrapped to their value.

  • include_ids – If True, numerical item ids are included in the output.

  • orient – If “item_id”, output format is a series of item records, each with an id and a value. If “kind”, all inputs or output labels are grouped together.

  • all_labels – A list of all possible labels, used by some formatters to determine the extractor.

Initialization

DEFAULT_NAMES = None#
format_datatable(data, offset: int = 0)#
format_single(attributes: dict = None, gold_label: dict = None, predicted_label: dict = None, x_id: int = 0) str#
format_batch(attributes: list[dict], gold_label: list[dict] = None, predicted_label: list[dict] = None, offset: int = 0)#
class sammo.dataformatters.JSONDataFormatter(newline_delimited=False, indent=None, **kwargs)#

Bases: sammo.dataformatters.DataFormatter

get_extractor(child, on_error='raise')#
class sammo.dataformatters.XMLDataFormatter(names: dict | None = None, flatten_1d_dicts: bool = True, include_ids: bool = True, orient: beartype.typing.Literal[item, kind] = 'item', all_labels=None, attributes_processor=None)#

Bases: sammo.dataformatters.DataFormatter

get_extractor(child, on_error='raise')#
class sammo.dataformatters.MultiLabelFormatter(all_labels: list, **kwargs)#

Bases: sammo.dataformatters.DataFormatter

get_extractor(child, on_error='raise')#
class sammo.dataformatters.QuestionAnswerFormatter(all_labels: list, **kwargs)#

Bases: sammo.dataformatters.MultiLabelFormatter

get_extractor(child, on_error='raise')#