code: def linear_search_wer(
      dists,
      scores1,
      scores2,
      total_len,
      coef_range=[0, 10],
      coef_steps=10000,
      param_name="parameter",
  ):
      """
      performs linear search to find the best coefficient when two set of scores are getting linearly fused.
  
      Args:
          dists: Tesnor of the distances between the ground truth and the candidates with shape of [number of samples, beam size]
          scores1: Tensor of the first set of scores with shape of [number of samples, beam size]
          scores2: Tensor of the second set of scores with shape of [number of samples, beam size]
          total_len: The total length of all samples
          coef_range: the search range for the coefficient
          coef_steps: the number of steps that the search range would get divided into
          param_name: the name of the parameter to be used in the figure
  
      Output:
          (best coefficient found, best WER achieved)
      """
      scale = scores1.mean().abs().item() / scores2.mean().abs().item()
      left = coef_range[0] * scale
      right = coef_range[1] * scale
      coefs = np.linspace(left, right, coef_steps)
  
      best_wer = 10000
      best_coef = left
      wers = []
      for coef in coefs:
          scores = scores1 + coef * scores2
          wer = compute_wer(dists, scores, total_len)
          wers.append(wer)
          if wer < best_wer:
              best_wer = wer
              best_coef = coef
  
      plt.plot(coefs, wers)
      plt.title(
          f"WER% after rescoring with different values of {param_name}"
      )
      plt.ylabel("WER%")
      plt.xlabel(param_name)
      plt.show()
      return best_coef, best_wer
  
imports: import contextlib
  import inspect
  import json
  from argparse import ArgumentParser
  import editdistance
  import matplotlib.pyplot
  import numpy
  import pandas
  import torch
  import tqdm
  from transformers import AutoModelForCausalLM
  from nemo.collections.nlp.models.language_modeling import TransformerLMModel
  from nemo.collections.nlp.modules.common.tokenizer_utils import get_tokenizer
  from nemo.utils import logging
label_desc: Use image node_id 1 for calling a global function with example usage: linear_search_wer(dists, scores1, scores2, total_len, coef_range, coef_steps, param_name) and returns: best_coef,  best_wer