LoginSignup
2

More than 5 years have passed since last update.

【AWSメモ】Amazon Comprehendで形態素解析

Posted at

AWS Summit 2018 New York で Amazon Comporehendの新機能がリリースされました.この機能を利用することで,形態素解析が容易に出来ます.現状は日本語はサポートされていません.

1. 環境構築

仮想環境を構築

$ virtualenv aws
$ cd aws
$ source bin/activate

1.1. AWSCLIのバージョンアップ

$ aws --version
aws-cli/1.15.10 Python/3.6.5 Darwin/17.5.0 botocore/1.10.10
$ sudo pip install -U awscli

インストール後にバージョン確認するとバージョンアップされていない

$ aws --version
aws-cli/1.15.10 Python/3.6.5 Darwin/17.5.0 botocore/1.10.10

一度仮想環境をログアウトしてから再度仮想環境にログインするとバージョンアップされている

$ aws --version
aws-cli/1.15.62 Python/3.6.5 Darwin/17.5.0 botocore/1.10.61

2. Amazon ComprehendをAWS CLIで試してみる

下記で紹介されていたので自分でも試してみる.

レスポンス内容は下記を参照

下記の通りAWS CLIから実行可能

$ aws comprehend detect-syntax --text "This is a pen. This is an apple." --language-code "en" --region us-east-1

{
    "SyntaxTokens": [
        {
            "TokenId": 1,
            "Text": "This",
            "BeginOffset": 0,
            "EndOffset": 4,
            "PartOfSpeech": {
                "Tag": "PRON",
                "Score": 0.9998180270195007
            }
        },
        {
            "TokenId": 2,
            "Text": "is",
            "BeginOffset": 5,
            "EndOffset": 7,
            "PartOfSpeech": {
                "Tag": "VERB",
                "Score": 0.9996470212936401
            }
        },
        {
            "TokenId": 3,
            "Text": "a",
            "BeginOffset": 8,
            "EndOffset": 9,
            "PartOfSpeech": {
                "Tag": "DET",
                "Score": 0.9999902248382568
            }
        },
        {
            "TokenId": 4,
            "Text": "pen",
            "BeginOffset": 10,
            "EndOffset": 13,
            "PartOfSpeech": {
                "Tag": "NOUN",
                "Score": 0.9989594221115112
            }
        },
        {
            "TokenId": 5,
            "Text": ".",
            "BeginOffset": 13,
            "EndOffset": 14,
            "PartOfSpeech": {
                "Tag": "PUNCT",
                "Score": 0.9999984502792358
            }
        },
        {
            "TokenId": 6,
            "Text": "This",
            "BeginOffset": 15,
            "EndOffset": 19,
            "PartOfSpeech": {
                "Tag": "PRON",
                "Score": 0.9997928738594055
            }
        },
        {
            "TokenId": 7,
            "Text": "is",
            "BeginOffset": 20,
            "EndOffset": 22,
            "PartOfSpeech": {
                "Tag": "VERB",
                "Score": 0.9998266100883484
            }
        },
        {
            "TokenId": 8,
            "Text": "an",
            "BeginOffset": 23,
            "EndOffset": 25,
            "PartOfSpeech": {
                "Tag": "DET",
                "Score": 0.9999901056289673
            }
        },
        {
            "TokenId": 9,
            "Text": "apple",
            "BeginOffset": 26,
            "EndOffset": 31,
            "PartOfSpeech": {
                "Tag": "NOUN",
                "Score": 0.9987043142318726
            }
        },
        {
            "TokenId": 10,
            "Text": ".",
            "BeginOffset": 31,
            "EndOffset": 32,
            "PartOfSpeech": {
                "Tag": "PUNCT",
                "Score": 0.9999967813491821
            }
        }
    ]
}

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
2