code: def _build_rare_word_f1(opt: Opt) -> RareWordF1Calculator:
      datapath = _datapath(opt)
  
      def _collect_convo_text(convo_data):
          convo_texts = []
          for conv in convo_data.values():
              # get all messages
              convo_texts.append(
                  " ".join([m["text"] for m in conv["history"]])
              )
          return convo_texts
  
      # use conversation data from all splits for consistency
      convos = []
      convo_files = _all_split_datafiles(opt)
  
      for fname in convo_files:
          with PathManager.open(
              os.path.join(datapath, f"conversations/{fname}")
          ) as f:
              data = json.load(f)
          convos += _collect_convo_text(data)
  
      return RareWordF1Calculator(" ".join(convos), top_p=0.5)
  
imports: import copy
  import json
  import os
  from enum import Enum
  from typing import List, Optional, Tuple
  from parlai.core.message import Message
  from parlai.core.metrics import F1Metric
  from parlai.core.mutators import EpisodeMutator, MessageMutator, register_mutator
  from parlai.core.opt import Opt
  from parlai.core.params import ParlaiParser
  from parlai.core.teachers import DialogTeacher
  from parlai.tasks.cmu_dog.build import build
  from parlai.tasks.wizard_of_wikipedia.agents import RareWordF1Calculator, TOKEN_KNOWLEDGE, TOKEN_END_KNOWLEDGE
  from parlai.utils.data import DatatypeHelper
  from parlai.utils.io import PathManager
  from parlai.utils.logging import logger
  from parlai.utils.typing import TShared
label_desc: Use image node_id 6 for calling a global function with example usage: _build_rare_word_f1(opt) and returns: RareWordF1Calculator, convo_texts