我正在使用Azure转换器API将瑞典语翻译为英语。
令人惊讶的是,这失败了一个非常简单的词:man
(这是瑞典语,在英语:P中表示man
)。
置信度为1,而不是将其转换为man
,而是将其转换为to
。
您可以使用其API来重现此行为,例如,使用以下python代码:https://github.com/MicrosoftTranslator/Text-Translation-API-V3-Python/blob/master/DictionaryLookup.py
我还要粘贴以下已为瑞典语和man
配置的代码。但您需要一个Azure API密钥:
# -*- coding: utf-8 -*-
import http.client, urllib.parse, uuid, json
# **********************************************
# *** Update or verify the following values. ***
# **********************************************
# Replace the subscriptionKey string value with your valid subscription key.
subscriptionKey = 'TODO: enter your key here'
host = 'api.cognitive.microsofttranslator.com'
path = '/dictionary/lookup?api-version=3.0'
params = '&from=sv&to=en';
text = 'man'
def lookup (content):
headers = {
'Ocp-Apim-Subscription-Key': subscriptionKey,
'Content-type': 'application/json',
'X-ClientTraceId': str(uuid.uuid4())
}
conn = http.client.HTTPSConnection(host)
conn.request ("POST", path + params, content, headers)
response = conn.getresponse ()
return response.read ()
requestBody = [{
'Text' : text,
}]
content = json.dumps(requestBody, ensure_ascii=False).encode('utf-8')
result = lookup (content)
# Note: We convert result, which is JSON, to and from an object so we can pretty-print it.
# We want to avoid escaping any Unicode characters that result contains. See:
# https://stackoverflow.com/questions/18337407/saving-utf-8-texts-in-json-dumps-as-utf8-not-as-u-escape-sequence
output = json.dumps(json.loads(result), indent=4, ensure_ascii=False)
print (output)
令人惊讶的是,bing翻译网站没有问题。
我可以访问Bing拥有的相同后端吗? 这是Azure中的错误,还是我缺少什么?