-
Notifications
You must be signed in to change notification settings - Fork 0
/
markov-text-generator.html
262 lines (212 loc) · 11.4 KB
/
markov-text-generator.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="HandheldFriendly" content="True" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="robots" content="index, follow" />
<link href="https://fonts.googleapis.com/css2?family=Source+Code+Pro:ital,wght@0,400;0,700;1,400&family=Source+Sans+Pro:ital,wght@0,300;0,400;0,700;1,400&display=swap" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="https://www.evandowning.com/theme/stylesheet/style.min.css">
<link id="dark-theme-style" rel="stylesheet" type="text/css"
media="(prefers-color-scheme: dark)"
href="https://www.evandowning.com/theme/stylesheet/dark-theme.min.css">
<link id="pygments-dark-theme" rel="stylesheet" type="text/css"
media="(prefers-color-scheme: dark)"
href="https://www.evandowning.com/theme/pygments/monokai.min.css">
<link id="pygments-light-theme" rel="stylesheet" type="text/css"
media="(prefers-color-scheme: light), (prefers-color-scheme: no-preference)"
href="https://www.evandowning.com/theme/pygments/monokai.min.css">
<link rel="stylesheet" type="text/css" href="https://www.evandowning.com/theme/font-awesome/css/fontawesome.css">
<link rel="stylesheet" type="text/css" href="https://www.evandowning.com/theme/font-awesome/css/brands.css">
<link rel="stylesheet" type="text/css" href="https://www.evandowning.com/theme/font-awesome/css/solid.css">
<link rel="stylesheet" type="text/css" href="https://www.evandowning.com/static/custom.css">
<link rel="shortcut icon" href="https://www.evandowning.com/images/favicon.ico" type="image/x-icon">
<link rel="icon" href="https://www.evandowning.com/images/favicon.ico" type="image/x-icon">
<!-- Chrome, Firefox OS and Opera -->
<meta name="theme-color" content="#333333">
<!-- Windows Phone -->
<meta name="msapplication-navbutton-color" content="#333333">
<!-- iOS Safari -->
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<!-- Microsoft EDGE -->
<meta name="msapplication-TileColor" content="#333333">
<link href="https://www.evandowning.com/feeds/all.atom.xml" type="application/atom+xml" rel="alternate" title="Evan Downing Atom">
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-C0W4PHDF8Y"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-C0W4PHDF8Y');
</script>
<meta name="author" content="Evan Downing" />
<meta name="description" content="For fun, I've recently created my own Markov text generator. Explanation A Markov text generator takes a piece of text as input and outputs new text that is seemingly random. It may even make syntactical and/or semantic sense if properly seeded with input text. It accomplishes this by splitting …" />
<meta name="keywords" content="markov">
<meta property="og:site_name" content="Evan Downing"/>
<meta property="og:title" content="Markov Text Generator"/>
<meta property="og:description" content="For fun, I've recently created my own Markov text generator. Explanation A Markov text generator takes a piece of text as input and outputs new text that is seemingly random. It may even make syntactical and/or semantic sense if properly seeded with input text. It accomplishes this by splitting …"/>
<meta property="og:locale" content="en_US"/>
<meta property="og:url" content="https://www.evandowning.com/markov-text-generator.html"/>
<meta property="og:type" content="article"/>
<meta property="article:published_time" content="2016-01-16 00:00:00-05:00"/>
<meta property="article:modified_time" content="2016-01-16 00:00:00-05:00"/>
<meta property="article:author" content="https://www.evandowning.com/author/evan-downing.html">
<meta property="article:section" content="coding-fun"/>
<meta property="article:tag" content="markov"/>
<meta property="og:image" content="https://www.evandowning.com/images/profile.png">
<title>Evan Downing – Markov Text Generator</title>
</head>
<body >
<aside>
<div>
<a href="https://www.evandowning.com/">
<img src="https://www.evandowning.com/images/profile.png" alt="Evan Downing" title="Evan Downing">
</a>
<h1>
<a href="https://www.evandowning.com/">Evan Downing</a>
</h1>
<p>Cybersecurity Researcher</p>
<nav>
<ul class="list">
<li>
<a target="_self"
href="https://www.evandowning.com/pages/about.html">
About
</a>
</li>
<li>
<a target="_self"
href="https://www.evandowning.com/pages/projects.html">
Projects
</a>
</li>
<li>
<a target="_self" href="https://docs.google.com/document/d/1sKsh88ZiiveotGS-KR4l-vESgfj_U_JifvH6nGat-Wk" >Resume</a>
</li>
<li>
<a target="_self" href="https://docs.google.com/document/d/1UcXkHeRCKpBvlf4KyW92GKjyEeoiPgXGdW7ARPSa2L4" >CV</a>
</li>
</ul>
</nav>
<ul class="social">
<li>
<a class="sc-github"
href="https://github.com/evandowning"
target="_blank">
<i class="fa-brands fa-github"></i>
</a>
</li>
<li>
<a class="sc-google"
href="https://scholar.google.com/citations?user=SnJNwIAAAAAJ&hl=en"
target="_blank">
<i class="fa-brands fa-google"></i>
</a>
</li>
<li>
<a class="sc-linkedin"
href="https://www.linkedin.com/in/evandowning/"
target="_blank">
<i class="fa-brands fa-linkedin"></i>
</a>
</li>
<li>
<a class="sc-mixcloud"
href="https://www.mixcloud.com/evandowning/"
target="_blank">
<i class="fa-brands fa-mixcloud"></i>
</a>
</li>
</ul>
</div>
</aside>
<main>
<nav>
<a href="https://www.evandowning.com/">Home</a>
<a href="/archives.html">Archives</a>
<a href="/categories.html">Categories</a>
<a href="/tags.html">Tags</a>
<a href="https://www.evandowning.com/feeds/all.atom.xml">Atom</a>
</nav>
<article class="single">
<header>
<h1 id="markov-text-generator">Markov Text Generator</h1>
<p>
Posted on January 16, 2016 in <a href="https://www.evandowning.com/category/coding-fun.html">coding-fun</a>
• 2 min read
</p>
</header>
<div>
<p>For fun, I've recently created my own <a href="https://en.wikipedia.org/wiki/Markov_chain">Markov</a> text generator.</p>
<h2>Explanation</h2>
<p>A Markov text generator takes a piece of text as input and outputs new text that is seemingly random. It may even make syntactical and/or semantic sense if properly seeded with input text.</p>
<p>It accomplishes this by splitting the inputted text into tokens based on some separation character. This can result in individual characters or sequences of characters (recognized as words if the separation character is a space).</p>
<p>It then creates a chain of these tokens based on the order of their appearance in the text. The length of this chain is chosen by the generator's user. It then adds the token appearing immediately after this chain of tokens to a list that is associated with that particular chain of tokens. Repeating this process for all inputted text creates the Markov chain.</p>
<p>To generate the random text, the program chooses a chain of tokens as the starting point of the output text.</p>
<p>It then chooses a random token from the list of tokens associated with the chain and add that token to the output text.</p>
<p>After, it extends the chain of tokens to include this next token while removing the first token from the chain. This creates a new chain of tokens to then choose another random token from the list associated with the chain.</p>
<p>After some determined stopping point, the generator ceases to create more text.</p>
<h2>Example</h2>
<p>So, let's say I have the input text "I like bananas and apples and oranges."</p>
<p>Let's say I want to split this text by spaces, isolating the words and character(s) that come immediately after the word.</p>
<p>I also want the chain's length (chain-size from 'Features' above) to be 1.</p>
<p>So the following chain would be created with its associated next tokens:</p>
<p>chain of tokens: list of tokens coming after the chain in the text</p>
<div class="highlight"><pre><span></span><code>"I": ["like"]
"like": ["bananas"]
"bananas": ["and"]
"and": ["apples", "oranges."]
"apples": ["and"]
As you can see, the chain "and" has two different words it sees after it in the sentence.
</code></pre></div>
<p>So, there's a 50% probability that "apples" or "oranges." will come after the word "and" according to this sentence. However, with the other words there is a 100% probability that the next word will be the only one contained in their list.</p>
<p>You can imagine how more text and chains with lengths greater than 1 will lead to more random and original sentences.</p>
<p>Suppose we don't have any separation. Doing this by character makes it more interesting. It will generate more random words, some misspelled because of the random aspects of chain, and will make less semantic sense than creating chains via words (characters separated by a space).</p>
<p>Here is a link to it: <a href="https://github.com/evandowning/markov-text-generator">https://github.com/evandowning/markov-text-generator</a></p>
</div>
<div class="tag-cloud">
<p>
<a href="https://www.evandowning.com/tag/markov.html">markov</a>
</p>
</div>
</article>
<footer>
<p>
© 2024 - This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/deed.en_US" target="_blank">Creative Commons Attribution-ShareAlike 4.0 International License</a>
</p>
<p>
Built with <a href="http://getpelican.com" target="_blank">Pelican</a> using <a href="http://bit.ly/flex-pelican" target="_blank">Flex</a> theme
<span class="footer-separator">|</span>
Switch to the <a href="javascript:void(0)" onclick="theme.switch(`dark`)">dark</a> | <a href="javascript:void(0)" onclick="theme.switch(`light`)">light</a> | <a href="javascript:void(0)" onclick="theme.switch(`browser`)">browser</a> theme
<script id="dark-theme-script"
src="https://www.evandowning.com/theme/dark-theme/dark-theme.min.js"
data-enable-auto-detect-theme="True"
data-default-theme="light"
type="text/javascript">
</script>
</p><p>
<a rel="license"
href="http://creativecommons.org/licenses/by-sa/4.0/"
target="_blank">
<img alt="Creative Commons License"
title="Creative Commons License"
style="border-width:0"
src="https://i.creativecommons.org/l/by-sa/4.0/80x15.png"
width="80"
height="15"/>
</a>
</p></footer> </main>
<script type="application/ld+json">
{
"@context" : "http://schema.org",
"@type" : "Blog",
"name": " Evan Downing ",
"url" : "https://www.evandowning.com",
"image": "https://www.evandowning.com/images/profile.png",
"description": ""
}
</script>
</body>
</html>