Skip to content

Instantly share code, notes, and snippets.

View lxuechen's full-sized avatar

Xuechen Li lxuechen

View GitHub Profile
@egel
egel / auto-remove-sublime-license-popup
Last active April 8, 2024 23:00
Auto-remove Sublime's license popup
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sublime_plugin
import subprocess
from time import sleep
import sys
cl = lambda line: subprocess.Popen(line, shell=True, stdout=subprocess.PIPE).communicate()[0].strip()
log = lambda message: sys.stderr.write("Log: %s\n" % message)
@ar45
ar45 / inspections.txt
Created November 3, 2015 19:41
PyCharm inspections
PyAbstractClass
PyArgumentEqualDefault
PyArgumentList
PyAssignmentToLoopOrWithParameter
PyAttributeOutsideInit
PyAugmentAssignment
PyBroadException
PyByteLiteral
PyCallByClass
PyCallingNonCallable
@tushortz
tushortz / UNICODE to ASCII python replace
Created April 6, 2016 22:14
Function to replace some annoying characters
def unicodetoascii(text):
TEXT = (text.
replace('\\xe2\\x80\\x99', "'").
replace('\\xc3\\xa9', 'e').
replace('\\xe2\\x80\\x90', '-').
replace('\\xe2\\x80\\x91', '-').
replace('\\xe2\\x80\\x92', '-').
replace('\\xe2\\x80\\x93', '-').
replace('\\xe2\\x80\\x94', '-').
@0xjac
0xjac / private_fork.md
Last active May 2, 2024 21:33
Create a private fork of a public repository

The repository for the assignment is public and Github does not allow the creation of private forks for public repositories.

The correct way of creating a private frok by duplicating the repo is documented here.

For this assignment the commands are:

  1. Create a bare clone of the repository. (This is temporary and will be removed so just do it wherever.)

git clone --bare git@github.com:usi-systems/easytrace.git

from graphviz import Digraph
import torch
from torch.autograd import Variable, Function
def iter_graph(root, callback):
queue = [root]
seen = set()
while queue:
fn = queue.pop()
if fn in seen:
@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
@W4ngatang
W4ngatang / download_glue_data.py
Last active April 16, 2024 06:10
Script for downloading data of the GLUE benchmark (gluebenchmark.com)
''' Script for downloading all GLUE data.
Note: for legal reasons, we are unable to host MRPC.
You can either use the version hosted by the SentEval team, which is already tokenized,
or you can download the original data from (https://download.microsoft.com/download/D/4/6/D46FF87A-F6B9-4252-AA8B-3604ED519838/MSRParaphraseCorpus.msi) and extract the data from it manually.
For Windows users, you can run the .msi file. For Mac and Linux users, consider an external library such as 'cabextract' (see below for an example).
You should then rename and place specific files in a folder (see below for an example).
mkdir MRPC
cabextract MSRParaphraseCorpus.msi -d MRPC
@bombs-kim
bombs-kim / install_custom_python_in_conda.sh
Created December 27, 2018 14:53
How to install a custom python binary(ex. python-dbg) in your conda environment.
# This instruction is for Unix-like OS users.
# I refered to the following guide when I wrote it.
# https://conda.io/docs/user-guide/tasks/build-packages/recipe.html
# Activate an environment if needed
conda activate myenv
# Install conda-build if you haven't. Ironically, installing conda-build
# includes installing python. This python will be effectively replaced with
# your new python binary so don't worry.
@sbarratt
sbarratt / torch_jacobian.py
Created May 9, 2019 19:40
Get the jacobian of a vector-valued function that takes batch inputs, in pytorch.
def get_jacobian(net, x, noutputs):
x = x.squeeze()
n = x.size()[0]
x = x.repeat(noutputs, 1)
x.requires_grad_(True)
y = net(x)
y.backward(torch.eye(noutputs))
return x.grad.data
@ybj14
ybj14 / jvp.py
Last active November 20, 2022 06:51
JVP
# Refer to `https://j-towns.github.io/2017/06/12/A-new-trick.html` for math details.
import torch
from torch import nn
from torch import autograd
def get_jvp(net, x, v):
'''
Generate jacobian vector product. Requires x.requires_grad()
and v.requires_grad().
Args: