Transformers
PyTorch
multilingual
seamless_translation
audio
text
multimodal
seamless
subtitle-editing-time-prediction
translation-aware
Instructions to use videoloc/seamless-translation with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use videoloc/seamless-translation with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import HFSeamlessTranslation model = HFSeamlessTranslation.from_pretrained("videoloc/seamless-translation", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download example_usage.py from videoloc/seamless-translation: direct link, hf CLI and curl.
- Browser
- Download file 2.11 kB
-
https://huggingface.co/videoloc/seamless-translation/resolve/main/example_usage.py
- Command line
-
hf download hf://videoloc/seamless-translation/example_usage.py
-
curl -L -o example_usage.py https://huggingface.co/videoloc/seamless-translation/resolve/main/example_usage.py
2.11 kB
| #!/usr/bin/env python3 | |
| # Example usage for videoloc/seamless-translation | |
| from transformers import AutoModel, AutoConfig | |
| from huggingface_hub import hf_hub_download | |
| import torch | |
| import numpy as np | |
| import importlib.util | |
| def load_model_and_collator(): | |
| # Load model - custom architecture requires importing the model class | |
| model_files = hf_hub_download(repo_id="videoloc/seamless-translation", filename="modeling_seamless_translation.py") | |
| spec = importlib.util.spec_from_file_location("modeling_seamless_translation", model_files) | |
| modeling_module = importlib.util.module_from_spec(spec) | |
| spec.loader.exec_module(modeling_module) | |
| # Now load the model using the custom class | |
| config = modeling_module.SeamlessTranslationConfig.from_pretrained("videoloc/seamless-translation") | |
| model = modeling_module.HFSeamlessTranslation.from_pretrained("videoloc/seamless-translation") | |
| # Load data collator | |
| collator_file = hf_hub_download(repo_id="videoloc/seamless-translation", filename="data_collator.py") | |
| spec = importlib.util.spec_from_file_location("data_collator", collator_file) | |
| collator_module = importlib.util.module_from_spec(spec) | |
| spec.loader.exec_module(collator_module) | |
| data_collator = collator_module.DataCollatorSimpleSeamless( | |
| processor="facebook/hf-seamless-m4t-medium", | |
| max_audio_length_sec=8.0, | |
| max_text_length=256 | |
| ) | |
| return model, data_collator | |
| def example_inference(): | |
| model, collator = load_model_and_collator() | |
| # Example data with translation awareness | |
| data = [{ | |
| 'raw_audio': np.random.randn(16000 * 3), # 3 seconds at 16kHz | |
| 'raw_text': "Example subtitle text for TTE prediction", | |
| 'is_translation': 1, # 1 for translated content, 0 for original | |
| }] | |
| batch = collator(data) | |
| model.eval() | |
| with torch.no_grad(): | |
| outputs = model(**batch) | |
| tte_prediction = outputs.logits.item() | |
| print(f"Predicted Time To Edit (TTE): {tte_prediction:.2f} seconds") | |
| return tte_prediction | |
| if __name__ == "__main__": | |
| example_inference() | |