ClassificationDataFilter Class
ml_debugger.data_filter.classification.classification_torch_data_filter.ClassificationTorchDataFilter
Bases: CommonDataFilter, ClassificationTorchTracer
DataFilter for classification tasks using PyTorch models.
__init__(model, model_name, version_name, result_name=None, n_epoch='latest', filter_config=None, target_layers=None, additional_fields=None, auto_sync=False, force_table_recreate=False, api_endpoint=None, api_key=None)
Initialize classification data filter.
引数:
| 名前 | タイプ | デスクリプション | デフォルト |
|---|---|---|---|
|
Module
|
PyTorch model to trace. |
必須 |
|
str
|
Name of the ML model. |
必須 |
|
str
|
Version identifier for the ML model. |
必須 |
|
Optional[str]
|
The name of the existing evaluation result to retrieve. |
None
|
|
Union[str, Optional[int]]
|
Filter option for n_epoch value. |
'latest'
|
|
Optional[Union[FilterConfig, Dict[str, Any]]]
|
Filter configuration for data filtering. Can be a FilterConfig instance or a dict that will be validated and converted to FilterConfig. Example: {"target_zones": ["hotspot"]} or {"conditions": [{"error_proba": ">=0.8"}]} |
None
|
|
Optional[Dict[str, str]]
|
Mapping of layer aliases to module paths. |
None
|
|
Optional[List[dict]]
|
Extra fields for database schema. |
None
|
|
bool
|
Enable backgroup syncing of logged data. |
False
|
|
bool
|
Whether to drop and recreate existing tables. |
False
|
|
Optional[str]
|
URL of the service API for data upload. |
None
|
|
Optional[str]
|
API key for authenticating with the service. |
None
|
__call__(model_input, input_ids, dataset_type='pool', **kwargs)
Invoke the tracer on a single inference, recording I/O data.
引数:
| 名前 | タイプ | デスクリプション | デフォルト |
|---|---|---|---|
|
Any
|
Input data for the model inference. |
必須 |
|
List[str]
|
Identifiers of each input data. |
必須 |
|
str
|
Identifier of input dataset. (e.g. 'pool') |
'pool'
|
|
Any
|
Additional keyword arguments for parsing and saving I/O data. (will be passed to |
{}
|
戻り値:
| タイプ | デスクリプション |
|---|---|
Tuple[Any, List[Optional[bool]]]
|
Tuple[Any, List[Optional[bool]]]: - model_output: Raw model output - filter_flags: List of booleans indicating if each input matches filter condition (True = matches filter / should be extracted, False = does not match, None = no filter configured) |
発生:
| タイプ | デスクリプション |
|---|---|
Any
|
Propagates exceptions from parsing and saving operations. |
get_hooked_features(layer_name)
Retrieve the captured output for a given layer alias.
引数:
| 名前 | タイプ | デスクリプション | デフォルト |
|---|---|---|---|
|
str
|
Alias of the layer whose activation was captured. |
必須 |
戻り値:
| 名前 | タイプ | デスクリプション |
|---|---|---|
Any |
Any
|
Activation data stored for the specified layer. |
発生:
| タイプ | デスクリプション |
|---|---|
KeyError
|
If no activation has been captured for |
export(output_path=None)
Export extracted features into a ZIP archive.
Uses the internal n_epoch resolved during validator setup to
filter records, consistent with upload() and wait_for_save().
引数:
| 名前 | タイプ | デスクリプション | デフォルト |
|---|---|---|---|
|
Optional[str]
|
Path or directory for saving the ZIP file. If no .zip extension, the default filename is appended. Defaults to cwd. |
None
|
戻り値:
| タイプ | デスクリプション |
|---|---|
Optional[Path]
|
Path to the created ZIP file, or None on non-primary distributed ranks. A |
Optional[Path]
|
model with named outputs returns one path per output name instead. |
wait_for_save(interval=3, *, force=False, timeout=None)
Flush pending writes and upload the monitoring log to the service.
引数:
| 名前 | タイプ | デスクリプション | デフォルト |
|---|---|---|---|
|
int
|
Poll interval (seconds) while waiting for background sync. |
3
|
|
bool
|
Upload even when nothing has been marked unsaved since the last upload. |
False
|
|
Optional[float]
|
Optional hard cap (seconds) on waiting for background sync before falling back to a direct upload / raising. |
None
|
Note
Monitoring logs are always appended on the server, so the upload mode
option offered by the training tracers does not apply to Logger /
DataFilter and is intentionally not exposed here.
upload(*, force=False)
Flush pending writes and upload the monitoring log to the service.
引数:
| 名前 | タイプ | デスクリプション | デフォルト |
|---|---|---|---|
|
bool
|
Upload even when nothing has been marked unsaved since the last upload. |
False
|
Note
Monitoring logs are always appended on the server, so the upload mode
option offered by the training tracers does not apply to Logger /
DataFilter and is intentionally not exposed here.
get_statistics()
Count what this instance has recorded locally, without returning any of it.
This is the supported way to confirm what was recorded: how many rows, how many distinct inputs and how many ground-truth rows each recorded group holds. It returns counts only, never recorded values. Writes still pending are completed first, so the counts include everything recorded so far. In a distributed run, each process counts the records it wrote itself.
戻り値:
| タイプ | デスクリプション |
|---|---|
Any
|
A list with one entry per |
Any
|
local records, each of the form ``{"dataset_type": str, "n_epoch": |
Any
|
Optional[int], "rows": int, "inputs": int, "ground_truth_rows": int}`` -- |
Any
|
|
Any
|
distinct input ids, and |
Any
|
recorded. A model with named outputs returns |
query(n_data=None, strategy=None, dataset_type='pool', type_cast=None, sampling=None)
Sort and query dataset based on strategy.
引数:
| 名前 | タイプ | デスクリプション | デフォルト |
|---|---|---|---|
|
Optional[Union[int, ALRecommendation]]
|
Maximum number of data to query. Optional when a recommendation is supplied and carries a budget (pass an explicit value to override it). |
None
|
|
Optional[Union[str, FilterConfig, Dict[str, Any], ALRecommendation]]
|
Query strategy.
- 'high_error_proba': Sort by error probability descending
- 'low_error_proba': Sort by error probability ascending
- FilterConfig or dict: Filter by conditions and return matching data
- file path: a YAML/JSON strategy file (.yaml / .yml / .json) whose
|
None
|
|
str
|
Filter of input dataset. (e.g. 'pool') |
'pool'
|
|
Optional[type]
|
Type for casting input_id. (e.g. int) |
None
|
|
Optional[Union[str, SamplingConfig, Dict[str, Any]]]
|
Sampling configuration for the final selection step. - None: No sampling; use existing sort+top-N behavior (default). - 'class_balanced': Per-class quota sampling using pred_class_id. - dict: Full SamplingConfig, e.g. {'method': 'random', 'min_value': 0.5} or {'method': 'random', 'min_value': 0.3, 'max_value': 0.9, 'seed': 42}. Note: 'random' method requires dict form with at least one of min_value/max_value (string shorthand 'random' is not supported). With several rankings, only 'class_balanced' is supported. - SamplingConfig: Used as-is. |
None
|
戻り値:
| タイプ | デスクリプション |
|---|---|
List[str]
|
List[str]: List of input_id of queried dataset. |
発生:
| タイプ | デスクリプション |
|---|---|
ValueError
|
If strategy is invalid. |
例:
>>> # Sort by high error probability
>>> ids = data_filter.query(n_data=10, strategy='high_error_proba')
>>>
>>> # Filter by zone
>>> ids = data_filter.query(n_data=10, strategy={'target_zones': ['hotspot']})
>>>
>>> # Filter by conditions
>>> ids = data_filter.query(n_data=10, strategy={'conditions': [{'error_proba': '>=0.8'}]})
>>>
>>> # Order by a built-in feature
>>> ids = data_filter.query(
... n_data=10,
... strategy={'target_column': {'name': 'mld_entropy'}, 'sort': 'desc'},
... )
>>>
>>> # Order by two rankings, each filling half of the batch
>>> ids = data_filter.query(
... n_data=10,
... strategy={
... 'target_column': [
... {'name': 'uncertain', 'inputs': ['margin', 'mld_entropy']},
... 'mld_confusion_proba',
... ],
... },
... )
>>>
>>> # Use the strategy recommended for an evaluation result
>>> rec = result.recommend_al_strategy()
>>> ids = data_filter.query(n_data=500, strategy=rec)
>>>
>>> # Random sampling from candidates with error_proba >= 0.5
>>> ids = data_filter.query(
... n_data=10,
... strategy='high_error_proba',
... sampling={'method': 'random', 'min_value': 0.5},
... )
>>>
>>> # Class-balanced sampling with seed
>>> ids = data_filter.query(
... n_data=10,
... strategy='high_error_proba',
... sampling={'method': 'class_balanced', 'min_per_class': 2, 'seed': 42},
... )