Implement the missing function: """ import pandas as pd import os """ Evaluate each GCA…
- User
Implement the missing function:
""" import pandas as pd import os
""" Evaluate each GCA aspect using LLM as a judge.
First, for each discussion and participant, create a text file in the following format:
"""
SEED = 30
def load_data(path: str) -> pd.DataFrame: """ load the CSV with all discussion turns : param path: :return: """ return pd.read_csv(path)
def create_judge_files(df: pd.DataFrame, output_dir: str): """ Create text files for each discussion and participant for LLM judging in the format: Discussion: <discussion_name> Participant: <participant_name> Text:
code:param df: :param output_dir: :return: """ # create directory if it does not exist if not os.path.exists(output_dir): os.makedirs(output_dir) discussions = df['discussion'].unique() for discussion in discussions: df_disc = df[df['discussion'] == discussion] participants = df_disc['author'].unique() for participant in participants: filename = f"{output_dir}/{discussion}_{participant}.txt" with open(filename, 'w') as f: f.write(f"Discussion: {discussion}\n") f.write(f"Participant: {participant}\n") f.write(f"Content:\n") # for each turn, write "<author>: <text>" for idx, row in df_disc.iterrows(): f.write(f"\n{row['author']}: {row['text']}\n") passdef main_preprocess(): data = load_data("/home/esther/PycharmProjects/Dialogos/role_discovery/data/turn_all_contributions.csv") create_judge_files(data, "/home/esther/PycharmProjects/Dialogos/role_discovery/data/judge_files")
def main_run_judge(judge_data_dir: str, test_data: pd.DataFrame, aspect: str, model: str): """ Run the LLM judge on the test data for the given aspect. For each discussion and participant in the test data, load the corresponding text file and run the LLM judge prompt for the given aspect. Save the results in a csv file.
code:param test_data: :param judge_data_dir: :param aspect: :return: """ passdef create_test_split(blocks: str, size: float) -> pd.DataFrame: """ If the test data already exists, just load it. Otherwise,load the data and create a test split of the given size
- Assistant