forked from vamsikrishna1902/IntentPredictionEval
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFullDimensionalityVectors.py
47 lines (42 loc) · 1.85 KB
/
FullDimensionalityVectors.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import sys
import os
import time, argparse
from bitmap import BitMap
import ParseConfigFile as parseConfig
from ParseConfigFile import getConfig
import QueryParser as qp
import TupleIntent as ti
import re
def computeEmbeddingVectors(inputFile, outputFile, bitOrWeighted):
try:
os.remove(outputFile)
except OSError:
pass
embedVocabulary = {} # dict with intent vector as key and bit position/dimension as value
len = 0
with open(inputFile) as f:
for line in f:
tokens = line.split(";")
intentVec = ';'.join(tokens[2:])
if intentVec not in embedVocabulary:
embedVocabulary[intentVec] = len
len+=1
f.close()
with open(inputFile) as f:
for line in f:
tokens = line.split(";")
intentVec = ';'.join(tokens[2:])
embedVec = BitMap(len)
pos = embedVocabulary[intentVec]
embedVec.set(pos)
if __name__ == "__main__":
configDict = parseConfig.parseConfigFile("configFile.txt")
tupleIntentInputFile = getConfig(configDict['TUPLEINTENTSESSIONS'])
tupleIntentOutputFile = getConfig(configDict['TUPLEINTENTSESSIONS_RNN_EMBEDDING'])
bitFragmentIntentInputFile = getConfig(configDict['BIT_FRAGMENT_INTENT_SESSIONS'])
bitFragmentIntentOutputFile = getConfig(configDict['BIT_FRAGMENT_INTENT_SESSIONS_RNN_EMBEDDING'])
weightedFragmentIntentInputFile = getConfig(configDict['WEIGHTED_FRAGMENT_INTENT_SESSIONS'])
weightedFragmentIntentOutputFile = getConfig(configDict['WEIGHTED_FRAGMENT_INTENT_SESSIONS_RNN_EMBEDDING'])
computeEmbeddingVectors(tupleIntentInputFile, tupleIntentOutputFile, 'BIT')
computeEmbeddingVectors(bitFragmentIntentInputFile, bitFragmentIntentOutputFile, 'BIT')
computeEmbeddingVectors(weightedFragmentIntentInputFile, weightedFragmentIntentOutputFile, 'WEIGHTED')