The model extends the SeamlessM4T architecture with bidirectional cross-attention layers that allow audio and text representations to attend to each other, creating rich cross-modal embeddings that capture temporal and semantic relationships across 5 languages: English, French, Spanish, Italian, and German.
1from transformers import AutoModel, AutoConfig
2from huggingface_hub import hf_hub_download
3import torch
4import numpy as np
5import importlib.util
6
7# Load model - custom architecture requires importing the model class
8model_files = hf_hub_download(repo_id="videoloc/seamless-crossattention", filename="modeling_seamless_crossattention.py")
9spec = importlib.util.spec_from_file_location("modeling_seamless_crossattention", model_files)
10modeling_module = importlib.util.module_from_spec(spec)
11spec.loader.exec_module(modeling_module)
12
13# Now load the model using the custom class
14config = modeling_module.SeamlessCrossAttentionConfig.from_pretrained("videoloc/seamless-crossattention")
15model = modeling_module.HFSeamlessCrossAttention.from_pretrained("videoloc/seamless-crossattention")
16
17# Load the data collator (included in this repo)
18collator_file = hf_hub_download(repo_id="videoloc/seamless-crossattention", filename="data_collator.py")
19spec = importlib.util.spec_from_file_location("data_collator", collator_file)
20collator_module = importlib.util.module_from_spec(spec)
21spec.loader.exec_module(collator_module)
22
23# Initialize data collator
24data_collator = collator_module.DataCollatorSimpleSeamless(
25 processor="facebook/hf-seamless-m4t-medium",
26 max_audio_length_sec=8.0,
27 max_text_length=256
28)
29
30# Prepare your data
31your_data = [
32 {
33 'raw_audio': np.random.randn(16000 * 5), # 5 seconds at 16kHz
34 'raw_text': "Your subtitle text here",
35 # Note: Cross-attention model doesn't require translation features
36 }
37]
38
39# Process and run inference
40batch = data_collator(your_data)
41model.eval()
42with torch.no_grad():
43 outputs = model(**batch)
44 tte_prediction = outputs.logits.item()
45
46print(f"Predicted Time To Edit (TTE): {tte_prediction:.2f} seconds")
1data = [
2 {
3 'raw_audio': audio_samples, # shape: (num_samples,) at 16kHz
4 'raw_text': "Subtitle text content",
5 'labels': 2.5 # optional TTE target value in seconds
6 }
7]