code: def get_codoc_frequencies(dtm, min_val=1, proportions=False):
      
      if dtm.ndim != 2:
          raise ValueError('`dtm` must be a 2D array/matrix')
  
      n_docs, n_vocab = dtm.shape
      if n_vocab < 2:
          raise ValueError('`dtm` must have at least two columns (i.e. 2 unique words)')
  
      word_in_doc = dtm >= min_val
  
      codoc_freq = {}
      for w1, w2 in itertools.combinations(range(n_vocab), 2):
          if issparse(dtm):
              w1_in_docs = word_in_doc[:, w1].A.flatten()
              w2_in_docs = word_in_doc[:, w2].A.flatten()
          else:
              w1_in_docs = word_in_doc[:, w1]
              w2_in_docs = word_in_doc[:, w2]
  
          freq = np.sum(w1_in_docs & w2_in_docs)
          if proportions:
              freq /= n_docs
          codoc_freq[(w1, w2)] = freq
  
      return codoc_freq
docs: For each unique pair of words `w1, w2` in the vocab of `dtm` (i.e. its columns), return how often both occur
      together at least `min_val` times. If `proportions` is True, return proportions scaled to the number of documents
      instead of absolute numbers.