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
# -*- coding: utf-8 -*- | |
import functools | |
import signal | |
class timeout(object): | |
r"""Context-manager that prevents function execution from timeout. | |
Also functions as a decorator. |
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
Windows Registry Editor Version 5.00 | |
[HKEY_CLASSES_ROOT\Directory\Background\shell\Bash] | |
@="Bash here" | |
"Icon"="C:\\Program Files\\WindowsApps\\CanonicalGroupLimited.UbuntuonWindows_2004.2020.424.0_x64__79rhkp1fndgsc\\ubuntu.exe" | |
[HKEY_CLASSES_ROOT\Directory\Background\shell\Bash\command] | |
@="C:\\Program Files\\WindowsApps\\CanonicalGroupLimited.UbuntuonWindows_2004.2020.424.0_x64__79rhkp1fndgsc\\ubuntu.exe -c bash" |
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
# -*- coding: utf-8 -*- | |
from parser.modules.dropout import SharedDropout | |
import torch | |
import torch.nn as nn | |
import torch.nn.functional as F | |
from torch.nn.utils.rnn import PackedSequence | |
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
# -*- coding: utf-8 -*- | |
import torch | |
import torch.nn as nn | |
class Transformer(nn.Module): | |
def __init__(self, n_layers, n_heads, n_model, n_embed, n_inner, | |
input_dropout=0.1, attn_dropout=0.1, ffn_dropout=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
# -*- coding: utf-8 -*- | |
import torch | |
from torch.nn.utils.rnn import pad_sequence | |
@torch.enable_grad() | |
def crf(scores, mask, target=None, partial=False): | |
lens = mask.sum(1) | |
total = lens.sum() |
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
# -*- coding: utf-8 -*- | |
import argparse | |
import unicodedata | |
# FF00-FF5F -> 0020-007E | |
MAP = {' ': ' ', '!': '!', '"': '"', '#': '#', '$': '$', '%': '%', '&': '&', | |
''': "'", '(': '(', ')': ')', '*': '*', '+': '+', ',': ',', '-': '-', | |
'.': '.', '/': '/', | |
'0': '0', '1': '1', '2': '2', '3': '3', '4': '4', '5': '5', '6': '6', |
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
# -*- coding: utf-8 -*- | |
import argparse | |
import os | |
import unicodedata | |
import torch | |
def ispunct(token): |
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 tarjan(tree): | |
tree[0] = -1 | |
# record the search order, i.e., the timestep | |
dfn = [-1] * len(tree) | |
# record the the smallest timestep in a SCC | |
low = [-1] * len(tree) | |
# push the visited into the stack | |
stack, onstack = [], [False] * len(tree) | |
def connect(i, timestep): |
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
# -*- coding: utf-8 -*- | |
import torch | |
import torch.autograd as autograd | |
import torch.nn as nn | |
class MatrixTree(nn.Module): | |
def __init__(self, *args, **kwargs): |
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
# -*- coding: utf-8 -*- | |
import torch | |
import torch.nn as nn | |
class GAT(nn.Module): | |
def __init__(self, n_input, n_inner, n_layers, alpha=0.1, dropout=0.5): | |
super(GAT, self).__init__() |
OlderNewer