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

Markovify - Markov chain : Seed and Condition to text generated based in input. #180

Open
wsricardo opened this issue Jun 8, 2023 · 2 comments

Comments

@wsricardo
Copy link

How can I condition the text generation given a previous input.

Example: After creating the model, I pass a 'seed' (a small string) so that the generated sentence is a response based on the text considering a 'seed' given by the user.

I tried to use the 'make_sentence' function passing a string and a list of strings but I got the error below

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/user/studyvenv/lib/python3.10/site-packages/markovify/text.py", line 231, in make_sentence
    words = prefix + self.chain.walk(init_state)
  File "/home/user/studyvenv/lib/python3.10/site-packages/markovify/chain.py", line 142, in walk
    return list(self.gen(init_state))
  File "/home/user/studyvenv/lib/python3.10/site-packages/markovify/chain.py", line 130, in gen
    next_word = self.move(state)
  File "/home/user/studyvenv/lib/python3.10/site-packages/markovify/chain.py", line 116, in move
    choices, weights = zip(*self.model[state].items())
KeyError: ('Hi.', 'How are you')

@jsvine
Copy link
Owner

jsvine commented Jun 13, 2023

Hi @wsricardo, and thanks for your interest in this library. Without access to the code or text corpus you're using, it's a bit hard to diagnose your issue definitively. But the issue appears to be that the prompt (('Hi.', 'How are you')) cannot be found in the corpus because it spans two sentences, while the default model first decomposes each corpus into single sentences. Is that helpful guidance? If not, could you provide more information and examples?

@wsricardo
Copy link
Author

Hi @jsvine ,

I search 'function' in module to return response based user input to prompt. I don't remember that exactly a I use this function. Thank you very much to answer.

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