code: def _evaluate_model(
      test_fpath: pathlib.Path,
      lang_identifier: textacy.lang_id.LangIdentifier,
  ) -> str:
      logging.info(
          "evaluating model on test data at %s ...", test_fpath
      )
      with test_fpath.open("r") as f:
          lines = (line.strip() for line in f)
          label_texts = (line.split(" ", maxsplit=1) for line in lines)
          labels, texts = tuple(zip(*label_texts))
  
      # using fasttext's underlying "multiline predict" should be faster than our python
      # pred_labels = tuple(lang_identifier.identify_lang(text) for text in texts)
      pred_labels, _ = lang_identifier.model.predict(list(texts), k=1)
  
      report = sklearn.metrics.classification_report(
          [lang_identifier._to_lang(label) for label in labels],
          [
              lang_identifier._to_lang(pred_label[0])
              for pred_label in pred_labels
          ],
      )
      assert isinstance(report, str)  # type guard
      return report
  
file_path: textacy/scripts/train_lang_identifier_v3.py
imports: from __future__ import annotations
  import argparse
  import logging
  import pathlib
  import floret
  import sklearn.metrics
  import textacy
  import textacy.lang_id
label_desc: Use image node_id 3 for calling a global function with example usage: _evaluate_model(test_fpath, lang_identifier) and returns: report