Skip to content
Snippets Groups Projects
Commit 316ee981 authored by Grießhaber Daniel's avatar Grießhaber Daniel :squid:
Browse files

use prompt ids in family tree

parent 85a06fd2
No related branches found
No related tags found
No related merge requests found
from functools import lru_cache
import os
from functools import lru_cache
from pathlib import Path
from typing import Any
......@@ -8,8 +8,8 @@ from numpy.random import choice
from tqdm import trange
from cli import argument_parser
from task import QuestionAnswering, SentimentAnalysis
from models import Llama2, OpenAI
from task import QuestionAnswering, SentimentAnalysis
from utils import (
Prompt,
log_calls,
......@@ -185,14 +185,16 @@ def run_episode(evo_alg_str: str, debug: bool = False):
# converting prompts to Prompt object
P = [
[
Prompt(p, score=score, gen=0, meta={"idx": idx})
Prompt(p, score=score, gen=0)
for idx, (p, score) in enumerate(zip(initial_population, population_scores))
]
]
# add initial prompts to family tree
# None marks that there is no parent
family_tree = [(prompt, None) for prompt in P[0]]
family_tree: dict[str, tuple[str, str] | None] = {
prompt.id: None for prompt in P[0]
}
# evolution = EvolutionGA(num_evolutions=N)
......@@ -224,10 +226,10 @@ def run_episode(evo_alg_str: str, debug: bool = False):
# s′_i ← f(p′i,D)
s_i = f_D(p_i)
evolved_prompt = Prompt(content=p_i, score=s_i, gen=t, meta={"idx": i})
evolved_prompt = Prompt(content=p_i, score=s_i, gen=t)
# keep track of genealogy
family_tree.append((evolved_prompt, (pr1, pr2)))
family_tree[evolved_prompt.id] = (pr1.id, pr2.id)
new_evolutions.append(evolved_prompt)
new_evolutions_scores.append(s_i)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment