-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTensorflowUtils.py
More file actions
39 lines (28 loc) · 1.46 KB
/
Copy pathTensorflowUtils.py
File metadata and controls
39 lines (28 loc) · 1.46 KB
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
import numpy as np
def createTrainingArrays(trainingData, numPreceeding, numFollowing):
"""
Takes the training data and returns the appropriate numpy arrays to feed to tensorflow. All of the training-data
points are combined into a single matrix and the sentence-boundary indicies are combined into a single matrix
ensuring that the value of the index reflects the training datum's position in the training-point array.
:param trainingData:
:return:
"""
numTrainingPoints = len(trainingData.trainingBoundries)
pointDimension = numPreceeding + numFollowing
trainingPointArray = np.zeros((numTrainingPoints, pointDimension))
boundaryList = np.zeros(numTrainingPoints)
for index, sentenceBoundary in enumerate(trainingData.trainingBoundries):
trainingPointArray[index] = np.array(sentenceBoundary.getArray())
if sentenceBoundary.isNewSentence:
boundaryList[index] = 1.
else:
boundaryList[index] = 0.
boundaryNpArray = np.array(boundaryList)
return trainingPointArray, boundaryNpArray
def createTestArray(testBoundaries, numPreceeding, numFollowing):
numTrainingPoints = len(testBoundaries)
pointDimension = numPreceeding + numFollowing
trainingPointArray = np.zeros((numTrainingPoints, pointDimension))
for index, sentenceBoundary in enumerate(testBoundaries):
trainingPointArray[index] = np.array(sentenceBoundary.getArray())
return trainingPointArray