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

Example of how to use .make_sentence(init_state = something)? #125

Closed
JGCoelho opened this issue Apr 23, 2020 · 2 comments
Closed

Example of how to use .make_sentence(init_state = something)? #125

JGCoelho opened this issue Apr 23, 2020 · 2 comments

Comments

@JGCoelho
Copy link

What exactly must be the format of the something? I tried putting a string of a word, putting a tuple with the word, putting a list with the word. Despite trying a lot of formats i keep getting this error

line 213, in make_sentence
    words = prefix + self.chain.walk(init_state)
  File "C:\Users\JGC\AppData\Local\Programs\Python\Python37\lib\site-packages\markovify\chain.py", line 137, in walk
    return list(self.gen(init_state))
  File "C:\Users\JGC\AppData\Local\Programs\Python\Python37\lib\site-packages\markovify\chain.py", line 126, in gen
    next_word = self.move(state)
  File "C:\Users\JGC\AppData\Local\Programs\Python\Python37\lib\site-packages\markovify\chain.py", line 112, in move
    choices, weights = zip(*self.model[state].items())
KeyError: 'was'

I'm using markovify 0.8.0 on a python 3.7 environment.

@jsvine
Copy link
Owner

jsvine commented Apr 24, 2020

It's difficult to debug this without the code and the corpus you're using. Can you provide that?

@JGCoelho
Copy link
Author

Sorry, forgot to include the code. I was trying to make a short sentence with a start, like that:

text = open("samples\\asoiaf.txt","r",encoding = "utf-8")
model = markovify.Text(text)
model.make_short_sentence(init_state = "was", max_chars = 40)

But i have noticed the error: only make_sentence has a parameter init_state, this parameter doesn't exists inside make_short_sentence, hence the error. So i guess i will need to override this method to introduce a new parameter.

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

2 participants