def index_items(self, items, voc: SimpleVocab, allow_unk: bool): for item in items: item.set_label_idx(voc.get_else_unk(item.label) if allow_unk else voc[item.label])
def index_char_seq(self, seq: InputCharSeqField, voc: SimpleVocab, allow_unk: bool): if seq is not None: seq_idxes = [[voc.get_else_unk(c) for c in z] for z in seq.vals] if allow_unk else [[voc[c] for c in z] for z in seq.vals] seq.set_idxes(seq_idxes)
def index_seq(self, seq: SeqField, voc: SimpleVocab, allow_unk: bool): if seq is not None: seq_idxes = [voc.get_else_unk(z) for z in seq.vals] if allow_unk else [voc[z] for z in seq.vals] seq.set_idxes(seq_idxes)