Computational Linguistics 8, Exercise 3: saying "unsure" Code (run with py -X utf8, after the chapter's lesk code): def lesk2(word, context): sc, b = lesk(word, context) top = sorted(sc.values(), reverse=True) return sc, ("unsure" if top[0] == top[1] else b) print(lesk2("light", "she took the light")) print(lesk2("light", "the light guides the boats at night")[1]) Output from the run: ({'lamp-light': 0, 'not-heavy': 0}, 'unsure') lamp-light The tie (0 against 0) now returns "unsure" instead of silently picking the first sense. The sentence with real overlap (3 against 0) still returns lamp-light. Another fallback: the WSD article reports that always choosing the most frequent sense scored 51.4% (SemEval-2007) and 57% (Senseval-2), so when the context gives no evidence a system can return the most frequent sense instead of guessing at random. I did not implement that here, since my two glosses have no frequency counts.