def gen_tf(text):
    """
    Given a segmented string, return a dict of tf.
    """
    tokens = text.decode("utf8").split()
    total = len(tokens)
    tf_dict = {}
    for w in tokens:
        tf_dict[w] = tf_dict.get(w, 0.0) + 1.0
    for k in tf_dict:
        tf_dict[k] /= total
    return tf_dict