def score_fn(rule, span_begin, span_end):
    """Returns scalar score for anchored rule application."""
    application_span_begin = token_start_wp_idx[span_begin]
    # Need to convert between token index used by QCFG rules,
    # and wordpiece indexes used by neural model.
    # token_end_wp_idx is an *inclusive* idx.
    # span_end is an *exclusive* idx.
    # application_span_end is an *inclusive* idx.
    application_span_end = token_end_wp_idx[span_end - 1]
    application_rule_idx = rule_key_to_idx_map[rule]
    application_score = model.application_score_layer.score_application(
        wordpiece_encodings, application_span_begin, application_span_end,
        application_rule_idx)
    return application_score.numpy()
Returns scalar score for anchored rule application.
language/compgen/nqg/model/parser/inference/inference_wrapper.py