So im trying to make a python dictionary comprising of a word and its model score for all of the words in my file. My issue is that I can’t find a way to put the keyword for my iterator, words
, into the .score function without it literally giving me the score for the word “words”. The score function gives you a probability score based on the word that is input but I need it to cycle through each word in the file and give me the score for each.
Here is my code:
unigram_probs = [(dict.fromkeys(words, unigram_model.score("words"))) for words in dracula]
When I run my code, this is the output I’m getting:
{'project': 0.0006792647638196416,
'gutenberg': 0.0006792647638196416,
'ebook': 0.0006792647638196416,
'dracula': 0.0006792647638196416}
Notice how in the above, every word is given the same probability score since its pulling the score for the word “words” and applying it to all of them.
Instead, I need it to give me the probability score for each word that it loops through.
This is what Im expecting:
project 0.0012090748539600599
gutenberg 0.0004211384322782231
ebook 0.00017660643934248063
dracula 0.0005298193180274419
Kevin Veeder is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.