class_docstr: Corpus handles input in `GibbsLda++ format <https://gibbslda.sourceforge.net/>`_.
  
  **Format description**
  
  Both data for training/estimating the model and new data (i.e., previously unseen data) have the same format
  as follows ::
  
      [M]
      [document1]
      [document2]
      ...
      [documentM]
  
  in which the first line is the total number for documents [M]. Each line after that is one document.
  [documenti] is the ith document of the dataset that consists of a list of Ni words/terms ::
  
      [documenti] = [wordi1] [wordi2] ... [wordiNi]
  
  in which all [wordij] (i=1..M, j=1..Ni) are text strings and they are separated by the blank character.
  
  Examples
  --------
  .. sourcecode:: pycon
  
      >>> from gensim.test.utils import get_tmpfile, common_texts
      >>> from gensim.corpora import LowCorpus
      >>> from gensim.corpora import Dictionary
      >>>
      >>> # Prepare needed data
      >>> dictionary = Dictionary(common_texts)
      >>> corpus = [dictionary.doc2bow(doc) for doc in common_texts]
      >>>
      >>> # Write corpus in GibbsLda++ format to disk
      >>> output_fname = get_tmpfile("corpus.low")
      >>> LowCorpus.serialize(output_fname, corpus, dictionary)
      >>>
      >>> # Read corpus
      >>> loaded_corpus = LowCorpus(output_fname)
class_docstr_tok: ["Corpus","handles","input","in","`","GibbsLda++","format","<","https",":","\/\/gibbslda.sourceforge.net\/",">","`","_",".","*","*","Format","description","*","*","Both","data","for","training\/estimating","the","model","and","new","data","(","i.e.",",","previously","unseen","data",")","have","the","same","format","as","follows",":",":","[","M","]","[","document1","]","[","document2","]","...","[","documentM","]","in","which","the","first","line","is","the","total","number","for","documents","[","M","]",".","Each","line","after","that","is","one","document",".","[","documenti","]","is","the","ith","document","of","the","dataset","that","consists","of","a","list","of","Ni","words\/terms",":",":","[","documenti","]","=","[","wordi1","]","[","wordi2","]","...","[","wordiNi","]","in","which","all","[","wordij","]","(","i=1","..","M",",","j=1","..","Ni",")","are","text","strings","and","they","are","separated","by","the","blank","character",".","Examples","--","--","--","--","..","sourcecode",":",":","pycon",">",">",">","from","gensim.test.utils","import","get_tmpfile",",","common_texts",">",">",">","from","gensim.corpora","import","LowCorpus",">",">",">","from","gensim.corpora","import","Dictionary",">",">",">",">",">",">","#","Prepare","needed","data",">",">",">","dictionary","=","Dictionary","(","common_texts",")",">",">",">","corpus","=","[","dictionary.doc2bow","(","doc",")","for","doc","in","common_texts","]",">",">",">",">",">",">","#","Write","corpus","in","GibbsLda++","format","to","disk",">",">",">","output_fname","=","get_tmpfile","(","``","corpus.low","''",")",">",">",">","LowCorpus.serialize","(","output_fname",",","corpus",",","dictionary",")",">",">",">",">",">",">","#","Read","corpus",">",">",">","loaded_corpus","=","LowCorpus","(","output_fname",")"]
docstr: Save a corpus in the GibbsLda++ format.
  
  Warnings
  --------
  This function is automatically called by :meth:`gensim.corpora.lowcorpus.LowCorpus.serialize`,
  don't call it directly, call :meth:`gensim.corpora.lowcorpus.LowCorpus.serialize` instead.
  
  Parameters
  ----------
  fname : str
      Path to output file.
  corpus : iterable of iterable of (int, int)
      Corpus in BoW format.
  id2word : {dict of (int, str), :class:`~gensim.corpora.dictionary.Dictionary`}, optional
      Mapping between word_ids (integers) and words (strings).
      If not provided, the mapping is constructed directly from `corpus`.
  metadata : bool, optional
      THIS PARAMETER WILL BE IGNORED.
  
  Return
  ------
  list of int
      List of offsets in resulting file for each document (in bytes),
      can be used for :meth:`~gensim.corpora.lowcorpus.LowCorpus.docbyoffset`
docstr_tok: ["Save","a","corpus","in","the","GibbsLda++","format",".","Warnings","--","--","--","--","This","function","is","automatically","called","by",":","meth",":","`","gensim.corpora.lowcorpus.LowCorpus.serialize","`",",","do","n't","call","it","directly",",","call",":","meth",":","`","gensim.corpora.lowcorpus.LowCorpus.serialize","`","instead",".","Parameters","--","--","--","--","--","fname",":","str","Path","to","output","file",".","corpus",":","iterable","of","iterable","of","(","int",",","int",")","Corpus","in","BoW","format",".","id2word",":","{","dict","of","(","int",",","str",")",",",":","class",":","`","~gensim.corpora.dictionary.Dictionary","`","}",",","optional","Mapping","between","word_ids","(","integers",")","and","words","(","strings",")",".","If","not","provided",",","the","mapping","is","constructed","directly","from","`","corpus","`",".","metadata",":","bool",",","optional","THIS","PARAMETER","WILL","BE","IGNORED",".","Return","--","--","--","list","of","int","List","of","offsets","in","resulting","file","for","each","document","(","in","bytes",")",",","can","be","used","for",":","meth",":","`","~gensim.corpora.lowcorpus.LowCorpus.docbyoffset","`"]
code: def save_corpus(fname, corpus, id2word=None, metadata=False):
      """Save a corpus in the GibbsLda++ format.
  
      Warnings
      --------
      This function is automatically called by :meth:`gensim.corpora.lowcorpus.LowCorpus.serialize`,
      don't call it directly, call :meth:`gensim.corpora.lowcorpus.LowCorpus.serialize` instead.
  
      Parameters
      ----------
      fname : str
          Path to output file.
      corpus : iterable of iterable of (int, int)
          Corpus in BoW format.
      id2word : {dict of (int, str), :class:`~gensim.corpora.dictionary.Dictionary`}, optional
          Mapping between word_ids (integers) and words (strings).
          If not provided, the mapping is constructed directly from `corpus`.
      metadata : bool, optional
          THIS PARAMETER WILL BE IGNORED.
  
      Return
      ------
      list of int
          List of offsets in resulting file for each document (in bytes),
          can be used for :meth:`~gensim.corpora.lowcorpus.LowCorpus.docbyoffset`
  
      """
      if id2word is None:
          logger.info(
              "no word id mapping provided; initializing from corpus"
          )
          id2word = utils.dict_from_corpus(corpus)
  
      logger.info(
          "storing corpus in List-Of-Words format into %s" % fname
      )
      truncated = 0
      offsets = []
      with utils.open(fname, "wb") as fout:
          fout.write(utils.to_utf8("%i\n" % len(corpus)))
          for doc in corpus:
              words = []
              for wordid, value in doc:
                  if abs(int(value) - value) > 1e-6:
                      truncated += 1
                  words.extend(
                      [utils.to_unicode(id2word[wordid])] * int(value)
                  )
              offsets.append(fout.tell())
              fout.write(utils.to_utf8("%s\n" % " ".join(words)))
  
      if truncated:
          logger.warning(
              "List-of-words format can only save vectors with integer elements; "
              "%i float entries were truncated to integer value",
              truncated,
          )
      return offsets
  
file_path: gensim/gensim/corpora/lowcorpus.py
imports: import logging
  from collections import Counter
  from gensim import utils
  from gensim.corpora import IndexedCorpus
  from gensim.parsing.preprocessing import split_on_space
label_desc: Use image node_id 6 for calling the LowCorpus obj's underlying member method code with example usage: obj.save_corpus(fname, corpus, id2word, metadata) and returns: offsets