This file contains hidden or 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 re | |
from datetime import datetime, timedelta | |
import arxiv | |
KEYS = ['adversarial', 'algebraic', 'algebratic', 'amr', 'auto-encoding', 'autoencoder', 'autoencoding', 'autoregressive', | |
'backward', 'bayes', 'bayesian', 'bethe', 'bilexical', 'bipartite', 'bregman', 'carlo', 'chomsky', 'circuit', 'clique', |
This file contains hidden or 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 functools import reduce | |
import torch | |
import torch.autograd as autograd | |
from supar.utils.common import MIN | |
from torch.autograd import Function | |
This file contains hidden or 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 | |
from functools import partial | |
from multiprocessing.dummy import Pool | |
import nltk | |
from google_trans_new import google_translator | |
from tqdm import tqdm |
This file contains hidden or 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 | |
from functools import partial | |
from multiprocessing.dummy import Pool | |
import nltk | |
from google_trans_new import google_translator | |
from tqdm import tqdm |
This file contains hidden or 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 | |
from collections import Counter | |
def factorize(tags): | |
spans = [] | |
for i, tag in enumerate(tags): | |
if tag.startswith(('B', 'S')): |
This file contains hidden or 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 | |
def bio2bioes(fin, fout): | |
r'''Convert BIO file to BIOES file. | |
Parameters: | |
fin (str): the file to convert. | |
fout (str): the file to save. |
This file contains hidden or 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 | |
import torch.nn.functional as F | |
class Biaffine(nn.Module): | |
""" | |
Biaffine layer for first-order scoring. |
This file contains hidden or 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__() |
This file contains hidden or 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 hidden or 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): |