Implement the missing function: """ import pandas as pd import os from…
- User
Implement the missing function:
""" import pandas as pd import os
from sklearn.model_selection import train_test_split
""" Evaluate each GCA aspect using LLM as a judge.
First, for each discussion and participant, create a text file in the following
"""
SEED = 30 TEST_PATH = "/home/esther/PycharmProjects/Dialogos/role_discovery/group_discussion_analysis_rep/evalGCA/test_data.csv" DATA_PATH = "/home/esther/PycharmProjects/Dialogos/role_discovery/data"
MODELS = {"GPT4_1": "gpt-4.1-2025-04-14", }
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.
- Assistant
- User
How to extract the score from a response to this prompt?
PARTICIPATION_SYS = """## Role
You are a psychologist specializing in collaborative learning, group interaction dynamics, and computational discourse analysis. Your task is to evaluate the Participation of a given participant within a group discussion.
Definition
Participation reflects the general level of an individual’s engagement in the discussion, irrespective of the content of their contributions. It captures the extent to which the participant actively contributes (e.g., number of turns, volume of words, visible presence in the conversation). High participation suggests active engagement and willingness to share ideas; low participation suggests passivity, withdrawal, or minimal involvement.
- Assistant
Great — since your system prompt explicitly instructs the model to return JSON, you can safely parse the response as JSON and extract the "score". Here’s a snippet that works robustly in main_run_judge: pythonCopy codeimport json
def extract_score(response_text: str): """ Parse model response and extract rationale + score. If parsing fails, fall back to raw text. """ try: # Try to parse JSON data = json.loads(response_text) score = int(data.get("score")) rationale = data.get("rationale", "") return score, rationale except Exception as e: # Fallback: attempt to extract just a digit 1-5 import re m = re.search(r"\b([1-5])\b", response_text) score = int(m.group(1)) if m else None return score, response_text.strip()
Usage inside your LLM call: pythonCopy coderesponse = openai.chat.completions.create( model=MODELS[model], messages=[ {"role": "system", "content": PARTICIPATION_SYS}, {"role": "user", "content": content} ], temperature=0, )
- User
Add progression save, incase the connection is lost
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 - Assistant
- User
Add the funtionality to load history, incase of loosing connention
- Assistant