Created
May 22, 2020 16:08
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#computer frequency of a pair of characters or character sequences | |
#accepts corpus and return frequency of each pair | |
def get_stats(corpus): | |
pairs = collections.defaultdict(int) | |
for word, freq in corpus.items(): | |
symbols = word.split() | |
for i in range(len(symbols)-1): | |
pairs[symbols[i],symbols[i+1]] += freq | |
return pairs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment