(input_graphs, s, qa_model, min_score, beam_size=10, verify_with_wikidata=True)
return all_chosen_graphs
:param input_graphs: a list of equivalent graph extensions to choose from.
    :param s: sentence
    :param qa_model: a model to evaluate graphs
    :param min_score: filter out graphs that receive a score lower than that from the model.
    :param beam_size: size of the beam
    :return: a list of selected graphs with size = beam_size
def ground_with_model(input_graphs, s, qa_model, min_score, beam_size=10, verify_with_wikidata=True):
    """

    :param input_graphs: a list of equivalent graph extensions to choose from.
    :param s: sentence
    :param qa_model: a model to evaluate graphs
    :param min_score: filter out graphs that receive a score lower than that from the model.
    :param beam_size: size of the beam
    :return: a list of selected graphs with size = beam_size
    """

    logger.debug("Input graphs: {}".format(len(input_graphs)))
    logger.debug("First input one: {}".format(input_graphs[:1]))

    grounded_graphs = [apply_grounding(s_g, p) for s_g in input_graphs for p in graph_queries.get_graph_groundings(s_g, use_wikidata=verify_with_wikidata)]
    grounded_graphs = filter_second_hops(grounded_graphs)
    logger.debug("Number of possible groundings: {}".format(len(grounded_graphs)))
    if len(grounded_graphs) == 0:
        return []

    sentences = []
    for i in range(0, len(grounded_graphs), V.MAX_NEGATIVE_GRAPHS):
        dummy_sentence = sentence.Sentence()
        dummy_sentence.__dict__.update(s.__dict__)
        dummy_sentence.graphs = [WithScore(s_g, (0.0, 0.0, min_score)) for s_g in grounded_graphs[i:i+V.MAX_NEGATIVE_GRAPHS]]
        sentences.append(dummy_sentence)
    if len(sentences) == 0:
        return []
    samples = V.encode_for_model(sentences, qa_model._model.__class__.__name__)
    model_scores = qa_model.predict_batchwise(*samples).view(-1).data

    logger.debug("model_scores: {}".format(model_scores))
    all_chosen_graphs = [WithScore(grounded_graphs[i], (0.0, 0.0, model_scores[i]))
                         for i in range(len(grounded_graphs)) if model_scores[i] > min_score]

    all_chosen_graphs = sorted(all_chosen_graphs, key=lambda x: x[1], reverse=True)
    if len(all_chosen_graphs) > beam_size:
        all_chosen_graphs = all_chosen_graphs[:beam_size]
    logger.debug("Number of chosen groundings: {}".format(len(all_chosen_graphs)))
    return all_chosen_graphs
def ground_with_model ( input_graphs , s , qa_model , min_score , beam_size = 10 , verify_with_wikidata = True ) : logger . debug ( "Input graphs: {}" . format ( len ( input_graphs ) ) ) logger . debug ( "First input one: {}" . format ( input_graphs [ : 1 ] ) ) grounded_graphs = [ apply_grounding ( s_g , p ) for s_g in input_graphs for p in graph_queries . get_graph_groundings ( s_g , use_wikidata = verify_with_wikidata ) ] grounded_graphs = filter_second_hops ( grounded_graphs ) logger . debug ( "Number of possible groundings: {}" . format ( len ( grounded_graphs ) ) ) if len ( grounded_graphs ) == 0 : return [ ] sentences = [ ] for i in range ( 0 , len ( grounded_graphs ) , V . MAX_NEGATIVE_GRAPHS ) : dummy_sentence = sentence . Sentence ( ) dummy_sentence . __dict__ . update ( s . __dict__ ) dummy_sentence . graphs = [ WithScore ( s_g , ( 0.0 , 0.0 , min_score ) ) for s_g in grounded_graphs [ i : i + V . MAX_NEGATIVE_GRAPHS ] ] sentences . append ( dummy_sentence ) if len ( sentences ) == 0 : return [ ] samples = V . encode_for_model ( sentences , qa_model . _model . __class__ . __name__ ) model_scores = qa_model . predict_batchwise ( * samples ) . view ( - 1 ) . data logger . debug ( "model_scores: {}" . format ( model_scores ) ) all_chosen_graphs = [ WithScore ( grounded_graphs [ i ] , ( 0.0 , 0.0 , model_scores [ i ] ) ) for i in range ( len ( grounded_graphs ) ) if model_scores [ i ] > min_score ] all_chosen_graphs = sorted ( all_chosen_graphs , key = lambda x : x [ 1 ] , reverse = True ) if len ( all_chosen_graphs ) > beam_size : all_chosen_graphs = all_chosen_graphs [ : beam_size ] logger . debug ( "Number of chosen groundings: {}" . format ( len ( all_chosen_graphs ) ) ) return all_chosen_graphs