jsvine / jsvine/markovify

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

Open
#180 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
3.4k
Forks
348
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with markovify/text.py at make_sentence and follow the call into chain.py, especially walk, gen, and move, using the traceback as the entry point. Reproduce the reported seed input and inspect how the initial state is formed. Done means conditioning generation on a user-provided seed is supported without the shown KeyError, with the expected behavior covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.