original_docstring: 
      Measure the semantic similarity between two documents using Word Movers Distance.
  
      Args:
          doc1
          doc2
          metric ({"cosine", "euclidean", "l1", "l2", "manhattan"})
  
      Returns:
          Similarity between ``doc1`` and ``doc2`` in the interval [0.0, 1.0],
          where larger values correspond to more similar documents.
  
      References:
          - Ofir Pele and Michael Werman, "A linear time histogram metric for improved
            SIFT matching," in Computer Vision - ECCV 2008, Marseille, France, 2008.
          - Ofir Pele and Michael Werman, "Fast and robust earth mover's distances,"
            in Proc. 2009 IEEE 12th Int. Conf. on Computer Vision, Kyoto, Japan, 2009.
          - Kusner, Matt J., et al. "From word embeddings to document distances."
            Proceedings of the 32nd International Conference on Machine Learning
            (ICML 2015). 2015. http://jmlr.org/proceedings/papers/v37/kusnerb15.pdf
      
docstring: Measure the semantic similarity between two documents using Word Movers Distance.
  
  
  
  Ofir Pele and Michael Werman, "A linear time histogram metric for improved
  SIFT matching," in Computer Vision - ECCV 2008, Marseille, France, 2008.
  Ofir Pele and Michael Werman, "Fast and robust earth mover's distances,"
  in Proc.
docstring_tokens: Measure the semantic similarity between two documents using Word Movers Distance . Ofir Pele and Michael Werman " A linear time histogram metric for improved SIFT matching " in Computer Vision - ECCV 2008 Marseille France 2008 . Ofir Pele and Michael Werman " Fast and robust earth mover ' s distances " in Proc .
code: def word_movers(doc1: Doc, doc2: Doc, metric: str = "cosine") -> float:
      """
      Measure the semantic similarity between two documents using Word Movers Distance.
  
      Args:
          doc1
          doc2
          metric ({"cosine", "euclidean", "l1", "l2", "manhattan"})
  
      Returns:
          Similarity between ``doc1`` and ``doc2`` in the interval [0.0, 1.0],
          where larger values correspond to more similar documents.
  
      References:
          - Ofir Pele and Michael Werman, "A linear time histogram metric for improved
            SIFT matching," in Computer Vision - ECCV 2008, Marseille, France, 2008.
          - Ofir Pele and Michael Werman, "Fast and robust earth mover's distances,"
            in Proc. 2009 IEEE 12th Int. Conf. on Computer Vision, Kyoto, Japan, 2009.
          - Kusner, Matt J., et al. "From word embeddings to document distances."
            Proceedings of the 32nd International Conference on Machine Learning
            (ICML 2015). 2015. http://jmlr.org/proceedings/papers/v37/kusnerb15.pdf
      """
      word_idxs: Dict[str, int] = dict()
  
      n = 0
      word_vecs = []
      for word in itertoolz.concatv(extract.words(doc1), extract.words(doc2)):
          if word.has_vector and word_idxs.setdefault(word.orth, n) == n:
              word_vecs.append(word.vector)
              n += 1
      distance_mat = pairwise_distances(np.array(word_vecs), metric=metric).astype(
          np.double
      )
      distance_mat /= distance_mat.max()
  
      vec1 = collections.Counter(
          word_idxs[word.orth] for word in extract.words(doc1) if word.has_vector
      )
      vec1 = np.array([vec1[word_idx] for word_idx in range(len(word_idxs))]).astype(
          np.double
      )
      vec1 /= vec1.sum()  # normalize word counts
  
      vec2 = collections.Counter(
          word_idxs[word.orth] for word in extract.words(doc2) if word.has_vector
      )
      vec2 = np.array([vec2[word_idx] for word_idx in range(len(word_idxs))]).astype(
          np.double
      )
      vec2 /= vec2.sum()  # normalize word counts
  
      return 1.0 - emd(vec1, vec2, distance_mat)
code_tokens: def word_movers ( doc1 : Doc , doc2 : Doc , metric : str = "cosine" ) -> float : word_idxs : Dict [ str , int ] = dict ( ) n = 0 word_vecs = [ ] for word in itertoolz . concatv ( extract . words ( doc1 ) , extract . words ( doc2 ) ) : if word . has_vector and word_idxs . setdefault ( word . orth , n ) == n : word_vecs . append ( word . vector ) n += 1 distance_mat = pairwise_distances ( np . array ( word_vecs ) , metric = metric ) . astype ( np . double ) distance_mat /= distance_mat . max ( ) vec1 = collections . Counter ( word_idxs [ word . orth ] for word in extract . words ( doc1 ) if word . has_vector ) vec1 = np . array ( [ vec1 [ word_idx ] for word_idx in range ( len ( word_idxs ) ) ] ) . astype ( np . double ) vec1 /= vec1 . sum ( ) vec2 = collections . Counter ( word_idxs [ word . orth ] for word in extract . words ( doc2 ) if word . has_vector ) vec2 = np . array ( [ vec2 [ word_idx ] for word_idx in range ( len ( word_idxs ) ) ] ) . astype ( np . double ) vec2 /= vec2 . sum ( ) return 1.0 - emd ( vec1 , vec2 , distance_mat )
short_docstring: Measure the semantic similarity between two documents using Word Movers Distance.
short_docstring_tokens: Measure the semantic similarity between two documents using Word Movers Distance .
comment: """
      Measure the semantic similarity between two documents using Word Movers Distance.
  
      Args:
          doc1
          doc2
          metric ({"cosine", "euclidean", "l1", "l2", "manhattan"})
  
      Returns:
          Similarity between ``doc1`` and ``doc2`` in the interval [0.0, 1.0],
          where larger values correspond to more similar documents.
  
      References:
          - Ofir Pele and Michael Werman, "A linear time histogram metric for improved
            SIFT matching," in Computer Vision - ECCV 2008, Marseille, France, 2008.
          - Ofir Pele and Michael Werman, "Fast and robust earth mover's distances,"
            in Proc. 2009 IEEE 12th Int. Conf. on Computer Vision, Kyoto, Japan, 2009.
          - Kusner, Matt J., et al. "From word embeddings to document distances."
            Proceedings of the 32nd International Conference on Machine Learning
            (ICML 2015). 2015. http://jmlr.org/proceedings/papers/v37/kusnerb15.pdf
      """$SEP$# normalize word counts$SEP$# normalize word counts