docstr: Computing the mean distance per layer between span tokens for target/pred == 1 and target/pred == 0.
docstr_tok: ["Computing","the","mean","distance","per","layer","between","span","tokens","for","target\/pred","==","1","and","target\/pred","==","0","."]
code: def get_dist_per_layer(
      self,
      option: str,
      model_selector_val: str,
      selected_sentences: pd.DataFrame,
  ) -> Tuple[np.array, np.array]:
      """Computing the mean distance per layer between span tokens for target/pred == 1 and target/pred == 0."""
      # Getting example rows and sentence rows (minus example rows) in df
      curr_model_full_df = self.map_model_to_full_df[
          self.map_model_name_to_id[model_selector_val]
      ]
      selected_sentence_rows = curr_model_full_df.loc[
          curr_model_full_df["sentence_idx"].isin(selected_sentences)
      ]
      all_ex_ids = selected_sentence_rows["id"].unique()
  
      span_agg_distance_0 = np.zeros(self.num_layers + 1)
      span_agg_distance_1 = np.zeros(self.num_layers + 1)
      count_0 = 0
      count_1 = 0
  
      for ex_id in all_ex_ids:
          ex_rows = selected_sentence_rows[
              selected_sentence_rows["id"] == ex_id
          ]
          span1 = ex_rows["span1"].iloc[0]
          span2 = ex_rows["span2"].iloc[0]
          span1_rows = ex_rows[ex_rows["span"] == span1]
          span2_rows = ex_rows[ex_rows["span"] == span2]
          span1_coords = [
              np.array(
                  (
                      span1_rows[f"layer_{layer:02}_tsne_x"].mean(),
                      span1_rows[f"layer_{layer:02}_tsne_y"].mean(),
                  )
              )
              for layer in range(self.num_layers + 1)
          ]
          span2_coords = [
              np.array(
                  (
                      span2_rows[f"layer_{layer:02}_tsne_x"].mean(),
                      span1_rows[f"layer_{layer:02}_tsne_y"].mean(),
                  )
              )
              for layer in range(self.num_layers + 1)
          ]
  
          dist_per_layer = np.array(
              [
                  np.linalg.norm(span1_coord - span2_coord)
                  for span1_coord, span2_coord in zip(
                      span1_coords, span2_coords
                  )
              ]
          )
  
          if ex_rows[option].iloc[0] == 1:
              span_agg_distance_1 += dist_per_layer
              count_1 += 1
          else:
              span_agg_distance_0 += dist_per_layer
              count_0 += 1
  
      # Averaging by number of examples
      span_mean_distance_0 = span_agg_distance_0 / count_0
      span_mean_distance_1 = span_agg_distance_1 / count_1
      return span_mean_distance_0, span_mean_distance_1
  
imports: from typing import List, Tuple, Dict, Union
  from abc import ABC, abstractmethod
  import torch
  import pandas
  import numpy
label_desc: Use image node_id 10 for calling the WSCTask obj's underlying member method code with example usage: obj.get_dist_per_layer(option, model_selector_val, selected_sentences) and returns: span_mean_distance_0,  span_mean_distance_1