Code Monkey home page Code Monkey logo

markovtext's Introduction

MarkovText

Text Generation through Markov Chains

SO this is my Markov text generator - I wrote this to learn about Markov Chains and to create a twitter bot at a later stage. Here's how to use the code.

Training Data

There are some data sets that have been provided in there which have been scoured from the web. What's included: 1. Script files from the West Wing with just Jed Bartlet quotes in a single file (there's a python script that pulls that out) 2. Eddie Murphy scripts - cleaned up 3. Obama Speeches 4. Donald Trumps Tweets

Generating a Dictionary

To generate a dictionary file, you'll need to run the genMarkovDict.py script as follows:


python genMarkovDict.py -k (the order of the markov chain; i.e. do you generate one word at a time or pairs of words) -i (input file with wild card) -d (output dictionary file)

For example, the following generates a dictionary of order 2 where the text was generated using two words at a time:
python genMarkovDict.py -k 2 -i "Data - Obama*.*" -d obamadict.txt

Generating Text

To generate the actual text, you'll need to run the genMarkovText.py script as follows:

python genMarkovText.py -w (maximum number of words in sentence) -n (number of sentences to generate) -d (source dictionary file)

For example, the following creates 5 generated text sentences with each one having a maximum of 20 words (if the end of sentence is found, then it will only go up to that last word)
python genMarkovText.py -w 20 -n 5 -d obamadict.txt

markovtext's People

Contributors

pub12 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

markovtext's Issues

Add requirements.txt

Can we add requirements.txt so that we can use pip to install all the required packages?

KeyError: '#BEGIN#'

Is this project/maintainer active?

I'm getting the following error using the suggested example in the README. How do I resolve it?

Is it a Python 3 compatibility issue. Python 2 is being deprecated and broken on my system.

Very curious to try this software, so hoping for help.

$ python3 genMarkovText.py -w 20 -n 5 -d obamadict.txt
Traceback (most recent call last):
  File "genMarkovText.py", line 54, in <module>
    main(maxWordInSentence, dictFile, genNSentences)
  File "genMarkovText.py", line 43, in main
    text = markovObj.genText() 
  File "MarkovText/markov.py", line 63, in genText
    key = list(random.choice(  self.table['#BEGIN#'] ))
KeyError: '#BEGIN#'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.