Skip to content

Instantly share code, notes, and snippets.

View JohnGiorgi's full-sized avatar

John Giorgi JohnGiorgi

View GitHub Profile
@scarecrow1123
scarecrow1123 / experiment.jsonnet
Last active May 8, 2020 18:06
A custom(read dirty) AllenNLP trainer subclass to use fp16 using `apex.amp`
{
// ....
"trainer": {
"type": "fp16-trainer",
"mixed_precision": true,
// other options
}
// ....
}
@JohnGiorgi
JohnGiorgi / word_dropout.py
Created August 20, 2019 13:07
A torch module for word dropout. Will randomly replace some words with a specified word (e.g. an UNK token).
import torch
from torch.nn.modules.dropout import _DropoutNd
class WordDropout(_DropoutNd):
"""During training, randomly replaces some of the elements of the input tensor with
`dropout_constant` with probability `p` using samples from a Bernoulli distriution. Each channel
will be zerored out independently on every forward call.
Input is expected to be a 2D tensor of indices representing tokenized sentences.
@JohnGiorgi
JohnGiorgi / biaffine_classifier.py
Last active November 2, 2023 04:58
PyTorch implementation of the biaffine attention operator from "End-to-end neural relation extraction using deep biaffine attention" (https://arxiv.org/abs/1812.11275) which can be used as a classifier for binary relation classification. If you spot an error or have an improvement, let me know!
import torch
class BiaffineAttention(torch.nn.Module):
"""Implements a biaffine attention operator for binary relation classification.
PyTorch implementation of the biaffine attention operator from "End-to-end neural relation
extraction using deep biaffine attention" (https://arxiv.org/abs/1812.11275) which can be used
as a classifier for binary relation classification.
@Mahedi-61
Mahedi-61 / cuda_11.8_installation_on_Ubuntu_22.04
Last active May 29, 2024 05:44
Instructions for CUDA v11.8 and cuDNN 8.9.7 installation on Ubuntu 22.04 for PyTorch 2.1.2
#!/bin/bash
### steps ####
# Verify the system has a cuda-capable gpu
# Download and install the nvidia cuda toolkit and cudnn
# Setup environmental variables
# Verify the installation
###
### to verify your gpu is cuda enable check
@cbaziotis
cbaziotis / AttentionWithContext.py
Last active April 25, 2022 14:37
Keras Layer that implements an Attention mechanism, with a context/query vector, for temporal data. Supports Masking. Follows the work of Yang et al. [https://www.cs.cmu.edu/~diyiy/docs/naacl16.pdf] "Hierarchical Attention Networks for Document Classification"
def dot_product(x, kernel):
"""
Wrapper for dot product operation, in order to be compatible with both
Theano and Tensorflow
Args:
x (): input
kernel (): weights
Returns:
"""
if K.backend() == 'tensorflow':
@kevin-smets
kevin-smets / iterm2-solarized.md
Last active May 28, 2024 07:00
iTerm2 + Oh My Zsh + Solarized color scheme + Source Code Pro Powerline + Font Awesome + [Powerlevel10k] - (macOS)

Default

Default

Powerlevel10k

Powerlevel10k