docstr: Score triplets using the trained model.
docstr_tok: ["Score","triplets","using","the","trained","model","."]
code: def _score_triplets(
      self,
      triplets,
      threshold,
      anomalous,
      retain_old_edges,
      return_dataframe,
  ):
      """Score triplets using the trained model."""
  
      log(f"{triplets.shape[0]} triplets for inference")
      ############################################################
      # the bees knees
      scores = self._score(triplets)
      ############################################################
      if len(triplets) > 1:
          if anomalous:
              predicted_links = triplets[scores < threshold]  # type: ignore
              this_score = scores[scores < threshold]  # type: ignore
          else:
              predicted_links = triplets[scores > threshold]  # type: ignore
              this_score = scores[scores > threshold]  # type: ignore
      else:
          predicted_links = triplets
          this_score = scores
  
      predicted_links = pd.DataFrame(
          predicted_links,
          columns=[self._source, self._relation, self._destination],
      )
      predicted_links[self._source] = predicted_links[self._source].map(
          self._id2node
      )
      predicted_links[self._relation] = predicted_links[
          self._relation
      ].map(self._id2relation)
      predicted_links[self._destination] = predicted_links[
          self._destination
      ].map(self._id2node)
  
      predicted_links["score"] = this_score.detach().numpy()
      predicted_links.sort_values(
          by="score", ascending=False, inplace=True
      )
  
      log(
          f"-- {predicted_links.shape[0]} triplets scored at threshold {threshold:.2f}"
      )
  
      if retain_old_edges:
          existing_links = self._edges[
              [self._source, self._relation, self._destination]
          ]
          all_links = pd.concat(
              [existing_links, predicted_links], ignore_index=True
          ).drop_duplicates()
      else:
          all_links = predicted_links
  
      if return_dataframe:
          return all_links
      else:
          g_new = self.nodes(self._nodes, self._node).edges(
              all_links, self._source, self._destination
          )
          return g_new
  
imports: import logging
  import numpy
  import pandas
  from typing import Optional, Union, Callable, List, TYPE_CHECKING, Any, Tuple
  from .PlotterBase import Plottable
  from .compute.ComputeMixin import ComputeMixin
label_desc: Use image node_id 8 for calling the HeterographEmbedModuleMixin obj's underlying member method code with example usage: obj._score_triplets(triplets, threshold, anomalous, retain_old_edges, return_dataframe) and returns: all_links, g_new