Choose a random starting word for building markov chain

0 votes
I have a python code that uses the markov chain to generate sentences. I have defined two starting words but I want the first one to be chosen randomly. Is this possible? If yes, how do I achieve it?
Aug 2 in Machine Learning by Greg
33 views

1 answer to this question.

0 votes

Hey @Greg, this is possible. You can use the random function. It will choose random numbers/words from the list or in this case, dictionary.

import random
previous[0] = random.choice(Map.keys())
answered Aug 2 by Bhavya

Related Questions In Machine Learning

0 votes
1 answer

Markov chain using processing - Python

Try something like this @Gujjar HashMap<String, int> wordCount; int ...READ MORE

answered Aug 2 in Machine Learning by Ashish
37 views
0 votes
1 answer
0 votes
1 answer
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 332 views
0 votes
1 answer