Help me implement my code. What is missing? " import pandas as pd import editdistance…
- User
Help me implement my code. What is missing?
" import pandas as pd import editdistance import numpy as np import segeval from dtaidistance import dtw
""" Performs accuracy and F1 score evaluation on the segments of a dataset using DTW and edit distance. TODO - add BF score? For both metrics, small values are better.
"""
PATH2SEGMENTS_V1 = "/home/esther/PycharmProjects/Dialogos/llm_eval/results/gpt/SINGLE_TURN_TO_DUS_V1/du_turn_segmentation_dev.csv" PATH2SEGMENTS_V2 = "/home/esther/PycharmProjects/Dialogos/llm_eval/results/gpt/SINGLE_TURN_TO_DUS_V2/du_turn_segmentation_dev.csv" PATH2SEGMENTS_V3 = "/home/esther/PycharmProjects/Dialogos/llm_eval/results/gpt/SINGLE_TURN_TO_DUS_V3/du_turn_segmentation_dev.csv" GOLD_DATA = "/home/esther/PycharmProjects/Dialogos/processing_data/segmented_dus_with_split.csv"
def convert_segments_to_list_eq_len(turn: str, segmented_turn: pd.Series) -> list: """ Given a turn and its segmented version, return a list of the segmentation boundaries. The length of the list is equal to the number of words in the turn. possible values are: 0: not a boundary, 1: boundary. the index of the list is the index of the word in the turn. :param turn: :param segmented_turn: :return: """ pass
def turn_edit_distance(turn: str, segmented_turn: pd.Series, gold_segmentation: pd.Series) -> int: """ Computes the edit distance between the original turn and the segmented turn. :param gold_segmentation: :param turn: Original turn :param segmented_turn: Segmented version of the turn :return: Edit distance """ # Convert the segmented turn and gold segmentation to lists segmented_turn_list = convert_segments_to_list_eq_len(turn, segmented_turn) gold_segmentation_list = convert_segments_to_list_eq_len(turn, gold_segmentation) # Calculate the edit distance edit_dist = editdistance.eval(segmented_turn_list, gold_segmentation_list) return edit_dist
def turn_dtw_score(turn: str, segmented_turn: pd.Series, gold_segmentation: pd.Series) -> float: """ Computes the DTW score between the original turn and the segmented turn. :return: DTW score """ # Convert the segmented turn and gold segmentation to lists segmented_turn_list = convert_segments_to_list(turn, segmented_turn) gold_segmentation_list = convert_segments_to_list(turn, gold_segmentation) # Calculate the DTW score dtw_score = dtw.distance(segmented_turn_list, gold_segmentation_list) return dtw_score
def convert_segments_to_list(turn: str, segmented_turn: pd.Series) -> list: """ Converts the segmented turn into a list of boundaries. The length of the list is equal to the number of segments-1 (the number of boundaries). Each value in the list is a index in the original turn where a boundary occurs. :param turn: :param segmented_turn: :return: """ pass
def eval_dtw(gold_df: pd.DataFrame, pred_df: pd.DataFrame, turn_col: str, segmented_turn_col: str, gold_segmentation_col: str) -> pd.DataFrame: """ Evaluates the DTW score for each turn in the DataFrame. :param gold_df: DataFrame containing the turns and their segmented versions :param pred_df: DataFrame containing the turns and their segmented versions :param turn_col: Column name for the original turns :param segmented_turn_col: Column name for the segmented turns :param gold_segmentation_col: Column name for the gold segmentation :return: DataFrame with DTW scores """ turns_dtw = [0]*gold_df.turn.nunique() # for each turn, calculate the DTW score between the segmented turn and the gold segmentation
- Assistant