本文整理汇总了Python中data.narrow方法的典型用法代码示例。如果您正苦于以下问题:Python data.narrow方法的具体用法?Python data.narrow怎么用?Python data.narrow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类data
的用法示例。
在下文中一共展示了data.narrow方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: batchify
# 需要导入模块: import data [as 别名]
# 或者: from data import narrow [as 别名]
def batchify(data, bsz):
# Work out how cleanly we can divide the dataset into bsz parts.
if isinstance(data, tuple):
nbatch = data[0].size(0) // bsz
# Trim off any extra elements that wouldn't cleanly fit (remainders).
tag_data = data[1].narrow(0, 0, nbatch * bsz)
data = data[0].narrow(0, 0, nbatch * bsz)
# Evenly divide the data across the bsz batches.
tag_data = tag_data.view(bsz, -1).t().contiguous()
else:
nbatch = data.size(0) // bsz
# Trim off any extra elements that wouldn't cleanly fit (remainders).
data = data.narrow(0, 0, nbatch * bsz)
# Evenly divide the data across the bsz batches.
data = data.view(bsz, -1).t().contiguous()
# Turning the data over to CUDA at this point may lead to more OOM errors
#if args.cuda:
# data = data.cuda()
if isinstance(data,tuple):
return data, tag_data
return data
示例2: batchify
# 需要导入模块: import data [as 别名]
# 或者: from data import narrow [as 别名]
def batchify(data, batch_size):
# Work out how cleanly we can divide the dataset into batch_size parts.
nbatch = data.size(0) // batch_size
# Trim off any extra elements that wouldn't cleanly fit (remainders).
data = data.narrow(0, 0, nbatch * batch_size)
# Evenly divide the data across the batch_size batches.
data = data.view(batch_size, -1).t().contiguous()
return data.to(device)
开发者ID:nadavbh12,项目名称:Character-Level-Language-Modeling-with-Deeper-Self-Attention-pytorch,代码行数:10,代码来源:main.py
示例3: batchify
# 需要导入模块: import data [as 别名]
# 或者: from data import narrow [as 别名]
def batchify(data, bsz):
# Work out how cleanly we can divide the dataset into bsz parts.
nbatch = data.size(0) // bsz
# Trim off any extra elements that wouldn't cleanly fit (remainders).
data = data.narrow(0, 0, nbatch * bsz)
# Evenly divide the data across the bsz batches.
data = data.view(bsz, -1).t().contiguous()
return data.to(device)
示例4: batchify
# 需要导入模块: import data [as 别名]
# 或者: from data import narrow [as 别名]
def batchify(data, bsz):
# Work out how cleanly we can divide the dataset into bsz parts.
nbatch = data.size(0) // bsz
# Trim off any extra elements that wouldn't cleanly fit (remainders).
data = data.narrow(0, 0, nbatch * bsz)
# Evenly divide the data across the bsz batches.
data = data.view(bsz, -1).t().contiguous()
if args.cuda:
data = data.cuda()
return data
示例5: batchify
# 需要导入模块: import data [as 别名]
# 或者: from data import narrow [as 别名]
def batchify(data, bsz, args):
# Work out how cleanly we can divide the dataset into bsz parts.
nbatch = data.size(0) // bsz
# Trim off any extra elements that wouldn't cleanly fit (remainders).
data = data.narrow(0, 0, nbatch * bsz)
# Evenly divide the data across the bsz batches.
data = data.view(bsz, -1).t().contiguous()
if args.cuda:
data = data.cuda()
return data
示例6: batchify
# 需要导入模块: import data [as 别名]
# 或者: from data import narrow [as 别名]
def batchify(data, bsz):
# Work out how cleanly we can divide the dataset into bsz parts.
nbatch = data.size(0) // bsz
# Trim off any extra elements that wouldn't cleanly fit (remainders).
data = data.narrow(0, 0, nbatch * bsz)
# Evenly divide the data across the bsz batches.
data = data.view(bsz, -1).t().contiguous()
if args.cuda:
data = data.cuda()
return data
#######################################################################
示例7: batchify
# 需要导入模块: import data [as 别名]
# 或者: from data import narrow [as 别名]
def batchify(data, bsz, random_start_idx=False):
# Work out how cleanly we can divide the dataset into bsz parts.
nbatch = data.size(0) // bsz
# Trim off any extra elements that wouldn't cleanly fit (remainders).
if random_start_idx:
start_idx = random.randint(0, data.size(0) % bsz - 1)
else:
start_idx = 0
data = data.narrow(0, start_idx, nbatch * bsz)
# Evenly divide the data across the bsz batches.
data = data.view(bsz, -1).t().contiguous()
if args.cuda:
data = data.cuda()
return data