前回までに紹介したRPAは、決められた手順に従って同じ処理を繰り返し実行するルールベースのAIを活用していました。

それに対して今後は、与えられた情報を元に判断/学習し動作する機械学習や深層学習(ディープラーニング)をベースにした、いわばRPA2.0が増えてくると期待されています。

こうした状況を自動化とAI化の2軸で整理すると図1のようになります。

図1 : AIを併用したRPA 2.0の位置付け

これまでのやりかたでは、人間が考えた手順を元に人間が作業していました。その作業をデジタルレイバーに任せるのがRPA1.0です。一方で、AIに考えてもらった手順/結果を元に人間が作業するのが機械学習や深層学習になります。今後これらを組み合わせたRPA2.0が増えてくるだろうというわけです。

今回は機械学習/深層学習の理解のため、Googleが開発し、OSS化した機械学習ライブラリ「TensorFlow」を紹介します。公式サイトに行けば、[GET STARTED]リンクからインストール手順や使い方を知ることができます。

図2 : TensorFlowトップページ

TensorFlowを使ってHelloWorld

TensorFlowの導入方法はいくつかありますが、筆者の場合、MacOS環境にてターミナルからdockerコマンドによりbash実行します。これにより最新のdockerイメージがダウンロードされ、インストール完了です。

$ docker run -it gcr.io/tensorflow/tensorflow bash
Unable to find image 'gcr.io/tensorflow/tensorflow:latest' locally
latest: Pulling from tensorflow/tensorflow
c62795f78da9: Pull complete
d4fceeeb758e: Pull complete
5c9125a401ae: Pull complete
0062f774e994: Pull complete
6b33fd031fac: Pull complete
353b34ef0a98: Pull complete
4f6aefc14b68: Pull complete
ce066374c6ca: Pull complete
c0755a91ab3a: Pull complete
f03279b52d25: Pull complete
d1c27c29b7e3: Pull complete
23807c5f4b3e: Pull complete
Digest: sha256:27bd43f1cf71c45eb48cb6e067b7cef47b168ac11c685d55a3495d27f0d59543
Status: Downloaded newer image for gcr.io/tensorflow/tensorflow:latest

動作確認のため、pythonコマンドを実行し、対話型でプログラムを投入していきます。以下の赤字部分を入力すると、その下にあるとおり、「Hello, TensorFlow!」と出力されます。

# python
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
2017-06-07 20:38:05.323535: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
2017-06-07 20:38:05.323607: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
2017-06-07 20:38:05.323621: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
2017-06-07 20:38:05.323635: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
2017-06-07 20:38:05.323654: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.
>>> print(sess.run(hello))
Hello, TensorFlow!

ブラウザから実行する環境の構築

Jupiter Notebookを使うことで、ブラウザからTensorFlowを実行できます。導入方法は以下のとおりです。

$ docker run -it -p 8888:8888 gcr.io/tensorflow/tensorflow
[I 21:00:54.315 NotebookApp] Writing notebook server cookie secret to /root/.local/share/jupyter/runtime/notebook_cookie_secret
[W 21:00:54.331 NotebookApp] WARNING: The notebook server is listening on all IP addresses and not using encryption. This is not recommended.
[I 21:00:54.341 NotebookApp] Serving notebooks from local directory: /notebooks
[I 21:00:54.341 NotebookApp] 0 active kernels
[I 21:00:54.342 NotebookApp] The Jupyter Notebook is running at: http://    [all ip addresses on your system]:8888/?token=3cb8c40639032df64ca6e39f2f010ed2f55db650590f2cc0
[I 21:00:54.342 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 21:00:54.343 NotebookApp]

    Copy/paste this URL into your browser when you connect for the first time,
    to login with a token:
        http://localhost:8888/?token=3cb8c40639032df64ca6e39f2f010ed2f55db650590f2cc0
[I 21:01:24.164 NotebookApp] 302 GET /?token=3cb8c40639032df64ca6e39f2f010ed2f55db650590f2cc0 (172.17.0.1) 0.58ms
[W 21:01:24.421 NotebookApp] 404 GET /apple-touch-icon-precomposed.png (172.17.0.1) 10.37ms referer=None
[W 21:01:24.534 NotebookApp] 404 GET /apple-touch-icon.png (172.17.0.1) 2.01ms referer=None

導入さえ終えれば、先ほどの手順にて紹介したコマンドラインに苦手意識がある方でも簡単に操作できます。

ブラウザにて[http://localhost:8888/tree?]にアクセスしてみましょう。[New]-[Python 2]をクリックし、コマンドを入力可能な状態にします。

図3 : 新規Notebookの作成

以下の通り入力し、[Shift]+[Enter]を入力します。

print([x + y for x, y in zip([1.0] * 4, [2.0] * 4)])

演算結果が以下の通り出力されます。なお、[Untiled]をクリックし、リネームして保存できます。

図4 : 実行結果

機械学習による画像分析

TensorFlowを使って、AIの一つである機械学習による画像分析を実行してみましょう。

tensorflow.org による予め訓練(図中の1)された学習モデルを利用するため、特段機械学習の知識は必要なく、データを投入するのみで投入結果が得られます(図中の2、3)。

図5 : 学習モデルによる投入データの分類

[Upload]ボタンをクリックし、任意の画像を選択します。筆者はgoogleで「ドラゴンボール」と検索して入手した「db.jpg」を選択しました。

図6 : 画像の選択

画像の分類処理(機械学習)が書かれたpythonファイルをTensorFlowのgithubから入手します。ターミナルからgitコマンドにより、TensorFlowのモデルファイルをクローン(複製・ダウンロード)します。入手した[classify_image.py]を先ほどと同じ要領でJupiter NotebookにUploadします。

$ git clone https://github.com/tensorflow/models.git
Cloning into 'models'...
remote: Counting objects: 6147, done.
remote: Total 6147 (delta 0), reused 0 (delta 0), pack-reused 6147
Receiving objects: 100% (6147/6147), 157.34 MiB | 2.57 MiB/s, done.
Resolving deltas: 100% (3128/3128), done.
$ ls models/tutorials/image/imagenet
BUILD classify_image.py

それでは機械学習により画像分析を実行してみましょう。[New]-[Terminal]をクリックし、ターミナルを立ち上げます。

図7 : ターミナル画面の起動

ターミナル画面にて[ls]コマンドにより、[classify_image.py]と[db.jpg]があることを確認します。pythonコマンドにより処理を実行します。scoreが0.81510で、[comic book]の可能性が高いと予測結果が出ました(図8)。

図8 : Jupyter Notebookのターミナル画面

RPAとの連携

Webで画像データを検索し、得られた情報を元に人手でシステムに投入していくという処理を効率化する場合、RPA1.0では、固定のURLを元に地図データを入手した結果を「そのまま」システムに投入したり、ワードファイル等の帳票に貼り付けたりするのが限界でしょう。

RPA2.0では、機械学習により画像検索などの結果を元に得られた情報をRPAへのインプットとすることで、自動で実現可能な範囲は格段に広がります。

以下の例では、「シマウマ」「カメ」「馬」「りんご」の画像を機械学習の学習モデルにより解析(図中の1、2)します。投入結果をRPAの入力とし(図中の3)RPAはシステムに投入します(図中の4)。つまり、これまで人間の眼で判断していた画像認識を省略し、RPAが自動でできる範囲を広げることが可能となります。

図9 : RPAとの連携

*  *  *

今回紹介した画像処理のみならず、自然言語処理や大量データの分析処理を用いた非定型処理対応型のRPAが増えてくることが考えられます。

ルールベースの第一フェーズをRPA1.0とした場合、AI(機械学習・深層学習)を用いた進化系の第二フェーズがRPA2.0として位置付けられ、今後の動きに注目です。

次回は自然言語処理を活用したチャットボットについて取り上げ、より深くRPA2.0について学んでいきます。

著者紹介


正野 勇嗣 (SHONO Yuji ) - NTTデータ シニアスペシャリスト

2011年頃まで開発自動化技術のR&Dに従事。その後、開発プロジェクト支援やトラブルシューティング等に主戦場を移す。「ソースコード自動生成」に加えて、JenkinsやMaven等の「ビルド自動化」、JsTestDriverやSelenium等の「テスト自動化」を扱うようになり、多様化する開発自動化技術動向に興味。

最近は第四の自動化であるInfrastructure as Code等の「基盤自動化」の魅力に惹かれている。開発自動化技術に関する雑誌・記事執筆も行う。2児のパパ。