Research Article

Implementation of Text Generation using Markov Chains in Python

by  Ahmad Farhan Alshammari
journal cover
International Journal of Computer Applications
Foundation of Computer Science (FCS), NY, USA
Volume 187 - Issue 66
Published: December 2025
Authors: Ahmad Farhan Alshammari
10.5120/ijca2025926115
PDF

Ahmad Farhan Alshammari . Implementation of Text Generation using Markov Chains in Python. International Journal of Computer Applications. 187, 66 (December 2025), 35-40. DOI=10.5120/ijca2025926115

                        @article{ 10.5120/ijca2025926115,
                        author  = { Ahmad Farhan Alshammari },
                        title   = { Implementation of Text Generation using Markov Chains in Python },
                        journal = { International Journal of Computer Applications },
                        year    = { 2025 },
                        volume  = { 187 },
                        number  = { 66 },
                        pages   = { 35-40 },
                        doi     = { 10.5120/ijca2025926115 },
                        publisher = { Foundation of Computer Science (FCS), NY, USA }
                        }
                        %0 Journal Article
                        %D 2025
                        %A Ahmad Farhan Alshammari
                        %T Implementation of Text Generation using Markov Chains in Python%T 
                        %J International Journal of Computer Applications
                        %V 187
                        %N 66
                        %P 35-40
                        %R 10.5120/ijca2025926115
                        %I Foundation of Computer Science (FCS), NY, USA
Abstract

The goal of this research is to implement text generation using Markov chains in Python. Text generation is the process of creating a new text by analyzing the input text and then predicting the new words. It is used to make posts, reviews, reports, stories, poems, summaries, etc. Markov chains is a mathematical method used to predict the next state based on the current state. The text is generated by randomly selecting the new words based on their probabilities (or weights). The basic steps of text generation using Markov chains are explained: reading file, cleaning text, creating words, creating chains, computing frequency, computing transition probability, generating text, and printing generated text. The developed program was tested on an experimental text. The program has successfully performed the basic steps of text generation using Markov chains and provided the required results.

References
  • Sammut, C., & Webb, G. I. (2011). "Encyclopedia of Machine Learning". Springer.
  • Jung, A. (2022). "Machine Learning: The Basics". Springer.
  • Kubat, M. (2021). "An Introduction to Machine Learning". Springer.
  • Li, H. (2023). "Machine Learning Methods". Springer.
  • Zollanvari, A. (2023). " Machine Learning with Python". Springer.
  • Chopra, D., & Khurana, R. (2023). "Introduction to Machine Learning with Python". Bentham Science Publishers.
  • Müller, A. C., & Guido, S. (2016). "Introduction to Machine Learning with Python: A Guide for Data Scientists". O'Reilly Media.
  • Raschka, S. (2015). "Python Machine Learning". Packt Publishing.
  • Forsyth, D. (2019). "Applied Machine Learning". Springer.
  • Sarkar, D., Bali, R., & Sharma, T. (2018). "Practical Machine Learning with Python". Apress.
  • Igual, L., & Seguí, S. (2017). "Introduction to Data Science: A Python Approach to Concepts, Techniques and Applications". Springer.
  • VanderPlas, J. (2017). "Python Data Science Handbook: Essential Tools for Working with Data". O'Reilly Media.
  • Muddana, A., & Vinayakam, S. (2024). "Python for Data Science". Springer.
  • Unpingco, J. (2022). "Python for Probability, Statistics, and Machine Learning". Springer.
  • Zelle, J. (2017). "Python Programming: An Introduction to Computer Science". Franklin, Beedle & Associates.
  • Chun, W. (2001). "Core Python Programming". Prentice Hall Professional.
  • Padmanabhan, T. (2016). "Programming with Python". Springer.
  • Beazley, D., & Jones, B. K. (2013). "Python Cookbook: Recipes for Mastering Python 3". O'Reilly Media.
  • Lee, R. (2023). "Natural Language Processing: A Textbook with Python Implementation". Springer.
  • Bird, S., Klein, E., & Loper, E. (2009). "Natural Language Processing with Python". O'Reilly Media.
  • Chopra, D., Joshi, N., & Mathur, I. (2016). "Mastering Natural Language Processing with Python". Packt Publishing.
  • Thanaki, J. (2017). "Python Natural Language Processing". Packt Publishing.
  • Arumugam. R., Shanmugamani, R. (2018). " Hands-On Natural Language Processing with Python". Packt Publishing.
  • Ghosh, S., & Gunning, D. (2019). "Natural Language Processing Fundamentals". Packt Publishing.
  • Kedia, A., & Rasu, M. (2020). " Hands-On Python Natural Language Processing". Packt Publishing.
  • Reiter, E. (2025). "Natural Language Generation". Springer.
  • Indurkhya, N., & Damerau, F. (2010). "Handbook of Natural Language Processing". CRC Press.
  • Clark, A., Fox, C., & Lappin, S. (2013). "The Handbook of Computational Linguistics and Natural Language Processing". John Wiley & Sons.
  • Norris, J. (2009). "Markov Chains". Cambridge University Press.
  • Tolver, A. (2016). "An Introduction to Markov Chains". Department of Mathematical Sciences, University of Copenhagen.
  • Weber, R. (2011). "Markov Chains". Department of Pure Mathematics and Mathematical Statistics. University of Cambridge.
  • Gagniuc, P. (2017). "Markov Chains: From Theory to Implementation and Experimentation". John Wiley & Sons.
  • Ching, W., Huang, S., Ng, M., & Siu, T. (2013). "Markov Chains: Models, Algorithms, and Applications". Springer.
  • Privault, N. (2018). "Understanding Markov Chains: Examples and Applications". Springer.
  • Ankan, A., & Panda, A. (2018). "Hands-On Markov Models with Python". Packt Publishing.
  • ELIZA: https://elizagen.org
  • ChatGPT: https://chatgpt.com
  • Grinstead, C., & Snell, J. (1997). "Introduction to Probability". American Mathematical Society. pp. 464–466.
  • Python: http://www.python.org
  • Numpy: http://www.numpy.org
  • Pandas: http://pandas.pydata.org
  • Matplotlib: http://www. matplotlib.org
  • Seaborn: http://seaborn.pydata.org
  • NLTK: http://www.nltk.org
  • SciPy: http://scipy.org
  • SK Learn: http://scikit-learn.org
Index Terms
Computer Science
Information Sciences
No index terms available.
Keywords

Computer Science Artificial Intelligence Machine Learning Natural Language Processing NLP Text Generation Markov Chains Python Programming

Powered by PhDFocusTM