Implement this script in Python """ This script evaluates the segmentation performance…
- User
Implement this script in Python
""" This script evaluates the segmentation performance of an LLM on a given dataset. We have gold standard segmentations and we want to compare the LLM's output against these standards. The evaluation includes: 1. Calculate the accuracy of number of Discourse Units (DUs) per dialogue in the LLM's output. 2. Calculate the number of rows with the same values of: DU_id, eTU_id, eTU_type, Text, Turn, Author. 3. Filter the rows that don't have the same Text value as the gold standard. 4. Filter the rows that don't have the same eTU_type as the gold standard. 5. For each Discussion, calculate the fraction of same rows out of the total number of rows in the gold standard. - Save the min value (most challenging discussion) and the max value, (easiest discussion).
"""
- Assistant
- User
How can this be?
pd.merge(gold_df, llm_df, on=common_cols, how="inner") Unnamed: 0_x Discussion_x ... Author_y split 0 2791 DATA_eTU_2018_5_cyberbullying_12 ... EF dev 1 2791 DATA_eTU_2018_5_cyberbullying_12 ... EF dev 2 2791 DATA_eTU_2018_5_cyberbullying_12 ... EF dev 3 2791 DATA_eTU_2018_5_cyberbullying_12 ... EF dev 4 2791 DATA_eTU_2018_5_cyberbullying_12 ... EF dev ... ... ... ... ... ... 112058 5976 s_Story_8 ... OK dev 112059 5976 s_Story_8 ... OK dev 112060 5976 s_Story_8 ... OK dev 112061 5976 s_Story_8 ... OK dev 112062 5976 s_Story_8 ... OK dev [112063 rows x 27 columns] llm_df.shape[0] 492 gold_df.shape[0] 633
- Assistant
Great observation — you're pointing out a very suspicious result. You merged gold_df and llm_df using: pythonCopyEditpd.merge(gold_df, llm_df, on=common_cols, how="inner")
And somehow ended up with 112,063 rows when the original DataFrames only had:
gold_df: 633 rows
llm_df: 492 rows
That should not be possible if the merge is working as expected. Here's what's almost certainly happening:
🔍 Problem: Merge is not truly on unique rows The merge is likely producing a Cartesian product within subsets of matching rows — that is, multiple rows in gold_df and llm_df share the same values on all columns in common_cols, so they multiply out when merged. For example, if: