def filter_example(config, example, mode="train"):
    """
    Whether filter a given example according to configure.
    :param config: config contains parameters for filtering example
    :param example: an example instance
    :param mode: "train" or "test", they differs in filter restrictions
    :return: boolean
    """
    if mode == "train":
        return (len(example["ans_sent_tokens"]) > config.sent_limit or
                len(example["ques_tokens"]) > config.ques_limit or
                (example["y2_in_sent"] - example["y1_in_sent"]) >
                config.ans_limit)
    elif mode == "test":
        return (len(example["ans_sent_tokens"]) > config.sent_limit or
                len(example["ques_tokens"]) > config.ques_limit)
    else:
        print("mode must be train or test")