def tf_sched(cur_epoch,epochs,final_tf_ratio):
    """
    modified teacher forcing ratio according to epoch counts

    Args:
        cur_epoch: (int) current epoch
        epochs: (int) total epochs
        final_tf_ration: (float) smallest teacher forcing ratio
    
    Returns:
        teacher forcing ratio for current epoch
    """
    thres=int(0.2*epochs)
    if cur_epoch<thres:
        tf_ratio=1
    else:
        tf_ratio=final_tf_ratio+(epochs-cur_epoch)*(1-final_tf_ratio)/(epochs-thres)
    if tf_ratio>1:
        tf_ratio=1
    elif tf_ratio<final_tf_ratio:
        tf_ratio=final_tf_ratio
    return tf_ratio