dqm_ml_core.api
API modules for DQM ML Core.
This package contains the base API components for data metric processors, feature extractors, and gap processors.
__all__ = ['FeaturesProcessor', 'GapProcessor', 'MetricsProcessor', 'Processor']
module-attribute
FeaturesProcessor
Bases: Processor
Base class for all feature extraction processors.
Feature processors transform raw data into per-sample features
(e.g., image luminosity, embeddings). The primary lifecycle method
is compute_features, which produces a dict of feature arrays
from each batch of raw data.
Source code in packages/dqm-ml-core/src/dqm_ml_core/api/features_processor.py
compute_features(batch: pa.RecordBatch, prev_features: dict[str, pa.Array]) -> dict[str, pa.Array]
Transform a raw data batch into features.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
RecordBatch
|
The input pyarrow RecordBatch. |
required |
prev_features
|
dict[str, Array]
|
Features already computed by preceding processors. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Array]
|
A dictionary mapping feature names to pyarrow Arrays. |
Source code in packages/dqm-ml-core/src/dqm_ml_core/api/features_processor.py
generated_features() -> list[str]
Return the list of columns generated by this processor during feature extraction.
Returns:
| Type | Description |
|---|---|
list[str]
|
A list of feature names. |
Source code in packages/dqm-ml-core/src/dqm_ml_core/api/features_processor.py
GapProcessor
Bases: Processor
Base class for all domain gap processors.
Gap processors compute distribution shift between two datasets
(e.g., MMD, FID, KL divergence). The primary lifecycle methods are
select_features (per-batch column selection aware of previous features),
compute_batch_metric (batch aggregation), compute (final dataset-level
statistics), and compute_delta (pairwise comparison).
Source code in packages/dqm-ml-core/src/dqm_ml_core/api/gap_processor.py
compute(batch_metrics: dict[str, pa.Array]) -> dict[str, Any]
Perform the final dataset-level aggregation of batch statistics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch_metrics
|
dict[str, Array]
|
The aggregated intermediate statistics from all batches. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dictionary containing the final dataset-level statistics. |
Source code in packages/dqm-ml-core/src/dqm_ml_core/api/gap_processor.py
compute_batch_metric(features: dict[str, pa.Array]) -> dict[str, pa.Array]
Aggregate features into intermediate statistics for the current batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
dict[str, Array]
|
Dictionary of feature arrays computed on the batch. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Array]
|
A dictionary of aggregated statistics. |
Source code in packages/dqm-ml-core/src/dqm_ml_core/api/gap_processor.py
compute_delta(source: dict[str, Any], target: dict[str, Any]) -> dict[str, Any]
Compare metrics between two different dataselections.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
dict[str, Any]
|
Final metrics from the source dataselection. |
required |
target
|
dict[str, Any]
|
Final metrics from the target dataselection. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dictionary containing distance or difference scores. |
Source code in packages/dqm-ml-core/src/dqm_ml_core/api/gap_processor.py
select_features(batch: pa.RecordBatch, prev_features: dict[str, pa.Array]) -> dict[str, pa.Array]
Extract relevant columns from a batch, resolving patterns against both batch columns and previously computed upstream features.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
RecordBatch
|
The input pyarrow RecordBatch. |
required |
prev_features
|
dict[str, Array]
|
Features already computed by preceding processors. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Array]
|
A dictionary mapping column names to pyarrow Arrays. |
Source code in packages/dqm-ml-core/src/dqm_ml_core/api/gap_processor.py
MetricsProcessor
Bases: Processor
Base class for all metric computation processors.
Metric processors compute dataset-level scores (e.g., completeness,
diversity, representativeness). The primary lifecycle methods are
select_columns (per-batch column selection), compute_batch_metric
(batch aggregation), and compute (final dataset-level computation).
Source code in packages/dqm-ml-core/src/dqm_ml_core/api/metrics_processor.py
compute(batch_metrics: dict[str, pa.Array]) -> dict[str, Any]
Perform the final dataset-level metric calculation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch_metrics
|
dict[str, Array]
|
The aggregated intermediate statistics from all batches. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dictionary containing the final metrics. |
Source code in packages/dqm-ml-core/src/dqm_ml_core/api/metrics_processor.py
compute_batch_metric(features: dict[str, pa.Array]) -> dict[str, pa.Array]
Aggregate features into intermediate statistics for the current batch.
This method is critical for scalability. It should return a compact representation of the data (e.g., partial sums) that can be efficiently combined later.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
dict[str, Array]
|
Dictionary of feature arrays computed on the batch. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Array]
|
A dictionary of aggregated statistics. |
Source code in packages/dqm-ml-core/src/dqm_ml_core/api/metrics_processor.py
generated_metrics() -> list[str]
Return the names of the final metrics produced by this processor.
Returns:
| Type | Description |
|---|---|
list[str]
|
A list of metric names. |
Source code in packages/dqm-ml-core/src/dqm_ml_core/api/metrics_processor.py
select_columns(batch: pa.RecordBatch, prev_features: dict[str, pa.Array]) -> dict[str, pa.Array]
Select relevant columns from a raw batch for metric computation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
RecordBatch
|
The input pyarrow RecordBatch. |
required |
prev_features
|
dict[str, Array]
|
Features already computed by preceding processors. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Array]
|
A dictionary mapping column names to pyarrow Arrays. |
Source code in packages/dqm-ml-core/src/dqm_ml_core/api/metrics_processor.py
Processor
Base class for all Data Quality metrics, feature extractors, and gap processors.
Provides shared initialization, failure-rate checking, and column resolution.
Lifecycle methods are defined in the appropriate subclass:
:class:FeaturesProcessor, :class:MetricsProcessor, or :class:GapProcessor.
Source code in packages/dqm-ml-core/src/dqm_ml_core/api/processor.py
columns_config = None
instance-attribute
compute_device: str = 'cpu'
instance-attribute
compute_seed: int | None = None
instance-attribute
config = config
instance-attribute
current_path_prefix: dict[str, str] = {}
instance-attribute
errors_config = None
instance-attribute
exclude_columns: list[str] | None = None
instance-attribute
input_columns: list[str] = []
instance-attribute
name = name
instance-attribute
storage_raw = config.pop('storage', None)
instance-attribute
__init__(name: str, config: dict[str, Any] | None)
Initialize the processor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Unique name of the processor instance. |
required |
config
|
dict[str, Any] | None
|
Configuration dictionary (optional). |
required |
Source code in packages/dqm-ml-core/src/dqm_ml_core/api/processor.py
needed_columns() -> list[str]
Return the list of raw input columns required for processing.
Returns:
| Type | Description |
|---|---|
list[str]
|
A list of column names. |
reset() -> None
Reset per-selection state between dataselections.
Processors that cache per-selection state (e.g. histogram bin edges in RepresentativenessProcessor) MUST override this to clear that state. Called by DatasetJob after each selection.