class_docstr: Training set contains history sessions
  
  Parameters
  ----------
  num_users: int, required
      Number of users.
  
  num_items: int, required
      Number of items.
  
  uid_map: :obj:`OrderDict`, required
      The dictionary containing mapping from user original ids to mapped integer indices.
  
  iid_map: :obj:`OrderDict`, required
      The dictionary containing mapping from item original ids to mapped integer indices.
  
  uir_tuple: tuple, required
      Tuple of 3 numpy arrays (user_indices, item_indices, rating_values).
  
  session_ids: numpy.array, required
      Array of session indices corresponding to observation in `uir_tuple`.
  
  timestamps: numpy.array, optional, default: None
      Numpy array of timestamps corresponding to feedback in `uir_tuple`.
      This is only available when input data is in `SIT`, `USIT`, SITJson`, and `USITJson` formats.
  
  extra_data: numpy.array, optional, default: None
      Array of json object corresponding to observations in `uir_tuple`.
  
  seed: int, optional, default: None
      Random seed for reproducing data sampling.
  
  Attributes
  ----------
  timestamps: numpy.array
      Numpy array of timestamps corresponding to feedback in `ubi_tuple`.
      This is only available when input data is in `UTB` format.
class_docstr_tok: ["Training","set","contains","history","sessions","Parameters","--","--","--","--","--","num_users",":","int",",","required","Number","of","users",".","num_items",":","int",",","required","Number","of","items",".","uid_map",":",":","obj",":","`","OrderDict","`",",","required","The","dictionary","containing","mapping","from","user","original","ids","to","mapped","integer","indices",".","iid_map",":",":","obj",":","`","OrderDict","`",",","required","The","dictionary","containing","mapping","from","item","original","ids","to","mapped","integer","indices",".","uir_tuple",":","tuple",",","required","Tuple","of","3","numpy","arrays","(","user_indices",",","item_indices",",","rating_values",")",".","session_ids",":","numpy.array",",","required","Array","of","session","indices","corresponding","to","observation","in","`","uir_tuple","`",".","timestamps",":","numpy.array",",","optional",",","default",":","None","Numpy","array","of","timestamps","corresponding","to","feedback","in","`","uir_tuple","`",".","This","is","only","available","when","input","data","is","in","`","SIT","`",",","`","USIT","`",",","SITJson","`",",","and","`","USITJson","`","formats",".","extra_data",":","numpy.array",",","optional",",","default",":","None","Array","of","json","object","corresponding","to","observations","in","`","uir_tuple","`",".","seed",":","int",",","optional",",","default",":","None","Random","seed","for","reproducing","data","sampling",".","Attributes","--","--","--","--","--","timestamps",":","numpy.array","Numpy","array","of","timestamps","corresponding","to","feedback","in","`","ubi_tuple","`",".","This","is","only","available","when","input","data","is","in","`","UTB","`","format","."]
docstr: Constructing Dataset from given data of specific format.
  
  Parameters
  ----------
  data: list, required
      Data in the form of tuple (user, session) for UB format,
      or tuple (user, timestamps, session) for UTB format.
  
  fmt: str, default: 'SIT'
      Format of the input data. Currently, we are supporting:
  
      'SIT': Session_ID, Item, Timestamp
      'USIT': User, Session_ID, Item, Timestamp
      'SITJson': Session_ID, Item, Timestamp, Extra data in Json format
      'USITJson': User, Session_ID, Item, Timestamp, Extra data in Json format
  
  global_uid_map: :obj:`defaultdict`, optional, default: None
      The dictionary containing global mapping from original ids to mapped ids of users.
  
  global_sid_map: :obj:`defaultdict`, optional, default: None
      The dictionary containing global mapping from original ids to mapped ids of sessions.
  
  global_iid_map: :obj:`defaultdict`, optional, default: None
      The dictionary containing global mapping from original ids to mapped ids of items.
  
  seed: int, optional, default: None
      Random seed for reproducing data sampling.
  
  exclude_unknowns: bool, default: False
      Ignore unknown users and items.
  
  Returns
  -------
  res: :obj:`<cornac.data.SequentialDataset>`
      SequentialDataset object.
docstr_tok: ["Constructing","Dataset","from","given","data","of","specific","format",".","Parameters","--","--","--","--","--","data",":","list",",","required","Data","in","the","form","of","tuple","(","user",",","session",")","for","UB","format",",","or","tuple","(","user",",","timestamps",",","session",")","for","UTB","format",".","fmt",":","str",",","default",":","'SIT'","Format","of","the","input","data",".","Currently",",","we","are","supporting",":","'SIT","'",":","Session_ID",",","Item",",","Timestamp","'USIT","'",":","User",",","Session_ID",",","Item",",","Timestamp","'SITJson","'",":","Session_ID",",","Item",",","Timestamp",",","Extra","data","in","Json","format","'USITJson","'",":","User",",","Session_ID",",","Item",",","Timestamp",",","Extra","data","in","Json","format","global_uid_map",":",":","obj",":","`","defaultdict","`",",","optional",",","default",":","None","The","dictionary","containing","global","mapping","from","original","ids","to","mapped","ids","of","users",".","global_sid_map",":",":","obj",":","`","defaultdict","`",",","optional",",","default",":","None","The","dictionary","containing","global","mapping","from","original","ids","to","mapped","ids","of","sessions",".","global_iid_map",":",":","obj",":","`","defaultdict","`",",","optional",",","default",":","None","The","dictionary","containing","global","mapping","from","original","ids","to","mapped","ids","of","items",".","seed",":","int",",","optional",",","default",":","None","Random","seed","for","reproducing","data","sampling",".","exclude_unknowns",":","bool",",","default",":","False","Ignore","unknown","users","and","items",".","Returns","--","--","--","-","res",":",":","obj",":","`","<","cornac.data.SequentialDataset",">","`","SequentialDataset","object","."]
code: def build(
      cls,
      data,
      fmt="SIT",
      global_uid_map=None,
      global_sid_map=None,
      global_iid_map=None,
      seed=None,
      exclude_unknowns=False,
  ):
      """Constructing Dataset from given data of specific format.
  
      Parameters
      ----------
      data: list, required
          Data in the form of tuple (user, session) for UB format,
          or tuple (user, timestamps, session) for UTB format.
  
      fmt: str, default: 'SIT'
          Format of the input data. Currently, we are supporting:
  
          'SIT': Session_ID, Item, Timestamp
          'USIT': User, Session_ID, Item, Timestamp
          'SITJson': Session_ID, Item, Timestamp, Extra data in Json format
          'USITJson': User, Session_ID, Item, Timestamp, Extra data in Json format
  
      global_uid_map: :obj:`defaultdict`, optional, default: None
          The dictionary containing global mapping from original ids to mapped ids of users.
  
      global_sid_map: :obj:`defaultdict`, optional, default: None
          The dictionary containing global mapping from original ids to mapped ids of sessions.
  
      global_iid_map: :obj:`defaultdict`, optional, default: None
          The dictionary containing global mapping from original ids to mapped ids of items.
  
      seed: int, optional, default: None
          Random seed for reproducing data sampling.
  
      exclude_unknowns: bool, default: False
          Ignore unknown users and items.
  
      Returns
      -------
      res: :obj:`<cornac.data.SequentialDataset>`
          SequentialDataset object.
  
      """
      fmt = validate_format(fmt, ["SIT", "USIT", "SITJson", "USITJson"])
  
      if global_uid_map is None:
          global_uid_map = OrderedDict()
      if global_sid_map is None:
          global_sid_map = OrderedDict()
      if global_iid_map is None:
          global_iid_map = OrderedDict()
  
      u_indices = []
      s_indices = []
      i_indices = []
      valid_idx = []
      extra_data = []
      for idx, tup in enumerate(data):
          uid, sid, iid, *_ = (
              tup if fmt in ["USIT", "USITJson"] else [None] + list(tup)
          )
          if exclude_unknowns and (iid not in global_iid_map):
              continue
          global_uid_map.setdefault(uid, len(global_uid_map))
          global_sid_map.setdefault(sid, len(global_sid_map))
          global_iid_map.setdefault(iid, len(global_iid_map))
  
          u_indices.append(global_uid_map[uid])
          s_indices.append(global_sid_map[sid])
          i_indices.append(global_iid_map[iid])
          valid_idx.append(idx)
  
      uir_tuple = (
          np.asarray(u_indices, dtype="int"),
          np.asarray(i_indices, dtype="int"),
          np.ones(len(u_indices), dtype="float"),
      )
  
      session_indices = np.asarray(s_indices, dtype="int")
  
      ts_pos = 3 if fmt in ["USIT", "USITJson"] else 2
      timestamps = (
          np.fromiter(
              (int(data[i][ts_pos]) for i in valid_idx), dtype="int"
          )
          if fmt in ["SIT", "SITJson", "USIT", "USITJson"]
          else None
      )
  
      extra_pos = ts_pos + 1
      extra_data = (
          [data[i][extra_pos] for i in valid_idx]
          if fmt in ["SITJson", "USITJson"]
          else None
      )
  
      dataset = cls(
          num_users=len(global_uid_map),
          num_sessions=len(set(session_indices)),
          num_items=len(global_iid_map),
          uid_map=global_uid_map,
          sid_map=global_sid_map,
          iid_map=global_iid_map,
          uir_tuple=uir_tuple,
          session_indices=session_indices,
          timestamps=timestamps,
          extra_data=extra_data,
          seed=seed,
      )
  
      return dataset
  
imports: import copy
  import os
  import pickle
  import warnings
  from collections import Counter, OrderedDict, defaultdict
  import numpy
  from scipy.sparse import csc_matrix, csr_matrix, dok_matrix
  from ..utils import estimate_batches, get_rng, validate_format
label_desc: Use image node_id 6 for calling the SequentialDataset obj's underlying member method code with example usage: obj.build(cls, data, fmt, global_uid_map, global_sid_map, global_iid_map, seed, exclude_unknowns) and returns: dataset