(jsn, graph_retriever_config)
return examples
Find the mximum size of the initial context (links are not included)
Find the mximum size of the initial context (links are not included)
Find the mximum size of the initial context ( links are not included )
def create_examples(jsn, graph_retriever_config):

    task = graph_retriever_config.task

    examples = []

    '''
    Find the mximum size of the initial context (links are not included)
    '''
    graph_retriever_config.max_context_size = 0

    for data in jsn:

        guid = data['q_id']
        question = data['question']
        context = data['context'] # {context title: paragraph}
        all_linked_paras_dic = {} # {context title: {linked title: paragraph}}

        '''
        Use TagMe-based context at test time.
        '''
        if graph_retriever_config.tagme:
            assert 'tagged_context' in data

            '''
            Reformat "tagged_context" if needed (c.f. the "context" case above)
            '''
            if type(data['tagged_context']) == list:
                tagged_context = {c[0]: c[1] for c in data['tagged_context']}
                data['tagged_context'] = tagged_context

            '''
            Append valid paragraphs from "tagged_context" to "context"
            '''
            for tagged_title in data['tagged_context']:
                tagged_text = data['tagged_context'][tagged_title]
                if tagged_title not in context and tagged_title is not None and tagged_title.strip() != '' and tagged_text is not None and tagged_text.strip() != '':
                    context[tagged_title] = tagged_text

        '''
        Clean "context" by removing invalid paragraphs
        '''
        removed_keys = []
        for title in context:
            if title is None or title.strip() == '' or context[title] is None or context[title].strip() == '':
                removed_keys.append(title)
        for key in removed_keys:
            context.pop(key)

        all_paras = {}
        for title in context:
            all_paras[title] = context[title]

        if graph_retriever_config.expand_links:
            expand_links(context, all_linked_paras_dic, all_paras)
            
        graph_retriever_config.max_context_size = max(graph_retriever_config.max_context_size, len(context))

        examples.append(InputExample(guid = guid,
                                     q = question,
                                     c = context,
                                     para_dic = all_linked_paras_dic,
                                     s_g = None, r_g = None, all_r_g = None,
                                     all_paras = all_paras))

    return examples
def create_examples ( jsn , graph_retriever_config ) : task = graph_retriever_config . task examples = [ ] graph_retriever_config . max_context_size = 0 for data in jsn : guid = data [ 'q_id' ] question = data [ 'question' ] context = data [ 'context' ] # {context title: paragraph} all_linked_paras_dic = { } # {context title: {linked title: paragraph}} '''
        Use TagMe-based context at test time.
        ''' if graph_retriever_config . tagme : assert 'tagged_context' in data '''
            Reformat "tagged_context" if needed (c.f. the "context" case above)
            ''' if type ( data [ 'tagged_context' ] ) == list : tagged_context = { c [ 0 ] : c [ 1 ] for c in data [ 'tagged_context' ] } data [ 'tagged_context' ] = tagged_context '''
            Append valid paragraphs from "tagged_context" to "context"
            ''' for tagged_title in data [ 'tagged_context' ] : tagged_text = data [ 'tagged_context' ] [ tagged_title ] if tagged_title not in context and tagged_title is not None and tagged_title . strip ( ) != '' and tagged_text is not None and tagged_text . strip ( ) != '' : context [ tagged_title ] = tagged_text '''
        Clean "context" by removing invalid paragraphs
        ''' removed_keys = [ ] for title in context : if title is None or title . strip ( ) == '' or context [ title ] is None or context [ title ] . strip ( ) == '' : removed_keys . append ( title ) for key in removed_keys : context . pop ( key ) all_paras = { } for title in context : all_paras [ title ] = context [ title ] if graph_retriever_config . expand_links : expand_links ( context , all_linked_paras_dic , all_paras ) graph_retriever_config . max_context_size = max ( graph_retriever_config . max_context_size , len ( context ) ) examples . append ( InputExample ( guid = guid , q = question , c = context , para_dic = all_linked_paras_dic , s_g = None , r_g = None , all_r_g = None , all_paras = all_paras ) ) return examples