SlideShare une entreprise Scribd logo
1  sur  33
Télécharger pour lire hors ligne
Kerasで作ったbotの話
GMOペパボ株式会社
情報システムグループ 西畑洵
スキルの話
● 機械学習のスキル
○ NECのRAPIDを使って評価・検証をしたことが有る
○ お遊びでTensorflowを少し触ったことが有る
○ 機械学習できます!と堂々と言うのは少し抵抗がある、ぐらいのスキルです
● 数学のスキル
○ 高専5年間の数学は赤点じゃないことのほうが珍しかったレベル
○ もはや微分積分すらも忘れている
● 他に使ったスキル
○ 自然言語処理を授業でやったのでなんとなく使ったかもしれない
○ つたない英語力←これが一番役に立った
2
Botを作ろうと思ったきっかけ
● shasysによく「勤之助が〜」とか「PC新しくしたいんだけど〜」という
問い合わせが来ていた
○ 直感的に考えて勤之助の管理を情シスがやってるとしても不思議はない
○ 同じように、PCは情シスから渡されるのだからその相談がくるのも分かる
● その度に「jinjiで〜」、「somuで〜」と案内する手間
● techやdev、その他いろんなチャンネルで
「◯◯ってどこで聞くのが良いの?」という話をする人がいる
○ 親切な人が教えてくれたりするけど、チャンネルの目的とは合わない
○ 誰もわからない、もしくは本務で忙しくて応えてもらえず悲しい
● 問い合わせ先を教えてくれるbotがいたら便利そう
3
Botの回答ロジック
4
回答を求めるためのアルゴリズム
● 質問:回答のヒモ付を持つデータを沢山作る 
● 検索エンジンのような動作をするbotを作って、検索対象のデータとしてSlackの会
話履歴を使う
● 会話履歴から機械学習でモデルを作ってそれを元に回答する
5
→すごく手間
→Slack検索します!となりそう
機械学習をどうやってやろう?
● ChainerやCaffeなど古くからあるフレームワーク
● Tensorflowのような比較的新しいフレームワーク
● スクラッチ
● Watsonみたいな製品
6
スクラッチは数学弱者な自分にはとても無理そうだし、作りたいものに対してコストが合わなそう
製品も同じく、お高いので全社的・事業部レベルのプロジェクトでもなければ厳しい
なにかしらのフレームワークを使って構築するのが現実的
Tenforflowを検討した
● GoogleがOSSとして公開していて今一番の流行り
● 注目されているが故にQiitaの投稿数も多い
● どうせ使うなら新しいのが良い!
● なんか簡単にDeep Learningを実装できるらしいぞ!
…ということで試してみた
7
Tensorflowのサンプル(MNISTのデータ読み込み)
データセットは用意されているので
データ加工は不要
Qiitaの記事とか参考にすると …
プレースホルダーを定義して値を代
入してモデルを作っている、と紹介さ
れていたりする
8
Tensorflowのサンプル(MNISTのデータ読み込み)
データセットは用意されているので
データ加工は不要
Qiitaの記事とか参考にすると …
プレースホルダーを定義して値を代
入してモデルを作っている、と紹介さ
れていたりする
プレースホルダーってなんだよ …
ベクトル化は特徴量をベクトルとしてみ
る、というので何となく分かる
zerosで全要素0の配列を作って
ベクトルを表現しているのだな
9
Tensorflowのサンプル(MNISTで学習・予測)
10
Tensorflowのサンプル(MNISTで学習・予測)
● 数学の知識が必須
● エントロピーってなに
● ソフトマックスってなに
11
Tensorflowを触って得た印象
● すごく数学的
● 機械学習をやるライブラリ、みたいな感じではなくて機械学習を
実装するために使われていた数式群のライブラリ、というイメージ
● Webページを作るのにRailsを使う、ぐらいの印象を受けた
○ 数学弱者な僕はRailsじゃなくてホームページビルダーがほしい、と感じてしまう
○ 数学(Railsで言えばRuby)が出来るのであれば色々なことができて良さそう
12
Keras
● OSSで開発されているTensorflow、Theanoのラッパー
● Tensorflowを生で書くよりカジュアル(?)に
機械学習のプログラムを書ける
○ 数式とかをあまり意識してなさそうな書き方ができる
● モデルの扱いがTensorflowよりも簡単にできる
○ モデルを層として重ねるイメージで書くことができる
● ただし細かいことはできない
● もっと多くの人にDeep Learningをという理念で開発
13
Kerasのサンプル(MNISTのデータ読み込み)
MNISTのサンプルデータをロードして
学習に使うデータと検証に使うデータを
分けている
Tensorflow、Theano両方をバックエンドに選
べる関係からか、前処理は少し多い
14
Kerasのサンプル(MNISTモデル作成)
読み込んだデータをベクトル化して
モデルを作成している
1. どんなモデルを作るか定義して
2. ニューラルネットワークの層を addする
数学的なことをあまり意識しないでプログラミングっぽく
ニューラルネットワークを構築できる 15
得られたKerasの印象
● 数学弱者の自分でもなんとなく、やってることが読み解ける
● さくさくっと実装できそう
● モデル構築途中でチェックポイントを作ったり補助的な関数が豊富で
便利そう
● バックエンドを比較的簡単に変えられる
● サンプルもTensorflowほどじゃないけどある
16
Kerasを使ってbotの学習モデルを作れば割りと簡単に
機械学習を使ったbotが作れそう!
データを集める
17
教師データに使うデータ
Slackの会話履歴をExportしたjsonファイルを加工する
● 1日ごとに1jsonファイルになる
● botの発言、join、leftメッセージは削除
● Slack利用開始から2016年12月までのデータを使用
上記のような形式のCSVに、チャンネルごとに分ける
ID チャンネル名 会話内容
18
出来上がった教師データ
こんな感じのCSVファイルが6つ、総量5MB程度、総件数約1万件
19
モデル作成
20
モデルとは
機械学習における出力(予測結果など)を出すためのロジックをひとまとまりにしたもの、
もしくは学習済みのデータを指す。
観測したデータの背景にある規則、などを数式で表したもの。
21
モデルの構築(イメージ)
入力層(入力次元の数、データの最大長を定義)
正確にはモデルのレイヤーではない
Embeddingレイヤー:インデックス( ID)を密ベクトルに変換
する
Denseレイヤー:全結合ニューラルネットワークレイヤー
BatchNormalizationレイヤー:全結合ニューラルネットワー
クレイヤー
Dropoutレイヤー:訓練時に各 Epoc毎に入力ユニットにラン
ダムに0をセットする
Denseレイヤー:出力数次元を入力次元と同等にする
22
学習する
23
学習する
● 学習とは:作成したモデルをコンパイルして、Epocの数だけ回すこと
○ Epocとは?:データをどれだけ回したか?という単位
○ 回すとは?:学習データを訓練・予測にわけてモデルに重みを付けて学習データの誤差を計算し、
その誤差を縮めるために重みを調整する、という一連の動作
● Epocごとにデータをシャッフルする、などもKerasはオプション指定だけでやってく
れる
24
出来上がったモデルについて
● 対象チャンネル:5チャンネル(jinji、somu、keiri、shasys、keiki、legal)
● サイズ:291MB
25
予測と評価
26
予測と評価
● 予測にかかる時間は2,3秒
● モデルの評価
○ 教師データでの評価 損失率: 0.7068 精度:0.8406
○ 2017年の応対    損失率:3.2902 精度:0.5676
27
botの動作の様子
#faqを見てくれ!!
28
今後の課題
29
今抱えている自身の課題
● モノは出来て動作もしているが、機械学習に使われている数式の理解がない
○ モデルの構築には必要になる
● 少ないデータで学習精度を上げる取り組みができていない
○ 全部で数万個程度の量しか期待できないので何かしら取り組みは必要
● 分類機への理解がたりない
30
作ったデータの課題
このチャンネルじゃないよ!というような質問
本来そのチャンネルでなされるべきではない会話がなされている
31
作ったデータの課題
● 下記のご確認お願いします!系
○ GHEのリンクが張ってあって Slackのデータだけでは見えない
● 絵文字オンリーの投稿
○ そのチャンネルの特徴量として適切とは思えない
● ただの相槌
32
今後取り組みたいこと
● 教師データのノイズを取り除きたい
● 強化学習の仕組みを取り入れたい
● モデルの構築をちゃんとしたい
○ 数学的理解が必要
○ データの数値化はUNICODEに変換する実装だが、それでいいのか?
● 分類器はこれでいいのか?検討したい
○ character-level cnnを使っていて、単語単位ではなく文字単位で処理している
■ だから「勤之助のパスワードリセット」だと shasysに分類され、「勤之助」だけだと jinjiに分類さ
れたりする
○ 楽だけど、特徴量抽出として正しいのかな?というのを考えたい
● 数学のお勉強
33

Contenu connexe

En vedette

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

En vedette (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Kerasで作ったbotの話