Skip to content

Instantly share code, notes, and snippets.

View louridas's full-sized avatar

Panos Louridas louridas

View GitHub Profile
import numpy as np
import gensim
def smart_procrustes_align_gensim(base_embed, other_embed, words=None):
"""Procrustes align two gensim word2vec models (to allow for comparison between same word across models).
Code ported from HistWords <https://github.com/williamleif/histwords> by William Hamilton <wleif@stanford.edu>.
(With help from William. Thank you!)
First, intersect the vocabularies (see `intersection_align_gensim` documentation).
Then do the alignment on the other_embed model.
Replace the other_embed model's syn0 and syn0norm numpy matrices with the aligned version.
def find_in_pq(pq, s, c):
if get_data(pq, s) == c:
return s
elif get_data(pq, s) > c:
return None
found_below = None
for i in children(pq, s):
found_below = find_in_pq(pq, i, c)
if found_below:
return found_below
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"$$\n",
"\\begin{bmatrix}\n",
"0 & 2 & 3 & 1\\\\\n",
"3 & 1 & 0 & 2\\\\\n",
@louridas
louridas / gist:3847173
Created October 7, 2012 05:06
changing output format based on submission-passed paramater
#incidents_controller.rb:
if params[:commit] == I18n.t(:text_search_results)
self.request.format = "text"
end
format.text do
self.response.headers["Content-Type"] ||= 'text/plain'
self.response.headers["Content-Disposition"] =
"attachment; filename=search.txt"
@louridas
louridas / volume-calculator.c
Created May 11, 2012 09:39
Solid volume calculator
#include <stdio.h>
#include <string.h>
#include <assert.h>
#define X 0
#define Y 1
#define Z 2
#define EPSILON 0.0001