This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Seq2SeqAttnRNN(nn.Module): | |
def __init__(self, vecs_enc, itos_enc, em_sz_enc, vecs_dec, itos_dec, em_sz_dec, nh, out_sl, nl=2): | |
super().__init__() | |
self.emb_enc = create_emb(vecs_enc, itos_enc, em_sz_enc) | |
self.nl,self.nh,self.out_sl = nl,nh,out_sl | |
self.gru_enc = nn.GRU(em_sz_enc, nh, num_layers=nl, dropout=0.25) | |
self.out_enc = nn.Linear(nh, em_sz_dec, bias=False) | |
self.emb_dec = create_emb(vecs_dec, itos_dec, em_sz_dec) | |
self.gru_dec = nn.GRU(em_sz_dec, em_sz_dec, num_layers=nl, dropout=0.1) | |
self.emb_enc_drop = nn.Dropout(0.15) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from torch.utils.data.sampler import Sampler | |
from torch.utils.data.sampler import RandomSampler | |
class WeightedLossSampler(Sampler, Callback): | |
def __init__(self, data_source, replacement=True, bs=64, init_fac=1, ls_init_fac=1e-2): | |
self.num_samples = len(data_source) | |
self.weights = to_gpu(torch.ones(self.num_samples)*init_fac) | |
self.replacement = replacement | |
self.i = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution { | |
public static int uniquePathsWithObstacles(int[][] obstacleGrid) { | |
if(obstacleGrid.length == 0 || obstacleGrid[0].length == 0) return 0; | |
int[][] res = new int[obstacleGrid.length][obstacleGrid[0].length]; | |
for(int i = 0; i < obstacleGrid.length; i++) { | |
for(int j = 0; j < obstacleGrid[0].length;j++) { | |
if(obstacleGrid[i][j] == 1) res[i][j] = 0; | |
else if(i == 0 && j == 0) res[0][0] = 1; | |
else if (i == 0) res[i][j] = res[i][j-1]; | |
else if (j == 0) res[i][j] = res[i-1][j]; |