def __init__(self, input_file, n_bkts, vocab):
self.vocab = vocab<EOL>sents = []<EOL>sent = [[ParserVocabulary.ROOT, ParserVocabulary.ROOT, <NUM_LIT:0>, ParserVocabulary.ROOT]]<EOL>with open(input_file) as f:<EOL><INDENT>for line in f:<EOL><INDENT>info = line.strip().split()<EOL>if info:<EOL><INDENT>arc_offset = <NUM_LIT:5><EOL>rel_offset = <NUM_LIT:6><EOL>if len(info) == <NUM_LIT:10>:<EOL><INDENT>arc_offset = <NUM_LIT:6><EOL>rel_offset = <NUM_LIT:7><EOL><DEDENT>assert info[rel_offset] in vocab._rel2id, '<STR_LIT>' % line<EOL>word, tag, head, rel = vocab.word2id(info[<NUM_LIT:1>].lower()), vocab.tag2id(info[<NUM_LIT:3>]), int(<EOL>info[arc_offset]), vocab.rel2id(info[rel_offset])<EOL>sent.append([word, tag, head, rel])<EOL><DEDENT>else:<EOL><INDENT>sents.append(sent)<EOL>sent = [[ParserVocabulary.ROOT, ParserVocabulary.ROOT, <NUM_LIT:0>, ParserVocabulary.ROOT]]<EOL><DEDENT><DEDENT>if len(sent) > <NUM_LIT:1>:  <EOL><INDENT>sents.append(sent)<EOL><DEDENT><DEDENT>self.samples = len(sents)<EOL>len_counter = Counter()<EOL>for sent in sents:<EOL><INDENT>len_counter[len(sent)] += <NUM_LIT:1><EOL><DEDENT>self._bucket_lengths = KMeans(n_bkts, len_counter).splits<EOL>self._buckets = [[] for i in range(n_bkts)]<EOL>"""<STR_LIT>"""<EOL>len2bkt = {}<EOL>prev_length = -<NUM_LIT:1><EOL>for bkt_idx, length in enumerate(self._bucket_lengths):<EOL><INDENT>len2bkt.update(list(zip(list(range(prev_length + <NUM_LIT:1>, length + <NUM_LIT:1>)), [bkt_idx] * (length - prev_length))))<EOL>prev_length = length<EOL><DEDENT>self._record = []<EOL>for sent in sents:<EOL><INDENT>bkt_idx = len2bkt[len(sent)]<EOL>idx = len(self._buckets[bkt_idx])<EOL>self._buckets[bkt_idx].append(sent)<EOL>self._record.append((bkt_idx, idx))<EOL><DEDENT>for bkt_idx, (bucket, length) in enumerate(zip(self._buckets, self._bucket_lengths)):<EOL><INDENT>self._buckets[bkt_idx] = np.zeros((length, len(bucket), <NUM_LIT:4>), dtype=np.int32)<EOL>for idx, sent in enumerate(bucket):<EOL><INDENT>self._buckets[bkt_idx][:len(sent), idx, :] = np.array(sent, dtype=np.int32)<EOL><DEDENT><DEDENT>
Create a data loader for a data set

        Parameters
        ----------
        input_file : str
            path to CoNLL file
        n_bkts : int
            number of buckets
        vocab : ParserVocabulary
            vocabulary object