-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
modify build message function for goal generation
- Loading branch information
Showing
3 changed files
with
53 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
""" | ||
generate user goal for collecting new multiwoz data | ||
""" | ||
|
||
from convlab2.task.multiwoz.goal_generator import GoalGenerator | ||
import random | ||
import numpy as np | ||
import json | ||
import datetime | ||
from pprint import pprint | ||
|
||
|
||
def generate(total_num=1000, seed=42, output_file='goal.json'): | ||
random.seed(seed) | ||
np.random.seed(seed) | ||
goal_generator = GoalGenerator() | ||
goals = [] | ||
avg_domains = [] | ||
while len(goals) < total_num: | ||
goal = goal_generator.get_user_goal() | ||
# pprint(goal) | ||
if 'police' in goal['domain_ordering']: | ||
no_police = list(goal['domain_ordering']) | ||
no_police.remove('police') | ||
goal['domain_ordering'] = tuple(no_police) | ||
del goal['police'] | ||
try: | ||
message = goal_generator.build_message(goal)[1] | ||
except: | ||
continue | ||
# print(message) | ||
avg_domains.append(len(goal['domain_ordering'])) | ||
goals.append({ | ||
"goals": [], | ||
"ori_goals": goal, | ||
"description": message, | ||
"timestamp": str(datetime.datetime.now()), | ||
"ID": len(goals) | ||
}) | ||
print('avg domains:', np.mean(avg_domains)) # avg domains: 1.827 | ||
json.dump(goals, open(output_file, 'w'), indent=4) | ||
|
||
|
||
if __name__ == '__main__': | ||
generate(output_file='goal20200623.json') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters