nltk.tag.HiddenMarkovModelTagger.random_sample

HiddenMarkovModelTagger.random_sample(rng, length)[source]

Randomly sample the HMM to generate a sentence of a given length. This samples the prior distribution then the observation distribution and transition distribution for each subsequent observation and state. This will mostly generate unintelligible garbage, but can provide some amusement.

Returns:

the randomly created state/observation sequence, generated according to the HMM’s probability distributions. The SUBTOKENS have TEXT and TAG properties containing the observation and state respectively.

Return type:

list

Parameters:
  • rng (Random (or any object with a random() method)) – random number generator
  • length (int) – desired output length