Repository: huggingface/transformers
File: src/transformers/pipelines/__init__.py (Python)

Code before:
            else:
                image_processor = None

    if load_feature_extractor or load_feature_extractor is None:
        try:
            # Try to infer feature extractor from model or config name (if provided as str)
            if feature_extractor is None:
                if isinstance(model_name, str):
                    feature_extractor = model_name
                elif isinstance(config, str):
                    feature_extractor = config
                else:
                    # Impossible to guess what is the right feature_extractor here
                    raise Exception(
                        "Impossible to guess which feature extractor to use. "
                        "Please provide a PreTrainedFeatureExtractor class or a path/identifier "
                        "to a pretrained feature extractor."
                    )

            # Instantiate feature_extractor if needed
            if isinstance(feature_extractor, (str, tuple)):
                feature_extractor = AutoFeatureExtractor.from_pretrained(
                    feature_extractor, _from_pipeline=task, **hub_kwargs, **model_kwargs
                )
                config_dict, _ = FeatureExtractionMixin.get_feature_extractor_dict(
                    pretrained_model_name_or_path,
                    **hub_kwargs,
                )
                processor_class = config_dict.get("processor_class", None)

                if processor_class is not None and processor_class.endswith("WithLM") and isinstance(model_name, str):
                    try:
                        import kenlm  # to trigger `ImportError` if not installed
                        from pyctcdecode import BeamSearchDecoderCTC

                        if os.path.isdir(model_name) or os.path.isfile(model_name):
                            decoder = BeamSearchDecoderCTC.load_from_dir(model_name)
                        else:
                            language_model_glob = os.path.join(
                                BeamSearchDecoderCTC._LANGUAGE_MODEL_SERIALIZED_DIRECTORY, "*"
                            )
                            alphabet_filename = BeamSearchDecoderCTC._ALPHABET_SERIALIZED_FILENAME
                            allow_patterns = [language_model_glob, alphabet_filename]
                            decoder = BeamSearchDecoderCTC.load_from_hf_hub(model_name, allow_patterns=allow_patterns)

                        kwargs["decoder"] = decoder
                    except ImportError as e:
                        logger.warning(
                            f"Could not load the `decoder` for {model_name}. Defaulting to raw CTC. Error: {e}"
                        )
                        if not is_kenlm_available():

Review comment (bug):
```suggestion
                    pretrained_model_name_or_path or model_name,
```

otherwise `pipeline("automatic-speech-recognition")` (without specifying a model) would fail, as `pretrained_model_name_or_path` will be `None`.

Code after:
            if load_image_processor:
                raise e
            else:
                image_processor = None

    if load_feature_extractor or load_feature_extractor is None:
        try:
            # Try to infer feature extractor from model or config name (if provided as str)
            if feature_extractor is None:
                if isinstance(model_name, str):
                    feature_extractor = model_name
                elif isinstance(config, str):
                    feature_extractor = config
                else:
                    # Impossible to guess what is the right feature_extractor here
                    raise Exception(
                        "Impossible to guess which feature extractor to use. "
                        "Please provide a PreTrainedFeatureExtractor class or a path/identifier "
                        "to a pretrained feature extractor."
                    )

            # Instantiate feature_extractor if needed
            if isinstance(feature_extractor, (str, tuple)):
                feature_extractor = AutoFeatureExtractor.from_pretrained(
                    feature_extractor, _from_pipeline=task, **hub_kwargs, **model_kwargs
                )
                config_dict, _ = FeatureExtractionMixin.get_feature_extractor_dict(
                    pretrained_model_name_or_path or model_name,
                    **hub_kwargs,
                )
                processor_class = config_dict.get("processor_class", None)

                if processor_class is not None and processor_class.endswith("WithLM") and isinstance(model_name, str):
                    try:
                        import kenlm  # to trigger `ImportError` if not installed
                        from pyctcdecode import BeamSearchDecoderCTC

                        if os.path.isdir(model_name) or os.path.isfile(model_name):
                            decoder = BeamSearchDecoderCTC.load_from_dir(model_name)
                        else:
                            language_model_glob = os.path.join(
                                BeamSearchDecoderCTC._LANGUAGE_MODEL_SERIALIZED_DIRECTORY, "*"
                            )
                            alphabet_filename = BeamSearchDecoderCTC._ALPHABET_SERIALIZED_FILENAME
                            allow_patterns = [language_model_glob, alphabet_filename]
                            decoder = BeamSearchDecoderCTC.load_from_hf_hub(model_name, allow_patterns=allow_patterns)

                        kwargs["decoder"] = decoder
                    except ImportError as e:
                        logger.warning(
                            f"Could not load the `decoder` for {model_name}. Defaulting to raw CTC. Error: {e}"