class_docstr: Mapping between words and their integer ids, using a hashing function.
  
  Unlike :class:`~gensim.corpora.dictionary.Dictionary`,
  building a :class:`~gensim.corpora.hashdictionary.HashDictionary` before using it **isn't a necessary step**.
  
  You can start converting words to ids immediately, without training on a corpus.
  
  Examples
  --------
  .. sourcecode:: pycon
  
      >>> from gensim.corpora import HashDictionary
      >>>
      >>> dct = HashDictionary(debug=False)  # needs no training corpus!
      >>>
      >>> texts = [['human', 'interface', 'computer']]
      >>> dct.doc2bow(texts[0])
      [(10608, 1), (12466, 1), (31002, 1)]
class_docstr_tok: ["Mapping","between","words","and","their","integer","ids",",","using","a","hashing","function",".","Unlike",":","class",":","`","~gensim.corpora.dictionary.Dictionary","`",",","building","a",":","class",":","`","~gensim.corpora.hashdictionary.HashDictionary","`","before","using","it","*","*","is","n't","a","necessary","step","*","*",".","You","can","start","converting","words","to","ids","immediately",",","without","training","on","a","corpus",".","Examples","--","--","--","--","..","sourcecode",":",":","pycon",">",">",">","from","gensim.corpora","import","HashDictionary",">",">",">",">",">",">","dct","=","HashDictionary","(","debug=False",")","#","needs","no","training","corpus","!",">",">",">",">",">",">","texts","=","[","[","'human","'",",","'interface","'",",","'computer","'","]","]",">",">",">","dct.doc2bow","(","texts","[","0","]",")","[","(","10608",",","1",")",",","(","12466",",","1",")",",","(","31002",",","1",")","]"]
docstr: Convert a sequence of words `document` into the bag-of-words format of `[(word_id, word_count)]`
  (e.g. `[(1, 4), (150, 1), (2005, 2)]`).
  
  Notes
  -----
  Each word is assumed to be a **tokenized and normalized** string. No further preprocessing
  is done on the words in `document`: you have to apply tokenization, stemming etc before calling this method.
  
  If `allow_update` or `self.allow_update` is set, then also update the dictionary in the process: update overall
  corpus statistics and document frequencies. For each id appearing in this document, increase its document
  frequency (`self.dfs`) by one.
  
  Parameters
  ----------
  document : sequence of str
      A sequence of word tokens = **tokenized and normalized** strings.
  allow_update : bool, optional
      Update corpus statistics and if `debug=True`, also the reverse id=>word mapping?
  return_missing : bool, optional
      Not used. Only here for compatibility with the Dictionary class.
  
  Return
  ------
  list of (int, int)
      Document in Bag-of-words (BoW) format.
  
  Examples
  --------
  .. sourcecode:: pycon
  
      >>> from gensim.corpora import HashDictionary
      >>>
      >>> dct = HashDictionary()
      >>> dct.doc2bow(["this", "is", "máma"])
      [(1721, 1), (5280, 1), (22493, 1)]
docstr_tok: ["Convert","a","sequence","of","words","`","document","`","into","the","bag-of-words","format","of","`","[","(","word_id",",","word_count",")","]","`","(","e.g",".","`","[","(","1",",","4",")",",","(","150",",","1",")",",","(","2005",",","2",")","]","`",")",".","Notes","--","--","-","Each","word","is","assumed","to","be","a","*","*","tokenized","and","normalized","*","*","string",".","No","further","preprocessing","is","done","on","the","words","in","`","document","`",":","you","have","to","apply","tokenization",",","stemming","etc","before","calling","this","method",".","If","`","allow_update","`","or","`","self.allow_update","`","is","set",",","then","also","update","the","dictionary","in","the","process",":","update","overall","corpus","statistics","and","document","frequencies",".","For","each","id","appearing","in","this","document",",","increase","its","document","frequency","(","`","self.dfs","`",")","by","one",".","Parameters","--","--","--","--","--","document",":","sequence","of","str","A","sequence","of","word","tokens","=","*","*","tokenized","and","normalized","*","*","strings",".","allow_update",":","bool",",","optional","Update","corpus","statistics","and","if","`","debug=True","`",",","also","the","reverse","id=",">","word","mapping","?","return_missing",":","bool",",","optional","Not","used",".","Only","here","for","compatibility","with","the","Dictionary","class",".","Return","--","--","--","list","of","(","int",",","int",")","Document","in","Bag-of-words","(","BoW",")","format",".","Examples","--","--","--","--","..","sourcecode",":",":","pycon",">",">",">","from","gensim.corpora","import","HashDictionary",">",">",">",">",">",">","dct","=","HashDictionary","(",")",">",">",">","dct.doc2bow","(","[","``","this","''",",","``","is","''",",","``","m\u00e1ma","''","]",")","[","(","1721",",","1",")",",","(","5280",",","1",")",",","(","22493",",","1",")","]"]
code: def doc2bow(self, document, allow_update=False, return_missing=False):
      """Convert a sequence of words `document` into the bag-of-words format of `[(word_id, word_count)]`
      (e.g. `[(1, 4), (150, 1), (2005, 2)]`).
  
      Notes
      -----
      Each word is assumed to be a **tokenized and normalized** string. No further preprocessing
      is done on the words in `document`: you have to apply tokenization, stemming etc before calling this method.
  
      If `allow_update` or `self.allow_update` is set, then also update the dictionary in the process: update overall
      corpus statistics and document frequencies. For each id appearing in this document, increase its document
      frequency (`self.dfs`) by one.
  
      Parameters
      ----------
      document : sequence of str
          A sequence of word tokens = **tokenized and normalized** strings.
      allow_update : bool, optional
          Update corpus statistics and if `debug=True`, also the reverse id=>word mapping?
      return_missing : bool, optional
          Not used. Only here for compatibility with the Dictionary class.
  
      Return
      ------
      list of (int, int)
          Document in Bag-of-words (BoW) format.
  
      Examples
      --------
      .. sourcecode:: pycon
  
          >>> from gensim.corpora import HashDictionary
          >>>
          >>> dct = HashDictionary()
          >>> dct.doc2bow(["this", "is", "máma"])
          [(1721, 1), (5280, 1), (22493, 1)]
  
      """
      result = {}
      missing = {}
      document = sorted(
          document
      )  # convert the input to plain list (needed below)
      for word_norm, group in itertools.groupby(document):
          frequency = len(
              list(group)
          )  # how many times does this word appear in the input document
          tokenid = self.restricted_hash(word_norm)
          result[tokenid] = result.get(tokenid, 0) + frequency
          if self.debug:
              # increment document count for each unique token that appeared in the document
              self.dfs_debug[word_norm] = (
                  self.dfs_debug.get(word_norm, 0) + 1
              )
  
      if allow_update or self.allow_update:
          self.num_docs += 1
          self.num_pos += len(document)
          self.num_nnz += len(result)
          if self.debug:
              # increment document count for each unique tokenid that appeared in the document
              # done here, because several words may map to the same tokenid
              for tokenid in result.keys():
                  self.dfs[tokenid] = self.dfs.get(tokenid, 0) + 1
  
      # return tokenids, in ascending id order
      result = sorted(result.items())
      if return_missing:
          return result, missing
      else:
          return result
  
file_path: gensim/gensim/corpora/hashdictionary.py
imports: import logging
  import itertools
  import zlib
  from gensim import utils
label_desc: Use image node_id 9 for calling the HashDictionary obj's underlying member method code with example usage: obj.doc2bow(document, allow_update, return_missing) and returns: result,  missing, result