Python data.narrow() Examples
The following are 17
code examples of data.narrow().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
data
, or try the search function
.
Example #1
Source File: main.py From LM_syneval with MIT License | 6 votes |
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
Example #2
Source File: main.py From Count-Sketch-Optimizers with Apache License 2.0 | 5 votes |
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)
Example #3
Source File: main.py From dni-pytorch with MIT License | 5 votes |
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
Example #4
Source File: dynamiceval.py From dynamic-evaluation with BSD 2-Clause "Simplified" License | 5 votes |
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 #######################################################################
Example #5
Source File: main.py From word-language-model with BSD 3-Clause "New" or "Revised" License | 5 votes |
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
Example #6
Source File: main.py From PyTorch with MIT License | 5 votes |
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)
Example #7
Source File: main_LM.py From PRPN with MIT License | 5 votes |
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
Example #8
Source File: main_LM.py From PRPN-Analysis with MIT License | 5 votes |
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
Example #9
Source File: main.py From examples with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #10
Source File: main.py From Character-Level-Language-Modeling-with-Deeper-Self-Attention-pytorch with MIT License | 5 votes |
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)
Example #11
Source File: utils.py From fraternal-dropout with BSD 3-Clause "New" or "Revised" License | 5 votes |
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
Example #12
Source File: dynamiceval.py From mos with MIT License | 5 votes |
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 #######################################################################
Example #13
Source File: main.py From YellowFin_Pytorch with Apache License 2.0 | 5 votes |
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
Example #14
Source File: train.py From reversible-rnn with MIT License | 5 votes |
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
Example #15
Source File: main.py From vmf_vae_nlp with MIT License | 5 votes |
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
Example #16
Source File: train_rnn.py From relational-rnn-pytorch with Apache License 2.0 | 5 votes |
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)
Example #17
Source File: train_rmc.py From relational-rnn-pytorch with Apache License 2.0 | 5 votes |
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)