4. 딥러닝으로 학습시킨 다양한 자연언어처리 관련 모델들을 API로 구성
NLP as (Micro) Service
의도 분류, 감정 분석, 정보 추출, 응답 생성 등 다양한 모델들
수많은 언어들
딥러닝으로 새로운 모델을 만들때마다 Lambda Function 하나씩 추가하면 어떨까
16. $ pip install aws-sam-cli
$ sam --version
SAM CLI, version 0.5.0
$ sam init --runtime python3.6 --name sentiment
[+] Initializing project structure...
[SUCCESS] - Read sentiment/README.md for further instructions on how to proceed
[*] Project initialization is now complete
$ ls -l
README.md
hello_world/
requirements.txt
template.yaml
tests/
$ sam local start-api
2018-07-26 08:32:33 Mounting SentimentFunction at http://127.0.0.1:3000/sentiment [GET]
2018-07-26 08:32:33 You can now browse to the above endpoints to invoke your functions. You do not need to
restart/reload SAM CLI while working on your functions changes will be reflected instantly/automatically. You only need
to restart SAM CLI if you update your AWS SAM template
2018-07-26 08:32:33 * Running on http://127.0.0.1:3000/ (Press CTRL+C to quit)
17. 람다는 Amazon Linux 위에서 동작
시스템 의존성이 있는 라이브러리를 이용한다면 Amazon Linux에 맞게 파이썬 패키지를 세
팅해야 함
Tensorflow가 바로 그 의존적인 녀석 😔
Docker Amazon Linux 이미지를 받고 그 안에서 파이썬 패키지 준비
18. 람다는 Amazon Linux 위에서 동작
시스템 의존성이 있는 라이브러리를 이용한다면 Amazon Linux에 맞게 파이썬 패키지를 세팅해야 함
Tensorflow가 바로 그 의존적인 녀석 😔
Docker Amazon Linux 이미지를 받고 그 안에서 파이썬 패키지 준비
pip install tensorflow==1.8.0
sam deploy
19. $ docker run -v $(pwd):/outputs --name lambdapack -d amazonlinux:latest tail -f /dev/null
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
493d257a3748 amazonlinux:latest "tail -f /dev/null" 6 hours ago Up 5 hours lambdapack
24. du -hs data/checkpoints data/vocab2id.pkl sentiment/build
261M data/checkpoints
1000K data/vocab2id.pkl
209M sentiment/build
500M가 넘는 모델은 람다로 올리는 것이 불가능
Disk & Memory Limit 😱
Code: Deployment Package
Data: S3 -> /tmp
Lambda 첫 호출, 초기화 로직에서 /tmp 디렉토리로 다운로드
26. # 로컬 테스트
$ sam local start-api
# AWS 람다로 배포
$ sam package …
$ sam deploy …
27. POST
{
"message": "Hi there! How's your day? It's very wonderful today!"
}
Response
{
"sentiment": 0.9833118915557861
}
POST
{
"message": "I didn't like it. The movie was so boring. Terrible.."
}
Response
{
"sentiment": 0.2814910411834717
}
😃
😡