MCPcopy
hub / github.com/ddbourgin/numpy-ml / random_paragraph

Function random_paragraph

numpy_ml/utils/testing.py:99–134  ·  view source on GitHub ↗

Generate a random paragraph consisting of `n_words` words. If `vocab` is not None, words will be drawn at random from this list. Otherwise, words will be sampled uniformly from a collection of 26 Latin words.

(n_words, vocab=None)

Source from the content-addressed store, hash-verified

97
98
99def random_paragraph(n_words, vocab=None):
100 """
101 Generate a random paragraph consisting of `n_words` words. If `vocab` is
102 not None, words will be drawn at random from this list. Otherwise, words
103 will be sampled uniformly from a collection of 26 Latin words.
104 """
105 if vocab is None:
106 vocab = [
107 "at",
108 "stet",
109 "accusam",
110 "aliquyam",
111 "clita",
112 "lorem",
113 "ipsum",
114 "dolor",
115 "dolore",
116 "dolores",
117 "sit",
118 "amet",
119 "consetetur",
120 "sadipscing",
121 "elitr",
122 "sed",
123 "diam",
124 "nonumy",
125 "eirmod",
126 "duo",
127 "ea",
128 "eos",
129 "erat",
130 "est",
131 "et",
132 "gubergren",
133 ]
134 return [np.random.choice(vocab) for _ in range(n_words)]
135
136
137#######################################################################

Callers 4

test_huffmanFunction · 0.90
test_tfidfFunction · 0.90
test_mleFunction · 0.85
test_additiveFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected