code: def performance_measure(y_true, y_pred):
      """
      Compute the performance metrics: TP, FP, FN, TN
  
      Args:
          y_true : 2d array. Ground truth (correct) target values.
          y_pred : 2d array. Estimated targets as returned by a tagger.
  
      Returns:
          performance_dict : dict
  
      Example:
          >>> from seqeval.metrics import performance_measure
          >>> y_true = [['O', 'O', 'O', 'B-MISC', 'I-MISC', 'O', 'B-ORG'], ['B-PER', 'I-PER', 'O', 'B-PER']]
          >>> y_pred = [['O', 'O', 'B-MISC', 'I-MISC', 'I-MISC', 'O', 'O'], ['B-PER', 'I-PER', 'O', 'B-MISC']]
          >>> performance_measure(y_true, y_pred)
          {'TP': 3, 'FP': 3, 'FN': 1, 'TN': 4}
      """
      performance_dict = dict()
      if any(isinstance(s, list) for s in y_true):
          y_true = [item for sublist in y_true for item in sublist]
          y_pred = [item for sublist in y_pred for item in sublist]
      performance_dict["TP"] = sum(
          y_t == y_p
          for y_t, y_p in zip(y_true, y_pred)
          if ((y_t != "O") or (y_p != "O"))
      )
      performance_dict["FP"] = sum(
          ((y_t != y_p) and (y_p != "O"))
          for y_t, y_p in zip(y_true, y_pred)
      )
      performance_dict["FN"] = sum(
          ((y_t != "O") and (y_p == "O"))
          for y_t, y_p in zip(y_true, y_pred)
      )
      performance_dict["TN"] = sum(
          (y_t == y_p == "O") for y_t, y_p in zip(y_true, y_pred)
      )
  
      return performance_dict
  
file_path: ktrain/ktrain/text/ner/metrics.py
imports: from __future__ import absolute_import, division, print_function
  import warnings
  from collections import defaultdict
  import numpy
label_desc: Use image node_id 8 for calling a global function with example usage: performance_measure(y_true, y_pred) and returns: performance_dict