code: def f1_score(
      y_true: List[List[str]],
      y_pred: List[List[str]],
      suffix: bool = False,
  ) -> float:
      """Compute the F1 score.
      The F1 score can be interpreted as a weighted average of the precision and
      recall, where an F1 score reaches its best value at 1 and worst score at 0.
      The relative contribution of precision and recall to the F1 score are
      equal. The formula for the F1 score is::
          F1 = 2 * (precision * recall) / (precision + recall)
      Args:
          y_true: 2d array. Ground truth (correct) target values.
          y_pred: 2d array. Estimated targets as returned by a tagger.
          suffix:
      Returns:
          score : float.
      Example:
          >>> from kashgari.metrics.sequence_labeling import f1_score
          >>> y_true = [['O', 'O', 'O', 'B-MISC', 'I-MISC', 'I-MISC', 'O'], ['B-PER', 'I-PER', 'O']]
          >>> y_pred = [['O', 'O', 'B-MISC', 'I-MISC', 'I-MISC', 'I-MISC', 'O'], ['B-PER', 'I-PER', 'O']]
          >>> f1_score(y_true, y_pred)
          0.50
      """
      true_entities = set(bulk_get_entities(y_true, suffix=suffix))
      pred_entities = set(bulk_get_entities(y_pred, suffix=suffix))
  
      nb_correct = len(true_entities & pred_entities)
      nb_pred = len(pred_entities)
      nb_true = len(true_entities)
  
      p = nb_correct / nb_pred if nb_pred > 0 else 0
      r = nb_correct / nb_true if nb_true > 0 else 0
      score = 2 * p * r / (p + r) if p + r > 0 else 0
  
      return score
  
file_path: Kashgari/kashgari/metrics/sequence_labeling.py
imports: from collections import defaultdict
  from typing import List, Dict, Tuple, Any
  import numpy
label_desc: Use image node_id 5 for calling a global function with example usage: f1_score(y_true, y_pred, suffix) and returns: score