class_docstr: A parser for LibSVM-formatted ranking files.
  
  This parser can parse an iterable of lines into an iterable of
  `RankingExampleTuple`s that contain the per-query labels and features.
  
  Example usage:
  >>> lines = ["1 qid:1 1:5.0 2:3.0", "2 qid:1 1:2.0 2:1.0"]
  >>> feature_names = {1: "bm25", 2: "tfidf"}
  >>> parser = LibSVMRankingParser(lines, feature_names)
  >>> for example in parser:
  ...   print(example[0])
  {'bm25': array([5., 2.]), 'tfidf': array([3., 1.]), 'label': array([1, 2])}
  
  The parser will raise a ParserError with an informative error message if the
  content being parsed does not match LibSVM ranking format.
class_docstr_tok: ["A","parser","for","LibSVM-formatted","ranking","files",".","This","parser","can","parse","an","iterable","of","lines","into","an","iterable","of","`","RankingExampleTuple","`","s","that","contain","the","per-query","labels","and","features",".","Example","usage",":",">",">",">","lines","=","[","``","1","qid:1","1:5.0","2:3.0","''",",","``","2","qid:1","1:2.0","2:1.0","''","]",">",">",">","feature_names","=","{","1",":","``","bm25","''",",","2",":","``","tfidf","''","}",">",">",">","parser","=","LibSVMRankingParser","(","lines",",","feature_names",")",">",">",">","for","example","in","parser",":","...","print","(","example","[","0","]",")","{","'bm25","'",":","array","(","[","5.",",","2",".","]",")",",","'tfidf","'",":","array","(","[","3.",",","1",".","]",")",",","'label","'",":","array","(","[","1",",","2","]",")","}","The","parser","will","raise","a","ParserError","with","an","informative","error","message","if","the","content","being","parsed","does","not","match","LibSVM","ranking","format","."]
docstr: Initializes the instance.
  
  Args:
    lines: The lines to parse.
    feature_names: A mapping from feature indices to feature names.
    label_feature_name: The name to assign to the label feature.
    query_id_feature_name: The name to assign to the query identifier feature.
    doc_id_feature_name: The name to assign to the document identifier
      feature.
    default_feature_value: The default feature value to use when a feature is
      missing from the input.
    combine_features: Whether to combine the features into a single
      'float_features' feature.
docstr_tok: ["Initializes","the","instance",".","Args",":","lines",":","The","lines","to","parse",".","feature_names",":","A","mapping","from","feature","indices","to","feature","names",".","label_feature_name",":","The","name","to","assign","to","the","label","feature",".","query_id_feature_name",":","The","name","to","assign","to","the","query","identifier","feature",".","doc_id_feature_name",":","The","name","to","assign","to","the","document","identifier","feature",".","default_feature_value",":","The","default","feature","value","to","use","when","a","feature","is","missing","from","the","input",".","combine_features",":","Whether","to","combine","the","features","into","a","single","'float_features","'","feature","."]
code: def __init__(
      self,
      lines: Iterable[str],
      feature_names: Mapping[int, str],
      label_feature_name: str = "label",
      query_id_feature_name: str = "query_id",
      doc_id_feature_name: str = "doc_id",
      default_feature_value: float = 0.0,
      combine_features: bool = False,
  ):
      """Initializes the instance.
  
      Args:
        lines: The lines to parse.
        feature_names: A mapping from feature indices to feature names.
        label_feature_name: The name to assign to the label feature.
        query_id_feature_name: The name to assign to the query identifier feature.
        doc_id_feature_name: The name to assign to the document identifier
          feature.
        default_feature_value: The default feature value to use when a feature is
          missing from the input.
        combine_features: Whether to combine the features into a single
          'float_features' feature.
      """
      self._lines = lines
      self._feature_names = feature_names
      self._label_feature_name = label_feature_name
      self._query_id_feature_name = query_id_feature_name
      self._doc_id_feature_name = doc_id_feature_name
      self._default_feature_value = default_feature_value
      self._current_example = None
      self._available_examples = collections.deque()
      self._combine_features = combine_features
  
file_path: datasets/tensorflow_datasets/ranking/libsvm_ranking_parser.py
imports: import collections
  import dataclasses
  import re
  from typing import Iterable, List, Mapping, Tuple
  import numpy
label_desc: Use image node_id 1 to create a new LibSVMRankingParser object from inherited base classes: Iterable with example: obj = LibSVMRankingParser(lines, feature_names, label_feature_name, query_id_feature_name, doc_id_feature_name, default_feature_value, combine_features)