ニューラルネットワークを用いて文章を生成するアプリ「literai」のチュートリアルをやってみた。

100SHIKIブログでも紹介されていて、気になったのでちょっとだけやってみた。
チュートリアルを動かすだけならニューラルネットの知識などは全く必要なく、公式サイトにアップされている学習済みモデルを使って簡単に試すことができる。
ただし、チュートリアルの実行環境がdockerで構築されているため、dockerがインストール済みであることが前提になる。(入れてさえあればチュートリアルのコマンドをコピペするだけで動く。)

まず以下のコマンドを実行してコンテナを取ってきて中に入る。

docker run -ti --rm --name literai crisbal/torch-rnn:base

次に、公式サイトから適当な学習済みモデルを取ってきてコンテナ内にコピーする。
学習済みモデルはこちら

コンテナにコピーするために適当なプロジェクトフォルダを作って、そこに先程ダウンロードしたモデルを置いておく。
今回は、ホーム直下に「literai-tutorial」というディレクトリを作ってこれをコンテナ内にコピーする。
ちなみに、公式チュートリアルにあるように、以下の動作は先程のターミナルとは別画面で行うことをおすすめする。(コンテナ作成直後にコンテナ内に遷移しているので、そのままだとホスト側からこぴーできないため)

mkdir ~/literai-tutorial
cp ~/Downloads/model-xxx.t7 # xxxは自分の環境に合わせて変更
docker cp ~/literai-tutorial/ literai:root/torch-rnn/literai-tutorial/

最後にサンプルプログラムの引数にコピーしたモデルを指定して文章を生成する。
コンテナ内で次のコマンドを実行する。

th sample.lua -checkpoint literai-tutorial/model-72645f9d48.t7 -length 2000 -temperature 0.7 -gpu -1

自分の環境では次のような結果になった。
チュートリアルに書かれていたのと同じモデルを用いたが、どうやらこのモデルはスターウォーズの文章を元に学習しているらしい。

‘SEND AURTS YOLI

                          CONTINUED:

                          KYLO REN
           I have been the ship shattle it.

                                     HAN
                         (continuing)
                         Let's enter that was a lot of hear your way
                         you did you think we can't give
                         here and me.
          POE and Han and Leia SROADS and TEETS OF GENERAL AND MONET, EXPLOSION and THE TOUND

          EXT. DESERT - DAY

          Finn rises up the two SUPER CLONES and MACKEN that concern.

                          FINN
           What is the nearly or Rebel fighters and
           what you can live it!

                                     LUKE
                         Don't go back, the Senate of the huge desert
                         make the frantical planet of the carbonite,
           bit in the trench.

               Luke continues to speak toward the Wookiee as an entire monster
               scratches on the surface of the hatch of the control panel.

               INT. MILLENNIUM FALCON - COCKPIT

               Luke's hold area, below attentions, comes on a droid. Bong fire slightly
               slams clear to blow the large back of the fighters.

                                     THREEPIO
                              (over headset)
                         Who was waiting in the saye with it,
                         more side!

                                     HAN
                         Luke! And they're
                         on the ways.

                                     LUKE
                         Well, come on!

                                     LUKE
                         I know the far was more transmitter.

               Suddenly. We retreat and starts to prepare the board.

                                     THREEPIO
                         Luke! What are you have forget
                         the master of you.

ちなみに自分で学習したモデルや生成した文章をアップロードすることもできるらしい。
今年は機械が執筆した脚本を元にした映画の制作が決まるなど、自然言語処理分野についても話題に事欠かない一年だった。

来年以降、この分野がどれだけ発展していくか注目である。