def _word_candidates(idx: int) -> Sequence[Mapping[str, str]]:
  """Extracts word candidates with a certain probability bucket."""
  factor = _LL_BUCKETS.value / (_MAX_LL.value - _MIN_LL.value)
  candidates = []
  with tf.io.gfile.GFile(_WORDS_PATH.value, 'r') as f:
    for line in f:
      root, score, morph = line.split('\t')
      candidate = dict(p.split(':') for p in morph.strip().split(','))
      if (idx < (float(score) - _MIN_LL.value) * factor <= idx + 1 and
          utils.is_candidate_new(candidate)):
        candidate[utils.ROOT] = root
        candidates.append(candidate)
  # We need enough candidates to build few-shot examples without repeating.
  if len(candidates) < 2 * max(map(int, _SHOTS.value)):
    raise ValueError(f'Only {len(candidates)} candidates in bucket {idx}.')
  logging.info('%d candidates in bucket %d.', len(candidates), idx)
  return candidates
Extracts word candidates with a certain probability bucket.
language/wino_dict/generate.py