# Translate short sentence

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftranslate-short-sentence%2F146293%3E%5C
**Category:** Beginners\
**Created:** [March 18, 2025, 2:20pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftranslate-short-sentence%2F146293 "2025-03-18T14:20:04Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Methos02](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Methos02](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FMethos02)%5C
**Post date:** [March 18, 2025, 2:20pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftranslate-short-sentence%2F146293%2F1 "2025-03-18T14:20:04Z")

</div>

Hello everyone,  
I am new to this field. I have set up a small API to dynamically translate my website. I have used several multilingual models because I need French, English, German, and Dutch (and soon Italian).

I am a beginner in Python, so I used ChatGPT to help me create this API.

Unfortunately, the translation quality is not very good…

- “Prénom” → “Name of family” in English
- “Envoyer” → “Send” in German

ChatGPT told me that the models I used were not designed for short sentences and that they work better with longer texts. It recommended using more traditional methods for this type of translation. I wanted to get your opinion and see which model you would recommend.

For now, I am leaning towards using a standard Google API for the site’s translation files and my API for translating user product descriptions.

Thanks in advance,

Methos

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FJohn6666)%5C
**Post date:** [March 18, 2025, 4:36pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftranslate-short-sentence%2F146293%2F2 "2025-03-18T16:36:35Z")

</div>

That’s true. With short sentences and words, there’s not much benefit to using LLM. There are ways to use smaller LMs, etc., but it’s true that you can use Google Translate.

> **[Translation](https://huggingface.co/docs/transformers/tasks/translation)**
>
> We’re on a journey to advance and democratize artificial intelligence through open source and open science.

> **[OPUS-MT multilingual (TC+Bible) - a Helsinki-NLP Collection](https://huggingface.co/collections/Helsinki-NLP/opus-mt-multilingual-tcbible-670570b993cf2ffd1749334b)**
>
> multilingual translation models trained on the Tatoeba Translation Challenge dataset (from OPUS) and a massively multilingual Bible corpus

> [@Multilingual T5 Model Not Found?](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fmultilingual-t5-model-not-found%2F1892)%3A
>
> I could not able to see T5 Multilingual Model in Multilingual Model page of [Hugging Face](https://huggingface.co/transformers/multilingual.html) page but i can able to see Multilingual Model of T5 in [Google research](https://github.com/google-research/multilingual-t5) Page When can i able to see the model available in Hugging Face repo

> **[facebook/mbart-large-50 · Hugging Face](https://huggingface.co/facebook/mbart-large-50)**
>
> We’re on a journey to advance and democratize artificial intelligence through open source and open science.

* * *

To address the translation issues with short sentences on your website, here are some recommendations that balance ease of implementation with effectiveness:

1. **HuggingFace OPUS-MT Model** : Utilize the “Helsinki-NLP/opus-mt-mul-en” model, which is designed for multilingual translations. It’s user-friendly with the Transformers library and can handle multiple languages, including French, German, Dutch, and Italian.

2. **Facebook’s mBART or M2M Models** : Use the EasyNMT package to leverage these models, which are multilingual and support a wide range of languages. They are efficient for short sentences and can be integrated with minimal code.

3. **MarianMT Models** : Consider these for their speed and efficiency. They are optimized for real-time translations and come in various language pairs, suitable for quick processing on a website.

4. **DeepL API** : If budget allows, DeepL’s API offers high-quality translations, particularly effective for short texts, though it may have usage limits.

5. **Testing and Evaluation** : Develop a script to test different models with your specific short phrases. This hands-on approach will help you evaluate which model provides the best accuracy for your needs.

6. **Adjustments for Short Texts** : Ensure proper tokenization and padding are applied, as some models may require fixed input lengths. This adjustments can improve translation quality for short sentences.

**Implementation Steps** :

- Start with installing necessary libraries like `transformers` or `easynmt`.
- Use HuggingFace’s pipeline for OPUS-MT or EasyNMT for Facebook’s models.
- Consider setting up a test environment to evaluate each model’s performance.

By exploring these options, you can enhance the accuracy of your translations while maintaining ease of use, especially since you’re a Python beginner.

---

<div class="post-metadata">

**Author:** ![Methos02](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Methos02](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FMethos02)%5C
**Post date:** [March 20, 2025, 2:50pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftranslate-short-sentence%2F146293%2F3 "2025-03-20T14:50:48Z")

</div>

Thank you very much, I’ll try that tomorrow afternoon!

---

<div class="post-metadata">

**Author:** ![Methos02](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Methos02](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FMethos02)%5C
**Post date:** [March 23, 2025, 11:47am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftranslate-short-sentence%2F146293%2F4 "2025-03-23T11:47:27Z")

</div>

I tried reading your post, but it’s a bit complicated ^^ Is it really for beginners? xD  
Here’s the code I have so far.

```auto

from fastapi import FastAPI
from pydantic import BaseModel
from transformers import pipeline

app = FastAPI()
pipe = pipeline(task='text2text-generation', model='facebook/m2m100_418M')

class TranslationRequest(BaseModel):
    source: str
    target: str
    texts: dict

@app.post("/translate")
def translate(request: TranslationRequest):
    translations = {}
    prefix = "translate French to German: "

    for key, text in request.texts.items():
        original_text = text.strip()

        result = pipe(
            prefix + original_text,
            forced_bos_token_id=pipe.tokenizer.get_lang_id(request.target)
        )

        translations[key] = result[0]["generated_text"]

    return translations

```

I already have the code for Google Translate, but that means I would have to use both technologies since I’d have both short texts and slightly longer ones. Ideally, it would be best to have just one technology for both situations.

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FJohn6666)%5C
**Post date:** [March 23, 2025, 2:48pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftranslate-short-sentence%2F146293%2F5 "2025-03-23T14:48:48Z")

</div>

Well, when it comes to creating APIs for the web, even if it’s aimed at beginners, it can be a little difficult…😅

---

<div class="post-metadata">

**Author:** ![Methos02](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Methos02](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FMethos02)%5C
**Post date:** [March 24, 2025, 9:37am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftranslate-short-sentence%2F146293%2F6 "2025-03-24T09:37:03Z")

</div>

The API works, only the translation are bad ^^

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FJohn6666)%5C
**Post date:** [March 24, 2025, 10:06am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftranslate-short-sentence%2F146293%2F7 "2025-03-24T10:06:16Z")

</div>

I think it’s often difficult to get satisfactory performance with the base model as it is. It’s a good idea to try out various models and, if they don’t seem to work, either fine-tune them or use a ready-made service.  
[https://huggingface.co/models?pipeline\_tag=text2text-generation&library=transformers&sort=trending](https://huggingface.co/models?pipeline_tag=text2text-generation&library=transformers&sort=trending)  
[https://huggingface.co/models?pipeline\_tag=translation&library=transformers&sort=trending](https://huggingface.co/models?pipeline_tag=translation&library=transformers&sort=trending)

---

<div class="post-metadata">

**Author:** ![Methos02](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Methos02](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FMethos02)%5C
**Post date:** [March 28, 2025, 1:49pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftranslate-short-sentence%2F146293%2F8 "2025-03-28T13:49:26Z")

</div>

Thx for your answer, I will look ASAP ! I have some bugs to fixe on the main branch ^^’
