我們在【Day17:TOD版的DialoGPT-ConvLab實作】介紹如何建構一個TOD對話系統,那今天我們來續講如何利用ConvLab-3來架設一個互動網站,看起來就像這樣:
互動網站包含:對話視窗(右半)、各個TOD模組的輸出(左半)
ConvLab-3已利用Flask建立一網站應用(程式碼可至convlab/deploy瀏覽),
將ConvLab-3 clone下來並安裝後,再輸入以下指令即可運行:
cd ./ConvLab-3/convlab
python ./deploy/run.py
在convlab/deploy/run.py尾部可看到Flask運行應用的app.run()
,
將host='127.0.0.1'改為host='0.0.0.0',即可用global IP分享網站啦:
if __name__ == '__main__':
# gunicorn deploy.run:app --threads 4
# Note that if you want to run this on a server, use host '0.0.0.0'
app.run(host='127.0.0.1', port=dep_conf['net']['port'], debug=True)
gunicorn -b 0.0.0.0:8888 deploy.run:app --threads 4
相關gunicorn參數設定可以瀏覽官方documentation
net
)在ConvLab-3只提供埠號的網路設定,需在dep_config.json
進行修改,以下是可修改項目及敘述:
KEY | DES | DEF |
---|---|---|
port |
後端服務開放埠 | N/A |
app_name |
服務存取介面路徑名稱 | N/A |
session_time_out |
會話閒置的最長生命週期(秒) | 600 |
可以設定成這樣:
"net":
{
"port": 8787,
"app_name": "convlab",
"session_time_out": 300
}
nlu
, dst
, policy
, nlg
)dep_config.json
進行修改,以下是可修改項目及敘述:KEY | DES | DEF |
---|---|---|
class_path |
目標模型類別的相對路徑 | not default |
data_set |
模型使用的資料集 | not default |
ini_params |
要實體化的類別所需的參數 | {} |
model_name |
前端顯示的模型名稱 | model key |
max_core |
此模型允許啟動的最大核心數 | 1 |
preload |
如果為假,此模型不會被預先載入 | true |
enable |
如果false,系統將忽略此配置 | true |
而在ConvLab-3的dep_config.json
只提供MultiWOZ的範例,
在此也提供如何使用CrossWOZ的dep_config.json
:
{
"net": {
"port": 8787,
"app_name": "convlab",
"session_time_out": 300
},
"nlu": {
"t5nlu-mul": {
"class_path": "convlab.base_models.t5.nlu.T5NLU",
"data_set": "multiwoz",
"ini_params": {
"speaker": "user",
"context_window_size": 0,
"model_name_or_path": "ConvLab/t5-small-nlu-multiwoz21"
},
"model_name": "t5nlu-mul",
"max_core": 1,
"preload": true,
"enable": true
},
"t5nlu-cro": {
"class_path": "convlab.base_models.t5.nlu.T5NLU",
"data_set": "crosswoz",
"ini_params": {
"speaker": "user",
"context_window_size": 0,
"model_name_or_path": "ConvLab/mt5-small-nlu-all-crosswoz"
},
"model_name": "t5nlu-cro",
"max_core": 1,
"preload": true,
"enable": true
}
},
"dst": {
"t5dst-mul": {
"class_path": "convlab.base_models.t5.dst.T5DST",
"data_set": "multiwoz",
"ini_params": {
"dataset_name": "multiwoz21",
"speaker": "user",
"context_window_size": 100,
"model_name_or_path": "ConvLab/t5-small-dst-multiwoz21"
},
"model_name": "t5dst-mul",
"max_core": 1,
"preload": true,
"enable": true
},
"t5dst-cro": {
"class_path": "convlab.base_models.t5.dst.T5DST",
"data_set": "crosswoz",
"ini_params": {
"dataset_name": "crosswoz",
"speaker": "user",
"context_window_size": 100,
"model_name_or_path": "ConvLab/mt5-small-dst-crosswoz"
},
"model_name": "t5dst-cro",
"max_core": 1,
"preload": true,
"enable": true
}
},
"policy": {
"ddpt-mul": {
"class_path": "convlab.policy.vtrace_DPT.VTRACE",
"data_set": "multiwoz",
"ini_params": {
"is_train": false,
"seed": 0,
"load_path": "from_pretrained",
"dataset_name": "multiwoz21"
},
"model_name": "ddpt-mul",
"max_core": 1,
"preload": true,
"enable": true
},
"rule-cro": {
"class_path": "convlab.policy.rule.crosswoz.Simulator",
"data_set": "crosswoz",
"ini_params": {},
"model_name": "rule-cro",
"max_core": 1,
"preload": true,
"enable": true
}
},
"nlg": {
"t5nlg-mul": {
"class_path": "convlab.base_models.t5.nlg.T5NLG",
"data_set": "multiwoz",
"ini_params": {
"speaker": "system",
"context_window_size": 0,
"model_name_or_path": "ConvLab/t5-small-nlg-multiwoz21"
},
"model_name": "t5nlg-mul",
"max_core": 1,
"preload": true,
"enable": true
},
"t5nlg-cro": {
"class_path": "convlab.base_models.t5.nlg.T5NLG",
"data_set": "crosswoz",
"ini_params": {
"speaker": "system",
"context_window_size": 0,
"model_name_or_path": "ConvLab/mt5-small-nlg-all-crosswoz"
},
"model_name": "t5nlg-cro",
"max_core": 1,
"preload": true,
"enable": true
}
}
}
在convlab/deploy/run.py中我們可以看到以下程式碼:
@app.route("/dialog")
def dialog():
return render_template("dialog.html")
這三行代表將HTML檔dialog.html
放至dialog
的路由(路徑),我們以下面的URL進入架好的網站:
http://127.0.0.1:8787/dialog
修改Broadcast IP和Port的URL像這樣 - http://0.0.0.0:[port]/dialog
Reference.
ConvLab-3 Visualization Service Deployment