docstr: Set the optimal threshold of the model from performance on validation set. This threshold is used to round the 
  logits to 0 or 1. 
  
  Args:
      test_ds: location of test dataset
      file_name: name of input file to retrieve validation set
  
  Returns:
      None
docstr_tok: ["Set","the","optimal","threshold","of","the","model","from","performance","on","validation","set",".","This","threshold","is","used","to","round","the","logits","to","0","or","1",".","Args",":","test_ds",":","location","of","test","dataset","file_name",":","name","of","input","file","to","retrieve","validation","set","Returns",":","None"]
code: def optimize_threshold(
      self, test_ds: DictConfig, file_name: str
  ) -> None:
      """
      Set the optimal threshold of the model from performance on validation set. This threshold is used to round the
      logits to 0 or 1.
  
      Args:
          test_ds: location of test dataset
          file_name: name of input file to retrieve validation set
  
      Returns:
          None
      """
  
      input_file = f"{self.data_dir}/{file_name}.tsv"
  
      with open(input_file, "r") as f:
          input_lines = f.readlines()[1:]  # Skipping headers at index 0
  
      dataset = list(input_lines)
  
      metrics_labels, sentences = [], []
  
      for input_line in dataset:
          sentence = input_line.strip().split("\t")[0]
          sentences.append(sentence)
          parts = input_line.strip().split("\t")[1:][0]
          parts = list(map(int, parts.split(",")))
          parts = [
              1 if label in parts else 0
              for label in range(len(self.cfg.data_desc.intent_labels))
          ]
          metrics_labels.append(parts)
  
      # Retrieve class probabilities for each sentence
      intent_probabilities = self.prediction_probabilities(
          sentences, test_ds
      )
  
      metrics_dict = {}
      # Find optimal logits rounding threshold for intents
      for i in np.arange(0.5, 0.96, 0.01):
          predictions = (intent_probabilities >= i).tolist()
          precision = precision_score(
              metrics_labels, predictions, average="micro"
          )
          recall = recall_score(
              metrics_labels, predictions, average="micro"
          )
          f1 = f1_score(metrics_labels, predictions, average="micro")
          metrics_dict[i] = [precision, recall, f1]
  
      max_precision = max(
          metrics_dict, key=lambda x: metrics_dict[x][0]
      )
      max_recall = max(metrics_dict, key=lambda x: metrics_dict[x][1])
      max_f1_score = max(metrics_dict, key=lambda x: metrics_dict[x][2])
  
      logging.info(
          f"Best Threshold for F1-Score: {max_f1_score}, [Precision, Recall, F1-Score]: {metrics_dict[max_f1_score]}"
      )
      logging.info(
          f"Best Threshold for Precision: {max_precision}, [Precision, Recall, F1-Score]: {metrics_dict[max_precision]}"
      )
      logging.info(
          f"Best Threshold for Recall: {max_recall}, [Precision, Recall, F1-Score]: {metrics_dict[max_recall]}"
      )
  
      if metrics_dict[max_f1_score][2] > self.max_f1:
          self.max_f1 = metrics_dict[max_f1_score][2]
  
          logging.info(f"Setting Threshold to: {max_f1_score}")
  
          self.threshold = max_f1_score
  
imports: import os
  from typing import List, Optional, Tuple
  import numpy
  import numpy.typing
  import torch
  from omegaconf import DictConfig, OmegaConf
  from pytorch_lightning import Trainer
  from sklearn.metrics import f1_score, precision_score, recall_score
  from torch.utils.data import DataLoader
  from nemo.collections.common.losses import AggregatorLoss, BCEWithLogitsLoss, CrossEntropyLoss
  from nemo.collections.nlp.data.intent_slot_classification import MultiLabelIntentSlotClassificationDataset, MultiLabelIntentSlotDataDesc
  from nemo.collections.nlp.metrics.classification_report import ClassificationReport, MultiLabelClassificationReport
  from nemo.collections.nlp.models.intent_slot_classification import IntentSlotClassificationModel
  from nemo.collections.nlp.modules.common import SequenceTokenClassifier
  from nemo.collections.nlp.parts.utils_funcs import tensor2list
  from nemo.core.classes.common import PretrainedModelInfo
  from nemo.utils import logging
label_desc: Use image node_id 7 for calling the MultiLabelIntentSlotClassificationModel obj's underlying member method code with example usage: obj.optimize_threshold(test_ds, file_name) without return types