T2TT in 96 languages?
I have been testing seamless-m4t-v2-large
following the example given on Hugging Face. I am trying to translate "Hello, my dog is cute" in all of the 96 languages. However, only 35 languages seem to work. Why is that?
Here's my code:
from transformers import AutoProcessor, SeamlessM4Tv2Model
import torch
import soundfile
import os
import json
# Load language codes and names from JSON file
with open('languages.json', 'r') as file:
data = json.load(file)
language_codes = list(data['languages'].keys())
language_names = data['languages']
# Load the Seamless model and processor
processor = AutoProcessor.from_pretrained("facebook/seamless-m4t-v2-large")
model = SeamlessM4Tv2Model.from_pretrained("facebook/seamless-m4t-v2-large")
# Set the device to CUDA if available, else use CPU
device = "cuda:0" if torch.cuda.is_available() else "cpu"
# List of target language codes
language_codes = [
'afr', 'amh', 'arb', 'ary', 'arz', 'asm', 'ast', 'azj', 'bel', 'ben',
'bos', 'bul', 'cat', 'ceb', 'ces', 'ckb', 'cmn', 'cmn_Hant', 'cym', 'dan',
'deu', 'ell', 'eng', 'est', 'eus', 'fin', 'fra', 'fuv', 'gaz', 'gle',
'glg', 'guj', 'heb', 'hin', 'hrv', 'hun', 'hye', 'ibo', 'ind', 'isl', 'ita',
'jav', 'jpn', 'kam', 'kan', 'kat', 'kaz', 'kea', 'khk', 'khm', 'kir', 'kor',
'lao', 'lit', 'ltz', 'lug', 'luo', 'lvs', 'mai', 'mal', 'mar', 'mkd', 'mlt',
'mni', 'mya', 'nld', 'nno', 'nob', 'npi', 'nya', 'oci', 'ory', 'pan', 'pbt',
'pes', 'pol', 'por', 'ron', 'rus', 'slk', 'slv', 'sna', 'snd', 'som', 'spa',
'srp', 'swe', 'swh', 'tam', 'tel', 'tgk', 'tgl', 'tha', 'tur', 'ukr', 'urd',
'uzn', 'vie', 'xho', 'yor', 'yue', 'zlm', 'zsm', 'zul'
]
text_to_translate = "Hello, my dog is cute"
# Translate and print results
for tgt_lang in language_codes:
try:
text_inputs = processor(text=text_to_translate, src_lang="eng", return_tensors="pt").to(device)
decoder_input_ids = model.generate(**text_inputs, tgt_lang=tgt_lang, generate_speech=False)[0].tolist()
translated_text = processor.decode(decoder_input_ids[0], skip_special_tokens=True)
print(f"=> {tgt_lang}: {translated_text}")
audio_array_from_text = model.generate(**text_inputs, tgt_lang=tgt_lang)[0].cpu().numpy().squeeze()
sample_rate = model.config.sampling_rate
soundfile.write(f"audio_output/{tgt_lang}_output_audio.wav", audio_array_from_text, sample_rate)
except ValueError as ve:
if "is not supported by this model" in str(ve):
continue
else:
print(f"Error translating to {tgt_lang}: {ve}")
continue
except Exception as e:
print(f"Error translating to {tgt_lang}: {e}")
continue
And here's the output:
=> arb: مرحباً، كلبي حلو
=> ben: হ্যালো, আমার কুকুরটা সুন্দর
=> cat: Hola, el meu gos és bonic.
=> ces: Ahoj, můj pes je roztomilý.
=> cmn: 你好,我的狗很可爱
=> cym: Helo, mae fy nghŵn yn ddoniol
=> dan: Hej, min hund er sød.
=> deu: Hallo, mein Hund ist süß.
=> eng: Hello, my dog is cute
=> est: Tere, mu koer on armas.
=> fin: Hei, koirani on söpö.
=> fra: Salut, mon chien est mignon
=> hin: हैलो, मेरे कुत्ते प्यारा है
=> ind: Halo, anjingku lucu
=> ita: Ciao, il mio cane è carino.
=> jpn: こんにちは私の犬は可愛いです
=> kor: 안하세요, 제 개는 귀습니다.
=> mlt: Hello, il-kelb tiegħi huwa ħelu
=> nld: Hallo, mijn hond is schattig.
=> pes: سلام، سگ من دوست داشتنی است.
=> pol: Cześć, mój pies jest uroczy.
=> por: Olá, o meu cão é bonito.
=> ron: Bună ziua, câinele meu este drăguţ.
=> rus: Привет, моя собака милая.
=> slk: Ahoj, môj pes je roztomilý.
=> spa: Hola, mi perro es lindo.
=> swe: Hallå, min hund är söt.
=> swh: Hello, mbwa wangu ni cute
=> tel: హలో, నా కుక్క అందమైన ఉంది
=> tgl: Kumusta, ang aking aso ay kaakit-akit
=> tha: สวัสดีครับ สุนัขผมน่ารักมาก
=> tur: Merhaba, köpeğim çok tatlı.
=> ukr: Привіт, мій собака мила.
=> urd: ہیلو، میرا کتا پیارا ہے
=> uzn: Assalomu alaykum, mening itim juda yoqimli.
=> vie: Xin chào, con chó của tôi rất dễ thương.
There are actually 98 text languages supported (we didn't count languages with 2 scripts like cmn
/cmn_Hant
or the two Norwegian varieties nno
/nob
).
This is the script I'm using to generate T2TT outputs in all 98 supported languages:
from transformers import AutoProcessor, SeamlessM4Tv2Model, SeamlessM4Tv2ForTextToText
import torch
# Set the device to CUDA if available, else use CPU
device = "cuda:0" if torch.cuda.is_available() else "cpu"
# Load the Seamless model and processor
processor = AutoProcessor.from_pretrained("facebook/seamless-m4t-v2-large")
model = SeamlessM4Tv2ForTextToText.from_pretrained("facebook/seamless-m4t-v2-large").to(device)
# List of target language codes
language_codes = [
'afr', 'amh', 'arb', 'ary', 'arz', 'asm', 'azj', 'bel',
'ben', 'bos', 'bul', 'cat', 'ceb', 'ces', 'ckb', 'cmn',
'cmn_Hant', 'cym', 'dan', 'deu', 'ell', 'eng', 'est',
'eus', 'fin', 'fra', 'fuv', 'gaz', 'gle', 'glg', 'guj',
'heb', 'hin', 'hrv', 'hun', 'hye', 'ibo', 'ind', 'isl',
'ita', 'jav', 'jpn', 'kan', 'kat', 'kaz', 'khk', 'khm',
'kir', 'kor', 'lao', 'lit', 'lug', 'luo', 'lvs', 'mai',
'mal', 'mar', 'mkd', 'mlt', 'mni', 'mya', 'nld', 'nno',
'nob', 'npi', 'nya', 'ory', 'pan', 'pbt', 'pes', 'pol',
'por', 'ron', 'rus', 'sat', 'slk', 'slv', 'sna', 'snd',
'som', 'spa', 'srp', 'swe', 'swh', 'tam', 'tel', 'tgk',
'tgl', 'tha', 'tur', 'ukr', 'urd', 'uzn', 'vie', 'yor',
'yue', 'zlm', 'zul'
]
text_to_translate = "Hello, my dog is cute"
# Translate and print results
for tgt_lang in language_codes:
text_inputs = processor(text=text_to_translate, src_lang="eng", return_tensors="pt").to(device)
decoder_input_ids = model.generate(**text_inputs, tgt_lang=tgt_lang)[0].tolist()
translated_text = processor.decode(decoder_input_ids, skip_special_tokens=True)
print(f"=> {tgt_lang}: {translated_text}")
These are the outputs I get:
=> afr: Hallo, my hond is oulik
=> amh: ጤና ይስጥልኝ፣ ውሻዬ በጣም ቆንጆ ነው።
=> arb: مرحباً، كلبي حلو
=> ary: أهلا، الكلب ديالي حلو.
=> arz: أهلا، كلبي حلو.
=> asm: হেল্লো, মোৰ কুকুৰাটো মৰমলগা
=> azj: Salam, mənim köpəyim çox şirindir.
=> bel: Прывітанне, мой сабака мілы
=> ben: হ্যালো, আমার কুকুরটা সুন্দর
=> bos: Zdravo, moj pas je slatki.
=> bul: Здравей, кучето ми е сладко.
=> cat: Hola, el meu gos és bonic.
=> ceb: Kumusta, ang akong iro matahom
=> ces: Ahoj, můj pes je roztomilý.
=> ckb: سڵاو، سەگەکەم زۆر خۆشە
=> cmn: 你好,我的狗很可爱
=> cmn_Hant: 大家好,我的狗很可愛
=> cym: Helo, mae fy nghŵn yn ddoniol
=> dan: Hej, min hund er sød.
=> deu: Hallo, mein Hund ist süß.
=> ell: Γεια σου, ο σκύλος μου είναι χαριτωμένος.
=> eng: Hello, my dog is cute
=> est: Tere, mu koer on armas.
=> eus: Kaixo, nire txakurra oso polita da.
=> fin: Hei, koirani on söpö.
=> fra: Salut, mon chien est mignon
=> fuv: Hello, my dog is cute. (Hello, my dog is cute.)
=> gaz: Salaam, sareen koo baay'ee bareedaa dha
=> gle: Dia duit, tá mo mhadra suimiúil
=> glg: Ola, o meu can é bonito.
=> guj: હેલો, મારો કૂતરો સુંદર છે
=> heb: שלום, הכלב שלי חמוד.
=> hin: हैलो, मेरे कुत्ते प्यारा है
=> hrv: Zdravo, moj pas je slatki.
=> hun: Helló, a kutyám aranyos.
=> hye: Ողջույն, իմ շունը քաղցր է:
=> ibo: Ndewo, nkịta m mara mma
=> ind: Halo, anjingku lucu
=> isl: Halló, hundurinn minn er sætur.
=> ita: Ciao, il mio cane è carino.
=> jav: Halo, segawonku lucu banget
=> jpn: こんにちは私の犬は可愛いです
=> kan: ಹಲೋ, ನನ್ನ ನಾಯಿ ಮುದ್ದಾಗಿದೆ
=> kat: ჰელო, ჩემი ძაღლი საყვარელია.
=> kaz: Сәлем, менің итім сүйкімді.
=> khk: Сайн байна уу, миний нохой гоё байна.
=> khm: សួស្តី ឆ្កែ របស់ខ្ញុំ ស្រស់ស្អាត ណាស់
=> kir: Саламатсызбы, менин итим сүйкүмдүү.
=> kor: 안하세요, 제 개는 귀습니다.
=> lao: ສະບາຍດີ, ຫມາ ຂອງຂ້ອຍຫນ້າຮັກ
=> lit: Sveiki, mano šuo yra mielas.
=> lug: Hello, embwa yange nnungi nnyo
=> luo: Hello, guok mara ber ahinya
=> lvs: Sveiki, mans suns ir jauks.
=> mai: हेलो, हमर कुत्ता बहुत प्यारा अछि
=> mal: ഹലോ, എന്റെ നായ സുന്ദരമാണ്.
=> mar: हॅलो, माझा कुत्रा गोड आहे
=> mkd: Здраво, моето куче е слатко.
=> mlt: Hello, il-kelb tiegħi huwa ħelu
=> mni: হেলো, ঐগী শগোল অসি য়াম্না নুংশিজৈ
=> mya: ဟဲလို၊ ငါ့ခွေးက ချစ်စရာကောင်းတယ်
=> nld: Hallo, mijn hond is schattig.
=> nno: Hallå, hunden min er søt.
=> nob: Hei, hunden min er søt.
=> npi: नमस्कार, मेरो कुकुर प्यारा छ
=> nya: Moni, galu wanga ndi wokongola
=> ory: ହେଲୋ, ମୋର କୁକୁରଟି ବହୁତ ସୁନ୍ଦରୀ
=> pan: ਹੈਲੋ, ਮੇਰਾ ਕੁੱਤਾ ਪਿਆਰਾ ਹੈ
=> pbt: سلام، زما سپي ډېر ښکلی دی
=> pes: سلام، سگ من دوست داشتنی است.
=> pol: Cześć, mój pies jest uroczy.
=> por: Olá, o meu cão é bonito.
=> ron: Bună ziua, câinele meu este drăguţ.
=> rus: Привет, моя собака милая.
=> sat: হেলো, ঐগী শগোল য়াম্না মধুর
=> slk: Ahoj, môj pes je roztomilý.
=> slv: Pozdravljeni, moj pes je srčkan.
=> sna: Mhoroi, imbwa yangu inotapira
=> snd: هيلو، منهنجو ڪتو پيارو آهي
=> som: Salaan, eeyga waa mid qurux badan
=> spa: Hola, mi perro es lindo.
=> srp: Здраво, мој пас је слатки.
=> swe: Hallå, min hund är söt.
=> swh: Hello, mbwa wangu ni cute
=> tam: ஹலோ, என் நாய் அழகாக இருக்கிறது
=> tel: హలో, నా కుక్క అందమైన ఉంది
=> tgk: Салом, саги ман хеле зебо аст.
=> tgl: Kumusta, ang aking aso ay kaakit-akit
=> tha: สวัสดีครับ สุนัขผมน่ารักมาก
=> tur: Merhaba, köpeğim çok tatlı.
=> ukr: Привіт, мій собака мила.
=> urd: ہیلو، میرا کتا پیارا ہے
=> uzn: Assalomu alaykum, mening itim juda yoqimli.
=> vie: Xin chào, con chó của tôi rất dễ thương.
=> yor: Ẹ kú o, ajá mi dùn ún wò.
=> yue: 大家好,我個狗好可愛
=> zlm: Hello, anjing saya sangat comel
=> zul: Sawubona, inja yami imnandi