|
2 | 2 | from unitxt.catalog import add_to_catalog |
3 | 3 | from unitxt.collections_operators import Filter |
4 | 4 | from unitxt.operators import ( |
5 | | - FilterByCondition, |
6 | | - FilterByExpression, |
| 5 | + ExecuteExpression, |
7 | 6 | ListFieldValues, |
8 | 7 | MapValues, |
9 | 8 | ) |
|
45 | 44 | "Sociology", |
46 | 45 | ] |
47 | 46 |
|
48 | | -mapping = {"A": 0, "B": 1, "C": 2, "D": 3, "E": 4, "?": None} |
| 47 | +mapping = {"A": 0, "B": 1, "C": 2, "D": 3, "E": 4, "F": 5, "G": 6, "H": 7, "I": 8} |
49 | 48 |
|
50 | 49 | for name in config_names: |
51 | 50 | card = TaskCard( |
|
58 | 57 | fields=[f"image_{i}" for i in range(1, 8)], to_field="media/images" |
59 | 58 | ), |
60 | 59 | Filter(field="media/images", values=[None]), |
| 60 | + ExecuteExpression( |
| 61 | + expression="options if options != '[]' else '[\"'+answer+'\"]'", |
| 62 | + to_field="options", |
| 63 | + ), |
| 64 | + ExecuteExpression( |
| 65 | + expression="'A' if options == '[\"'+answer+'\"]' else answer", |
| 66 | + to_field="answer", |
| 67 | + ), |
61 | 68 | MapReplace( |
62 | 69 | field_to_field={"question": "question", "options": "choices"}, |
63 | 70 | mapping={ |
|
67 | 74 | ), |
68 | 75 | LiteralEval(field="choices"), |
69 | 76 | Lower(field="subfield", to_field="topic"), |
70 | | - FilterByCondition(values={"answer": list(mapping.keys())}, condition="in"), |
71 | 77 | MapValues( |
72 | 78 | field="answer", |
73 | 79 | mapping=mapping, |
74 | 80 | ), |
75 | | - FilterByExpression(expression="answer < len(choices)"), |
76 | 81 | ], |
77 | 82 | task="tasks.qa.multiple_choice.with_topic", |
78 | 83 | templates="templates.qa.multiple_choice.with_topic.all", |
|
0 commit comments