本文整理汇总了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))