-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexamine_results.py
65 lines (51 loc) · 2.11 KB
/
examine_results.py
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
#!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates.
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
from mephisto.abstractions.databases.local_database import LocalMephistoDB
from mephisto.tools.examine_utils import run_examine_or_review, print_results
from mephisto.data_model.worker import Worker
from mephisto.data_model.unit import Unit
db = None
def format_for_printing_data(data):
global db
# Custom tasks can define methods for how to display their data in a relevant way
worker_name = Worker.get(db, data["worker_id"]).worker_name
contents = data["data"]
duration = data["task_end"] - data["task_start"]
metadata_string = (
f"Worker: {worker_name}\nUnit: {data['unit_id']}\n"
f"Duration: {int(duration)}\nStatus: {data['status']}\n"
)
inputs = contents["inputs"]
outputs = contents["outputs"]
# Case 1: CAD was submitted
if inputs['stage'] == "CAD" and 'cad' in outputs:
inputs_string = (
f"Original: {inputs['original']}"
)
output_string = (
f"CAD: {outputs['cad']}"
)
# Case 2: CAD was rejected and explanation provided
elif inputs['stage'] == "CAD" and 'explanation' in outputs:
inputs_string = (
f"Original: {inputs['original']}"
)
output_string = (
f"Worker rejected the input as not sexist and provided the following explanation:\n{outputs['explanation']}"
)
# Case 3: Ranking was submitted
elif inputs['stage'] == "RANKING":
inputs_string = "Input sentences:\n"
inputs_string += "\n".join([f"{num}. {sentence}" for (num, sentence) in enumerate(inputs['sentences'])])
output_string = f"Permutation: {outputs['permutation']}"
else:
raise Exception("Unknown unit type")
return f"-------------------\n{metadata_string}\n{inputs_string}\n{output_string}"
def main():
global db
db = LocalMephistoDB()
run_examine_or_review(db, format_for_printing_data)
if __name__ == "__main__":
main()