jsvine / markovify

A simple, extensible Markov chain generator.
MIT License
3.31k stars 350 forks source link

markov_text_model.make_sentence_with_start KeyError #161

Open asigalov61 opened 3 years ago

asigalov61 commented 3 years ago

KeyError Traceback (most recent call last)

in () 25 out = markov_text_model.make_sentence_with_start(' '.join(TXT[10:12]), strict=True, min_chars=minimum_number_of_characters_to_generate, 26 tries=number_of_cycles_to_try_to_generate_desired_result, ---> 27 max_overlap_ratio=overlap_ratio) 28 else: 29 out = markov_text_model.make_sentence() 4 frames /content/tegridy-tools/tegridy-tools/markovify.py in make_sentence_with_start(self, beginning, strict, **kwargs) 516 517 for init_state in init_states: --> 518 output = self.make_sentence(init_state, **kwargs) 519 if output is not None: 520 return output /content/tegridy-tools/tegridy-tools/markovify.py in make_sentence(self, init_state, **kwargs) 460 461 for _ in range(tries): --> 462 words = prefix + self.chain.walk(init_state) 463 if (max_words != None and len(words) > max_words) or (min_words != None and len(words) < min_words): 464 continue # pragma: no cover # see https://github.com/nedbat/coveragepy/issues/198 /content/tegridy-tools/tegridy-tools/markovify.py in walk(self, init_state) 166 (as a tuple). 167 """ --> 168 return list(self.gen(init_state)) 169 170 def to_json(self): /content/tegridy-tools/tegridy-tools/markovify.py in gen(self, init_state) 155 state = init_state or (BEGIN,) * self.state_size 156 while True: --> 157 next_word = self.move(state) 158 if next_word == END: break 159 yield next_word /content/tegridy-tools/tegridy-tools/markovify.py in move(self, state) 135 """ 136 if self.compiled: --> 137 choices, cumdist = self.model[state] 138 elif state == tuple([ BEGIN ] * self.state_size): 139 choices = self.begin_choices KeyError: ('___BEGIN__', '田疭畩', '疭疭畩'
asigalov61 commented 3 years ago

Its works great with strict=False but if you set it to True you get the above debug