Added alirezamsh/small100, salamandrata pipe, remove Llamax 8b too big and slow
Browse files
app.py
CHANGED
|
@@ -38,19 +38,18 @@ models = ["Helsinki-NLP", "QUICKMT", "Argos", "Lego-MT/Lego-MT", "HPLT", "HPLT-O
|
|
| 38 |
"Helsinki-NLP/opus-mt-tc-bible-big-roa-en",
|
| 39 |
"facebook/nllb-200-distilled-600M", "facebook/nllb-200-distilled-1.3B", "facebook/nllb-200-1.3B", "facebook/nllb-200-3.3B",
|
| 40 |
"facebook/mbart-large-50-many-to-many-mmt", "facebook/mbart-large-50-one-to-many-mmt", "facebook/mbart-large-50-many-to-one-mmt",
|
| 41 |
-
"facebook/m2m100_418M", "facebook/m2m100_1.2B",
|
| 42 |
"bigscience/mt0-small", "bigscience/mt0-base", "bigscience/mt0-large", "bigscience/mt0-xl",
|
| 43 |
"bigscience/bloomz-560m", "bigscience/bloomz-1b1", "bigscience/bloomz-1b7", "bigscience/bloomz-3b",
|
| 44 |
"t5-small", "t5-base", "t5-large",
|
| 45 |
"google/flan-t5-small", "google/flan-t5-base", "google/flan-t5-large", "google/flan-t5-xl",
|
| 46 |
"google/madlad400-3b-mt", "Heng666/madlad400-3b-mt-ct2", "Heng666/madlad400-3b-mt-ct2-int8", "Heng666/madlad400-7b-mt-ct2-int8",
|
| 47 |
-
"BSC-LT/salamandraTA-2b-instruct", "BSC-LT/salamandraTA-7b-instruct",
|
| 48 |
"utter-project/EuroLLM-1.7B", "utter-project/EuroLLM-1.7B-Instruct",
|
| 49 |
"Unbabel/Tower-Plus-2B", "Unbabel/TowerInstruct-7B-v0.2", "Unbabel/TowerInstruct-Mistral-7B-v0.2",
|
| 50 |
-
"HuggingFaceTB/SmolLM3-3B",
|
| 51 |
"winninghealth/WiNGPT-Babel-2-1", "winninghealth/WiNGPT-Babel-2", "winninghealth/WiNGPT-Babel",
|
| 52 |
-
"tencent/Hunyuan-MT-7B",
|
| 53 |
-
"openGPT-X/Teuken-7B-instruct-commercial-v0.4", "openGPT-X/Teuken-7B-instruct-v0.6",
|
| 54 |
]
|
| 55 |
class Translators:
|
| 56 |
def __init__(self, model_name: str, sl: str, tl: str, input_text: str):
|
|
@@ -214,10 +213,9 @@ class Translators:
|
|
| 214 |
def salamandratapipe(self):
|
| 215 |
pipe = pipeline("text-generation", model=self.model_name)
|
| 216 |
messages = [{"role": "user", "content": f"Translate the following text from {self.sl} into {self.tl}.\n{self.sl}: {self.input_text} \n{self.tl}:"}]
|
| 217 |
-
return pipe(messages)[0]["generated_text"]
|
| 218 |
|
| 219 |
def salamandrata(self):
|
| 220 |
-
# from datetime import datetime
|
| 221 |
text = f"Translate the following text from {self.sl} into {self.tl}.\n{self.sl}: {self.input_text} \n{self.tl}:"
|
| 222 |
tokenizer = AutoTokenizer.from_pretrained(self.model_name)
|
| 223 |
model = AutoModelForCausalLM.from_pretrained(
|
|
@@ -225,7 +223,8 @@ class Translators:
|
|
| 225 |
device_map="auto",
|
| 226 |
torch_dtype=torch.bfloat16
|
| 227 |
)
|
| 228 |
-
message = [
|
|
|
|
| 229 |
# date_string = datetime.today().strftime('%Y-%m-%d')
|
| 230 |
prompt = tokenizer.apply_chat_template(
|
| 231 |
message,
|
|
@@ -283,6 +282,16 @@ class Translators:
|
|
| 283 |
generated_tokens = model.generate(**encoded, forced_bos_token_id=tokenizer.get_lang_id(self.tl))
|
| 284 |
return tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)[0]
|
| 285 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 286 |
def madlad(self):
|
| 287 |
model = T5ForConditionalGeneration.from_pretrained(self.model_name, device_map="auto")
|
| 288 |
tokenizer = T5Tokenizer.from_pretrained(self.model_name)
|
|
@@ -598,9 +607,9 @@ def translate_text(model_name: str, s_language: str, t_language: str, input_text
|
|
| 598 |
|
| 599 |
elif "HPLT" in model_name:
|
| 600 |
if model_name == "HPLT-OPUS":
|
| 601 |
-
translated_text,
|
| 602 |
else:
|
| 603 |
-
translated_text,
|
| 604 |
|
| 605 |
elif model_name == 'Argos':
|
| 606 |
translated_text = Translators(model_name, sl, tl, input_text).argos()
|
|
@@ -611,6 +620,9 @@ def translate_text(model_name: str, s_language: str, t_language: str, input_text
|
|
| 611 |
elif "salamandra" in model_name.lower():
|
| 612 |
translated_text = Translators(model_name, s_language, t_language, input_text).salamandratapipe()
|
| 613 |
|
|
|
|
|
|
|
|
|
|
| 614 |
elif "m2m" in model_name.lower():
|
| 615 |
translated_text = Translators(model_name, sl, tl, input_text).mtom()
|
| 616 |
|
|
|
|
| 38 |
"Helsinki-NLP/opus-mt-tc-bible-big-roa-en",
|
| 39 |
"facebook/nllb-200-distilled-600M", "facebook/nllb-200-distilled-1.3B", "facebook/nllb-200-1.3B", "facebook/nllb-200-3.3B",
|
| 40 |
"facebook/mbart-large-50-many-to-many-mmt", "facebook/mbart-large-50-one-to-many-mmt", "facebook/mbart-large-50-many-to-one-mmt",
|
| 41 |
+
"facebook/m2m100_418M", "facebook/m2m100_1.2B", "alirezamsh/small100",
|
| 42 |
"bigscience/mt0-small", "bigscience/mt0-base", "bigscience/mt0-large", "bigscience/mt0-xl",
|
| 43 |
"bigscience/bloomz-560m", "bigscience/bloomz-1b1", "bigscience/bloomz-1b7", "bigscience/bloomz-3b",
|
| 44 |
"t5-small", "t5-base", "t5-large",
|
| 45 |
"google/flan-t5-small", "google/flan-t5-base", "google/flan-t5-large", "google/flan-t5-xl",
|
| 46 |
"google/madlad400-3b-mt", "Heng666/madlad400-3b-mt-ct2", "Heng666/madlad400-3b-mt-ct2-int8", "Heng666/madlad400-7b-mt-ct2-int8",
|
| 47 |
+
"BSC-LT/salamandraTA-2b-instruct", "BSC-LT/salamandraTA-7b-instruct", "BSC-LT/salamandraTA-2B-academic", "BSC-LT/salamandraTA-7B-academic",
|
| 48 |
"utter-project/EuroLLM-1.7B", "utter-project/EuroLLM-1.7B-Instruct",
|
| 49 |
"Unbabel/Tower-Plus-2B", "Unbabel/TowerInstruct-7B-v0.2", "Unbabel/TowerInstruct-Mistral-7B-v0.2",
|
| 50 |
+
"HuggingFaceTB/SmolLM3-3B",
|
| 51 |
"winninghealth/WiNGPT-Babel-2-1", "winninghealth/WiNGPT-Babel-2", "winninghealth/WiNGPT-Babel",
|
| 52 |
+
"tencent/Hunyuan-MT-7B", "openGPT-X/Teuken-7B-instruct-commercial-v0.4", "openGPT-X/Teuken-7B-instruct-v0.6",
|
|
|
|
| 53 |
]
|
| 54 |
class Translators:
|
| 55 |
def __init__(self, model_name: str, sl: str, tl: str, input_text: str):
|
|
|
|
| 213 |
def salamandratapipe(self):
|
| 214 |
pipe = pipeline("text-generation", model=self.model_name)
|
| 215 |
messages = [{"role": "user", "content": f"Translate the following text from {self.sl} into {self.tl}.\n{self.sl}: {self.input_text} \n{self.tl}:"}]
|
| 216 |
+
return pipe(messages)[0]["generated_text"][1]["content"]
|
| 217 |
|
| 218 |
def salamandrata(self):
|
|
|
|
| 219 |
text = f"Translate the following text from {self.sl} into {self.tl}.\n{self.sl}: {self.input_text} \n{self.tl}:"
|
| 220 |
tokenizer = AutoTokenizer.from_pretrained(self.model_name)
|
| 221 |
model = AutoModelForCausalLM.from_pretrained(
|
|
|
|
| 223 |
device_map="auto",
|
| 224 |
torch_dtype=torch.bfloat16
|
| 225 |
)
|
| 226 |
+
message = [{"role": "user", "content": text}]
|
| 227 |
+
# from datetime import datetime
|
| 228 |
# date_string = datetime.today().strftime('%Y-%m-%d')
|
| 229 |
prompt = tokenizer.apply_chat_template(
|
| 230 |
message,
|
|
|
|
| 282 |
generated_tokens = model.generate(**encoded, forced_bos_token_id=tokenizer.get_lang_id(self.tl))
|
| 283 |
return tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)[0]
|
| 284 |
|
| 285 |
+
def smallonehundred(self):
|
| 286 |
+
from transformers import M2M100ForConditionalGeneration
|
| 287 |
+
from tokenization_small100 import SMALL100Tokenizer
|
| 288 |
+
model = M2M100ForConditionalGeneration.from_pretrained(self.model_name)
|
| 289 |
+
tokenizer = SMALL100Tokenizer.from_pretrained(self.model_name)
|
| 290 |
+
tokenizer.tgt_lang = self.tl
|
| 291 |
+
encoded_sl = tokenizer(self.input_text, return_tensors="pt")
|
| 292 |
+
generated_tokens = model.generate(**encoded_sl, max_length=256, num_beams=5)
|
| 293 |
+
return tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)[0]
|
| 294 |
+
|
| 295 |
def madlad(self):
|
| 296 |
model = T5ForConditionalGeneration.from_pretrained(self.model_name, device_map="auto")
|
| 297 |
tokenizer = T5Tokenizer.from_pretrained(self.model_name)
|
|
|
|
| 607 |
|
| 608 |
elif "HPLT" in model_name:
|
| 609 |
if model_name == "HPLT-OPUS":
|
| 610 |
+
translated_text, message_text = Translators(model_name, sl, tl, input_text).hplt(opus = True)
|
| 611 |
else:
|
| 612 |
+
translated_text, message_text = Translators(model_name, sl, tl, input_text).hplt()
|
| 613 |
|
| 614 |
elif model_name == 'Argos':
|
| 615 |
translated_text = Translators(model_name, sl, tl, input_text).argos()
|
|
|
|
| 620 |
elif "salamandra" in model_name.lower():
|
| 621 |
translated_text = Translators(model_name, s_language, t_language, input_text).salamandratapipe()
|
| 622 |
|
| 623 |
+
elif "small100" in model_name.lower():
|
| 624 |
+
translated_text = Translators(model_name, sl, tl, input_text).smallonehundred()
|
| 625 |
+
|
| 626 |
elif "m2m" in model_name.lower():
|
| 627 |
translated_text = Translators(model_name, sl, tl, input_text).mtom()
|
| 628 |
|