Skip to content

Commit

Permalink
story teller
Browse files Browse the repository at this point in the history
  • Loading branch information
breznak committed Nov 16, 2013
1 parent bef1c2d commit 0ec5509
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
30 changes: 27 additions & 3 deletions client/linguist.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
import model_params
import re

NUM_REPEATS = 1000
NUM_REPEATS = 1
PRINT_EVERY_REPEAT_N = 1
TERMINATORS = ['.','!','?','|']

def clean(s):
return re.sub('\n', '|', s)
Expand Down Expand Up @@ -83,16 +84,39 @@ def runLinguist(datapath):

modelInput = {'letter': c}
result = model.run(modelInput)

if should_print:
print "[%i]\t %s ==> %s\t(%s)" % (i, clean(modelInput['letter']), prediction(result.inferences), confidences(result.inferences))
if c in TERMINATORS:
model.resetSequenceStates()
print "reset"

i += 1

return model

def tellStory(model, startSent, lenght):
for s in startSent:
print(s)
modelInput = {'letter': s}
result = model.run(modelInput)

numSent = 0
c = s
while numSent <= lenght:
print c
modelInput = {'letter': c}
result = model.run(modelInput)
print(result)
print(result.inferences)
if c in TERMINATORS:
numSent += 1



if __name__ == "__main__":
if len(sys.argv) > 1:
datapath = sys.argv[1]
runLinguist(datapath)
model = runLinguist(datapath)
tellStory(model, 'The dog ', 5)
else:
print "Usage: python linguist.py [path/to/data.txt]"
3 changes: 2 additions & 1 deletion client/model_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@

# This is set after the call to updateConfigFromSubConfig and is
# computed from the aggregationInfo and predictAheadTime.
'steps': '1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16',
#'steps': '1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16',
'steps': '1',
},

'trainSPNetOnlyIfRequested': True,
Expand Down

0 comments on commit 0ec5509

Please sign in to comment.