def get_shortest_path(kb, topic_ent, answers, num_hop):
  """Get all shortest path from topic entity to answers.

  Args:
    kb: dictionary to store the KB {subject: {relation: objects}}
    topic_ent: topic entity
    answers: a set of answers
    num_hop: max number of hops

  Returns:
    a list of shortest paths
  """
  cur_ents = set([(topic_ent, ())])
  candidate_chains = set()
  for _ in range(num_hop):
    next_ents = set()
    for ent, prev_path in cur_ents:
      prev_path = list(prev_path)
      if ent in kb:
        for rel, objs in kb[ent].items():
          if objs & answers:
            candidate_chains.add(tuple(prev_path + [rel]))
          next_ents.update([(obj, tuple(prev_path + [rel])) for obj in objs])
    cur_ents = next_ents

  return [list(chain) for chain in candidate_chains]