Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ print(combined_model.make_sentence())
- [fakesocial](https://fakesocial.net), Fake social network using generated content. [[code](https://github.com/berfr/fakesocial)]
- [Slovodel Bot](https://github.com/weiss-d/slovodel-bot), a Telegram bot that generates non-existent Russian words using corpus made by algorithmically dividing existent words into syllables.
- [Deuterium](https://github.com/portasynthinca3/deuterium) is a Discord bot that generates messages on its own, after analyzing yours, and learning constantly. There's also a global model shared with all other servers.
- [Markovify Piano](https://github.com/asigalov61/Markovify-Piano) Coherent and plausible Piano music generation with Markov-chain/model.

Have other examples? Pull requests welcome.

Expand Down
4 changes: 3 additions & 1 deletion markovify/chain.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import random
import secrets
import operator
import bisect
import json
Expand Down Expand Up @@ -111,7 +112,8 @@ def move(self, state):
else:
choices, weights = zip(*self.model[state].items())
cumdist = list(accumulate(weights))
r = random.random() * cumdist[-1]
# r = random.random() * cumdist[-1]
r = secrets.choice([random.random(), random.random()]) * cumdist[-1]
selection = choices[bisect.bisect(cumdist, r)]
return selection

Expand Down
5 changes: 4 additions & 1 deletion markovify/text.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import re
import json
import random
import secrets
from .splitters import split_into_sentences
from .chain import Chain, BEGIN, END
from unidecode import unidecode
Expand Down Expand Up @@ -262,7 +263,9 @@ def make_sentence_with_start(self, beginning, strict=True, **kwargs):
# check for starting with begin as well ordered lists
if tuple(filter(lambda x: x != BEGIN, key))[:word_count] == split ]

random.shuffle(init_states)
#random.shuffle(init_states)
for i in range(secrets.choice([1, 2])):
random.shuffle(init_states)
else:
err_msg = "`make_sentence_with_start` for this model requires a string containing 1 to {0} words. Yours has {1}: {2}".format(self.state_size, word_count, str(split))
raise ParamError(err_msg)
Expand Down