Skip to content

Instantly share code, notes, and snippets.

View neubig's full-sized avatar

Graham Neubig neubig

View GitHub Profile
@neubig
neubig / petstory.yaml
Created April 23, 2019 05:04
petstore with oneOf
openapi: "3.0.0"
info:
version: 1.0.0
title: Swagger Petstore
license:
name: MIT
servers:
- url: http://petstore.swagger.io/v1
paths:
/pets:
package edu.cmu.empty;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.openapi.ui.popup.ListPopup;
import com.intellij.openapi.ui.popup.PopupStep;
import com.intellij.openapi.ui.popup.util.BaseListPopupStep;
@neubig
neubig / print-trees.py
Created October 18, 2011 07:15
A file to print parse trees from standard input using NLTK
#!/usr/bin/python
from nltk.tree import Tree
import sys
# A program to display parse trees (in Penn treebank format) with NLTK
#
# To install NLTK on ubuntu: sudo apt-get install python-nltk
for line in sys.stdin:
@neubig
neubig / identify_japanese_pronouns.py
Created June 25, 2019 18:37
A script to identify Japanese pronouns
import sys
import re
from collections import defaultdict
# This is a script to identify pronouns in Japanese
# It requires data segmented by KyTea (http://www.phontron.com/kytea/)
#
# If you have raw Japanese text (with no spaces), use this script like:
# cat japanese.txt | kytea | python identify_japanese_pronouns.py > japanese_with_pronouns.txt
#
@neubig
neubig / orid_to_s2_papers.py
Created May 14, 2021 15:31
Convert OpenReview IDs to Semantic Scholar Papers
import openreview
import argparse
import requests
import time
import sys
import csv
import json
from tqdm import tqdm # Progress bar
# This is a utility script to get a CSV of papers from semantic scholar given OpenReview ids
@neubig
neubig / kyteapos2en.pl
Created April 30, 2012 04:08
A program to change KyTea's Japanese POS tags to english tags
#!/usr/bin/perl
# This is a script to change KyTea's POS tags in Japanese to English
# abbreviations
use strict;
use utf8;
use Getopt::Long;
use List::Util qw(sum min max shuffle);
binmode STDIN, ":utf8";
binmode STDOUT, ":utf8";
@neubig
neubig / crf.py
Created November 7, 2013 10:59
This is a script to train conditional random fields. It is written to minimize the number of lines of code, with no regard for efficiency.
#!/usr/bin/python
# crf.py (by Graham Neubig)
# This script trains conditional random fields (CRFs)
# stdin: A corpus of WORD_POS WORD_POS WORD_POS sentences
# stdout: Feature vectors for emission and transition properties
from collections import defaultdict
from math import log, exp
import sys
@neubig
neubig / plot-gp.py
Created November 19, 2014 02:25
A simple program to sample functions from a Gaussian process and plot them
#!/usr/bin/python
from math import exp
import numpy as np
import matplotlib.pyplot as plt
def rbf_kernel(x1, x2, variance = 1):
return exp(-1 * ((x1-x2) ** 2) / (2*variance))
def gram_matrix(xs):
@neubig
neubig / get_citations.py
Created October 21, 2021 22:39
Comparing citations between EMNLP 2020 and EMNLP 2020 findings
import requests
import sys
import time
sleep_time = 20
def query_api(url, session):
global sleep_time
time.sleep(sleep_time / 1000.0)
r = session.get(url)
while r.status_code == 429:
@neubig
neubig / linalg-calcfunction.py
Last active October 19, 2022 09:50
Examples of linear algebra in numpy
import numpy as np
import sys
################# Explanation ##################
# This is a function to calculate house prices h(x) = -40 + 0.25x
# The first term (-40) is the base price, and "x" is the number of square feet in the house
################################################
# Set up the function
my_function = np.array([-40, 0.25])