| 549 | |
| 550 | |
| 551 | def clone_output_row( |
| 552 | row: Dict[str, Any], |
| 553 | label: Dict[str, Any], |
| 554 | score_payload: Dict[str, Any], |
| 555 | rank: int, |
| 556 | top_k: int, |
| 557 | ) -> Dict[str, Any]: |
| 558 | output = dict(row) |
| 559 | shown = rank <= top_k |
| 560 | output.update( |
| 561 | { |
| 562 | "baseline_method": METHOD_NAME, |
| 563 | "ranking_source": "baselines.discourse_aware.runner", |
| 564 | "ranking_fallback": False, |
| 565 | "shown": shown, |
| 566 | "pool_rank": rank, |
| 567 | "system_rank": rank if shown else None, |
| 568 | "system_score": round(float(score_payload["system_score"]), 6), |
| 569 | "system_label": score_payload["system_label"], |
| 570 | "show_target_count": top_k, |
| 571 | "drift_bonus": 0.0, |
| 572 | "drift_topics": [], |
| 573 | "reading_signal_bonus": 0.0, |
| 574 | "reading_signal_topics": [], |
| 575 | "selected": bool(label.get("selected")), |
| 576 | "oracle_score": label.get("oracle_score", 0.0), |
| 577 | "oracle_label": label.get("oracle_label", "irrelevant"), |
| 578 | "select_probability": 0.0, |
| 579 | } |
| 580 | ) |
| 581 | for key, value in score_payload.items(): |
| 582 | if key in {"system_score", "system_label"}: |
| 583 | continue |
| 584 | if isinstance(value, float): |
| 585 | output[key] = round(value, 6) |
| 586 | else: |
| 587 | output[key] = value |
| 588 | return output |
| 589 | |
| 590 | |
| 591 | def group_by_episode(rows: Sequence[Dict[str, Any]]) -> Dict[str, List[Dict[str, Any]]]: |