class_docstr: Defines end to end MatchLSTM and Answer_Pointer network for Reading Comprehension
class_docstr_tok: ["Defines","end","to","end","MatchLSTM","and","Answer_Pointer","network","for","Reading","Comprehension"]
docstr: Function to calculate F-1 and EM scores
  
  Args:
      ground_truths: labels given in the dataset
      predictions: logits predicted by the network
  
  Returns:
      F1 score and Exact-Match score
docstr_tok: ["Function","to","calculate","F-1","and","EM","scores","Args",":","ground_truths",":","labels","given","in","the","dataset","predictions",":","logits","predicted","by","the","network","Returns",":","F1","score","and","Exact-Match","score"]
code: def cal_f1_score(self, ground_truths, predictions):
      """
      Function to calculate F-1 and EM scores
  
      Args:
          ground_truths: labels given in the dataset
          predictions: logits predicted by the network
  
      Returns:
          F1 score and Exact-Match score
      """
      start_idx, end_idx = self.obtain_indices(
          predictions[0], predictions[1]
      )
      f1 = 0
      exact_match = 0
      for i in range(self.batch_size):
          ele1 = start_idx[i]
          ele2 = end_idx[i]
          preds = np.linspace(ele1, ele2, abs(ele2 - ele1 + 1))
          length_gts = abs(
              ground_truths[i][1] - ground_truths[i][0] + 1
          )
          gts = np.linspace(
              ground_truths[i][0], ground_truths[i][1], length_gts
          )
          common = Counter(preds) & Counter(gts)
          num_same = sum(common.values())
  
          exact_match += int(np.array_equal(preds, gts))
          if num_same == 0:
              f1 += 0
          else:
              precision = 1.0 * num_same / len(preds)
              recall = 1.0 * num_same / len(gts)
              f1 += (2 * precision * recall) / (precision + recall)
  
      return 100 * (f1 / self.batch_size), 100 * (
          exact_match / self.batch_size
      )
  
file_path: nlp-architect/examples/reading_comprehension/match_lstm_mrc/matchlstm_ansptr.py
imports: from __future__ import division
  from __future__ import print_function
  import re
  from collections import Counter
  import numpy
  import tensorflow
  from nlp_architect.utils.text import SpacyInstance
label_desc: Use image node_id 7 for calling the MatchLSTMAnswerPointer obj's underlying member method code with example usage: obj.cal_f1_score(ground_truths, predictions) and returns: unknown,  unknown