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
git clone --bare [email protected]:anna-hope/dotfiles.git $HOME/.cfg | |
function dotfiles { | |
/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME $@ | |
} | |
mkdir -p .dotfiles-backup | |
dotfiles checkout | |
if [ $? = 0 ]; then | |
echo "Checked out the dotfiles."; | |
else | |
echo "Backing up pre-existing dot files."; |
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
package main | |
import ( | |
"image" | |
"image/color" | |
"math/rand" | |
"time" | |
"golang.org/x/tour/pic" | |
) |
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
package main | |
import ( | |
"io" | |
"os" | |
"strings" | |
) | |
type rot13Reader struct { | |
r io.Reader |
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 Union, Dict | |
import pandas as pd | |
from torchtext.data import (Field, Example, Iterator, BucketIterator, Dataset) | |
from tqdm import tqdm | |
class DataFrameExampleSet: | |
def __init__(self, df: pd.DataFrame, fields: Dict[str, Field]): | |
self._df = df |
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
# Implementation of Structured Self-Attention mechanism | |
# from Lin et al. 2017 (https://arxiv.org/pdf/1703.03130.pdf) | |
# Anton Melnikov | |
import torch | |
import torch.nn as nn | |
class StructuredAttention(nn.Module): | |
def __init__(self, *, input_dim: int, hidden_dim: int, attention_hops: int): |
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 numpy as np | |
def get_conv_out(dim_in, padding, kernel_size, stride): | |
out_dim = (dim_in + 2 * padding - kernel_size) / stride | |
out_dim += 1 | |
return int(np.floor(out_dim)) | |
layers = [(0, 7, 1), | |
(0, 3, 3), | |
(0, 7, 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
# Implementation of the Hierarchical Attention Network from Yang et al. 2016 | |
# https://www.cs.cmu.edu/~diyiy/docs/naacl16.pdf | |
# Anton Melnikov | |
import torch | |
from torch import nn | |
import torch.nn.functional as F | |
class SequenceClassifierAttention(nn.Module): |
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
# Very Deep Convolutional Network (http://aclweb.org/anthology/E17-1104) | |
# PyTorch implementation by Anton Melnikov | |
from typing import Iterable, Tuple | |
import torch | |
from torch import nn | |
import torch.nn.functional as F | |
from torch.autograd import Variable |
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
# Convolutional block from http://aclweb.org/anthology/E17-1104 | |
# Anton Melnikov | |
import numpy as np | |
import torch | |
from torch import nn | |
class ConvBlock(nn.Module): | |
def __init__(self, in_channels, out_channels, *, | |
kernel_size, stride=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 pandas as pd | |
from torchtext import data | |
from tqdm import tqdm | |
def make_examples(df: pd.DataFrame, fields: Dict[str, data.Field]): | |
fields = {field_name: (field_name, field) | |
for field_name, field in fields.items()} | |
for _, row in tqdm(df.iterrows()): | |
example = data.Example.fromdict(row, fields) |
NewerOlder