Various scripts for playing around with natural language processing/generation

code_random_text.py 323B

123456789101112
  1. import nltk
  2. # Natural Language Toolkit: code_random_text
  3. def generate_model(cfdist, word, num=15):
  4. for i in range(num):
  5. print word,
  6. word = cfdist[word].max()
  7. text = nltk.corpus.genesis.words('english-kjv.txt')
  8. bigrams = nltk.bigrams(text)
  9. cfd = nltk.ConditionalFreqDist(bigrams) # [_bigram-condition]