code: def console_label(
      deduper: dedupe.api.ActiveMatching,
  ) -> None:  # pragma: no cover
      """
      Train a matcher instance (Dedupe, RecordLink, or Gazetteer) from the command line.
      Example
  
      .. code:: python
  
         > deduper = dedupe.Dedupe(variables)
         > deduper.prepare_training(data)
         > dedupe.console_label(deduper)
      """
  
      finished = False
      use_previous = False
      fields = unique(
          var.field for var in deduper.data_model.primary_variables
      )
  
      buffer_len = 1  # Max number of previous operations
      unlabeled: list[RecordDictPair] = []
      labeled: list[LabeledPair] = []
  
      n_match = len(deduper.training_pairs["match"])
      n_distinct = len(deduper.training_pairs["distinct"])
  
      while not finished:
          if use_previous:
              record_pair, label = labeled.pop(0)
              if label == "match":
                  n_match -= 1
              elif label == "distinct":
                  n_distinct -= 1
              use_previous = False
          else:
              try:
                  if not unlabeled:
                      unlabeled = deduper.uncertain_pairs()
  
                  record_pair = unlabeled.pop()
              except IndexError:
                  break
  
          for record in record_pair:
              for field in fields:
                  line = "%s : %s" % (field, record[field])
                  _print(line)
              _print()
          _print(f"{n_match}/10 positive, {n_distinct}/10 negative")
          _print("Do these records refer to the same thing?")
  
          valid_response = False
          user_input = ""
          while not valid_response:
              if labeled:
                  _print(
                      "(y)es / (n)o / (u)nsure / (f)inished / (p)revious"
                  )
                  valid_responses = {"y", "n", "u", "f", "p"}
              else:
                  _print("(y)es / (n)o / (u)nsure / (f)inished")
                  valid_responses = {"y", "n", "u", "f"}
              user_input = input()
              if user_input in valid_responses:
                  valid_response = True
  
          if user_input == "y":
              labeled.insert(0, (record_pair, "match"))
              n_match += 1
          elif user_input == "n":
              labeled.insert(0, (record_pair, "distinct"))
              n_distinct += 1
          elif user_input == "u":
              labeled.insert(0, (record_pair, "unsure"))
          elif user_input == "f":
              _print("Finished labeling")
              finished = True
          elif user_input == "p":
              use_previous = True
              unlabeled.append(record_pair)
  
          while len(labeled) > buffer_len:
              _mark_pair(deduper, labeled.pop())
  
      for labeled_pair in labeled:
          _mark_pair(deduper, labeled_pair)
  
imports: from __future__ import annotations
  import collections
  import itertools
  import random
  import sys
  import warnings
  from typing import Iterator, Tuple, overload
  import numpy
  import dedupe
  from dedupe._typing import DataInt, DataStr, Literal, RecordDict, RecordDictPair, RecordID, TrainingData
  from dedupe.canonical import getCanonicalRep
  from dedupe.core import unique
label_desc: Use image node_id 6 for calling a global function with example usage: console_label(deduper) without return types