Skip to content

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

Open
@wsricardo

Description

@wsricardo

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')

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions