Commit a877a089 authored by Carel van Niekerk's avatar Carel van Niekerk
Browse files

Merge branch 'add_code' into 'main'

Add code for our work

See merge request !1
parents 25bc35c1 370a1ff7
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
include LICENSE.txt
include README.md
prune convlab2/*/__pycache__
This project may include a number of subcomponents with separate copyright notices
and license terms.
This product includes software from https://github.com/budzianowski/multiwoz under Apache License 2.0
This product includes software from https://github.com/thu-coai/CrossWOZ under Apache License 2.0
This product includes software from https://github.com/ConvLab/ConvLab under MIT License
This product includes software from https://bitbucket.org/dialoguesystems/pydial/src/master/semi/CNetTrain/ under Apache License 2.0
This product includes software from https://github.com/osmanio2/multi-domain-belief-tracking
This product includes software from https://github.com/jasonwu0731/trade-dst
This product includes software from https://github.com/SKTBrain/SUMBT under MIT License
This product includes software from https://github.com/renll/ComerNet under Apache License 2.0
This product includes software from https://github.com/truthless11/GDPL
This product includes software from https://github.com/snakeztc/NeuralDialog-LaRL under Apache License 2.0
This product includes software from https://github.com/wenhuchen/HDSA-Dialog under MIT License
This product includes software from https://github.com/andy194673/nlg-sclstm-multiwoz
This product includes software from https://github.com/WING-NUS/sequicity
This product includes software from https://github.com/thu-spmi/damd-multiwoz under Apache License 2.0
This product includes software from https://github.com/facebookresearch/end-to-end-negotiator
**Description:**
**Reference Issues:** #XX (XX is the issue number you work on)
Code will be released here soon.
# Uncertainty Measures in Neural Belief Tracking and the Effects on Dialogue Policy Performance
For the code used in our paper navigate to convlab/dst/setsumbt. See below info regarding the use and installation of the convlab environment.
# ConvLab-2
[![Build Status](https://travis-ci.com/thu-coai/ConvLab-2.svg?branch=master)](https://travis-ci.com/thu-coai/ConvLab-2)
**ConvLab-2** is an open-source toolkit that enables researchers to build task-oriented dialogue systems with state-of-the-art models, perform an end-to-end evaluation, and diagnose the weakness of systems. As the successor of [ConvLab](https://github.com/ConvLab/ConvLab), ConvLab-2 inherits ConvLab's framework but integrates more powerful dialogue models and supports more datasets. Besides, we have developed an analysis tool and an interactive tool to assist researchers in diagnosing dialogue systems. [[paper]](https://arxiv.org/abs/2002.04793)
- [Installation](#installation)
- [Tutorials](#tutorials)
- [Documents](#documents)
- [Models](#models)
- [Supported Datasets](#Supported-Datasets)
- [End-to-end Performance on MultiWOZ](#End-to-end-Performance-on-MultiWOZ)
- [Module Performance on MultiWOZ](#Module-Performance-on-MultiWOZ)
- [Issues](#issues)
- [Contributions](#contributions)
- [Citing](#citing)
- [License](#license)
## Installation
Require python 3.6.
Clone this repository:
```bash
git clone https://github.com/thu-coai/ConvLab-2.git
```
Install ConvLab-2 via pip:
```bash
cd ConvLab-2
pip install -e .
```
## Tutorials
- [Getting Started](https://github.com/thu-coai/ConvLab-2/blob/master/tutorials/Getting_Started.ipynb) (Have a try on [Colab](https://colab.research.google.com/github/thu-coai/ConvLab-2/blob/master/tutorials/Getting_Started.ipynb)!)
- [Add New Model](https://github.com/thu-coai/ConvLab-2/blob/master/tutorials/Add_New_Model.md)
- [Train RL Policies](https://github.com/thu-coai/ConvLab-2/blob/master/tutorials/Train_RL_Policies)
- [Interactive Tool](https://github.com/thu-coai/ConvLab-2/blob/master/deploy) [[demo video]](https://youtu.be/00VWzbcx26E)
## Documents
Our documents are on https://thu-coai.github.io/ConvLab-2_docs/convlab2.html.
## Models
We provide following models:
- NLU: SVMNLU, MILU, BERTNLU
- DST: rule, TRADE, SUMBT
- Policy: rule, Imitation, REINFORCE, PPO, GDPL, MDRG, HDSA, LaRL
- Simulator policy: Agenda, VHUS
- NLG: Template, SCLSTM
- End2End: Sequicity, DAMD, RNN_rollout
For more details about these models, You can refer to `README.md` under `convlab2/$module/$model/$dataset` dir such as `convlab2/nlu/jointBERT/multiwoz/README.md`.
## Supported Datasets
- [Multiwoz 2.1](https://github.com/budzianowski/multiwoz)
- We add user dialogue act (*inform*, *request*, *bye*, *greet*, *thank*), remove 5 sessions that have incomplete dialogue act annotation and place it under `data/multiwoz` dir.
- Train/val/test size: 8434/999/1000. Split as original data.
- LICENSE: Attribution 4.0 International, url: http://creativecommons.org/licenses/by/4.0/
- [CrossWOZ](https://github.com/thu-coai/CrossWOZ)
- We offers a rule-based user simulator and a complete set of models for building a pipeline system on the CrossWOZ dataset. We correct few state annotation and place it under `data/crosswoz` dir.
- Train/val/test size: 5012/500/500. Split as original data.
- LICENSE: Attribution 4.0 International, url: http://creativecommons.org/licenses/by/4.0/
- [Camrest](https://www.repository.cam.ac.uk/handle/1810/260970)
- We add system dialogue act (*inform*, *request*, *nooffer*) and place it under `data/camrest` dir.
- Train/val/test size: 406/135/135. Split as original data.
- LICENSE: Attribution 4.0 International, url: http://creativecommons.org/licenses/by/4.0/
- [Dealornot](https://github.com/facebookresearch/end-to-end-negotiator/tree/master/src/data/negotiate)
- Placed under `data/dealornot` dir.
- Train/val/test size: 5048/234/526. Split as original data.
- LICENSE: Attribution-NonCommercial 4.0 International, url: https://creativecommons.org/licenses/by-nc/4.0/
## End-to-end Performance on MultiWOZ
*Notice*: The results are for commits before [`bdc9dba`](https://github.com/thu-coai/ConvLab-2/commit/bdc9dba72c957d97788e533f9458ed03a4b0137b) (inclusive). We will update the results after improving user policy.
We perform end-to-end evaluation (1000 dialogues) on MultiWOZ using the user simulator below (a full example on `tests/test_end2end.py`) :
```python
# BERT nlu trained on sys utterance
user_nlu = BERTNLU(mode='sys', config_file='multiwoz_sys_context.json', model_file='https://convlab.blob.core.windows.net/convlab-2/bert_multiwoz_sys_context.zip')
user_dst = None
user_policy = RulePolicy(character='usr')
user_nlg = TemplateNLG(is_user=True)
user_agent = PipelineAgent(user_nlu, user_dst, user_policy, user_nlg, name='user')
analyzer = Analyzer(user_agent=user_agent, dataset='multiwoz')
set_seed(20200202)
analyzer.comprehensive_analyze(sys_agent=sys_agent, model_name='sys_agent', total_dialog=1000)
```
Main metrics (refer to `convlab2/evaluator/multiwoz_eval.py` for more details):
- Complete: whether complete the goal. Judged by the Agenda policy instead of external evaluator.
- Success: whether all user requests have been informed and the booked entities satisfy the constraints.
- Book: how many the booked entities satisfy the user constraints.
- Inform Precision/Recall/F1: how many user requests have been informed.
- Turn(succ/all): average turn number for successful/all dialogues.
Performance (the first row is the default config for each module. Empty entries are set to default config.):
| NLU | DST | Policy | NLG | Complete rate | Success rate | Book rate | Inform P/R/F1 | Turn(succ/all) |
| ----------- | --------- | -------------- | ----------- | ------------- | ------------ | --------- | --------- | -------------- |
| **BERTNLU** | RuleDST | RulePolicy | TemplateNLG | 90.5 | 81.3 | 91.1 | 79.7/92.6/83.5 | 11.6/12.3 |
| **MILU** | RuleDST | RulePolicy | TemplateNLG | 93.3 | 81.8 | 93.0 | 80.4/94.7/84.8 | 11.3/12.1 |
| BERTNLU | RuleDST | RulePolicy | **SCLSTM** | 48.5 | 40.2 | 56.9 | 62.3/62.5/58.7 | 11.9/27.1 |
| BERTNLU | RuleDST | **MLEPolicy** | TemplateNLG | 42.7 | 35.9 | 17.6 | 62.8/69.8/62.9 | 12.1/24.1 |
| BERTNLU | RuleDST | **PGPolicy** | TemplateNLG | 37.4 | 31.7 | 17.4 | 57.4/63.7/56.9 | 11.0/25.3 |
| BERTNLU | RuleDST | **PPOPolicy** | TemplateNLG | 61.1 | 44.0 | 44.6 | 63.9/76.8/67.2 | 12.5/20.8 |
| BERTNLU | RuleDST | **GDPLPolicy** | TemplateNLG | 49.4 | 38.4 | 20.1 | 64.5/73.8/65.6 | 11.5/21.3 |
| None | **TRADE** | RulePolicy | TemplateNLG | 32.4 | 20.1 | 34.7 | 46.9/48.5/44.0 | 11.4/23.9 |
| None | **SUMBT** | RulePolicy | TemplateNLG | 34.5 | 29.4 | 62.4 | 54.1/50.3/48.3 | 11.0/28.1 |
| BERTNLU | RuleDST | **MDRG** | None | 21.6 | 17.8 | 31.2 | 39.9/36.3/34.8 | 15.6/30.5|
| BERTNLU | RuleDST | **LaRL** | None | 34.8 | 27.0 | 29.6 | 49.1/53.6/47.8 |13.2/24.4|
| None | **SUMBT** | **LaRL** | None | 32.9 | 23.7 | 25.9 | 48.6/52.0/46.7 | 12.5/24.3|
| None | None | **DAMD*** | None | 39.5| 34.3 | 51.4 | 60.4/59.8/56.3 | 15.8/29.8 |
*: end-to-end models used as sys_agent directly.
## Module Performance on MultiWOZ
### NLU
By running `convlab2/nlu/evaluate.py MultiWOZ $model all`:
| | Precision | Recall | F1 |
| ------- | --------- | ------ | ----- |
| BERTNLU | 82.48 | 85.59 | 84.01 |
| MILU | 80.29 | 83.63 | 81.92 |
| SVMNLU | 74.96 | 50.74 | 60.52 |
### DST
By running `convlab2/dst/evaluate.py MultiWOZ $model`:
| | Joint accuracy | Slot accuracy | Joint F1 |
| -------- | ------------- | ------------- | --------|
| MDBT | 0.06 | 0.89 | 0.43 |
| SUMBT | 0.30 | 0.96 | 0.83 |
| TRADE | 0.40 | 0.96 | 0.84 |
### Policy
*Notice*: The results are for commits before [`bdc9dba`](https://github.com/thu-coai/ConvLab-2/commit/bdc9dba72c957d97788e533f9458ed03a4b0137b) (inclusive). We will update the results after improving user policy.
By running `convlab2/policy/evalutate.py --model_name $model`
| | Task Success Rate |
| --------- | ----------------- |
| MLE | 0.56 |
| PG | 0.54 |
| PPO | 0.74 |
| GDPL | 0.58 |
### NLG
By running `convlab2/nlg/evaluate.py MultiWOZ $model sys`
| | corpus BLEU-4 |
| -------- | ------------- |
| Template | 0.3309 |
| SCLSTM | 0.4884 |
## Translation-train SUMBT for cross-lingual DST
### Train
With Convlab-2, you can train SUMBT on a machine-translated dataset like this:
```python
# train.py
import os
from sys import argv
if __name__ == "__main__":
if len(argv) != 2:
print('usage: python3 train.py [dataset]')
exit(1)
assert argv[1] in ['multiwoz', 'crosswoz']
from convlab2.dst.sumbt.multiwoz_zh.sumbt import SUMBT_PATH
if argv[1] == 'multiwoz':
from convlab2.dst.sumbt.multiwoz_zh.sumbt import SUMBTTracker as SUMBT
elif argv[1] == 'crosswoz':
from convlab2.dst.sumbt.crosswoz_en.sumbt import SUMBTTracker as SUMBT
sumbt = SUMBT()
sumbt.train(True)
```
### Evaluate
Execute `evaluate.py` (under `convlab2/dst/`) with following command:
```bash
python3 evaluate.py [CrossWOZ-en|MultiWOZ-zh] [val|test|human_val]
```
evaluation of our pre-trained models are: (joint acc.)
| type | CrossWOZ-en | MultiWOZ-zh |
| ----- | ----------- | ----------- |
| val | 12.4% | 45.1% |
| test | 12.4% | 43.5% |
| human_val | 10.6% | 49.4% |
`human_val` option will make the model evaluate on the validation set translated by human.
Note: You may want to download pre-traiend BERT models and translation-train SUMBT models provided by us.
Without modifying any code, you could:
- download pre-trained BERT models from:
- [bert-base-uncased](https://huggingface.co/bert-base-uncased) for CrossWOZ-en
- [chinese-bert-wwm-ext](https://huggingface.co/hfl/chinese-bert-wwm-ext) for MultiWOZ-zh
extract it to `./pre-trained-models`.
- for translation-train SUMBT model:
- [trained on CrossWOZ-en](https://convlab.blob.core.windows.net/convlab-2/crosswoz_en-pytorch_model.bin.zip)
- [trained on MultiWOZ-zh](https://convlab.blob.core.windows.net/convlab-2/multiwoz_zh-pytorch_model.bin.zip)
- Say the data set is CrossWOZ (English), (after extraction) just save the pre-trained model under `./convlab2/dst/sumbt/crosswoz_en/pre-trained` and name it with `pytorch_model.bin`.
## Issues
You are welcome to create an issue if you want to request a feature, report a bug or ask a general question.
## Contributions
We welcome contributions from community.
- If you want to make a big change, we recommend first creating an issue with your design.
- Small contributions can be directly made by a pull request.
- If you like make contributions to our library, see issues to find what we need.
## Team
**ConvLab-2** is maintained and developed by Tsinghua University Conversational AI group (THU-coai) and Microsoft Research (MSR).
We would like to thank:
Yan Fang, Zhuoer Feng, Jianfeng Gao, Qihan Guo, Kaili Huang, Minlie Huang, Sungjin Lee, Bing Li, Jinchao Li, Xiang Li, Xiujun Li, Lingxiao Luo, Wenchang Ma, Mehrad Moradshahi, Baolin Peng, Runze Liang, Ryuichi Takanobu, Hongru Wang, Jiaxin Wen, Yaoqin Zhang, Zheng Zhang, Qi Zhu, Xiaoyan Zhu.
## Citing
If you use ConvLab-2 in your research, please cite:
```
@inproceedings{zhu2020convlab2,
title={ConvLab-2: An Open-Source Toolkit for Building, Evaluating, and Diagnosing Dialogue Systems},
author={Qi Zhu and Zheng Zhang and Yan Fang and Xiang Li and Ryuichi Takanobu and Jinchao Li and Baolin Peng and Jianfeng Gao and Xiaoyan Zhu and Minlie Huang},
year={2020},
booktitle={Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics},
}
```
## License
Apache License 2.0
import os
from convlab2.nlu import NLU
from convlab2.dst import DST
from convlab2.policy import Policy
from convlab2.nlg import NLG
from convlab2.dialog_agent import Agent, PipelineAgent
from convlab2.dialog_agent import Session, BiSession, DealornotSession
from os.path import abspath, dirname
def get_root_path():
return dirname(dirname(abspath(__file__)))
DATA_ROOT = os.path.join(get_root_path(), 'data')
'''
AgentFactory.py - Session management between agents and dialogue server.
==========================================================================
@author: Songbo and Neo
'''
from convlab2.dialog_agent import agent
from convlab2 import policy
import copy
import json
import numpy as np
from convlab2.dialcrowd_server.SubjectiveFeedbackManager import SubjectiveFeedbackManager
from convlab2.util import ContextLogger
from configparser import ConfigParser
import logging
import time
import os
logger = ContextLogger.getLogger('')
class AgentFactory(object):
def __init__(self, configPath, savePath, saveFlag):
self.init_agents()
self.session2agent = {}
self.historical_sessions = []
self.savepath = savePath
self.saveFlag = saveFlag
self.number_agents_total = 0
# These messages will control sessions for dialogueCrowd. Be careful when you change them, particularly for the fisrt two.
self.ending_message = "Thanks for your participation. You can now click the Blue Finish Button."
self.query_taskID_message = "Please now enter the 5 digit task number"
self.willkommen_message = "Welcome to the dialogue system. How can I help you?"
self.query_feedback_message = "Got it, thanks. Have you found all the information you were looking for and were all necessary entities booked? Please enter 1 for yes, and 0 for no."
self.ask_rate_again_message = "Please try again. Have you found all the information you were looking for and were all necessary entities booked? Please enter 1 for yes, and 0 for no."
configparser = ConfigParser()
configparser.read(configPath)
agentPath = (configparser.get("AGENT", "agentPath"))
agentClass = (configparser.get("AGENT", "agentClass"))
self.maxTurn = int(configparser.get("AGENT", "maxTurn"))
self.maxNumberAgent = int(configparser.get("AGENT", "maxNumberAgent"))
mod = __import__(agentPath, fromlist=[agentClass])
klass = getattr(mod, agentClass)
self.template_agent_class = klass
self.template_agent_instances = klass()
self.policy = self.template_agent_instances.policy
self.nlu = copy.deepcopy(self.template_agent_instances.nlu)
self.template_agent_instances.policy = None
self.template_agent_instances.nlu = None
self.subjectiveFeedbackEnabled = (
configparser.getboolean("SUBJECTIVE", "enabled"))
self.subjectiveFeedbackManager = None
self.terminateFlag = False
self.filepath = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) #get parent directory
self.filepath = os.path.dirname(self.filepath) #get grandparent directory
self.filepath = os.path.join(self.filepath, 'user_trial', time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime()))
os.makedirs(self.filepath)
# TODO
# subjectiveFeedbackManager should be independent with subjectiveFeedbackEnabled
# subjectiveFeedbackManager is used for saving every information
# subjectiveFeedbackEnabled is used for updating the policy through interacting with real users
if self.subjectiveFeedbackEnabled:
self.subjectiveFeedbackManager = SubjectiveFeedbackManager(
configPath,
self.policy,
agent_name=self.template_agent_instances.agent_name)
def init_agents(self):
self.agents = {}
def start_call(self, session_id):
'''
Locates an agent to take this call and uses that agents start_call method.
:param session_id: session_id
:type session_id: string
:return: start_call() function of agent id (String)
'''
agent_id = None
print(session_id)
# 1. make sure session_id is not in use by any agent
if session_id in list(self.session2agent.keys()):
agent_id = self.session2agent[session_id]