Spaces:
Sleeping
Sleeping
nicekd commited on
Commit ·
d6f9eeb
1
Parent(s): 72aa052
first update
Browse files- README.md +30 -1
- app.py +42 -0
- requirements.txt +6 -0
README.md
CHANGED
|
@@ -11,4 +11,33 @@ license: apache-2.0
|
|
| 11 |
short_description: ES→PT Translation (BART from scratch)
|
| 12 |
---
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
short_description: ES→PT Translation (BART from scratch)
|
| 12 |
---
|
| 13 |
|
| 14 |
+
## Overview
|
| 15 |
+
This Space provides a simple **Spanish → Portuguese (ES→PT)** translation demo using a **BART-style encoder–decoder Transformer trained from scratch**.
|
| 16 |
+
|
| 17 |
+
- **Dataset:** Helsinki-NLP/Tatoeba (es-pt)
|
| 18 |
+
- **Tokenizer:** Subword BPE (32k vocab)
|
| 19 |
+
- **Metric reported:** chrF (beam search)
|
| 20 |
+
|
| 21 |
+
## Model
|
| 22 |
+
This demo loads the model from the Hugging Face Hub:
|
| 23 |
+
|
| 24 |
+
**Model card:** REPLACE_WITH_YOUR_MODEL_LINK
|
| 25 |
+
(e.g., `https://huggingface.co/<username>/<model-repo>`)
|
| 26 |
+
|
| 27 |
+
## How to use
|
| 28 |
+
1. Enter a sentence in **Spanish (es)**.
|
| 29 |
+
2. Click **Submit**.
|
| 30 |
+
3. The app returns the model’s **Portuguese (pt)** translation.
|
| 31 |
+
|
| 32 |
+
## Notes / Limitations
|
| 33 |
+
- The model was trained on Tatoeba-style sentence pairs, so very long or highly technical sentences may perform worse.
|
| 34 |
+
- Minor punctuation differences or occasional repetition can occur with beam search.
|
| 35 |
+
|
| 36 |
+
## Example inputs
|
| 37 |
+
- `¡Intentemos algo!`
|
| 38 |
+
- `Las personas dicen que estoy loco.`
|
| 39 |
+
- `¿Cuál es el significado de la vida en la tierra?`
|
| 40 |
+
|
| 41 |
+
## References
|
| 42 |
+
- Dataset: https://huggingface.co/datasets/Helsinki-NLP/tatoeba
|
| 43 |
+
- Spaces config reference: https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 4 |
+
|
| 5 |
+
MODEL_ID = "liansheng06/bart-tatoeba-es-pt"
|
| 6 |
+
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
|
| 8 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_ID)
|
| 9 |
+
|
| 10 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 11 |
+
model.to(device)
|
| 12 |
+
model.eval()
|
| 13 |
+
|
| 14 |
+
def translate_es_to_pt(text):
|
| 15 |
+
if not text or not text.strip():
|
| 16 |
+
return ""
|
| 17 |
+
inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=256).to(device)
|
| 18 |
+
with torch.no_grad():
|
| 19 |
+
outputs = model.generate(
|
| 20 |
+
**inputs,
|
| 21 |
+
max_new_tokens=128,
|
| 22 |
+
num_beams=5,
|
| 23 |
+
length_penalty=1.0,
|
| 24 |
+
early_stopping=True,
|
| 25 |
+
)
|
| 26 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 27 |
+
|
| 28 |
+
demo = gr.Interface(
|
| 29 |
+
fn=translate_es_to_pt,
|
| 30 |
+
inputs=gr.Textbox(lines=4, label="Spanish (es) input"),
|
| 31 |
+
outputs=gr.Textbox(lines=4, label="Portuguese (pt) output"),
|
| 32 |
+
title="ES → PT Translator (BART from scratch)",
|
| 33 |
+
description="Model trained from scratch on Helsinki-NLP/Tatoeba (es-pt).",
|
| 34 |
+
examples=[
|
| 35 |
+
["¡Intentemos algo!"],
|
| 36 |
+
["Las personas dicen que estoy loco."],
|
| 37 |
+
["¿Cuál es el significado de la vida en la tierra?"],
|
| 38 |
+
],
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
if __name__ == "__main__":
|
| 42 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
torch
|
| 3 |
+
transformers
|
| 4 |
+
sentencepiece
|
| 5 |
+
safetensors
|
| 6 |
+
accelerate
|