Evaluates accuracy given predictions and labels. Args: preds: predictions labels: labels input: optional, only needed for verbosity verbose: if true prints [input], golden labels and predictions Returns accuracy
(
preds: List[str], labels: List[str], input: Optional[List[str]] = None, verbose: bool = True
)
| 106 | |
| 107 | |
| 108 | def evaluate( |
| 109 | preds: List[str], labels: List[str], input: Optional[List[str]] = None, verbose: bool = True |
| 110 | ) -> float: |
| 111 | """ |
| 112 | Evaluates accuracy given predictions and labels. |
| 113 | |
| 114 | Args: |
| 115 | preds: predictions |
| 116 | labels: labels |
| 117 | input: optional, only needed for verbosity |
| 118 | verbose: if true prints [input], golden labels and predictions |
| 119 | |
| 120 | Returns accuracy |
| 121 | """ |
| 122 | acc = 0 |
| 123 | nums = len(preds) |
| 124 | for i in range(nums): |
| 125 | pred_norm = clean_generic(preds[i]) |
| 126 | label_norm = clean_generic(labels[i]) |
| 127 | if pred_norm == label_norm: |
| 128 | acc = acc + 1 |
| 129 | else: |
| 130 | if input: |
| 131 | print(f"inpu: {json.dumps(input[i])}") |
| 132 | print(f"gold: {json.dumps(label_norm)}") |
| 133 | print(f"pred: {json.dumps(pred_norm)}") |
| 134 | return acc / nums |
| 135 | |
| 136 | |
| 137 | def training_data_to_tokens( |
no test coverage detected
searching dependent graphs…