class_docstr: Defines the top-level RAITextInsights API.
  
  Use RAITextInsights to assess text machine learning models in a
  single API.
class_docstr_tok: ["Defines","the","top-level","RAITextInsights","API",".","Use","RAITextInsights","to","assess","text","machine","learning","models","in","a","single","API","."]
code: def compute_f1(self, prediction, truth):
      pred_tokens = self.normalize_text(prediction).split()
      truth_tokens = self.normalize_text(truth).split()
  
      # if either the prediction or the truth is no-answer
      # then f1 = 1 if they agree, 0 otherwise
      if len(pred_tokens) == 0 or len(truth_tokens) == 0:
          return int(pred_tokens == truth_tokens)
  
      common_tokens = set(pred_tokens) & set(truth_tokens)
  
      # if there are no common tokens then f1 = 0
      if len(common_tokens) == 0:
          return 0
  
      prec = len(common_tokens) / len(pred_tokens)
      rec = len(common_tokens) / len(truth_tokens)
  
      return 2 * (prec * rec) / (prec + rec)
  
imports: import json
  import logging
  import pickle
  import warnings
  from enum import Enum
  from pathlib import Path
  from typing import Any, List, Optional, Union
  import numpy
  import pandas
  from ml_wrappers import wrap_model
  from erroranalysis._internal.cohort_filter import FilterDataWithCohortFilters
  from raiutils.data_processing import convert_to_list, serialize_json_safe
  from raiutils.models import SKLearn, is_classifier
  from responsibleai._interfaces import Dataset, RAIInsightsData
  from responsibleai._internal.constants import ManagerNames, Metadata, SerializationAttributes
  from responsibleai.exceptions import UserConfigValidationException
  from responsibleai.feature_metadata import FeatureMetadata
  from responsibleai.rai_insights.rai_base_insights import RAIBaseInsights
  from responsibleai_text.common.constants import ModelTask
  from responsibleai_text.managers.error_analysis_manager import ErrorAnalysisManager
  from responsibleai_text.managers.explainer_manager import ExplainerManager
  from responsibleai_text.utils.feature_extractors import extract_features, get_text_columns
label_desc: Use image node_id 24 for calling the RAITextInsights obj's underlying member method code with example usage: obj.compute_f1(prediction, truth) and returns: unknown, int, int