Skip to content

Instantly share code, notes, and snippets.

Brendan O'Connor brendano

Block or report user

Report or block brendano

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
brendano / gist:39760
Created Dec 24, 2008
load the MNIST data set in R
View gist:39760
# Load the MNIST digit recognition dataset into R
# assume you have all 4 files and gunzip'd them
# creates train$n, train$x, train$y and test$n, test$x, test$y
# e.g. train$x is a 60000 x 784 matrix, each row is one digit (28x28)
# call: show_digit(train$x[5,]) to see a digit.
# brendan o'connor - -
load_mnist <- function() {
load_image_file <- function(filename) {
brendano /
Created Oct 10, 2008
python decorators to log all method calls, show call graphs in realtime too
# Written by Brendan O'Connor,,
# * Originally written Aug. 2005
# * Posted to on Oct. 2008
# Copyright (c) 2003-2006 Open Source Applications Foundation
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
brendano / .Rhistory
Last active Aug 31, 2019
View .Rhistory
ifelse(runif(1000)>.5, 1.5, .6)
x=ifelse(runif(1000)>.5, 1.5, .6)
x=ifelse(runif(10)>.5, 1.5, .6)
y=replicate(100000,{x=ifelse(runif(10)>.5, 1.5, .6); prod(x)})
brendano /
Created Jan 2, 2011
Publish Zotero papers as HTML and symlinks
#!/usr/bin/env python
# From your Zotero database and file storage,
# creates a simple HTML table, and directory full of symlinks,
# for quick-and-dirty web or Dropbox viewing.
# Installation: place in your Zotero folder
# e.g. ~/Documents/zotero/
# And run it
# e.g. python ~/Documents/zotero/
brendano / .RData
Last active Jun 27, 2019
google ngram books plot
brendano / example.ipynb
Last active Apr 30, 2019
l1 generative implementation with liblbfgs (owl-qn)
View example.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
brendano /
Created Nov 7, 2008
xlsx2tsv: python command-line script to convert xlsx (Excel "OOXML") into tab-separated values
#!/usr/bin/env python
xlsx2tsv filename.xlsx [sheet number or name]
Parse a .xlsx (Excel OOXML, which is not OpenOffice) into tab-separated values.
If it has multiple sheets, need to give a sheet number or name.
Outputs honest-to-goodness tsv, no quoting or embedded \\n\\r\\t.
One reason I wrote this is because Mac Excel 2008 export to csv or tsv messes
up encodings, converting everything to something that's not utf8 (macroman
brendano /
Last active Jul 15, 2018
example of using corenlp server from python
example of using corenlp server from python
This code requires server to already be running:
To start server:
java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 9000 -timeout 15000
To call it, e.g.:
curl --data "The man wanted to go to work." 'http://localhost:9000/?properties={%22annotators%22%3A%22tokenize%2Cssplit%2Cpos%2Cdepparse%22%2C%22outputFormat%22%3A%22conllu%22}'
View bla.csv
We can make this file beautiful and searchable if this error is corrected: It looks like row 6 should actually have 30 columns, instead of 9. in line 5.,,,"Numer of paper submissions and acceptances for various conferences over time. Trying to only select full-length or ""main"" research papers, though others are sometimes included.
The first several columns are the main data. Sources on the right. Sometimes I tried to put in original source data in different columns. Sometimes data contradicts",,,,,,,,,,,,,,,,,,,,,,,,,,
area,conference,year,submit,accept,accept rates - some are messy or partial from copy-and-paste,joint,attendance,source/notes,other notes,other notes,other notes,other notes,other notes,other notes,,,,,,,,,,,,,,,
,,,,,,,,,,,the ACM table:,,,,,,,,,,,,,,,,,,
webir,sigir,1999,135,33,,,,,,22nd annual,SIGIR '99,135,33,24%,,,,,,,,,,,,,,,
brendano /
Last active Apr 6, 2018
numerically stable implementation of the log-logistic function

Binary case

This is just the middle section of Bob Carpenter's note for evaluating log-loss via the binary logistic functoin

The logp function calculates the negative cross-entropy:

    dotproduct( [y, 1-y],  [logP(y=1), logP(y=0)] )

where the input s is the beta'x log-odds scalar value. The trick is to make this numerically stable for any choice of s and y.

You can’t perform that action at this time.