Search code examples
microsoft-translator

Microsoft Translator Text not raising error when wrong params passed with custom engine


I've noticed 2 cases in which Microsoft Translator Text should raise errors when using custom engines, but instead has an unexpected behavior.

Normal Case

I send a request with the method POST.
URL = https://api.cognitive.microsofttranslator.com/translate
parameters :
- api-version=3.0
- textType=plain
- category=my_engine_id
- from=de
- to=en

Headers={"Ocp-Apim-Subscription-Key": my_key,'Content-type': 'application/json'}

Body (JSON format) :

[{"Text": "Klicken Sie in jedem Bildschirm auf das Textbeispiel, das am besten lesbar ist."},
{"Text": "Verschiedene Themen aus den Bereichen Wortschatz, Satzbau, Kohärenz, Textwiedergabe,
Kommasetzung und Orthographie werden anhand von Textbeispielen und Übungen vorgestellt."},
{"Text": "„Auch wenn zwei Staaten in Deutschland existieren, sind sie doch füreinander nicht Ausland; ihre Beziehungen zueinander können nur von besonderer Art sein.“"},
{"Text": "Mit dieser Formel bricht der neue Kanzler ein jahrzehntelanges Tabu."},
{"Text": "Bislang wird der östliche Teil Deutschlands von den bundesdeutschen Politikern als SBZ, Zone oder „sogenannte DDR“ bezeichnet."}]

The response is as expected:

[{"translations":
[{"text": "On each screen, click on the text sample that is most readable.",
"to": "en"}]},
{"translations":
[{"text": "Various topics from the fields of vocabulary, typesetting, coherence, text reproduction, comma setting and orthography are presented using text examples and exercises.",
"to": "en"}]},
etc.

Case 1

I change the parameter to=fr in the URL (instead of "en").

The response shows that the text has been translated into french, although the custom engine is only trained from DE>EN (therefore I think a generic engine was used instead, but there is no info in the HTTP response) !

[{"translations":[{"text":"Sur chaque écran, cliquez sur l’échantillon de texte le plus lisible.","to":"fr"}]},{"translations":[{"text":"Divers sujets des domaines du vocabulaire, du typage, de la cohérence, de la reproduction du texte, du décor de virgule et de l’orthographe sont présentés à l’aide d’exemples de textes et d’exercices.","to":"fr"}]},{"translations":[{"text":"\"Même si deux États existent en Allemagne, ils ne sont pas étrangers l’un à l’autre; Leurs relations les uns avec les autres ne peuvent être que d’un genre particulier.","to":"fr"}]},{"translations":[{"text":"Avec cette formule, le nouveau chancelier brise un tabou de dix ans.","to":"fr"}]},{"translations":[{"text":"Jusqu’à présent, la partie orientale de l’Allemagne est appelée par les politiciens fédéraux allemands SBZ, zone ou « soi-disant DDR ».","to":"fr"}]}]

Instead of this behaviour, I would have expected an error in the HTTP response :
400075 The language pair and category combination is not valid.

Case 2

I change the parameter from=da in the URL (instead of "de").

The response shows that the translation is simply a copy of the source text, although it indicates that it was translated into "en" !

[{"translations":[{"text":"Klicken Sie in jedem Bildschirm auf das Textbeispiel, das am besten lesbar ist.","to":"en"}]},{"translations":[{"text":"Verschiedene Themen aus den Bereichen Wortschatz, Satzbau, Kohärenz, Textwiedergabe, Kommasetzung und Orthographie werden anhand von Textbeispielen und Übungen vorgestellt.","to":"en"}]},{"translations":[{"text":"\"Auch wenn zwei Staaten in Deutschland existieren, sind sie doch füreinander nicht Ausland; ihre Beziehungen zueinander können nur von besonderer Art sein.\"","to":"en"}]},{"translations":[{"text":"Mit dieser Formula bricht der neue Kanzler ein jahrzehntelanges Tabu.","to":"en"}]},{"translations":[{"text":"Bislang wird der östliche Teil Deutschlands von den bundesdeutschen Politikern als SBZ, Zone oder \"sogenannte DDR\" bezeichnet.","to":"en"}]}]

Same as for Case 1, instead of this behaviour, I would have expected an error in the HTTP response :
400075 The language pair and category combination is not valid.

Is it normal that I don't get an error for these 2 cases ? Has anybody else encountered this behavior before ?

Actually I would like to either use these error codes, or else check before sending the translation request that the language pair corresponds to the custom engine, do you know of some way to do it ?


Solution

  • For case1, translation is done in two hops - de>en, en>fr. The custom engine is used for the first hop, and our general model is used for the second. If you want the translation to fail in this case instead, you can set the parameter allowFallback to false

    allowFallback Optional parameter. Specifies that the service is allowed to fallback to a general system when a custom system does not exist. Possible values are: true (default) or false. docs

    In the second case, the request contains German text but is labeled as Danish. There is nothing we can do here except return the input. If you want the api to detect the from language, omit it from the parameters and the api will run auto-detect on the text.

    If the from parameter is not specified, automatic language detection is applied to determine the source language.