Skip to content

Instantly share code, notes, and snippets.

@madaan
madaan / ngram.py
Last active November 18, 2019 05:46
NLTK n-gram model
from nltk.corpus import brown
from nltk.lm import MLE
from nltk import bigrams
from nltk.lm.preprocessing import padded_everygram_pipeline
def get_model(order=2):
lm = MLE(order)
train, vocab = padded_everygram_pipeline(order=2, text=brown.sents())
lm.fit(train, vocab)
return lm

Castle Bill Split

  • We have 8 people living in the castle. Thus, the bill gets split in 8 parts.

  • Each part is thus 1/8

  • 4 of these parts are paid by AS. Thus, AS pays 4/8th.

  • Because AS pays 4/8th of the bill, we are left with 4/8th of the bill to pay.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@madaan
madaan / gist:b7d8f0336ca9fe3925d2
Last active August 29, 2015 14:22
Relevant snippet from full inference to show the agreeing k.
/*
* Now start the agreeing k
*/
//Different deltas for different relations
double delta = GoldDbInference.marginMap.get(lrg.relation);
int leastFlips = Integer.MAX_VALUE;
double bestCentralValue = -1;
/**
* Find the optimal central value
*/
@madaan
madaan / 300 topics 5k sentences
Last active August 29, 2015 14:13
100 topics 5k sentences
rrb lrb xinhua aug tuesday wednesday dec official hail
afp lrb rrb 2009 2010 thursday dec friday urgent
particulate level 12 china pollution city reading air quality
stock percent point close share market index exchange higher
say deal source buy march arm asian 35 like
2010 rrb afp saturday lrb feb jan defend 25
year month 15 investment 10 direct foreign consumer 28
guinea country civilian rule african west junta attempt leader
late member early state president 1998 people away counterpart
japan japanese tokyo naoto kan honda yen shed expand
@madaan
madaan / spaceShip_8dir.cpp
Last active August 29, 2015 14:11
SDL2 code for capturing multiple keypresses in one go, based on http://www.programmersranch.com/2014/02/sdl2-keyboard-and-mouse-movement-events.html
#include <SDL.h>
#include <iostream>
using namespace std;
int main(int argc, char ** argv)
{
bool quit = false;
SDL_Event event;
int x = 288;
int y = 208;
@madaan
madaan / depparsing.java
Created October 6, 2014 10:47
Stanford CoreNLP Dependency parsing
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import org.apache.commons.io.FileUtils;
import edu.stanford.nlp.ling.CoreAnnotations.SentencesAnnotation;
#sg
#This script iterates over documents in a directory and strips tags
#Thanks to http://stackoverflow.com/questions/753052/strip-html-from-strings-in-python
from HTMLParser import HTMLParser
class MLStripper(HTMLParser):
def __init__(self):
self.reset()
self.fed = []
@madaan
madaan / sgconfig.json
Created August 1, 2014 08:19
Configuration file used with MultiR
{
"corpusPath" :
"jdbc:derby:/mnt/a99/d0/aman/multir-exp-second/MultirExperiments-master/data/FullCorpus-First100Sentences",
"train" : "true",
"testDocumentsFile" :
"data/emptyFile",
"fg" :
"edu.washington.multirframework.featuregeneration.DefaultFeatureGenerator",
"ai" :