code: def learn_binary_search(word_counts, lower, upper, params):
      """Performs binary search to find wordcount frequency threshold.
  
      Given upper and lower bounds and a list of (word, count) tuples, performs
      binary search to find the threshold closest to producing a vocabulary
      of size vocab_size.
  
      Args:
        word_counts: list of (string, int) tuples
        lower: int, lower bound for binary search
        upper: int, upper bound for binary search
        params: Params namedtuple, parameters for learning
  
      Returns:
        list of strings, vocab that is closest to target vocab_size
      """
      thresh = (upper + lower) // 2
      current_vocab = learn_with_thresh(word_counts, thresh, params)
      current_vocab_size = len(current_vocab)
  
      # Allow count to be within k% of the target count, where k is slack ratio.
      slack_count = params.slack_ratio * params.vocab_size
      if slack_count < 0:
          slack_count = 0
  
      is_within_slack = (current_vocab_size <= params.vocab_size) and (
          params.vocab_size - current_vocab_size <= slack_count
      )
  
      # We've created a vocab within our goal range (or, ran out of search space).
      if is_within_slack or lower >= upper or thresh <= 1:
          return current_vocab
  
      current_vocab = None
  
      if current_vocab_size > params.vocab_size:
          return learn_binary_search(
              word_counts, thresh + 1, upper, params
          )
  
      else:
          return learn_binary_search(
              word_counts, lower, thresh - 1, params
          )
  
file_path: text/tensorflow_text/tools/wordpiece_vocab/wordpiece_tokenizer_learner_lib.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import collections
  from typing import List, Optional
  import numpy
label_desc: Use image node_id 10 for calling a global function with example usage: learn_binary_search(word_counts, lower, upper, params) and returns: current_vocab, learn_binary_search, learn_binary_search