About using inference API of this model
I am trying to use inference API of this mbart50 model but I am not able to pass target language code in query. I want to translate text to required target language. How can I acheive this through inference API. Can someone help me with it?
Regards,
Sanjita
Please help me out.
Hey @sanjitaa I believe the model is incorrectly deployed using Text2TextGeneration instead of Translation, which means that it currently cannot be used through the InferenceApi with specific target languages.
I'm updating it here: https://huggingface.co./facebook/mbart-large-50-many-to-many-mmt/discussions/11
In the meantime, here's how you can already use it:
import json
import requests
headers = {"Authorization": f"Bearer xxx"}
API_URL = "https://api-inference.huggingface.co/pipeline/translation/facebook/mbart-large-50-many-to-many-mmt"
def query(payload):
data = json.dumps(payload)
response = requests.request("POST", API_URL, headers=headers, data=data)
return json.loads(response.content.decode("utf-8"))
data = query({"inputs": "My name is Sarah Jessica Parker but you can call me Jessica", "parameters": {"src_lang": "en_XX", "tgt_lang": "fr_XX"}})
print(data)
This returns
[{'translation_text': "Mon nom est Sarah Jessica Parker mais vous pouvez m'appeler Jessica"}]
The language codes can be found in the README.md file. Make sure you change "xxx" to your personal token!
I believe there is a limit of 1024
tokens given the max_position_embeddings
field in the config.json
Models such as MBART have a maximum size, unfortunately. You could split it into smaller texts and translate in batches. Some models, like the Longformer, can translate very large texts; unfortunately, it is not the case for this model.
I invite you to read the documentation of the inference API, available here: https://huggingface.co./docs/api-inference/quicktour
It contains answers to your questions :)
Thanks!