Created
December 13, 2012 10:59
-
-
Save shuyo/4275721 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# ldig features extractor | |
# This code is available under the MIT License. | |
# (c)2012 Nakatani Shuyo / Cybozu Labs Inc. | |
import sys, os, codecs, numpy | |
import ldig | |
model = sys.argv[1] | |
size = int(sys.argv[2]) | |
ldig = ldig.ldig(model) | |
features = ldig.load_features() | |
labels = ldig.load_labels() | |
param = numpy.load(ldig.param) | |
top_index = numpy.abs(param).max(axis=1).argsort()[-size:] | |
f = open("parameters.txt", "wb") | |
g = codecs.open("features.txt", "wb", "utf-8") | |
g.write("\t".join(labels)) | |
g.write("\n") | |
for id in top_index: | |
phi = param[id,] | |
f.write("\t".join("%0.5g" % x for x in phi)) | |
f.write("\n") | |
g.write(features[id][0]) | |
g.write("\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment