Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using make_sentence_with_start? #15

Closed
ghost opened this issue Apr 19, 2016 · 5 comments
Closed

using make_sentence_with_start? #15

ghost opened this issue Apr 19, 2016 · 5 comments

Comments

@ghost
Copy link

ghost commented Apr 19, 2016

What is the proper way to call this function? When I try to pass a string of two words I get an error:

Also, is there a way to feed with only one words? Like Say I want the generated text to start with "You", is there a way to do this?

Thank you

Traceback (most recent call last):
  File "reddit.py", line 6, in <module>
    print(text_model.make_sentence_with_start('you need'))
  File "C:\Python3\lib\site-packages\markovify\text.py", line 139, in make_sentence_with_start
    return self.make_sentence(init_state, **kwargs)
  File "C:\Python3\lib\site-packages\markovify\text.py", line 122, in make_sentence
    words = prefix + self.chain.walk(init_state)
  File "C:\Python3\lib\site-packages\markovify\chain.py", line 98, in walk
    return list(self.gen(init_state))
  File "C:\Python3\lib\site-packages\markovify\chain.py", line 87, in gen
    next_word = self.move(state)
  File "C:\Python3\lib\site-packages\markovify\chain.py", line 73, in move
    choices, weights = zip(*self.model[state].items())
KeyError: ('you', 'need')
@jsvine
Copy link
Owner

jsvine commented Apr 19, 2016

Hiya, @QuadCityCJ. Thanks for pasting the error. Based on that, it looks like there aren't any sentences in your corpus that begins with "you need". It's worth trying "You need", or simply "You". Does those work?

@ghost
Copy link
Author

ghost commented Apr 19, 2016

@jsvine Tried with a bunch of different combinations while looking at my corpus and I keep receiving the same error.

@jsvine
Copy link
Owner

jsvine commented Apr 19, 2016

Hmmm, strange. Could you send over the corpus and code? Happy to take a look. Email is jsvine@gmail.com

@ghost
Copy link
Author

ghost commented Apr 19, 2016

@jsvine Ahh I actually figured it out. I had the state_size set to 3 and it was throwing errors.

@jsvine
Copy link
Owner

jsvine commented Apr 19, 2016

Ah, makes sense! I'll add a to-do to throw a more constructive/descriptive error in those cases.

@jsvine jsvine closed this as completed Apr 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant