Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Finalized model code #10

Merged
merged 6 commits into from
Jun 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ Once the predictative files are generated, we will depend on the [AirDialogue to
We are currently working on the scoring script.
```
airdialogue score --pred_data ./data/out_dir/dev_inference_out.txt \
--true_data ./data/airdialogue/json/dev_data.json \
--true_kb ./data/airdialogue/json/dev_kb.json \
--true_data ./data/airdialogue/tokenized/dev.infer.tar.data \
--true_kb ./data/airdialogue/tokenied/dev.infer.kb \
--task infer \
--output ./data/out_dir/dev_bleu.json
```
Expand Down Expand Up @@ -155,8 +155,8 @@ bash ./scripts/evaluate.sh -p dev -a ood1 -m ./data/synthesized_out_dir -o ./dat
###### Scoring
```
airdialogue score --pred_data ./data/synthesized_out_dir/dev_inference_out.txt \
--true_data ./data/synthesized/json/dev_data.json \
--true_kb ./data/airdialogue/json/dev_kb.json \
--true_data ./data/synthesized/tokenized/dev.infer.tar.data \
--true_kb ./data/airdialogue/tokenized/dev.infer.kb \
--task infer \
--output ./data/synthesized_out_dir/dev_bleu.json
```
Expand Down
6 changes: 6 additions & 0 deletions airdialogue_model_tf.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,11 @@ def add_arguments(parser):
type=int,
default=50,
help="maximum sentence length for dialogue inference")
parser.add_argument(
"--self_play_start_turn",
type=str,
default=None,
help="Force self-play to run for an agent/customer start. [agent | customer]")
parser.add_argument(
"--num_kb_fields_per_entry",
type=int,
Expand Down Expand Up @@ -592,6 +597,7 @@ def create_hparams(flags):
vocab_file=flags.vocab_file,
max_dialogue_len=flags.max_dialogue_len,
max_inference_len=flags.max_inference_len,
self_play_start_turn=flags.self_play_start_turn,
num_kb_fields_per_entry=flags.num_kb_fields_per_entry,
len_action=flags.len_action,
# selfplay
Expand Down
6 changes: 3 additions & 3 deletions scripts/evaluate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ echo "out_dir", ${out_dir}
echo "num_gpus", ${num_gpus}

# run in foreground once and display the results
# python airdialogue_model_tf.py --task_type INFER --eval_prefix $partition --num_gpus $num_gpus \
# --input_dir ${input_dir} --out_dir ${out_dir} \
# --inference_output_file ${out_dir}/dev_inference_out.txt
python airdialogue_model_tf.py --task_type INFER --eval_prefix $partition --num_gpus $num_gpus \
--input_dir ${input_dir} --out_dir ${out_dir} \
--inference_output_file ${out_dir}/dev_inference_out.txt

# run in foreground once and display the results
python airdialogue_model_tf.py --task_type SP_EVAL --eval_prefix $partition --num_gpus $num_gpus \
Expand Down
17 changes: 15 additions & 2 deletions utils/dialogue_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import codecs
import random
import re
import numpy as np
import tensorflow.compat.v1 as tf
from airdialogue.evaluator.metrics import f1
Expand Down Expand Up @@ -217,7 +218,7 @@ def decode_and_evaluate(name,
trans_f.write('') # Write empty string to ensure file is created.
while True:
try:
ut1, ut2, _ = model.generate_infer_utterance(sess,
ut1, ut2, action = model.generate_infer_utterance(sess,
data_iterator_handle)
batch_size = ut1.shape[0]
for sent_id in range(batch_size):
Expand All @@ -226,7 +227,19 @@ def decode_and_evaluate(name,
nmt_outputs = [ut1, ut2][speaker]
translation = get_translation_cut_both(nmt_outputs, sent_id,
hparams.t1.encode(), hparams.t2.encode())
trans_f.write((translation + b'\n').decode('utf-8'))
translation = translation.decode('utf-8')
if hparams.self_play_start_turn == 'agent':
if '<eod>' in translation:
ac_arr = [w.decode('utf-8') for w in action[sent_id]]
name = ac_arr[0] + ' ' + ac_arr[1]
flight = re.match(r'<fl_(\d+)>', ac_arr[2])
flight = flight.group(1) if flight else ''
status = re.match(r'<st_(\w+)>', ac_arr[3])
status = status.group(1) if status else ''
translation += '|' + '|'.join([name, flight, status])
else:
translation += '|||'
trans_f.write(translation + '\n')
cnt += 1
if last_cnt - cnt >= 10000: # 400k in total
utils.print_out('cnt= ' + str(cnt))
Expand Down
2 changes: 1 addition & 1 deletion utils/iterator_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def get_sub_items_supervised(data, kb):

def get_sub_items_infer(data, kb):
"""process procedure for inference."""
all_data = tf.string_split([data], sep="|").values
all_data = tf.string_split([data], sep="|", skip_empty=False).values
intent, dialogue_context = all_data[0], all_data[1]
return intent, dialogue_context, kb

Expand Down