Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

A Python program that generates n-grams from a text file

Notifications You must be signed in to change notification settings

soft-pure-empty/markov-ngram-python

Open more actions menu
 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Markov n-gram demo program
by Paul Ebreo

Inspired by Brit Cruise's Markov videos:
https://www.khanacademy.org/math/applied-math/informationtheory/moderninfotheory/v/a-mathematical-theory-of-communication

Usage

>>> from ngram import NGRAM
>>> NGRAM.generate(3, 'sample-hamlet.txt', 100)

mind to suffer the slings and arrows of outrageous fortune or to take arms again
st a sea of troubles and by opposing end them To die to sleep no more and by a s
leep to say we end the heart ache and the thousand natural shocks that flesh is
heir to tis a consummation devoutly to be wishd To die to sleep no more and by a
 sleep to say we end the heart ache and the thousand natural shocks that flesh i
s heir to tis a consummation devoutly to be wishd To die to sleep no more and by
 a sleep to


Bugs

I need to diagnose and fix the following error:

>>> NGRAM.generate(2, 'sample-hamlet.txt', 200)                                                                                                                                                                                                
Traceback (most recent call last):                                                                                                                                                                                                             
  File "<stdin>", line 1, in <module>                                                                                                                                                                                                          
  File "ngram.py", line 83, in generate                                                                                                                                                                                                        
    next_word = NGRAM.topword(1, cups[this_token])                                                                                                                                                                                             
KeyError: ('something', 'after')                                                                                                                                                                                                               

About

A Python program that generates n-grams from a text file

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%
Morty Proxy This is a proxified and sanitized view of the page, visit original site.