class_docstr: Dictionary encapsulates the mapping between normalized words and their integer ids.
  
  Notable instance attributes:
  
  Attributes
  ----------
  token2id : dict of (str, int)
      token -> token_id. I.e. the reverse mapping to `self[token_id]`.
  cfs : dict of (int, int)
      Collection frequencies: token_id -> how many instances of this token are contained in the documents.
  dfs : dict of (int, int)
      Document frequencies: token_id -> how many documents contain this token.
  num_docs : int
      Number of documents processed.
  num_pos : int
      Total number of corpus positions (number of processed words).
  num_nnz : int
      Total number of non-zeroes in the BOW matrix (sum of the number of unique
      words per document over the entire corpus).
class_docstr_tok: ["Dictionary","encapsulates","the","mapping","between","normalized","words","and","their","integer","ids",".","Notable","instance","attributes",":","Attributes","--","--","--","--","--","token2id",":","dict","of","(","str",",","int",")","token","-",">","token_id",".","I.e",".","the","reverse","mapping","to","`","self","[","token_id","]","`",".","cfs",":","dict","of","(","int",",","int",")","Collection","frequencies",":","token_id","-",">","how","many","instances","of","this","token","are","contained","in","the","documents",".","dfs",":","dict","of","(","int",",","int",")","Document","frequencies",":","token_id","-",">","how","many","documents","contain","this","token",".","num_docs",":","int","Number","of","documents","processed",".","num_pos",":","int","Total","number","of","corpus","positions","(","number","of","processed","words",")",".","num_nnz",":","int","Total","number","of","non-zeroes","in","the","BOW","matrix","(","sum","of","the","number","of","unique","words","per","document","over","the","entire","corpus",")","."]
docstr: Convert `document` into the bag-of-words (BoW) format = list of `(token_id, token_count)` tuples.
  
  Parameters
  ----------
  document : list of str
      Input document.
  allow_update : bool, optional
      Update self, by adding new tokens from `document` and updating internal corpus statistics.
  return_missing : bool, optional
      Return missing tokens (tokens present in `document` but not in self) with frequencies?
  
  Return
  ------
  list of (int, int)
      BoW representation of `document`.
  list of (int, int), dict of (str, int)
      If `return_missing` is True, return BoW representation of `document` + dictionary with missing
      tokens and their frequencies.
  
  Examples
  --------
  .. sourcecode:: pycon
  
      >>> from gensim.corpora import Dictionary
      >>> dct = Dictionary(["máma mele maso".split(), "ema má máma".split()])
      >>> dct.doc2bow(["this", "is", "máma"])
      [(2, 1)]
      >>> dct.doc2bow(["this", "is", "máma"], return_missing=True)
      ([(2, 1)], {u'this': 1, u'is': 1})
docstr_tok: ["Convert","`","document","`","into","the","bag-of-words","(","BoW",")","format","=","list","of","`","(","token_id",",","token_count",")","`","tuples",".","Parameters","--","--","--","--","--","document",":","list","of","str","Input","document",".","allow_update",":","bool",",","optional","Update","self",",","by","adding","new","tokens","from","`","document","`","and","updating","internal","corpus","statistics",".","return_missing",":","bool",",","optional","Return","missing","tokens","(","tokens","present","in","`","document","`","but","not","in","self",")","with","frequencies","?","Return","--","--","--","list","of","(","int",",","int",")","BoW","representation","of","`","document","`",".","list","of","(","int",",","int",")",",","dict","of","(","str",",","int",")","If","`","return_missing","`","is","True",",","return","BoW","representation","of","`","document","`","+","dictionary","with","missing","tokens","and","their","frequencies",".","Examples","--","--","--","--","..","sourcecode",":",":","pycon",">",">",">","from","gensim.corpora","import","Dictionary",">",">",">","dct","=","Dictionary","(","[","``","m\u00e1ma","mele","maso","''",".split","(",")",",","``","ema","m\u00e1","m\u00e1ma","''",".split","(",")","]",")",">",">",">","dct.doc2bow","(","[","``","this","''",",","``","is","''",",","``","m\u00e1ma","''","]",")","[","(","2",",","1",")","]",">",">",">","dct.doc2bow","(","[","``","this","''",",","``","is","''",",","``","m\u00e1ma","''","]",",","return_missing=True",")","(","[","(","2",",","1",")","]",",","{","u'this","'",":","1",",","u'is","'",":","1","}",")"]
code: def doc2bow(self, document, allow_update=False, return_missing=False):
      """Convert `document` into the bag-of-words (BoW) format = list of `(token_id, token_count)` tuples.
  
      Parameters
      ----------
      document : list of str
          Input document.
      allow_update : bool, optional
          Update self, by adding new tokens from `document` and updating internal corpus statistics.
      return_missing : bool, optional
          Return missing tokens (tokens present in `document` but not in self) with frequencies?
  
      Return
      ------
      list of (int, int)
          BoW representation of `document`.
      list of (int, int), dict of (str, int)
          If `return_missing` is True, return BoW representation of `document` + dictionary with missing
          tokens and their frequencies.
  
      Examples
      --------
      .. sourcecode:: pycon
  
          >>> from gensim.corpora import Dictionary
          >>> dct = Dictionary(["máma mele maso".split(), "ema má máma".split()])
          >>> dct.doc2bow(["this", "is", "máma"])
          [(2, 1)]
          >>> dct.doc2bow(["this", "is", "máma"], return_missing=True)
          ([(2, 1)], {u'this': 1, u'is': 1})
  
      """
      if isinstance(document, str):
          raise TypeError(
              "doc2bow expects an array of unicode tokens on input, not a single string"
          )
  
      # Construct (word, frequency) mapping.
      counter = defaultdict(int)
      for w in document:
          counter[w if isinstance(w, str) else str(w, "utf-8")] += 1
  
      token2id = self.token2id
      if allow_update or return_missing:
          missing = sorted(
              x for x in counter.items() if x[0] not in token2id
          )
          if allow_update:
              for w, _ in missing:
                  # new id = number of ids made so far;
                  # NOTE this assumes there are no gaps in the id sequence!
                  token2id[w] = len(token2id)
      result = {
          token2id[w]: freq
          for w, freq in counter.items()
          if w in token2id
      }
  
      if allow_update:
          self.num_docs += 1
          self.num_pos += sum(counter.values())
          self.num_nnz += len(result)
          # keep track of document and collection frequencies
          for tokenid, freq in result.items():
              self.cfs[tokenid] = self.cfs.get(tokenid, 0) + freq
              self.dfs[tokenid] = self.dfs.get(tokenid, 0) + 1
  
      # return tokenids, in ascending id order
      result = sorted(result.items())
      if return_missing:
          return result, dict(missing)
      else:
          return result
  
imports: from collections import defaultdict
  from collections.abc import Mapping
  import logging
  import itertools
  from typing import Optional, List, Tuple
  from gensim import utils
label_desc: Use image node_id 11 for calling the Dictionary obj's underlying member method code with example usage: obj.doc2bow(document, allow_update, return_missing) and returns: result,  dict, result