Skip to content

Commit

Permalink
Merge pull request #3 from breznak/story-teller
Browse files Browse the repository at this point in the history
Story teller - randomized start of new sentence
  • Loading branch information
chetan51 committed Nov 17, 2013
2 parents 642606d + d2eb7ac commit 8fa3194
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
24 changes: 16 additions & 8 deletions client/linguist.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@
from nupic.frameworks.opf.modelfactory import ModelFactory
import model_params
import re
import random


NUM_REPEATS = 5
PRINT_EVERY_REPEAT_N = 1

TERMINATORS = ['.','!','?','|']
TERMINATORS = ['.','!','?','|','\n']
NUM_SENTENCES = 5 # number for story sentences generated
STORY_START = "The dog"
_QUIT = "QUIT"
Expand Down Expand Up @@ -117,19 +119,25 @@ def tellStory(model, startSent, lenght):
print(c),
modelInput = {'letter': c}
result = model.run(modelInput)
c=result.inferences['prediction'][0]

c=result.inferences['prediction'][0] # bug in model randomization of same-probability states
#print "c=",c
sentence_len += 1
if(sentence_len > 30): #limit, sometimes there's no sentence terminator generated and we'd run forever
numSent += 1
sentence_len = 0

if c in TERMINATORS:
if (c in TERMINATORS) or (sentence_len > 30): #limit, sometimes there's no sentence terminator generated and we'd run forever
# new sentence
numSent += 1
sentence_len = 0
print(' \n')
c = _generateRandomStartingLetter()


###################################################################
def _generateRandomStartingLetter():
"""generates a random starting letter for sequence after the RESET.
TODO: add probability based distribution later"""
return chr(random.randint(65,90)) # A-Z == chr(65)-chr(90)


###################################################################
if __name__ == "__main__":
if len(sys.argv) > 1:
datapath = sys.argv[1]
Expand Down
6 changes: 3 additions & 3 deletions client/model_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@
# elements to append to the end of a learned sequence at a time.
# Smaller values are better for datasets with short sequences,
# higher values are better for datasets with long sequences.
'pamLength': 5,
'pamLength': 6,
},

'clParams': {
Expand All @@ -240,14 +240,14 @@

# This controls how fast the classifier learns/forgets. Higher values
# make it adapt faster and forget older patterns faster.
'alpha': 0.01080959960713530062,
'alpha': 0.001080959960713530062,

# 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',
},

'trainSPNetOnlyIfRequested': True,
'trainSPNetOnlyIfRequested': False,
},
}

0 comments on commit 8fa3194

Please sign in to comment.