本文整理匯總了Python中torchtext.data.interleave_keys方法的典型用法代碼示例。如果您正苦於以下問題:Python data.interleave_keys方法的具體用法?Python data.interleave_keys怎麽用?Python data.interleave_keys使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類torchtext.data
的用法示例。
在下文中一共展示了data.interleave_keys方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from torchtext import data [as 別名]
# 或者: from torchtext.data import interleave_keys [as 別名]
def __init__(self, args):
self.RAW = data.RawField()
self.RAW.is_target = False
tokenize = lambda x: list(x)
self.TEXT = data.Field(batch_first=True, tokenize=tokenize)
self.LABEL = data.Field(sequential=False, unk_token=None)
self.train, self.dev, self.test = data.TabularDataset.splits(
path='/data/nfsdata/nlp/datasets/sentence_pair/bq_corpus_torch10',
train='BQ_train.json',
validation='BQ_dev.json',
test='BQ_test.json',
format='json',
fields={"gold_label": ("label", self.LABEL),
"sentence1": ("q1", self.TEXT),
"sentence2": ("q2", self.TEXT),
"ID": ("id", self.RAW)})
self.TEXT.build_vocab(self.train, self.dev, self.test, vectors=Vectors("BQ300", args.data))
self.LABEL.build_vocab(self.train)
sort_key = lambda x: data.interleave_keys(len(x.q1), len(x.q2))
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
self.train_iter = data.BucketIterator(self.train, batch_size=args.batch_size, device=device, sort_key=sort_key, sort=True)
self.dev_iter = data.BucketIterator(self.dev, batch_size=args.batch_size, device=device, sort_key=sort_key, sort=True)
self.test_iter = data.BucketIterator(self.test, batch_size=args.batch_size, device=device, sort_key=sort_key, sort=True)
示例2: sort_key
# 需要導入模塊: from torchtext import data [as 別名]
# 或者: from torchtext.data import interleave_keys [as 別名]
def sort_key(ex):
# don't work for pack_padded_sequences
# return data.interleave_keys(len(ex.source), len(ex.target))
return len(ex.source)
示例3: sort_key
# 需要導入模塊: from torchtext import data [as 別名]
# 或者: from torchtext.data import interleave_keys [as 別名]
def sort_key(ex):
return data.interleave_keys(len(ex.src), len(ex.trg))
示例4: sort_key
# 需要導入模塊: from torchtext import data [as 別名]
# 或者: from torchtext.data import interleave_keys [as 別名]
def sort_key(ex):
return data.interleave_keys(
len(ex.premise), len(ex.hypothesis))
示例5: sort_key
# 需要導入模塊: from torchtext import data [as 別名]
# 或者: from torchtext.data import interleave_keys [as 別名]
def sort_key(ex):
return interleave_keys(
len(ex.sentence_a), len(ex.sentence_b))