Skip to content

Instantly share code, notes, and snippets.

View kaniblu's full-sized avatar

Kang Min Yoo kaniblu

  • NAVER Corporation
  • Seoul
View GitHub Profile
join_by () {
# Argument #1 is the separator. It can be multi-character.
# Argument #2, 3, and so on, are the elements to be joined.
# Usage: join_by ", " "${array[@]}"
local SEPARATOR="$1"
shift
local F=0
for x in "$@"
do
torch.einsum("blm,mn->bln", torch.randn(3, 4, 5), torch.randn(5, 6)).size() # torch.Size([3, 4, 6])
(torch.randn(3, 4, 5) @ torch.randn(5, 6)).size() # torch.Size([3, 4, 6])
torch.randn(3, 4, 5).view(12, 5).mm(torch.randn(5, 6)).view(3, 4, 6).size() # torch.Size([3, 4, 6])
torch.randn(3, 4, 5).mm(torch.randn(5, 6)).size()
# RuntimeError: matrices expected, got 3D, 2D tensors at
import torch
(torch.randn(3, 4, 5).bmm(torch.randn(3, 5, 6))).size() # torch.Size([3, 4, 6])
import torch
(torch.randn(3, 4) @ torch.randn(4, 5)).size() # torch.Size([3, 5])
import torch
torch.mm(torch.randn(3, 4), torch.randn(4, 5)).size() # torch.Size([3, 5])
torch.randn(3, 4).mm(torch.randn(4, 5)).size() # torch.Size([3, 5])
__all__ = ["BLEUEvaluator"]
import bisect
import logging
import collections
from dataclasses import dataclass
from typing import Sequence, Optional, List
import torch
import numpy as np
@kaniblu
kaniblu / split.py
Created April 29, 2020 03:10
Split a sequence into chunks closest to the given ratio
from typing import Sequence
import numpy as np
def split_list(items: Sequence, ratios: Sequence[float]):
ratios = np.cumsum(np.array(ratios) / sum(ratios)).tolist()
indices = [0] + [int(round(len(items) * r)) for r in ratios]
return [items[i:j] for i, j in zip(indices, indices[1:])]