Python과 Tensorflow를 활용한 AI Chatbot 개발 및 실무 적용

59
WRITTEN BY SuSang Kim [email protected] PythonTensorflow를 활용한 AI Chatbot 개발 및 실무 적용

Transcript of Python과 Tensorflow를 활용한 AI Chatbot 개발 및 실무 적용

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

WRITTEN BY SuSang [email protected]

Python과 Tensorflow를활용한AI Chatbot 개발 및 실무 적용

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

1.도커실행환경https://github.com/TensorMSA/skp_edu_docker

2. 소스설명코드 - jupyter (/chap13_chatbot_lecture)git clone https://github.com/TensorMSA/tensormsa_jupyter.git

3. Python 3.5 / Tensorflow 1.2

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

! I am Susang Kim as a developer

•Chatbot Develover

- Released in POSCO (Find people using by NLP/AI)

- Deep Learning MSA (ML,DNN, CNN, RNN)

•Agile Develover (Experienced in Pivotal Labs)

- TDD, CI, Pair programming, User Story

•iOS Develover (Ranked App store in 100th - 2011 Korea)

•Front-End Developer (React, D3, Typescript and ES6)

•POSCO MES ... (working at POSCO ICT for 10 year)

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

! Contents

1. 도입

2. AI Chatbot 소개Chatbot Ecosystem

Closed vs Open Domain

Rule Based vs AI

Chat IF Flow and Story Slot

3. AI기반의학습을 위한 Data 구성 방법Data를구하는법 / Train을 위한 Word Representation

Data의구성 / Data Augmentation(Intent, NER)

4. 자연어처리위한 AI 적용 방안Intent (Char-CNN) / QnA (Seq2Seq)

Named Entity Recognition (Bi-LSTM CRF) / Ontology (Graph DB)

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

! Contents

6. Chatbot Service를 위한 Architecture 구성Chatbot Architecture

NLP Architecture

Web Service Architecture

Bot builder / Chatbot API

Test Codes for Chatbot

7. 실무에서 발생하는 문제와 해결 Tips

Ensemble and voting / Trigger / Synonym(N-Gram)

Tone Generator / Parallel processing / Response Speed

8. 마무리

[설명코드]

Text Augmentation / Char-CNN / NER /Slot Bot / QA Bot / Graph DB / Response Generator

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

도입

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

Facebook AI shut down after creating their own language

논문 https://arxiv.org/abs/1706.05125

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

Chatbot을개발하게된이유?

• 많은기술이 필요 (NLP, AI, F/W, Text Mining and 다양한개발 skill)

• Deep Learning을 공부하는 입장에서 결과확인이빠름- 적은 Computing으로빠른결과확인 가능 (Text 기반)

• 재미가있음(Micro Data처리에 비해 Biz dependency가 적은편)- 이미지(CNN)이나정형Data(DNN)보다는 Data처리에 대한부담감이적음

(형태소 분석기등으로쉽게전처리 쓴다는가정하에)

• 응용분야가 많음 (API기반의 다양한서비스연결 Smart Management)- Intent와 Slot만채워주면 어느서비스와연결가능

• 관련오픈소스가 적어블루오션 (한글은 대부분자체개발해야함)- 다행인건 딥러닝 기반의언어독립적 Text algorithm이 많이 공개되어활용가능

• Bot Service가 있으나가격부담, 한국어는잘안됨, Customize 불가

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

Chatbot은?

AI(패턴,맥락)

언어학(자연언어처리)

프로그래밍(Data처리-Python)

Bot F/W(Story/Slot설계)

Architecture (응답속도)

Text Mining(Data구성)

Chatbot

Chatbot 구현을위해서는많은분야의다양한기술필요

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

AI Chatbot 소개

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

[출처 Deview 2016 - https://deview.kr/2016/schedule#session/176]

요즘왜 Chatbot이뜨는가??

직관적인 UX

일관성있는경험음성과연결가능별도 App 설치필요없음다양한서비스와연결가능빠른 Feedback

플랫폼에독립

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

Chatbot Ecosystem

[출처 Digital Landscapes - https://www.linkedin.com/pulse/curated-list-digital-landscapes-marek-rakowski]

Chatbot 생태계는계속증가하고있음

이번에중점적으로설명할부분은NLP와 Bot Builder

(Slot기반챗봇 / QA봇 위주)

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

다양한 Chatbot Platform이 존재는하고있음

API.AI로코딩없이 챗봇만들기 https://calyfactory.github.io/api.ai-chatbot/

모든챗봇에는의도와개체인식이존재또한그것을위해서는 Data가중요함!!!

api.ai에가입해서챗봇을만들어보면서원리를파악해보면도움이됨

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

Closed Domain vs Open Domain

Rule Based

General

(abstract)

Open

Closed

Retrieval

(accuracy)

Impossible Strong AI

Weak AI

level of difficulty

작은 Biz 도메인으로시작해서정확도를높이면서여러 Biz를추가하는상황

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

Rule Based vs AI

Computer Input

ProgramOutput

Rule

이름, 지역, 팀등조건별로 일일이 rule을 등록해야한다- 정확도는올라가나모든질문을다등록??

Computer Input

OutputProgram

AI

라벨링된 Data만으로결과를 구할수있는모델을 만들수있다- 비슷한 Data들도 잘찾는편(W2V,GloVe)

intent = 판교에근무하는 김수상찾아줘 => Intent : 특정지역사람찾아줘NER = 판교에근무하는김수상찾아줘 => B-Loc O O B-Name O

정확한 결과를얻을 수 있으나모든 질문은 불가

비슷한유형의질문은적당히잘찾아줌 Data가많을수록정확도향상(학습효과)

If (loc = 판교 and comp = 포스코ICT)

person = 김수상elif (loc = 판교 and comp = SK Planet)

person = 임재우else

person = 홍길동

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

Chatbot Interface Flow

NLP

Context Analyzer

Decision Maker

판교에 포스코ICT에배달해줘Intent : 피자주문Entity : 장소 = 판교포스코ICT

Service Manager

Response

Generator메뉴=null

시간=null

배달관련 Slot 분석(Knowlodge Base)

Entity : 메뉴:Null, 시간:null

피자주문처리가완료되었습니다.

피자주문 Slot 완성

어떤메뉴를원하시나요?

어떤메뉴를원해? (Tone Gen)

Slot OK

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

Story slot의구성 (Frame-based DM)

피자 주문하고 싶어

Pizza Slot

Size

Type

Side menu

피자 주문의도파악피자 Bot의 스토리구성1) 어떤사이즈를 원하시나요?

2) 어떤종류를 원하시나요?

3) 사이드 메뉴는필요하신가요?

사용자답변- 페파로니피자로라지사이즈에콜라추가해주세요

NER처리및 Slot 구성

Pizza Slot

Size Large

Type Pepperoni

Side menu cola

서비스 연결(Slot API Call)

처리를위해 Slot를보여주는것도방법

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

! 1. 맥북프로검색해줘2. 전처리 -> 맥북프로 NER

3. 맥북프로 -> 대표 Entity처리 -> MacBook Pro API Call

4. 검색결과출력5. 상세서비스조회를위한 Slot 출력6. 새상담원할경우새상담클릭

Slot를선택할수있게화면에출력함으로써챗봇의정확도를대폭향상시킬수있음(해당 Frame안에서만선택할수있기에…)

ex) “삼성노트북”쳐보면 Slot별선택

바로봇http://www.11st.co.kr/toc/bridge.tmall?method=chatPage

Slot

Trigger

API

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

AI기반의 학습을 위한

Data 구성방법

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

일반적으로 Biz에따른 Text는존재하나 Deep Learning를구현하기위해서는

정제된 Text Tagging이가능한매우많은 Data가있어야함

한국어 Corpus를일반적으로세종말뭉치를사용하여추가적인 Biz 어휘는새로학습시킴(노가다)

- Corpus (annotation) 세종말뭉치(2007 ) https://ithub.korean.go.kr/user/main.do

- 물결21 (2001~2014) 소스는없음 http://corpus.korea.ac.kr/

- Web Crawling or down (Wiki, Namu Wiki)

- Domain Specific의경우엔 Text Data는만들어야함

특화된단어의경우새로학습시켜야함 (ㅎㅇ? , 방가방가)

※고유명사등새로운어휘가생성될때새로등록을해주어야함

Data를 어떻게얻는가?

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

Word Represention의정의 (컴퓨터가잘이해할수있게)

- One Hot은단어별강한신호적특성으로 Train 에효과적 (Scope가작을경우-Sparse)

- Word 단위 Embedding 은단어를잘기억함 (But Sparse) / W2V (유사도)

- GloVe는단어의세부종류까지도구분 (Global Vector : 카라칼-고양이)

- Char 단위 Embedding 은미훈련단어처리에용이 (Vector을줄이기위한영어변환)

- 한글을변환한영어 Char 단위 Embedding는백터수를줄이면서영어처리도가능

Train을 위한 Word Representation

15 한국어에 적합한 단어임베딩모델및 파라미터튜닝에관한연구.pdf

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

Train Vector를정한후 Feature를뽑아야함

Cleansing -> Feature Engineering -> Train

(상황별특수문자제거, 의미있는단어도출 - Tagging)

의도나객체와상관있는단어만추출해내어

성능을향상시킴Train Cost를줄이고모델의성능을향상)

임베딩차원도줄이는효과 (Dense Respresention-SVD)

abcd~z, 0~9, ?, !, (,),’,’,공백등약 70여개

초중종성으로글자를쪼개기에는어려움

.lower()를활용하는것도방법백터줄이기

학습시킬Data의구성

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

Data Augmentation for Deep Learning (Intent - tag)

판교에오늘피자주문해줘 Story Definition

Intent Mapping주문해줘 Entity Mapping 메뉴 : 피자, 장소 : 판교, 날짜 : 오늘

Pattern Generation

30% of Train Data

의도 : 피자주문 (주문)

Preprocessing판교오늘피자주문

Story key value (주문)

tagloc tagdate tagmenu 주문

Model Train

Evaluation

tagloc tagdate tagmenu 주문tagloc tagdate 주문tagdate tagmenu 주문tagloc tagmenu 주문

Predictiontagloc tagdate 주문 tagmenu

Hyper parameter

Selection

의도 = 주문

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

Data flow for Model in Deep Learning (NER - BIO)

판교에오늘피자주문해줘 Story Definition

tagloc tagdate tagmenu 주문

BIO-Mapping

Preprocessing판교오늘피자주문

B_Loc / B_Date / B_menu

Model Train(Bi-LSTM)

B-loc B-date B-menu O

B-loc B-date O

B-date B-menu O

B-loc B-menu O

Text Generator

Pattern Matching

tagloc tagdate tagmenu 주문tagloc tagdate 주문tagdate tagmenu 주문tagloc tagmenu 주문

W2V

30% of Train Data Evaluation

Prediction판교오늘피자주문

Hyper parameter

Selection

피자 : 0.12

장소 : 0.7

메뉴 : 0.3

객체인식B_loc B_Date B_menu O

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

자연어처리 위한

AI 적용 방안

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

Intent를알아내는법 (Text Classification)

피자주문하고 싶어 / 여행정보 알려줘 / 호텔예약해줘

주문, 정보, 예약의 3가지 의도

문장내 Word검색으로 일일이파악할 수도있으나 한계가있음ex) 피쟈 시켜먹고 싶어 / 여행좋은데 알려줘….

Deeplearning를 활용하면 이런 문제들을 해결할 수있음

Char + CNN으로분류해보자(CNN - Feature 주문, 정보, 예약)

(Word Similarity 피자, 피쟈 / 정보, 갈만한데)

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

Intent를알아내는법 (Text Classification - Data 구성)

Word

피자주문하고싶어

Vector가 많다면

영어발음변환PIJA

JUMUN

HAGO

SIPO

숫자, 특수문자,공백등

모두고려해야함

W2V(Pretrained)

피자 (0.12, 0.54, 0.72)

주문(0.56, 0.65, 0.64)

하고(0.67, 0.91, 0.13)

싶어(0.89, 0.14, 0.11)

Ont Hotencoding (Word단위 or 글자단위)

(0100000000)

(0000010000)

(0010000000)

(0000000100)

Ont Hotencoding (A~Z Vector)

(0100000000)

(0000010000)

(0010000000)

(0000000100)

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

Char CNN?

CNN은일반적으로이미지의특징을추출하여인식하는데많이쓰이나이미지도결국은 Vector이고텍스트도 Vector을감안하면텍스트의 Feature를뽑아낼수있음

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

Text Classification - Char CNN

지금피자주문하고싶어

[논문 Convolutional Neural Networks for Sentence Classification - Yoon Kim - https://arxiv.org/abs/1408.5882]

예약주문정보

Feature바라볼단어수[3,4,5 filter]

Vector (W2V)길이/차원/윈도우Static / Non Static

/ Random

pooling추상화

classification분류

Char-CNN을활용하여의도를파악해보자

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

Why Char-CNN??

Char-CNN이일반적인다른알고리즘과비교하여압도적성능을보임

논문 Convolutional Neural Networks for Sentence Classification - Yoon Kim - https://arxiv.org/abs/1408.5882

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

RNN에대한이해

연속된 Data에대한모델링에유용시퀀스를입력으로받기때문에Backpropagation을시간에대해서도수행(BPTT)

http://aikorea.org/blog/rnn-tutorial-3/

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

http://cs231n.stanford.edu/slides/2016/winter1516_lecture10.pdf

Seq2Seq (RNN+RNN) 이해

Chatbot에서는Generator의역활Sentence Generator

영화자막이나소설책을활용하여학습시킬수있음(형태소분석기로 input/output정의)

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

Attention Mechanism이해

https://www.slideshare.net/KeonKim/attention-mechanisms-with-tensorflow

Attention을통해 Computing Cost를줄이고문장의길이에따른복잡도를줄임

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

http://cs231n.stanford.edu/slides/2016/winter1516_lecture10.pdf

LSTM에 대한이해

Cell State

https://brunch.co.kr/@chris-song/9

updateforget out

cell state

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

http://cs231n.stanford.edu/slides/2016/winter1516_lecture10.pdf

ResNet과 RNN의 LSTM은 비슷한개념

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

Named Entity Recognition 알아내기

Bidirectional LSTM (양방향 Layer)

- RNN기반의모델- 특정위치에있는단어의태깅에유용

문장내단어위치에따른의미처리하는효과적인방법

[ 한국어정보처리학술대회 - https://sites.google.com/site/2016hclt/jalyosil]

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

Why Bi-LSTM CRF ?

[ Bidirectional LSTM-CRF Models for Sequence Tagging - https://arxiv.org/pdf/1508.01991.pdf ]

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

피자주문하고싶어B-Pizza B-Order O O

여행정보알려줘B-Travel B-Information O

호텔예약해줘B-Hotel B-Reserve O

Named Entity Recognition 알아내기

brat를활용 BIO Tagging

B-시작어휘I-이어지는어휘O-어휘아님, 공백(OUT)

U-Unknown

(Word Embedding이없을시)

※New York?,수상하다?

Brat - http://brat.nlplab.org/examples.html / https://wapiti.limsi.fr/

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

Bi-LSTM으로 사전강화 -> 모델학습

피자주문하고싶어B-Pizza B-Order O O

여행정보알려줘B-Travel B-Info O

호텔예약해줘B-Hotel B-Reserve O

피이쟈주문하고싶어

놀러갈정보알려줘

숙소예약해줘

피자

여행

호텔

Bi-LSTM을통해서신규어휘를도출하고학습Data에반영하여모델의성능을지속적으로향상시킴

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

엑소브레인 with Ontology

문장별머신러닝기법을적용하여자연어를이해한후

웹크롤링으로습득한지식DB의정보를통해가져옴

더지속적인학습을통해진화

객관식이더어려움지식구축에만수년...

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

Ontology with syntaxnet

Neo4j - https://github.com/TensorMSA/tensormsa_jupyter/blob/master/chap13_chatbot_lecture/6.Ontology(Neo4J).ipynb

Ontology구축을위한Neo4j DB를활용

구문분석기의자체제작이나구글의Syntaxnet를활용

A는B이다 B는 C이다추론 : A는 C이다

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

Chatbot Service를 위한

Architecture 구성

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

ChatBot Layer

Log File

Chatbot Architecture

Deep Learning Layer 위에 ChatBot Layer 와같은 Application Layer 를구성하고각 Application Layer 는필요한기능을 DL Layer 와연동.

DeepLearning Layer

Bi-LSTM Char-CNN Seq2Seq

NAS File

Model

Bot DB

Residual

NLPContext

Analyzer

Decision

MakerResponse

Genertor

※이미지검색을 위해 Residual등과같은모델 활용

Bot Builder

GPU

Deeplearning

Predict

Dict File

Bot config

Train

Train

Intent /

NER

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

NLP Architecture

Preprocessing

Python 3.5

Konlpy

Mecab

(Sejong Corpus)

Tensorflow 1.1

AutoEncoder

Char-CNN

Bi-LSTM CRF

Gensim

FastText

User-Dic

Synonym

Voting

Python 3.5

API Service

(Swagger)

판교근무하는포스코ICT에김수상한테피자주문하고싶어...

[Intent 도출]

피자주문[NER 도출]

판교 - Loc

포스코ICT - Loc

김수상 - Name

고유명사

('포스코'ICT'', 'NNP'),

('김수상', 'NNP'),

※Mecab 고유명사등록

링크

문장길이체크 ,

특수기호(...) 삭제명사추출

명사추출

[('판교', 'NNG'),

('근무', 'NNG'),

('하', 'XSV'),

('는', 'ETM'),

('포스코'ICT'', 'NNP'),

('에', 'JKB'),

('김수상', 'NNP'),

('한테', 'JKB'),

('피자', 'NNG'),

('주문', 'NNG'),

('하', 'XSV'),

('고', 'EC'),

('싶', 'VX'),

('어', 'EC')]

Intent Slot 및모델비교피자주문 Slot의 Entity값NER 결과값

Input Data=’’판교근무하는포스코ICT에김수상한테피자주문하고싶어…”

Intent=’피자주문’

Intent_History=[‘피자주문’,’’]

story_slot_entity

{

‘메뉴’:피자’’,

‘지역’ : ’판교포스코ICT’,

‘이름’ : ‘김수상’}

request_type=’text’

service_type=’pizza order’

output_data=’’

}

Meta

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

Docker (Ubuntu) in AWS EC2

(c4.8xlarge / p2.xlarge GPU)

NAS

DB Server

Bot Builder

(analysis)

ReactChatbot Server (Django)

Python 3.5

Tensorflow

Postgres

SQL

Bootstrap

Web Service Architecture

D3

SCSSKonlpy

Nginx

Celery

Log File Model File

Rabbit

MQ

Service

Java

Node

Python

Rest

Gensim

Front-End

Java

(Trigger)

Rest

LB Rest

AP2

GPU Server

(HDF5)

GPU Server

(HDF5)

Dict File

Hbase

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

Bot Builder and UX

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

ChatBot

DefinitionChatBot Intent

ChatBot

Service

ChatBot Intent

Entity

ChatBot

Story

ChatBot

Response

ChatBot

Model

ChatBot

Tagging

ChatBot

Entity Relation

ChatBot

Synonym

Bot Builder DB

Service의확대를위해가능하면 Common하게구성

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

Rest API

Client

Input Data=페파로니피자주문할께Intent=’’

Intent_History=[‘ ’,’’]

story_slot_entity

{

메뉴:’’,

사이즈:’’,

사이드:’’

}

request_type=text

service_type=’’

output_data=’’

Server

Input Data= 페파로니피자주문할께Intent=피자주문Intent_History=[‘피자주문’,’’]

story_slot_entity

{

메뉴:피자,

사이즈:라지,

사이드: 콜라}

request_type=text

service_type=’’

output_data=주문완료

Chatbot API

※ json의길이가길어지면 log파일로관리

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

Case별 Test Coverage 코드 구현1. 로직변경 (단위테스트)

2. Model 변경 (Hyper Parameter)

3. Data 변경(Slot, Dict, Entity,유의어)

4. 속성값변경 (Threshold, Rule기준)

단순 로직변경과는다르게 Data와 Model의 변경사항을 지속적검증할수 있는방안필요가동상황에서 정확도를올리기위해선 Continous Integration이 필수 (Jenkins / Travis CI등)

Test Codes for Chatbot피자주문호텔예약 의도점검->NER점검->

Slot점검여행정보

input 판교에피자주문할께 -> intent : 피자주문slot : {메뉴,크리,사이드-extra}

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

실무에서 발생하는

문제와 해결 Tips

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

모델의정합성을올리기위해복수개의모델과로직으로보완 (Scoring / Voting)

의도를찾는경우여러모델을비교하여가장근접한값을찾는다

Textming과앙상블의조합으로정합도르올리자

포스코ICT에지금 피자배달해줘

Char-CNN

VotingSVM(Radial Basis/linear) Result

naive_bayes.MultinomialNB

(TF-IDF)각의도별 Slot 비교배달의경우엔

장소,시간이필수

여행정보

메뉴배달

메뉴배달 피자배달

Ensemble and Voting

모델별가중치

Slot

비교

병렬 수행

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

Trigger 처리 (사랑, 이미지검색)

1. 사랑단어가 포함될경우<실재 가동 사례>

직원 : XXX 사원에게사랑한다고포스톡보내줘

챗봇 : 너무 쉽게사랑하지마세요.

직원 : 니가 먼제내 사랑을논해

챗봇 : 학습중이라 아직잘모르는게 많아요.

직원 : ㅋㅋㅋㅋ

챗봇 : ㅋㅋㅋ

[안녕, 사랑, ㅋㅋㅋ] 등에 Trigger를적용하고이에확보된Data를 Seq2Seq모델에학습시켜 NLP전처리모델로사용

2.이미지 검색시(ResNet Model Call)

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

필요시 Tone Generater을쓰자

말투를 다르게만듬 (지역별, 존댓말 , 부하톤)주문이 완료되었습니다 (일반)주문이 완료되었단다 (공손)주문이 완료되었어요 (존대)주문이 완료되었다니깐 (짜증)

Seq2Seq Model활용 - Encoder에 명사등 구성Decoder에 명사+조사 구성

Response Generator의 경우형태소 분석기의 응용

https://github.com/TensorMSA/tensormsa_jupyter/blob/master/chap13_chatbot_lecture/4.Chatbot(Response-seq2seq).ipynb

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

유의어처리(N-Gram)

페파로니 - Pepperoni, 폐파로니, 페파피자..... / Mac Book Pro - 맥프로, 맥북프로...

고객별로다양한 단어를사용하나 API호출시에는지정값으로해야함

N-Gram을활용하여유의어로학습한결과를 Dict에찾는방식 (일반적 trigram)

링크 https://www.simplicity.be/article/throwing-dices-recognizing-west-flemish-and-other-languages/

각 Entity별 N과Threshold 값을적절하게조절

※ threshold :

작을수록비슷하게찾음

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

Response Speed

LB 구성

Nginx 사용

적절한수의 Thread와 AP

Caching of Data (Memory - API사용)

Chatbot에서수용할수있는 MAX Time반영

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

학습시병렬처리를위한 Coding

tf.device를통해연산할Device를지정CPU와 GPU의적절한분배

GPU가많다고무조건빠른지는...

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

마무리

● 챗봇의구현에있어서 Hot한기술의사용도중요하지만

무엇보다 Domain별 Data의의미를알고컴퓨터가잘이해할수있게해야함

● 학습할 Data와예측 Data의패턴을일치화하는것이중요(일관성)

● 딥러닝은대량의정제된 Data와확보가중요함

● 딥러닝은성능개선에있어충분한해결방안이될수있음

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

When the singularity comes...

Fin

d m

ore

Pow

erP

oin

t te

mpla

tes

on p

rezentr

.com

!

Reference모두를위한딥러닝http://hunkim.github.io/ml/

제28회 한글및 한국어정보처리학술대회

https://sites.google.com/site/2016hclt/jalyosil

Stanford University CS231n

http://cs231n.stanford.edu/

Creating AI chat bot with Python 3 and Tensorflow[신정규]

https://speakerdeck.com/inureyes/building-ai-chat-bot-using-python-3-and-tensorflow

파이썬으로챗봇_만들기 [김선동]

https://www.slideshare.net/KimSungdong1/20170227-72644192?next_slideshow=1

딥러닝을이용한지역컨텍스트검색 [김진호]

http://www.slideshare.net/deview/221-67605830

Developing Korean Chatbot 101 [조재민]

https://www.slideshare.net/JaeminCho6/developing-korean-chatbot-101-71013451

Tensorflow-Tutorials

https://github.com/golbin/TensorFlow-Tutorials