code: def compute_embedding_scores(
      self,
      hypo: Chain,
      context: Chain,
      reference: Optional[Chain],
      score_types: List[str],
      scores: Dict[str, List],
  ) -> Dict[str, List]:
      h_steps_embeddings = hypo.sentence_embeddings
      c_steps_embeddings = context.sentence_embeddings
      h_whole_chain_embedding = hypo.whole_chain_embedding
      c_whole_chain_embedding = context.whole_chain_embedding
      # Sentence Embedding Matching between context and hypos
      y_x_sent_emb = embedding_alignment(
          ref_emb=c_steps_embeddings, hypo_emb=h_steps_embeddings
      )
      x_y_sent_emb = embedding_alignment(
          ref_emb=h_steps_embeddings, hypo_emb=c_steps_embeddings
      )
  
      if FAITHFUL_SENT in score_types:
          scores[FAITHFUL_SENT].append(al_mean(y_x_sent_emb))
      if INFORM_STEP in score_types:
          scores[INFORM_STEP].append(
              (al_mean(y_x_sent_emb) + al_mean(x_y_sent_emb)) / 2.0
          )
      if INFORM_CHAIN in score_types:
          scores[INFORM_CHAIN].append(
              (
                  1.0
                  + cosine_similarity_scaled(
                      h_whole_chain_embedding, c_whole_chain_embedding
                  )
              )
              / 2.0
          )
      if self.word_model_name:
          h_word_embeddings = self.embed_words(hypo.chain)
          c_word_embeddings = self.embed_words(context.chain)
          if FAITHFUL_WORD in score_types:
              scores[FAITHFUL_WORD].append(
                  al_mean(
                      np.append(
                          y_x_sent_emb,
                          embedding_alignment(
                              ref_emb=self.linearize_array(
                                  c_word_embeddings
                              ),
                              hypo_emb=self.linearize_array(
                                  h_word_embeddings
                              ),
                          ),
                      )
                  )
              )
          if REPETITION_WORD in score_types:
              # requires at least 2 sentences
              if len(h_word_embeddings) > 1:
                  scores[REPETITION_WORD].append(
                      1 - self.repetitions(h_word_embeddings)
                  )
              # otherwise give perfect score
              else:
                  scores[REPETITION_WORD].append(1.0)
      if REPETITION_SENT in score_types and self.word_model_name:
          # requires at least 2 sentences
          if len(h_steps_embeddings) > 1:
              scores[REPETITION_SENT].append(
                  (1.0 - self.repetitions(h_steps_embeddings)) / 2.0
              )
          # otherwise give perfect score
          else:
              scores[REPETITION_SENT].append(1.0)
  
      if reference and any(s in SUPERVISED_SCORES for s in score_types):
          r_steps_embeddings = reference.sentence_embeddings
          r_whole_chain_embedding = reference.whole_chain_embedding
          # Sentence Embedding Matching between references and hypos
          y_r_sent_emb = embedding_alignment(
              ref_emb=r_steps_embeddings, hypo_emb=h_steps_embeddings
          )
          r_y_sent_emb = embedding_alignment(
              ref_emb=h_steps_embeddings, hypo_emb=r_steps_embeddings
          )
          r_x_sent_emb = embedding_alignment(
              ref_emb=c_steps_embeddings, hypo_emb=r_steps_embeddings
          )
          if CHAIN_ALIGNMENT in score_types:
              scores[CHAIN_ALIGNMENT].append(al_mean(y_r_sent_emb))
          if EXT_HALLUCINATION in score_types:
              scores[EXT_HALLUCINATION].append(
                  1
                  - max(
                      np.multiply(
                          [1 - x for x in y_r_sent_emb],
                          [1 - x for x in y_x_sent_emb],
                      )
                  )
              )
          if REDUNDANCY in score_types:
              scores[REDUNDANCY].append(min(y_r_sent_emb))
          if COMMON_SENSE_ERROR in score_types:
              scores[COMMON_SENSE_ERROR].append(
                  1
                  - max(
                      np.multiply(
                          [1 - x for x in r_y_sent_emb],
                          [1 - x for x in r_x_sent_emb],
                      )
                  )
              )
          if MISSING_STEP in score_types:
              scores[MISSING_STEP].append(min(r_y_sent_emb))
          if SEMANTIC_COVERAGE_STEP in score_types:
              scores[SEMANTIC_COVERAGE_STEP].append(
                  1 - abs(al_mean(r_x_sent_emb) - al_mean(y_x_sent_emb))
              )
          if SEMANTIC_COVERAGE_CHAIN in score_types:
              scores[SEMANTIC_COVERAGE_CHAIN].append(
                  (
                      1.0
                      + cosine_similarity_scaled(
                          h_whole_chain_embedding,
                          r_whole_chain_embedding,
                      )
                  )
                  / 2.0
              )
  
      return scores
  
imports: from collections import defaultdict
  import itertools
  import math
  import numpy
  from typing import Any, Dict, Iterable, List, Optional, Tuple, Union
  import torch
  from torch import nn
  from tqdm import tqdm
  from projects.roscoe.utils import cosine_similarity_scaled, embedding_alignment, al_mean
label_desc: Use image node_id 26 for calling the Evaluator obj's underlying member method code with example usage: obj.compute_embedding_scores(hypo, context, reference, score_types, scores) and returns: scores