{"id":1578,"date":"2022-02-23T05:07:42","date_gmt":"2022-02-23T05:07:42","guid":{"rendered":"https:\/\/salarydistribution.com\/machine-learning\/2022\/02\/23\/control-formality-in-machine-translated-text-using-amazon-translate\/"},"modified":"2022-02-23T05:07:42","modified_gmt":"2022-02-23T05:07:42","slug":"control-formality-in-machine-translated-text-using-amazon-translate","status":"publish","type":"post","link":"https:\/\/salarydistribution.com\/machine-learning\/2022\/02\/23\/control-formality-in-machine-translated-text-using-amazon-translate\/","title":{"rendered":"Control formality in machine translated text using Amazon Translate"},"content":{"rendered":"<div id=\"\">\n<p><a href=\"https:\/\/aws.amazon.com\/translate\/\" target=\"_blank\" rel=\"noopener noreferrer\">Amazon Translate<\/a><span>\u00a0<\/span>is a neural machine translation service that delivers fast, high-quality, affordable, and customizable language translation. Amazon Translate now supports formality customization. This feature allows you to customize the level of formality in your translation output. At the time of writing, the formality customization feature is available for six target languages: French, German, Hindi, Italian, Japanese, and Spanish. You can customize the formality of your translated output to suit your communication needs.<span>\u00a0<\/span><\/p>\n<p>You have three options to control the level of formality in the output:<\/p>\n<ul>\n<li><strong>Default\u00a0<\/strong>\u2013 No control over formality by letting the neural machine translation operate with no influence<\/li>\n<li><strong>Formal<\/strong> \u2013 Useful in the insurance and healthcare industry, where you may prefer a more formal translation<\/li>\n<li><strong>Informal<\/strong> \u2013 Useful for customers in gaming and social media who prefer an informal translation<\/li>\n<\/ul>\n<p>Formality customization is available in real-time translation operations in commercial <a href=\"https:\/\/aws.amazon.com\/about-aws\/global-infrastructure\/regional-product-services\/\" target=\"_blank\" rel=\"noopener noreferrer\">AWS Regions<\/a> where Amazon Translate is available. In this post, we walk you through how to use the formality customization feature <span>and get a customized translated output securely.<\/span><\/p>\n<h2>Solution overview<\/h2>\n<p>To get formal or informal words and phrases in your translation output, you can toggle the formality button under the additional settings on the Amazon Translate console when you run the translations through real-time requests. The following sections describe using formality customization via the Amazon Translate console, <a href=\"http:\/\/aws.amazon.com\/cli\" target=\"_blank\" rel=\"noopener noreferrer\">AWS Command Line Interface<\/a> (AWS CLI), or the Amazon Translate SDK (Python Boto3).<\/p>\n<h2>Amazon Translate console<\/h2>\n<p>To demonstrate the formality customization with real-time translation, we use the sample text \u201c<em>Good morning, how are you doing today? <\/em>\u201d in English:<\/p>\n<ol>\n<li>On the Amazon Translate console, choose<strong>\u00a0English (en)<\/strong> for <strong>Source language<\/strong>.<\/li>\n<li>Choose <strong>Spanish<\/strong> <strong>(es)<\/strong> for <strong>Target language<\/strong>.<\/li>\n<li>Enter the quoted text in the <strong>Source language<\/strong> text field.<\/li>\n<li>In the <strong>Additional settings<\/strong> section, enable <strong>Formality<\/strong>, and select <strong>Informal<\/strong> on the drop-down menu.<\/li>\n<\/ol>\n<p>The translated output is \u201c<em><span>Buenos d\u00edas, \u00bfc\u00f3mo te va hoy?<\/span><\/em> \u201d which is casual way of speaking in Spanish.<\/p>\n<p><em><span><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-33286\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2022\/02\/18\/Picture1-3.png\" alt=\"English to Spanish informal translation \" width=\"977\" height=\"531\"><\/span><\/em><\/p>\n<div>\n<ol start=\"5\">\n<li>Now, select <strong>Formal<\/strong> on the drop-down <strong>Formality\u00a0<\/strong>menu.<\/li>\n<\/ol><\/div>\n<p>The translated output changes to \u201c<em><span>Buenos d\u00edas, \u00bfc\u00f3mo le va hoy?<\/span><\/em> \u201d which is a more formal way of speaking in Spanish.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-33288\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2022\/02\/18\/Picture2-2.png\" alt=\"English to Spanish formal translation \" width=\"977\" height=\"529\"><\/p>\n<p>You can follow the preceding steps to change the target language to other supported languages and note the difference between the informal and formal translations. Let\u2019s try some more sample text.<\/p>\n<p>In the following examples, we translate \u201c<em>So what do you think?<\/em> \u201d from English to German. The first screenshot shows an informal translation.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-33289\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2022\/02\/18\/Picture3-1.png\" alt=\"English to German informal translation \" width=\"897\" height=\"487\"><\/p>\n<p>The following screenshot shows the formal translation.\u00a0<img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-33290\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2022\/02\/18\/Picture4-1.png\" alt=\"English to German formal translation \" width=\"906\" height=\"491\"><\/p>\n<p>In another example, we translate \u201c<em>Can I help you?<\/em> \u201d from English to Japanese. The first screenshot shows an informal translation.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-33292\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2022\/02\/18\/Picture5-1.png\" alt=\"English to Japanese informal translation \" width=\"977\" height=\"510\"><\/p>\n<p>The following screenshot shows the formal translation.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-33294\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2022\/02\/18\/Picture6-1.png\" alt=\"English to Japanese formal translation \" width=\"977\" height=\"514\"><\/p>\n<h3>AWS CLI<\/h3>\n<p>The <code>translate-text<\/code> AWS CLI command with <code>--settings Formality=FORMAL | INFORMAL<\/code> translates words and phrases in your translated text appropriately.<\/p>\n<p>The following AWS CLI commands are formatted for Unix, Linux, and macOS. For Windows, replace the backslash (<code><\/code>) Unix continuation character at the end of each line with a caret (<code>^<\/code>).<\/p>\n<p>In the following code, we translate \u201c<em>How are you?<\/em> \u201d from English to Hindi, using the <code>FORMAL<\/code> setting:<\/p>\n<pre><code class=\"lang-cli\">aws translate translate-text \n--text \"How are you?\" \n--source-language-code \"en\" \n--target-language-code \"hi\" \n--settings Formality=FORMAL<\/code><\/pre>\n<p>You get a response like the following snippet:<\/p>\n<pre><code class=\"lang-json\">{\u00a0 \u00a0 \u00a0\"TranslatedText\": \"\u0906\u092a \u0915\u0948\u0938\u0947 \u0939\u094b?\",\u00a0\n       \"SourceLanguageCode\": \"en\",\u00a0 \u00a0 \u00a0 \n       \"TargetLanguageCode\": \"hi\",\u00a0\n       \"AppliedSettings\": {\u00a0 \u00a0 \u00a0 \u00a0 \u00a0\n                            \"Formality\": \"FORMAL\"\n                           }\u00a0\n}<\/code><\/pre>\n<p>The following code translates the same text into informal Hindi:<\/p>\n<pre><code class=\"lang-cli\">aws translate translate-text \n--text \"How are you?\" \n--source-language-code \"en\" \n--target-language-code \"hi\" \n--settings Formality=INFORMAL<\/code><\/pre>\n<p>You get a response like the following snippet:<\/p>\n<pre><code class=\"lang-json\">{\u00a0 \u00a0 \u00a0\"TranslatedText\": \"\u0924\u0941\u092e \u0915\u0948\u0938\u0947 \u0939\u094b?\",\u00a0 \u00a0 \u00a0 \n      \"SourceLanguageCode\": \"en\",\u00a0 \u00a0 \u00a0 \n      \"TargetLanguageCode\": \"hi\",\u00a0 \u00a0 \u00a0\n      \"AppliedSettings\": {\u00a0 \u00a0 \u00a0 \u00a0 \u00a0\n                          \"Formality\": \"INFORMAL\"\u00a0 \u00a0 \u00a0\n                          }\u00a0\n}<\/code><\/pre>\n<h2>Amazon Translate SDK (Python Boto3)<\/h2>\n<p>The following Python Boto3 code uses the real-time translation call with both formality settings to translate \u201c<em>How are you? <\/em>\u201d from English to Hindi.<\/p>\n<pre><code class=\"lang-python\">import boto3\nimport json\n\ntranslate = boto3.client(service_name='translate', region_name='us-west-2')\n\nresult = translate.translate_text(Text=\"How are you?\", SourceLanguageCode=\"en\", TargetLanguageCode=\"hi\", Settings={\"Formality\": \"INFORMAL\"})\nprint('TranslatedText: ' + result.get('TranslatedText'))\nprint('SourceLanguageCode: ' + result.get('SourceLanguageCode'))\nprint('TargetLanguageCode: ' + result.get('TargetLanguageCode'))\nprint('AppliedSettings: ' + json.dumps(result.get('AppliedSettings')))\n\nprint('')\n\nresult = translate.translate_text(Text=\"How are you?\", SourceLanguageCode=\"en\", TargetLanguageCode=\"hi\", Settings={\"Formality\":\"FORMAL\"})\nprint('TranslatedText: ' + result.get('TranslatedText'))\nprint('SourceLanguageCode: ' + result.get('SourceLanguageCode'))\nprint('TargetLanguageCode: ' + result.get('TargetLanguageCode'))\nprint('AppliedSettings: ' + json.dumps(result.get('AppliedSettings')))\n<\/code><\/pre>\n<h2>Conclusion<\/h2>\n<p>You can use the formality customization feature in Amazon Translate to control the level of formality in machine translated text to meet your application context and business requirements. You can customize your translations using Amazon Translate in multiple ways, including <a href=\"https:\/\/docs.aws.amazon.com\/translate\/latest\/dg\/how-custom-terminology.html\" target=\"_blank\" rel=\"noopener noreferrer\">custom terminology<\/a>, <a href=\"https:\/\/docs.aws.amazon.com\/translate\/latest\/dg\/customizing-translations-profanity.html\" target=\"_blank\" rel=\"noopener noreferrer\">profanity masking<\/a>, and <a href=\"https:\/\/docs.aws.amazon.com\/translate\/latest\/dg\/customizing-translations-parallel-data.html\" target=\"_blank\" rel=\"noopener noreferrer\">active custom translation<\/a>.<\/p>\n<hr>\n<h3>About the Authors<\/h3>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignleft wp-image-32778\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2022\/02\/07\/Siva-Rajamani.jpg\" alt=\"\" width=\"100\" height=\"120\"><span><strong>Siva Rajamani<\/strong> is a Boston-based Enterprise Solutions Architect at AWS. He enjoys working closely with customers and supporting their digital transformation and AWS adoption journey. His core areas of focus are serverless, application integration, and security. Outside of work, he enjoys outdoors activities and watching documentaries.<\/span><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignleft wp-image-32779\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2022\/02\/07\/Sudhanshu-Malhotra.jpg\" alt=\"\" width=\"100\" height=\"127\"><span><strong>Sudhanshu Malhotra<\/strong> is a Boston-based Enterprise Solutions Architect for AWS. He\u2019s a technology enthusiast who enjoys helping customers find innovative solutions to complex business challenges. His core areas of focus are DevOps, machine learning, and security. When he\u2019s not working with customers on their journey to the cloud, he enjoys reading, hiking, and exploring new cuisines.<\/span><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignleft wp-image-11440 size-full\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2020\/03\/20\/watson-srivathsan-100.jpg\" alt=\"\" width=\"100\" height=\"132\"><span><strong>Watson G. Srivathsan<\/strong> is the Sr. Product Manager for Amazon Translate, AWS\u2019s natural language processing service. On weekends you will find him exploring the outdoors in the Pacific Northwest.<\/span><\/p>\n<p>       <!-- '\"` -->\n      <\/div>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/aws.amazon.com\/blogs\/machine-learning\/control-formality-in-machine-translated-text-using-amazon-translate\/<\/p>\n","protected":false},"author":0,"featured_media":1579,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[],"_links":{"self":[{"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/posts\/1578"}],"collection":[{"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/comments?post=1578"}],"version-history":[{"count":0,"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/posts\/1578\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/media\/1579"}],"wp:attachment":[{"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/media?parent=1578"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/categories?post=1578"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/tags?post=1578"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}