markov: try harder to get a right len sentence
this puts additional pressure on the sentence generator, retrying many times to get something that's long but not too long. only testing on a small context so far, so this is certainly not yet ready to go live, but the results are pretty good so far
This commit is contained in:
		
							parent
							
								
									897f29c8d4
								
							
						
					
					
						commit
						db3e2a27a0
					
				| @ -34,7 +34,7 @@ def generate_line(context, topics=None, min_words=15, max_words=30, max_sentence | ||||
|     return line | ||||
| 
 | ||||
| 
 | ||||
| def generate_longish_sentence(context, topics=None, min_words=15, max_words=30, max_tries=5): | ||||
| def generate_longish_sentence(context, topics=None, min_words=15, max_words=30, max_tries=100): | ||||
|     """Generate a Markov chain, but throw away the short ones unless we get desperate.""" | ||||
| 
 | ||||
|     sent = "" | ||||
| @ -114,6 +114,11 @@ def generate_sentence(context, topics=None, min_words=15, max_words=30): | ||||
|     words = [word for word in words if word not in | ||||
|              (MarkovState._start1, MarkovState._start2, MarkovState._stop)] | ||||
| 
 | ||||
|     # if what we found is too long, abandon it, sadly | ||||
|     if len(words) > max_words: | ||||
|         log.debug("%s is too long, i'm going to give up on it", words) | ||||
|         words.clear() | ||||
| 
 | ||||
|     return words | ||||
| 
 | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user