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
def init_gru(cell, gain=1): | |
cell.reset_parameters() | |
# orthogonal initialization of recurrent weights | |
for _, hh, _, _ in cell.all_weights: | |
for i in range(0, hh.size(0), cell.hidden_size): | |
I.orthogonal(hh[i:i + cell.hidden_size], gain=gain) | |
def init_lstm(cell, gain=1): |
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
import itertools | |
import multiprocessing | |
import multiprocessing.pool as mp | |
import tqdm | |
# gensim.utils.chunkize_serial | |
def chunkize_serial(iterable, chunksize, as_numpy=False): | |
""" |
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
import torch | |
import torch.nn as nn | |
class MaskedSoftmax(nn.Module): | |
def __init__(self): | |
super(MaskedSoftmax, self).__init__() | |
self.softmax = nn.Softmax(1) | |
def forward(self, x, mask=None): |
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
auto eno1 | |
iface eno1 inet static | |
address 147.46.15.255 | |
hwaddress ether 00:50:56:00:00:00 | |
gateway 147.46.15.1 | |
netmask 255.255.255.0 | |
dns-nameservers 147.46.37.10 147.46.80.1 8.8.8.8 |
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
import torch.sparse as sp | |
def sparse_2d_densesum(x, dim=None) | |
assert len(x.size()) == 2 | |
if dim is None: | |
return x.values().sum() | |
values = x.values() | |
return values.new(x.size(1 - dim)).zero_() \ | |
.scatter_add(0, x.indices()[1 - dim], values) |
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
import torch | |
def gumbel_softmax(logits, tau=1.0, eps=1e-10): | |
"""Generate samples from the Gumbel-softmax distribution. | |
(arXiv: 1611.01144) | |
Examples: | |
>>> # sampling from a Gumbel-softmax distribution given a categorical distribution | |
>>> gumbel_softmax(torch.tensor([0.3, 0.7]).log(), tau=0.1) |
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
#!/bin/bash | |
if [ "$EUID" -ne 0 ] | |
then | |
echo "root privilege is required. re-run this script with 'sudo'." >&2 | |
exit 1 | |
fi | |
TEMP_PATH=$(tempfile -d $(pwd)) |
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
#!/usr/bin/env python | |
import io | |
import sys | |
import yaml | |
import pathlib | |
import argparse | |
import smtplib | |
import getpass |
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 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:])] |
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
__all__ = ["BLEUEvaluator"] | |
import bisect | |
import logging | |
import collections | |
from dataclasses import dataclass | |
from typing import Sequence, Optional, List | |
import torch | |
import numpy as np |
OlderNewer