-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparaboth_sentences.py
More file actions
76 lines (65 loc) · 2.11 KB
/
paraboth_sentences.py
File metadata and controls
76 lines (65 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python
import argparse
import os
from paraboth.data import Text
from paraboth.normalizer import TextNormalizer
from paraboth.paraboth_sentences import paraboth
from paraphraser import Paraphraser
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Evaluate ASR predictions against ground truth."
)
parser.add_argument(
"--gt", type=str, required=True, help="Path to ground truth text file."
)
parser.add_argument(
"--pred", type=str, required=True, help="Path to predictions text file."
)
parser.add_argument(
"--n_paraphrases",
type=int,
default=6,
help="Number of paraphrases to generate.",
)
parser.add_argument(
"--paraphrase_gt",
type=bool,
default=True,
help="Whether to paraphrase ground truth as well.",
)
parser.add_argument(
"--paraphrase_pred",
type=bool,
default=True,
help="Whether to paraphrase predictions as well.",
)
parser.add_argument(
"--base_output_dir",
type=str,
default="results",
help="Base output directory for results.",
)
args = parser.parse_args()
# Read files
gt_sentences = Text(args.gt).to_list_of_strings()
pred_sentences = Text(args.pred).to_list_of_strings()
# Normalize the sentences
normalizer = TextNormalizer()
normalized_gt = normalizer.normalize(gt_sentences)
normalized_pred = normalizer.normalize(pred_sentences)
# Initialize the paraphraser
paraphraser = Paraphraser()
metrics, detailed_alignment_info = paraboth(
normalized_gt,
normalized_pred,
paraphraser=paraphraser,
n_paraphrases=args.n_paraphrases,
paraphrase_gt=args.paraphrase_gt,
paraphrase_pred=args.paraphrase_pred,
)
# Save results
os.makedirs(args.base_output_dir, exist_ok=True)
metrics.to_csv(os.path.join(args.base_output_dir, "metrics.csv"), index=False)
detailed_alignment_info.to_csv(
os.path.join(args.base_output_dir, "detailed_alignment_info.csv"), index=False
)