Skip to content

Instantly share code, notes, and snippets.

@usamec
usamec / resumable_sampler.py
Created August 25, 2020 10:50
Resumable (and savable) random sampler for Pytorch data loader
import torch
class ResumableRandomSampler(torch.utils.data.Sampler):
r"""Samples elements randomly. If without replacement, then sample from a shuffled dataset.
If with replacement, then user can specify :attr:`num_samples` to draw.
Arguments:
data_source (Dataset): dataset to sample from
replacement (bool): samples are drawn on-demand with replacement if ``True``, default=``False``
num_samples (int): number of samples to draw, default=`len(dataset)`. This argument
is supposed to be specified only when `replacement` is ``True``.
@usamec
usamec / GRU tuning.ipynb
Created February 6, 2020 14:24
GRU tuning
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
package com.example
import scala.annotation.tailrec
import scala.collection.immutable.Queue
case class TrieNode[Char, Value](values: List[Value], next: Map[Char, TrieNode[Char, Value]]) {
def add(str: Seq[Char], value: Value): TrieNode[Char, Value] = {
@tailrec
def addWalkDown(node: TrieNode[Char, Value], stack: List[(Char, TrieNode[Char, Value])], remaining: List[Char], value: Value): TrieNode[Char, Value] = {
remaining match {