def audio_classification_pre_process(
    dataset,
    model_name: str,
    input_cols: list,
    label_col: str = "label",
    max_samples: Optional[int] = None,
    trust_remote_code: Optional[bool] = None,
    feature_extractor_args: Optional[dict[str, Any]] = None,
    **kwargs,
):
    """Pre-process data for audio classification task.

    Args:
        dataset (object): Data to be pre-processed, reserved for internal dataset assignment.
        model_name (str): Name of the huggingface model.
        input_cols (list): List of input columns.
        label_col (str): Label column. Defaults to "label".
        max_samples (int, optional): Max number of samples to use. Defaults to None.
        trust_remote_code (bool, optional): Whether or not to allow for custom models defined on the Hub in their own
            modeling files. Defaults to None.
        feature_extractor_args (dict, optional): Additional arguments for feature extractor.
        **kwargs: Additional arguments.
            The common arguments are the fields in olive.data.component.audio_classification.AudioClassificationParams.
            Extra arguments:
                - max_duration (int, optional): Max duration of audio in seconds. Defaults to 30.
                - labels_to_filter (list, optional): List of labels to filter. Defaults to None.
            Note: the AudioClassificationParams subclass already includes the common arguments.

    """
    from datasets import Audio
    from transformers import AutoFeatureExtractor

    assert len(input_cols) == 1, "Only one input column is supported for audio classification task."

    # align labels with model configs
    model_config = get_model_config(model_name, trust_remote_code=trust_remote_code)
    labels_to_filter = kwargs.get("labels_to_filter") or []
    dataset = dataset.filter(
        lambda x: x not in dataset.features["label"].str2int(labels_to_filter), input_columns=[label_col]
    )
    dataset = dataset.align_labels_with_mapping(model_config.label2id, label_col)

    fe_args = feature_extractor_args or {}
    fea_extractor = AutoFeatureExtractor.from_pretrained(model_name, trust_remote_code=trust_remote_code, **fe_args)
    dataset.cast_column(input_cols[0], Audio(sampling_rate=fea_extractor.sampling_rate))

    def _tokenizer_and_align_labels(examples):
        max_duration = kwargs.get("max_duration", 30)

        audio_arrays = [x["array"] for x in examples[input_cols[0]]]
        tokenized_inputs = fea_extractor(
            audio_arrays,
            sampling_rate=fea_extractor.sampling_rate,
            max_length=int(fea_extractor.sampling_rate * max_duration),
            truncation=True,
            return_attention_mask=True,
        )

        tokenized_inputs["label"] = examples[label_col]

        return tokenized_inputs

    tokenized_datasets = _huggingface_pre_process_helper(dataset, _tokenizer_and_align_labels, max_samples, **kwargs)
    return BaseDataset(tokenized_datasets, label_col="label", max_samples=max_samples)
Pre-process data for audio classification task.

    Args:
        dataset (object): Data to be pre-processed, reserved for internal dataset assignment.
        model_name (str): Name of the huggingface model.
        input_cols (list): List of input columns.
        label_col (str): Label column. Defaults to "label".
        max_samples (int, optional): Max number of samples to use. Defaults to None.
        trust_remote_code (bool, optional): Whether or not to allow for custom models defined on the Hub in their own
            modeling files. Defaults to None.
        feature_extractor_args (dict, optional): Additional arguments for feature extractor.
        **kwargs: Additional arguments.
            The common arguments are the fields in olive.data.component.audio_classification.AudioClassificationParams.
            Extra arguments:
                - max_duration (int, optional): Max duration of audio in seconds. Defaults to 30.
                - labels_to_filter (list, optional): List of labels to filter. Defaults to None.
            Note: the AudioClassificationParams subclass already includes the common arguments.

    
olive/data/component/pre_process_data.py