A Python implementation of a Markov chain text generator that creates random text based on patterns learned from sample text. The generator uses bigrams (2-word sequences) to build a probabilistic model and generate coherent text.
- Markov Chain Implementation: Uses bigrams to build text generation model
- Multiple Input Options:
- Pre-loaded sample texts
- User-entered custom text
- File input capability
- Text Processing: Cleans and normalizes input text for better results
- Configurable Generation: Adjustable text length and chain order
- Interactive CLI: User-friendly command-line interface
- Text Analysis: Breaks input text into word sequences
- Chain Building: Creates a dictionary mapping word pairs to possible next words
- Generation: Randomly walks through the chain to create new text
- Output: Produces coherent text based on learned patterns
python mini_markov_text_generator.py- Use Sample Text: Choose from pre-loaded examples
- Enter Custom Text: Input your own text for generation
- Load from File: Read text from an external file
# Sample input:
"Python is a great programming language. Python makes programming fun."
# Possible output:
"Python is a great programming fun and easy. Programming in Python makes programming language."- Language: Python 3
- Dependencies: Standard library only (random, re, collections)
- Chain Order: 2 (bigrams)
- Default Output Length: 30 words
clean_text(): Preprocesses input textbuild_markov_chain(): Creates the Markov chain dictionarygenerate_text(): Generates random text from the chainmain(): Handles user interaction and program flow
Fixes #1020 - Mini Markov Text Generator
Contribution to 100LinesOfPythonCode repository