comparison sandbox/embeddings/one-per-line.py @ 456:131e19dfe793

Added sandbox.embeddings
author Joseph Turian <turian@iro.umontreal.ca>
date Tue, 07 Oct 2008 17:56:52 -0400
parents
children
comparison
equal deleted inserted replaced
455:fb62f0e4bcfe 456:131e19dfe793
1 #!/usr/bin/python
2
3 import string
4 #import psyco
5
6 weightsfile = "lm-weights.txt"
7 vocabfile = "words.asc"
8 size = 30000
9 dimensions = 50
10
11 import numpy, math
12 import sys
13 from common.str import percent
14
15 word_to_vector = {}
16
17 f = open(weightsfile)
18 f.readline()
19 vals = [float(v) for v in string.split(f.readline())]
20 assert len(vals) == size * dimensions
21 vals.reverse()
22 #for i in range(size):
23 r = range(size)
24 r.reverse()
25 for i in r:
26 l = vals[dimensions*i:dimensions*(i+1)]
27 print string.join([`s` for s in l], "\t")