LoginSignup
14
13

More than 5 years have passed since last update.

リアルタイム翻訳のAmazon Translateが日本語対応したので触ってみた

Posted at

docomo Developer support@akatsukahaです

下記のAWS Blogで紹介されているAmazon Translateの日本語対応について触ってみました.

この機能を利用することで,利用している言語からAPI通して翻訳を容易に実行できそうです.

なお,日本語対応しているようですが,東京リージョンでは2018年8月1日現在は利用できません.

1. Amazon Translateの利用方法

1.1. Amazon Management Consoleでの実行

Amazon Management Consoleから触ってみることが出来ます.

Source languageのところに翻訳対象の文字列を記入すると,自動的にTarget languageの枠に翻訳が表示されます.

スクリーンショット 2018-07-18 11.39.38.png

1.2. PythonからAPIを通して実行

下記からAPIとして利用することが出来ます.APIを通してお手軽に使えるのはいいですね.

インストール

$ sudo pip install boto3
$ $ sudo pip list | grep boto3
boto3           1.7.59

AWSの設定

$ aws configure
AWS Access Key ID [None]: <適切な情報を入力>
AWS Secret Access Key [None]: <適切な情報を入力>
Default region name [None]: ap-northeast-1
Default output format [None]: json

コード

translate.py
import boto3
translate = boto3.client("translate", region_name="us-west-2")
response = translate.translate_text(
    Text="NTT DOCOMO, INC.  is the predominant mobile phone operator in Japan. The name is officially an abbreviation of the phrase, \"do communications over the mobile network\", and is also from a compound word dokomo, meaning \"everywhere\" in Japanese. Docomo provides phone, video phone (FOMA and Some PHS), i-mode(internet), and mail (i-mode mail, Short Mail, and SMS) services. ",
    SourceLanguageCode="auto",
    TargetLanguageCode="ja"
)
print(response['TranslatedText'])

翻訳実行

$ python translate.py
日本で有数の携帯電話事業者です。 この名前は、正式に「モバイルネットワーク経由で通信を行う」という語句の略語で、日本語で「どこでも」を意味する複合語ドコモ。 ドコモは、電話、ビデオ電話(FOMA、一部のPHS)、iモード(インターネット)、メール(iモードメール、ショートメール、SMS)サービスを提供しています。

1.3. AWS CLIを通して実行

AWS CLIを利用した場合は下記のように実行可能です.

$ aws translate translate-text --region us-west-2 --text "NTT DOCOMO, INC.  is the predominant mobile phone operator in Japan. The name is officially an abbreviation of the phrase, \"do communications over the mobile network\", and is also from a compound word dokomo, meaning \"everywhere\" in Japanese. Docomo provides phone, video phone (FOMA and Some PHS), i-mode(internet), and mail (i-mode mail, Short Mail, and SMS) services. " --source-language-code en --target-language-code ja
{
    "TranslatedText": "日本で有数の携帯電話事業者です。 この名前は、正式に「モバイルネットワーク経由で通信を行う」という語句の略語で、日本語で「どこでも」を意味する複合語ドコモ。 ドコモは、電話、ビデオ電話(FOMA、一部のPHS)、iモード(インターネット)、メール(iモードメール、ショートメール、SMS)サービスを提供しています。",
    "SourceLanguageCode": "en",
    "TargetLanguageCode": "ja"
}

2. Amazon Translate vs Google翻訳 (和訳)

ここではGoogle翻訳とAmazon Translateの両方で翻訳した結果を表示しています.
対象となるドメインによって精度は異なる可能性があるので,ここでは特に翻訳精度について記載していません.

2.1. ケース①

翻訳対象の文章
ドコモの英語wikiページから文.

NTT DOCOMO, INC.  is the predominant mobile phone operator in Japan. The name is officially an abbreviation of the phrase, "do communications over the mobile network", and is also from a compound word dokomo, meaning "everywhere" in Japanese. Docomo provides phone, video phone (FOMA and Some PHS), i-mode(internet), and mail (i-mode mail, Short Mail, and SMS) services. 

Amazon Translate

日本で有数の携帯電話事業者です。 この名前は、正式に「モバイルネットワーク経由で通信を行う」という語句の略語で、日本語で「どこでも」を意味する複合語ドコモ。 ドコモは、電話、ビデオ電話(FOMA、一部のPHS)、iモード(インターネット)、メール(iモードメール、ショートメール、SMS)サービスを提供しています。

Google翻訳

NTTドコモは日本の携帯電話事業者の大半を占めています。この名前は正式には「モバイルネットワーク上でのコミュニケーション」という言葉の略語であり、日本語の「どこでも」を意味する複合語「ドコモ」からのものでもあります。 Docomoでは、電話、ビデオ電話(FOMAと一部のPHS)、iモード(インターネット)、メール(iモードメール、ショートメール、SMS)サービスを提供しています。

2.2. ケース②

翻訳対象の文章
Dart公式のA Tour of the Dart Languageの記載文.

This page shows you how to use each major Dart feature, from variables and operators to classes and libraries, with the assumption that you already know how to program in another language.

Amazon Translate

このページでは、変数や演算子からクラスやライブラリまで、Dartの各主要機能の使用方法について説明します。また、他の言語でのプログラミング方法を既に理解していると仮定しています。

Google翻訳

このページでは、変数や演算子からクラスやライブラリまでの各主要なDart機能の使い方を、別の言語でプログラミングする方法をすでに知っていることを前提に説明します。

3. 参考リンク

14
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
13