docstr: Calculate generation metrics
docstr_tok: ["Calculate","generation","metrics"]
code: def calculate_generation_metrics(
      self,
      df: pd.DataFrame,
      generated_answer_embeddings,
      reference_answer_embeddings,
      prefix="generator_",
  ):
      """Calculate generation metrics"""
  
      for metric in self.generator_metrics:
          col_name = f"{prefix}{metric}"
          if metric == "cosine_similarity":
              df[col_name] = self.calculate_cosine_similarities(
                  generated_answer_embeddings,
                  reference_answer_embeddings,
              )
          elif metric == "accuracy":
              col_name = f"{prefix}match"
              df[col_name] = self.get_matches(
                  gt_embeddings=reference_answer_embeddings,
                  test_embeddings=generated_answer_embeddings,
                  threshold=self.args.generator_match_threshold,
              )
          elif metric == "rouge":
              df[col_name] = df.apply(
                  lambda x: self.metric_map[metric](
                      x["generated_answers"], x["reference_answers"]
                  ),
                  axis=1,
              )
              self.extract_rogue_scores(df, rogue_scores_col=col_name)
          elif metric == "bleu":
              df[col_name] = df.apply(
                  lambda x: self.metric_map[metric](
                      x["tokenized_generated_answers"],
                      x["tokenized_reference_answers"],
                  ),
                  axis=1,
              )
          elif metric == "meteor":
              df[col_name] = df.apply(
                  lambda x: self.calculate_meteor(
                      x["tokenized_generated_answers"],
                      x["tokenized_reference_answers"],
                  ),
                  axis=1,
              )
          else:
              raise ValueError(f"metric {metric} not supported")
  
          if metric != "rouge":
              self.store_mean_metric(
                  col_name=col_name, mean_metric=df[col_name].mean()
              )
  
      return df
  
imports: import ast
  from collections import defaultdict
  from typing import List
  import nltk
  import pandas
  from nltk import word_tokenize
  from nltk.translate.bleu_score import sentence_bleu
  from nltk.translate.meteor_score import meteor_score
  from rouge_score import rouge_scorer
  from scipy.spatial import distance
  from mindsdb.integrations.handlers.writer_handler.settings import WriterHandlerParameters
  from mindsdb.utilities import log
label_desc: Use image node_id 3 for calling the WriterEvaluator obj's underlying member method code with example usage: obj.calculate_generation_metrics(df, generated_answer_embeddings, reference_answer_embeddings, prefix) and returns: df