home *** CD-ROM | disk | FTP | other *** search
/ The Unsorted BBS Collection / thegreatunsorted.tar / thegreatunsorted / misc / markv.doc < prev    next >
Text File  |  1991-10-16  |  14KB  |  316 lines

  1.  
  2.                         Mark V. Shaney V1.3
  3.                    a probabilistic text generator
  4.                   Copyright (c) 1991 Stefan Strack
  5.                Internet: stracks@ctrvax.vanderbilt.edu
  6.                       Bitnet: stracks@vuctrvax
  7.                          released 11/01/91
  8.  
  9.  
  10. You may copy this program freely, provided you leave the program and this
  11. documentation unchanged. You may not charge more than the cost of the media
  12. for its distribution. I disclaim all liabilities for any damages or loss of
  13. data incurred by using this program. Comments and suggestions to the above
  14. email-addresses are appreciated.
  15.  
  16.  
  17. --------------------
  18. Origin
  19.  
  20. Mark V. Shaney featured in the "Computer Recreations" column by A.K.Dewdney
  21. in Scientific American. The original program (for a mainframe, I believe)
  22. was written by Bruce Ellis based on an idea by Don P. Mitchell. Dewdney tells
  23. the amusing story of a riot on net.singles when Mark V. Shaney's ramblings
  24. were unleashed.
  25.  
  26.  
  27. --------------------
  28. Who is Mark V. Shaney?
  29.  
  30. Mark V. Shaney produces a confused imitation of style and contents of a piece 
  31. of writing. Mark reads the original text and builds a "word probability 
  32. table" that reflects the probability of a word following a sequence of words.  
  33. In output mode, Mark will generate random text weighed by the probabilities 
  34. in this table (a so-called Markov chain, hence Mark's name). Since Mark 
  35. considers punctuation as part of the word, he is likely to produce 
  36. grammatical sentences, albeit a caricature of the original text. Mark V.  
  37. Shaney is in the same league with the famous ELIZA and RACTER programs, and 
  38. shows that you don't need AI for "almost human" writing. This implementation 
  39. of Mark V. Shaney allows you to vary the "randomness" of the text output and 
  40. supports huge probability tables in expanded memory or on disk. Version 1.0 
  41. of this program was posted on comp.binaries.ibm.pc in June 91.
  42.  
  43.  
  44. --------------------
  45. New in Version 1.3
  46.  
  47.      *  Text reading and generating is slightly faster than in V1.0. A
  48.         "percent done" counter displays the progress of text reading.
  49.  
  50.      *  "Keywords" can be specified to focus Mark V. Shaney's ramblings on a
  51.         particular topic.
  52.  
  53.      *  A "maximum word length" command line parameter /L# was added. /L1 for
  54.         example tells Mark to create a frequency table for single characters.
  55.         Small values for L create interesting "foreign language" versions of
  56.         the original text.
  57.  
  58.  
  59. --------------------
  60. What the program runs on
  61.  
  62. A 640K AT system with a hard disk is recommended as the minimum
  63. configuration, although it is possible to run Mark V. Shaney on a lower-end
  64. machine.  If you have memory above 640K and an expanded memory driver
  65. installed, Mark V. Shaney will try to use it.
  66.  
  67.  
  68. --------------------
  69. Using the program
  70.  
  71. Type MARKV to start Mark V. Shaney. The menu on the bottom line of the screen
  72. gives you the following choices invoked by pressing their first letter:
  73.  
  74.         Read text
  75.  
  76.         The program will prompt you for a text file to read, building a word
  77.         probability table as it goes along. Text files should not contain
  78.         control or formatting characters other than tabs and carriage
  79.         return/line feeds. Reading is very slow and can take several minutes
  80.         for large files. Speed can be improved by increasing the number of
  81.         DOS buffers in CONFIG.SYS. The bottle neck seems to be the CPU, which
  82.         means you won't gain much from reading from a RAM drive.  You can
  83.         repeat this command to build a table from several text files. Reading
  84.         will stop if you press any key.
  85.  
  86.  
  87.         Generate text
  88.  
  89.         After you created a working probability table by either reading text
  90.         files or loading a saved table, "Generate text" will start the
  91.         probabilistic text generator. You are prompted for a file to append
  92.         the text output to. If you press <Return>, output will go to the
  93.         screen. You are then given the option to start the Markov chain with
  94.         a word other than the default, the first word of the input text.
  95.         Mark's ramblings will word-wrap automatically; no other formatting is
  96.         done. The output will stop, when (a) Mark comes across a word that is
  97.         the last word in one of the input texts, or (b) you press <Escape>.
  98.         You can pause and continue output by pressing any key.
  99.  
  100.  
  101.         Load table
  102.  
  103.         Once a probability table has been build, it can be saved to a file
  104.         (see Save table). "Load table" prompts you for a table to be
  105.         retrieved from disk. This is somewhat faster than re-creating the
  106.         table from scratch by reading the original text files again. The
  107.         down-side is that saved tables are huge.
  108.  
  109.  
  110.         Save table
  111.  
  112.         Saves the probability table to disk.
  113.  
  114.  
  115.         Keywords
  116.  
  117.         Keywords are used to control the flow of Mark V. Shaney's ramblings.  
  118.         By specifying a keyword and an associated integer emphasis-factor,
  119.         you can increase or decrease the probability with which this word
  120.         will occur in the output. E.g. an emphasis-factor of 3 will triple
  121.         the chances that a keyword will appear in the generated text. An
  122.         emphasis-factor of 0 de-emphasizes a word completely. Keywords often
  123.         have little impact on the output text, because they will affect
  124.         Mark's chaining only if they occur as one of two or more choices.
  125.         Keywords will be more effective for longer texts and lower order
  126.         (/O#) and length (/L#) values (see below). After selecting "Keywords"
  127.         from the menu, you are given the option of clearing all existing
  128.         keywords. This is followed by a prompt for a file name from which to
  129.         read the keyword list. Hitting <Enter> lets you input keywords
  130.         interactively. Keyword lists consist of alternating lines of the
  131.         keyword itself and its emphasis-factor. Specifying keywords does not
  132.         actually modify the frequency table; rather, weighted probabilities
  133.         are calculated "on the fly" during output generation. Mark needs to
  134.         have read some text before you can define keywords.
  135.  
  136.  
  137.         Quit
  138.  
  139.         Exits the program.
  140.  
  141.  
  142.         >
  143.  
  144.         Hitting the greater-than symbol starts a DOS shell. Type 'EXIT' at
  145.         the DOS prompt to return to Mark V. Shaney.
  146.  
  147.  
  148. --------------------
  149. Command line options
  150.  
  151.         MARKV [-e|m|d[d:path]] [-o#] [-l#] [-s#]
  152.  
  153.                 -e              use EMS (default)
  154.                 -m              use conventional memory
  155.                 -d[d:path]      use disk
  156.                 -o#             set order to # (default 2)
  157.                 -l#             set max. word length to # (default 255)
  158.                 -s#             set random number seed to #
  159.  
  160.         These options are explained in the next sections. Mark will also
  161.         accept the slash (/) character instead of the hyphen, or simply the
  162.         option letter by itself.
  163.  
  164.  
  165. --------------------
  166. The Markov order parameter
  167.  
  168. The order (O) and maximum word length (L) options allow changing the
  169. randomness of Mark V. Shaney's text output. The order parameter specifies the
  170. degree of "grammatical correctness", whereas the length option controls
  171. Mark's "orthography". Interesting effects can be obtained by varying both
  172. parameters together.
  173.  
  174. In the original description of Mark V. Shaney's algorithm, the Markov order
  175. is 2. This means that the program breaks down an input text into pairs of
  176. words, and calculates the probability of a third word following a given pair
  177. of words. The probability table then looks like this:
  178.  
  179.      order 2
  180.  
  181.                  \Next Word
  182.         Word seq  \   A       B       C        D       ..
  183.         ---------------------------------------------------
  184.             AB     |  0.0     0.02    0.08     0.15    ..
  185.             BC     |  0.0     0.0     0.0      0.02    ..
  186.             CD     |  0.02    0.22    0.0      0.0     ..
  187.             DE     |  0.1     0.06    0.03     0.0     ..
  188.             ..     |  ..      ..      ..       ..      ..
  189.  
  190. Mark allows you to choose the order, i.e. the number of words that make up a
  191. word sequence, with the command line option -o#.
  192.  
  193. E.g.:   MARKV -O3
  194.  
  195. After reading a text, this results in the following probability table:
  196.  
  197.      order 3
  198.  
  199.                  \Next Word
  200.         Word seq  \   A       B       C       D       ..
  201.         --------------------------------------------------
  202.             ABC    |  0.01    0.0     0.0     0.02    ..
  203.             BCD    |  0.0     0.0     0.0     0.0     ..
  204.             CDE    |  0.04    0.01    0.0     0.0     ..
  205.             DEF    |  0.02    0.0     0.08    0.0     ..
  206.             ..     |  ..      ..      ..      ..      ..
  207.  
  208. Similarly, -o1 breaks down an input text into word sequences of length 1. The
  209. order can be any number greater than or equal 1. Word sequences of longer
  210. than 3 are not very interesting, since Mark V. Shaney will essentially
  211. re-create the original text when in output mode.
  212.  
  213. In general, large order values produce low variability in the output text.
  214. Also, large input texts tend to result in more diverse output. You can create
  215. a sufficiently variable output from a short text sample with order=1.
  216.  
  217. Table creation speed is largely independent of the order value, whereas table
  218. size increases with order value.
  219.  
  220.  
  221. --------------------
  222. The maximum word length option
  223.  
  224. By default, Mark V. Shaney parses input text into words, i.e.
  225. variable-length strings delimited by white-space characters (space, tab and
  226. newline). Mark will produce non-english output if you set the maximum word
  227. length (L) parameter to a value shorter than the average length of words in
  228. the input text. E.g. if Mark is invoked with
  229.  
  230. MARKV -L2
  231.  
  232. and the word "again" appears in the input, Mark breaks the word up into
  233. strings of length 2 or shorter, i.e. "ag", "ai" and "n". The frequency table
  234. is then updated according to the current setting for the Markov order
  235. parameter with these short strings as entries. Similarly, -L1 builds a table
  236. of character frequencies. Tables built with low values for L (< 3) give rise
  237. to foreign-sounding output with often ludicrous word concoctions.
  238. Specifying keywords has a large impact on output from low L-value tables; by
  239. emphasizing or de-emphasizing certain vowels or consonants or combinations
  240. thereof you can change the "sound" of Mark's ramblings dramatically.
  241.  
  242. Text reading is slowest for small L values. The size of the frequency table
  243. generally increases with increasing L values. Text playback depends on the
  244. structure of the current probability table, but is independent of the value
  245. of the order or length parameters with which the program was invoked.
  246.  
  247.  
  248. --------------------
  249. Storage options
  250.  
  251. MARKV.EXE is able to use EMS memory or a disk for storing huge probability
  252. tables. The location of the working probability table can be specified by one
  253. of the following options:
  254.  
  255. MARKV -E
  256.  
  257. This tells Mark to use expanded memory if available; this is also the
  258. default. If expanded memory is not available, the table will reside in
  259. conventional memory. 1 MB of EMS allows you to process about 110K of text
  260. input.
  261.  
  262. MARKV -M
  263.  
  264. Mark will keep the table in conventional memory along with the program code.
  265. On a 640K machine, this gives you room for processing approx. 40K of original
  266. text.
  267.  
  268. MARKV -D[Drive:Path]
  269.  
  270. Mark uses the disk to store the working probability table. The optional 
  271. Drive:Path specifies were the temporary file is to be stored. This is the 
  272. slowest option, but you can speed up processing greatly by specifying a RAM 
  273. drive. The amount of input text that can be processed is limited only by the
  274. available disk space.  Example: MARKV -DE: will set up temporary disk storage
  275. on drive E:.
  276.  
  277.  
  278. --------------------
  279. The random number seed option
  280.  
  281. Mark will initialize the random number generator by reading the system time
  282. at program start. This makes sure that the random output is different every
  283. time you use the same probability table. In case you see some particularly
  284. interesting output scrolling off screen, you may wish to restart the program
  285. under identical conditions. For this purpose, Mark displays the number that
  286. initialized the random number generator when you exit the program. You can
  287. then provide this seed on the command line as in
  288.  
  289. MARKV -S12345
  290.  
  291. to re-create a previous run.
  292.  
  293.  
  294. --------------------
  295. Sources of text
  296.  
  297. The larger the input text, the more diversified will be Mark V. Shaney's
  298. ramblings. With a Markov order of 2, a 15 to 30K text will produce a varied,
  299. but still comprehensible output. Good choices for input text are: personal
  300. letters, text books, childrens' books, simple narratives, poems (anything
  301. made up of simple, short sentences). Poor choices are texts containing
  302. incomplete or complicated sentences with special terminology (technical
  303. writing, program documentation (this one's especially poor :-) )).
  304.  
  305.  
  306. --------------------
  307. Implementation
  308.  
  309. The source for Mark V. Shaney is ca. 500 lines of code written in PDC Prolog
  310. V3.21. Word probability tables are stored in external databases. The
  311. dictionary (list of unique words) and frequency table are hashed to speed up
  312. table generation, and cross-referenced for text output in constant time. I
  313. designed this program for flexibility (i.e. adjustable order and word length)
  314. and speedy output generation. The trade-offs are relatively slow text
  315. scanning and large memory/disk space requirements.
  316.