본문으로 바로가기

라사(Rasa) 튜토리얼 -1 : 설치 및 구동

category Bot 2020. 7. 17. 14:46

Rasa

  • Rasa는 텍스트 및 음성 기반 대화에 자동화(챗봇)하는 오픈소스 기계학습 프레임워크이다.

연동할 수 있는 대화채널

  • Facebook Messenger

  • Slack

  • Google Hangouts

  • Webex Teams

  • Microsoft Bot Framework

  • Rocket.Chat

  • Mattermost

  • Telegram

  • Twilio

  • Your own custom conversational channels

 

Rasa에서 지원하는 NLU 모델은 학습을 통해 ClassificationRecognition 이 가능합니다.

AI 에 관한 지식이 없어도 제공해주는 기능을 활용하면 쓰임새는 다양할 것으로 생각됩니다.

 

Rasa Community Forum

A community of makers pushing the limits of conversational AI software

forum.rasa.com

 

 

가상환경 생성

 

라사는 잦은 업데이트?로 인해 설치 및 구동에 어려움이 많습니다.

그런만큼 conda 가상환경을 통해 버전 관리가 이루어져야합니다.

 

라사는 파이썬 3.6, 3.7을 지원합니다.

 

 

가상환경을 생성해봅니다.

conda create -n rasa python=3.6

(base) PS C:\Users\Desktop\rasa> conda create -n rasa python=3.6

 

패키지 설치

 

생성한 가상 환경으로 activate 하고 패키지를 설치합니다.

conda activate rasa
pip rasa

 

위 명령어로 tensorflow 등 각종 패키지 및 모듈들이 설치됩니다.

설치가 에러가 난다면 tensorflow 쪽을 먼저 확인하셔야합니다. 

 

설치가 완료되었습니다.

튜토리얼 디렉터리를 하나 생성하고 rasa init 을 합니다.

(rasa) PS C:\Users\Desktop\rasa> mkdir tutorial_
(rasa) PS C:\Users\Desktop\rasa> cd tutorial_

(rasa) PS C:\Users\pju99\Desktop\rasa\tutorial_> rasa init
Welcome to Rasa! �🤖

To get started quickly, an initial project will be created.
If you need some help, check out the documentation at https://rasa.com/docs/rasa.
Now let's start! ��🏽🏽

 

현재 디렉터리(경로지정 가능)안에 환경파일, 데이터 파일 등 템플릿이 생성됩니다.

? Please enter a path where the project will be created [default: current directory] .

 

초기 데이터에 관해 훈련을 시킬 것이냐고 묻고있습니다.

튜토리얼이니 Y

(train에서 에러가 발생하면 패키지 설치시 tesorflow가 오류난 것입니다.)

? Please enter a path where the project will be created [default: current directory] .
Created project directory at 'C:\Users\Desktop\rasa\tutorial_'.
Finished creating project structure.
? Do you want to train an initial model? ����🏽  (Y/n)

 

참고용 콘솔출력.

현재폴더/model 디렉터리에 훈련된 모델이 생성됩니다.

Training an initial model...
Training Core model...
Processed Story Blocks: 100%|█████████████████████████████████████████████████████████████████████████| 5/5 [00:00<00:00, 2506.16it/s, # trackers=1]
Processed Story Blocks: 100%|█████████████████████████████████████████████████████████████████████████| 5/5 [00:00<00:00, 1671.04it/s, # trackers=5] 
Processed Story Blocks: 100%|█████████████████████████████████████████████████████████████████████████| 5/5 [00:00<00:00, 417.76it/s, # trackers=20]
Processed Story Blocks: 100%|█████████████████████████████████████████████████████████████████████████| 5/5 [00:00<00:00, 278.52it/s, # trackers=24]
Processed trackers: 100%|██████████████████████████████████████████████████████████████████████████████| 5/5 [00:00<00:00, 455.80it/s, # actions=16]
Processed actions: 16it [00:00, 5346.89it/s, # examples=16]
Processed trackers: 100%|█████████████████████████████████████████████████████████████████████████| 231/231 [00:00<00:00, 444.56it/s, # actions=126] 
Epochs:   0%|                                                                                                               | 0/100 [00:00<?, ?it/s]c:\programdata\anaconda3\envs\rasa\lib\site-packages\rasa\utils\tensorflow\model_data.py:386: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray
  final_data[k].append(np.concatenate(np.array(v)))
Epochs: 100%|████████████████████████████████████████████████████████████████| 100/100 [00:07<00:00, 13.20it/s, t_loss=0.081, loss=0.010, acc=1.000]
2020-07-17 14:22:51 INFO     rasa.utils.tensorflow.models  - Finished training.
2020-07-17 14:22:52 INFO     rasa.core.agent  - Persisted model to 'C:\Users\AppData\Local\Temp\tmph0dzp9aa\core'
Core model training completed.
Training NLU model...
2020-07-17 14:22:52 INFO     rasa.nlu.training_data.training_data  - Training data stats:
2020-07-17 14:22:52 INFO     rasa.nlu.training_data.training_data  - Number of intent examples: 43 (7 distinct intents)
2020-07-17 14:22:52 INFO     rasa.nlu.training_data.training_data  -   Found intents: 'bot_challenge', 'mood_unhappy', 'deny', 'goodbye', 'affirm', 'greet', 'mood_great'
2020-07-17 14:22:52 INFO     rasa.nlu.training_data.training_data  - Number of response examples: 0 (0 distinct responses)
2020-07-17 14:22:52 INFO     rasa.nlu.training_data.training_data  - Number of entity examples: 0 (0 distinct entities)
2020-07-17 14:22:52 INFO     rasa.nlu.model  - Starting to train component WhitespaceTokenizer
2020-07-17 14:22:52 INFO     rasa.nlu.model  - Finished training component.
2020-07-17 14:22:52 INFO     rasa.nlu.model  - Starting to train component RegexFeaturizer
2020-07-17 14:22:52 INFO     rasa.nlu.model  - Finished training component.
2020-07-17 14:22:52 INFO     rasa.nlu.model  - Starting to train component LexicalSyntacticFeaturizer
2020-07-17 14:22:52 INFO     rasa.nlu.model  - Finished training component.
2020-07-17 14:22:52 INFO     rasa.nlu.model  - Starting to train component CountVectorsFeaturizer
2020-07-17 14:22:52 INFO     rasa.nlu.model  - Finished training component.
2020-07-17 14:22:52 INFO     rasa.nlu.model  - Starting to train component CountVectorsFeaturizer
2020-07-17 14:22:52 INFO     rasa.nlu.model  - Finished training component.
2020-07-17 14:22:52 INFO     rasa.nlu.model  - Starting to train component DIETClassifier
c:\programdata\anaconda3\envs\rasa\lib\site-packages\rasa\utils\common.py:363: UserWarning: You specified 'DIET' to train entities, but no entities are present in the training data. Skip training of entities.
Epochs:   0%|                                                                                                               | 0/100 [00:00<?, ?it/s]c:\programdata\anaconda3\envs\rasa\lib\site-packages\rasa\utils\tensorflow\model_data.py:386: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray
  final_data[k].append(np.concatenate(np.array(v)))
Epochs: 100%|████████████████████████████████████████████████████████████| 100/100 [00:06<00:00, 14.30it/s, t_loss=1.715, i_loss=0.323, i_acc=1.000] 
2020-07-17 14:23:02 INFO     rasa.utils.tensorflow.models  - Finished training.
2020-07-17 14:23:02 INFO     rasa.nlu.model  - Finished training component.
2020-07-17 14:23:02 INFO     rasa.nlu.model  - Starting to train component EntitySynonymMapper
2020-07-17 14:23:02 INFO     rasa.nlu.model  - Finished training component.
2020-07-17 14:23:02 INFO     rasa.nlu.model  - Starting to train component ResponseSelector
2020-07-17 14:23:02 INFO     rasa.nlu.selectors.response_selector  - Retrieval intent parameter was left to its default value. This response selector will be trained on training examples combining all retrieval intents.
2020-07-17 14:23:02 INFO     rasa.nlu.model  - Finished training component.
2020-07-17 14:23:02 INFO     rasa.nlu.model  - Successfully saved model into 'C:\Users\AppData\Local\Temp\tmph0dzp9aa\nlu'
NLU model training completed.
Your Rasa model is trained and saved at 'C:\Users\Desktop\rasa\tutorial_\models\20200717-142238.tar.gz'.

 

위에 보시는 것처럼

Training Core model 과 Training NLU model 이 있습니다.

 

NLU 모델은 언어 이해(분류, 인식)만을 합니다.

코어 모델은 Stories(대화 흐름, 이야기) 와의 관계, 커스터마이징 Action 등 좀더 큰 틀(챗봇)의 영역까지를 정의합니다.

 

Tip

나중에 다루겠지만 NLU 모델을 독립적인 훈련사용이 가능합니다.

이것만으로도 분류 모델을 손쉽게 만드는 것이 가능합니다.

 

 

 

train 을 끝내고 커맨드라인을 실행해봅니다.

템플릿의 샘플 데이터 파일을 가지고 훈련된 모델의 응답들입니다.

? Do you want to speak to the trained assistant on the command line? ���  Yes
2020-07-17 14:41:20 INFO     root  - Connecting to channel 'cmdline' which was specified by the '--connector' argument. Any other channels will be ignored. To connect to all given channels, omit the '--connector' argument.
2020-07-17 14:41:20 INFO     root  - Starting Rasa server on http://localhost:5005
2020-07-17 14:41:23 INFO     root  - Rasa server is up and running.
Bot loaded. Type a message and press enter (use '/stop' to exit): 
Your input ->  hi                                                                                                                                    
Hey! How are you?
Your input ->  perfect                                                                                                                               
Great, carry on!
Your input ->  I'm sad                                                                                                                               
Here is something to cheer you up:
Image: https://i.imgur.com/nGF1K8f.jpg
Did that help you?
Your input ->