Skip to content

Instantly share code, notes, and snippets.

View gavinmh's full-sized avatar

Gavin Hackeling gavinmh

View GitHub Profile
asdasdasdasdas
@gavinmh
gavinmh / featurizer_sub.py
Created December 4, 2012 01:59
Lexical entailment featurizer for substitution edits
from __future__ import division
from nltk.corpus import wordnet as wn
from nltk.corpus import wordnet_ic
from nltk.metrics import edit_distance
from nltk.corpus.reader.wordnet import WordNetError
import numpy as np
import logging, os
import Alignment_sub
@gavinmh
gavinmh / Alignment_sub.py
Created December 4, 2012 02:05
A substitution alignment
# -*- coding: utf-8 -*-
"""
Created on Fri Nov 23 11:25:40 2012
@author: gavin
"""
import logging
from nltk.corpus import wordnet as wn
class Alignment_sub:
@gavinmh
gavinmh / classifier_substition.py
Created December 4, 2012 02:07
Substition classifier
try:
import cPickle as pickle
except:
import pickle
from sklearn.ensemble import RandomForestClassifier
import logging, os
class Lexent_classifier_sub:
@gavinmh
gavinmh / harness_substitution.py
Created December 4, 2012 02:08
substitution classifier harness
import logging
import numpy as np
import Alignment_sub
import lexent_featurizer_sub
try:
import cPickle as pickle
except:
import pickle
@gavinmh
gavinmh / 52-displaylink.conf
Created December 22, 2012 17:41
Dual head with DisplayLink for Linux
@gavinmh
gavinmh / naive_summarizer
Last active December 10, 2015 03:58
A naive, unsupervised text summarizer.
# -*- coding: utf-8 *-*
'''
The following is a naive, unsupervised text summarizer.
It extracts N of the text's most salient sentences.
Salience is defined as the average of the tf-idf weights of the words in a sentence.
'''
from nltk import sent_tokenize, word_tokenize
from collections import Counter
from math import log10
@gavinmh
gavinmh / generators.py
Created May 18, 2013 20:51
An introduction to generator functions and generator expressions in Python
'''
A generator is a function or expression that returns multiple items, rather than a single item that may contain multiple items.
A generator is often consumed in a for loop.
Some practical points:
-Generators use the yield statement.
-Calling a generator creates the object, but does not return any items.
-You can iterate over the generator's returned items once. You can iterate over a list an arbitrary number of times.
'''

Approximate Algoritm Completion Times, N=100

10^-6 seconds
O(log(N)) 10^-7 seconds
O(N)
@gavinmh
gavinmh / bing_search.py
Created June 15, 2013 23:05
Bing Search API Python example
import urllib
import json
bing_account_key = '<YOURKEY>'
search_base_url = \
'https://user:%s@api.datamarket.azure.com/Bing/SearchWeb/Web?' \
% bing_account_key
query = 'les paul'
num_results = 40