corpora.svmlightcorpus – Corpus in SVMlight format — gensim documentation

### Navigation

- index
- modules |
- next |
- previous |
- home|
- search|
- documentation »
- API Reference »

# `corpora.svmlightcorpus` – Corpus in SVMlight format

Corpus in SVMlight format.

class `gensim.corpora.svmlightcorpus.` `SvmLightCorpus`(fname)

  Corpus in SVMlight format.

  Quoting http://svmlight.joachims.org/: The input file example_file contains the training examples. The first lines may contain comments and are ignored if they start with #. Each of the following lines represents one training example and is of the following format:

      <line> .=. <target> <feature>:<value> <feature>:<value> ... <feature>:<value> # <info>
      <target> .=. +1 | -1 | 0 | <float>
      <feature> .=. <integer> | "qid"
      <value> .=. <float>
      <info> .=. <string>

  The “qid” feature (used for SVMlight ranking), if present, is ignored.

  Although not mentioned in the specification above, SVMlight also expect its feature ids to be 1-based (counting starts at 1). We convert features to 0-base internally by decrementing all ids when loading a SVMlight input file, and increment them again when saving as SVMlight.

  Initialize the corpus from a file.

  classmethod `load`(fname)
    Load a previously saved object from file (also see save).
  `save`(fname)
    Save the object to file via pickling (also see load).
  static `saveCorpus`(fname, corpus, id2word=None)

    Save a corpus in the SVMlight format.

    The SVMlight <target> class tag is set to 0 for all documents.

### Navigation

- index
- modules |
- next |
- previous |
- home|
- search|
- documentation »
- API Reference »