Convert the experience to a dictionary.
(self)
| 468 | return experiences |
| 469 | |
| 470 | def to_dict(self) -> dict: |
| 471 | """Convert the experience to a dictionary.""" |
| 472 | res = { |
| 473 | "eid": self.eid.to_dict(), |
| 474 | "type": self.experience_type, |
| 475 | "prompt_length": self.prompt_length, |
| 476 | "response_length": len(self.tokens) - self.prompt_length, # type: ignore [arg-type] |
| 477 | "info": self.info, |
| 478 | "metrics": self.metrics, |
| 479 | } |
| 480 | if self.prompt_text is not None: |
| 481 | res["prompt_text"] = self.prompt_text |
| 482 | if self.response_text is not None: |
| 483 | res["response_text"] = self.response_text |
| 484 | if self.messages is not None: |
| 485 | res["messages"] = self.messages |
| 486 | if self.tools is not None: |
| 487 | res["tools"] = self.tools |
| 488 | if self.chosen_messages is not None: |
| 489 | res["chosen_messages"] = self.chosen_messages |
| 490 | if self.rejected_messages is not None: |
| 491 | res["rejected_messages"] = self.rejected_messages |
| 492 | if self.reward is not None: |
| 493 | res["reward"] = float(self.reward) |
| 494 | if self.truncate_status is not None: |
| 495 | res["truncate_status"] = self.truncate_status |
| 496 | return res |
| 497 | |
| 498 | |
| 499 | def split_dpo_experience_to_single_turn(experiences: List[Experience]) -> List[Experience]: |