Download tcod/trinity/algorithm/sample_strategy/utils.py from SeanWang0027/ftb-sciworld-repro: direct link, hf CLI and curl.
- Browser
- Download file 1.34 kB
-
https://huggingface.co/SeanWang0027/ftb-sciworld-repro/resolve/main/tcod/trinity/algorithm/sample_strategy/utils.py
- Command line
-
hf download hf://SeanWang0027/ftb-sciworld-repro/tcod/trinity/algorithm/sample_strategy/utils.py
-
curl -L -o utils.py https://huggingface.co/SeanWang0027/ftb-sciworld-repro/resolve/main/tcod/trinity/algorithm/sample_strategy/utils.py
1.34 kB
| import random | |
| from typing import List | |
| from trinity.common.experience import Experience | |
| def representative_sample(experiences: List[Experience]) -> List[dict]: | |
| if experiences[0].reward is None: | |
| sample = random.choice(experiences) | |
| return [ | |
| { | |
| "prompt": sample.prompt_text, | |
| "response": sample.response_text, | |
| } | |
| ] | |
| samples = [] | |
| min_reward_sample = None | |
| max_reward_sample = None | |
| for exp in experiences: | |
| if exp.reward is None: | |
| continue | |
| if min_reward_sample is None or exp.reward < min_reward_sample.reward: | |
| min_reward_sample = exp | |
| if max_reward_sample is None or exp.reward > max_reward_sample.reward: | |
| max_reward_sample = exp | |
| if min_reward_sample is not None: | |
| samples.append( | |
| { | |
| "prompt": min_reward_sample.prompt_text, | |
| "response": min_reward_sample.response_text, | |
| "reward": min_reward_sample.reward, | |
| } | |
| ) | |
| if max_reward_sample is not None: | |
| samples.append( | |
| { | |
| "prompt": max_reward_sample.prompt_text, | |
| "response": max_reward_sample.response_text, | |
| "reward": max_reward_sample.reward, | |
| } | |
| ) | |
| return samples | |