code: def cosine_lesk(context_sentence: str, ambiguous_word: str,
                  pos: str = None, lemma=True, stem=True, hyperhypo=True,
                  stop=True, context_is_lemmatized=False,
                  nbest=False, from_cache=True) -> "wn.Synset":
      
  
      # Ensure that ambiguous word is a lemma.
      ambiguous_word = lemmatize(ambiguous_word)
  
      # If ambiguous word not in WordNet return None
      if not wn.synsets(ambiguous_word):
          return None
      ss_sign = simple_signatures(ambiguous_word, pos, lemma, stem, hyperhypo, stop,
                                  from_cache=from_cache)
      if context_is_lemmatized:
          context_sentence = " ".join(context_sentence.split())
      else:
          context_sentence = " ".join(lemmatize_sentence(context_sentence))
  
      scores = []
      for ss, signature in ss_sign.items():
          # Lowercase and replace "_" with spaces.
          signature = " ".join(map(str, signature)).lower().replace("_", " ")
          scores.append((cos_sim(context_sentence, signature), ss))
  
      scores = sorted(scores, reverse=True)
      return scores if nbest else scores[0][1]
docs: In line with vector space models, we can use cosine to calculate overlaps
      instead of using raw overlap counts. Essentially, the idea of using
      signatures (aka 'sense paraphrases') is lesk-like.
  
      :param context_sentence: String, sentence or document.
      :param ambiguous_word: String, a single word.
      :param pos: String, one of 'a', 'r', 's', 'n', 'v', or None.
      :return: A Synset for the estimated best sense.