Feature Extraction
Transformers
Safetensors
granite_speech_nar
speech
asr
non-autoregressive
ctc
speech_recognition
automatic_speech_recognition
custom_code
Instructions to use ibm-granite/granite-speech-4.1-2b-nar with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ibm-granite/granite-speech-4.1-2b-nar with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="ibm-granite/granite-speech-4.1-2b-nar", trust_remote_code=True)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("ibm-granite/granite-speech-4.1-2b-nar", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
| # Copyright 2026 IBM and The HuggingFace Team. All rights reserved. | |
| # | |
| # Licensed under the Apache License, Version 2.0 (the "License"); | |
| # you may not use this file except in compliance with the License. | |
| # You may obtain a copy of the License at | |
| # | |
| # http://www.apache.org/licenses/LICENSE-2.0 | |
| # | |
| # Unless required by applicable law or agreed to in writing, software | |
| # distributed under the License is distributed on an "AS IS" BASIS, | |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| # See the License for the specific language governing permissions and | |
| # limitations under the License. | |
| """Processor for Granite Speech NAR.""" | |
| from transformers.processing_utils import ProcessorMixin | |
| from transformers.tokenization_utils_base import AudioInput | |
| from transformers.utils import is_torch_available | |
| from .feature_extraction_granite_speech_nar import GraniteSpeechNarFeatureExtractor | |
| if is_torch_available(): | |
| import torch | |
| class GraniteSpeechNarProcessor(ProcessorMixin): | |
| """Processor combining audio feature extraction and tokenizer for GraniteSpeechNar.""" | |
| tokenizer_class = "AutoTokenizer" | |
| def __init__(self, feature_extractor: GraniteSpeechNarFeatureExtractor, tokenizer=None, **kwargs): | |
| super().__init__(feature_extractor=feature_extractor, tokenizer=tokenizer, **kwargs) | |
| def __call__( | |
| self, | |
| audios: AudioInput, | |
| device: str | None = None, | |
| **kwargs, | |
| ) -> dict: | |
| return self.feature_extractor(audios, device=device) | |
| def batch_decode(self, token_ids_list: list["torch.Tensor"], **kwargs) -> list[str]: | |
| if self.tokenizer is None: | |
| raise ValueError("Tokenizer not set. Pass tokenizer to GraniteSpeechNarProcessor.") | |
| return [self.tokenizer.decode(ids, skip_special_tokens=True) for ids in token_ids_list] | |
| __all__ = ["GraniteSpeechNarProcessor"] | |