(self, data, set_type)
return examples
Creates examples for the training and dev sets.
Creates examples for the training and dev sets.
Creates examples for the training and dev sets .
def _create_examples(self, data, set_type):
        """Creates examples for the training and dev sets."""
        cache_dir = os.path.join(self.data_dir, set_type + '_examples.pkl')
        if os.path.exists(cache_dir):
            examples = pickle.load(open(cache_dir, 'rb'))
        else:
            examples = []
            for (i, d) in enumerate(data):
                answer = -1
                # 这里data[i]有6个元素，0是context，1是问题，2~5是choice，6是答案
                for k in range(4):
                    if data[i][2 + k] == data[i][6]:
                        answer = str(k)

                label = tokenization.convert_to_unicode(answer)

                for k in range(4):
                    guid = "%s-%s-%s" % (set_type, i, k)
                    text_a = tokenization.convert_to_unicode(data[i][0])
                    text_b = tokenization.convert_to_unicode(data[i][k + 2])
                    text_c = tokenization.convert_to_unicode(data[i][1])
                    examples.append(InputExample(guid=guid, text_a=text_a, text_b=text_b, label=label, text_c=text_c))

            with open(cache_dir, 'wb') as w:
                pickle.dump(examples, w)

        return examples
def _create_examples ( self , data , set_type ) : cache_dir = os . path . join ( self . data_dir , set_type + '_examples.pkl' ) if os . path . exists ( cache_dir ) : examples = pickle . load ( open ( cache_dir , 'rb' ) ) else : examples = [ ] for ( i , d ) in enumerate ( data ) : answer = - 1 # 这里data[i]有6个元素，0是context，1是问题，2~5是choice，6是答案 for k in range ( 4 ) : if data [ i ] [ 2 + k ] == data [ i ] [ 6 ] : answer = str ( k ) label = tokenization . convert_to_unicode ( answer ) for k in range ( 4 ) : guid = "%s-%s-%s" % ( set_type , i , k ) text_a = tokenization . convert_to_unicode ( data [ i ] [ 0 ] ) text_b = tokenization . convert_to_unicode ( data [ i ] [ k + 2 ] ) text_c = tokenization . convert_to_unicode ( data [ i ] [ 1 ] ) examples . append ( InputExample ( guid = guid , text_a = text_a , text_b = text_b , label = label , text_c = text_c ) ) with open ( cache_dir , 'wb' ) as w : pickle . dump ( examples , w ) return examples