Computational Linguistics 3, Exercise 2: observed versus expected Code (run with py -X utf8, after the chapter's script): for pair in [("the", "sea"), ("the", "lighthouse"), ("strong", "winds")]: obs = pairs[pair] exp = c[pair[0]] * c[pair[1]] / n print(pair, obs, round(exp, 2)) Output from the run: ('the', 'sea') 2 0.42 ('the', 'lighthouse') 1 0.42 ('strong', 'winds') 1 0.05 Largest ratio: "strong winds" (1 observed, 0.05 expected: about 20 times chance). Why to hesitate: it occurred once. One occurrence in a 66-word paragraph is no evidence of a pattern; the ratio is large only because the expected value is tiny. "the sea" (2 against 0.42) is a smaller ratio but twice observed. The Collocation article defines collocation as co-occurring more often than would be expected by chance and says the association scores are used to test whether co-occurrence is due to chance; with counts this small, no such test could support a claim. The expected calculation is my simplification, not one of the measures the article names (mutual information, t-scores, log-likelihood).