Skip to content

Instantly share code, notes, and snippets.

View lxuechen's full-sized avatar

Xuechen Li lxuechen

View GitHub Profile
@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
@rkern
rkern / seed_seq.py
Last active August 14, 2020 03:09
Python implementation of SeedSequence
#!/usr/bin/env python
""" PRNG seed sequence implementation for np.random.
The algorithms are derived from Melissa E. O'Neill's C++11 `std::seed_seq`
implementation, as it has a lot of nice properties that we want.
https://gist.github.com/imneme/540829265469e673d045
http://www.pcg-random.org/posts/developing-a-seed_seq-alternative.html
The MIT License (MIT)
@ar45
ar45 / inspections.txt
Created November 3, 2015 19:41
PyCharm inspections
PyAbstractClass
PyArgumentEqualDefault
PyArgumentList
PyAssignmentToLoopOrWithParameter
PyAttributeOutsideInit
PyAugmentAssignment
PyBroadException
PyByteLiteral
PyCallByClass
PyCallingNonCallable
@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:
@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', '-').
@0xabad1dea
0xabad1dea / copilot-risk-assessment.md
Last active September 11, 2023 10:21
Risk Assessment of GitHub Copilot

Risk Assessment of GitHub Copilot

0xabad1dea, July 2021

this is a rough draft and may be updated with more examples

GitHub was kind enough to grant me swift access to the Copilot test phase despite me @'ing them several hundred times about ICE. I would like to examine it not in terms of productivity, but security. How risky is it to allow an AI to write some or all of your code?

Ultimately, a human being must take responsibility for every line of code that is committed. AI should not be used for "responsibility washing." However, Copilot is a tool, and workers need their tools to be reliable. A carpenter doesn't have to

@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
@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.
@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)
@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