Skip to content

Instantly share code, notes, and snippets.

@korakot
korakot / sheet_df.py
Last active March 29, 2024 23:33
Save dataframe to Google Sheet from Colab
# authenticate
from google.colab import auth
auth.authenticate_user()
import gspread
from oauth2client.client import GoogleCredentials as GC
gc = gspread.authorize(GC.get_application_default())
# create, and save df
from gspread_dataframe import set_with_dataframe
title = 'New Sheet'
gc.create(title) # if not exist
@yzh119
yzh119 / st-gumbel.py
Created January 12, 2018 12:25
ST-Gumbel-Softmax-Pytorch
from __future__ import print_function
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.autograd import Variable
def sample_gumbel(shape, eps=1e-20):
U = torch.rand(shape).cuda()
return -Variable(torch.log(-torch.log(U + eps) + eps))
@neubig
neubig / dynet-tagger.py
Last active May 21, 2018 06:01
A small sequence labeler in DyNet
"""
DyNet implementation of a sequence labeler (POS taggger).
This is a translation of this tagger in PyTorch: https://gist.github.com/hal3/8c170c4400576eb8d0a8bd94ab231232
Basic architecture:
- take words
- run though bidirectional GRU
- predict labels one word at a time (left to right), using a recurrent neural network "decoder"
The decoder updates hidden state based on:
- most recent word
@noisychannel
noisychannel / extractMonotonePhrasePairs.py
Last active February 3, 2016 21:25
Extracts monotone phrase pairs from aligned bitext
#!/usr/bin/env python
# NOTE : This script assumes that the aligments are in the src-tgt format
import optparse
import pprint
import sys
import numpy as np
optparser = optparse.OptionParser()
@mjpost
mjpost / unicode_header.py
Last active September 10, 2015 13:33
Standard Python header
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Python *sucks* at UTF-8 (don't tell me "It's fixed in Python 3"; I don't care, plus no one uses Python 3)
# If you put this at the top of every Python script, however, it get rids of most of the headaches dealing with STDIN
# and STDOUT (basically, akin to "perl -C31"). I don't know if it's all necessary; I just know that if I put it at
# the top of my scripts, most of the problems go away, and I can stop thinking about it.
import sys
import codecs