Data loading#

Supported formats#

TPPDataLoader supports pkl and json. In both formats event type indices start at 0, and dim_process is the number of event types without the padding type configured by pad_token_id.

Legacy pickle files#

A pickle file contains dim_process and one split named train, dev, or test. The split is a list of event sequences, and every event must provide the three fields read by the loader:

{
    "dim_process": 5,
    "train": [
        [
            {
                "time_since_start": 1.0267814,
                "time_since_last_event": 1.0267814,
                "type_event": 3,
            },
            {
                "time_since_start": 1.4297082,
                "time_since_last_event": 0.4029268,
                "type_event": 0,
            },
        ],
    ],
}

Use one file per split and configure train_dir, valid_dir, and test_dir accordingly.

JSON and Hugging Face datasets#

JSON data represents each event sequence as one record. The loader reads four columns: time_since_start, time_since_last_event, type_event, and dim_process. The first three are equally sized arrays; dim_process is the same scalar number of unpadded event types for every record. Local .json and .jsonl files support both JSON arrays and JSON lines.

The optional data config field source accepts auto (default), hub, json, jsonl, or pkl; data_format remains json or pkl. In auto mode, existing local paths take priority. A directory is searched for <split>.json, <split>.jsonl, or <split>.pkl; validation filenames may use dev, validation, or valid. Otherwise, an identifier of the form owner/name without a file suffix selects the Hugging Face Hub. Missing paths raise FileNotFoundError with the accepted forms (or directory contents). Explicit source: hub selects the Hub directly; source: json, jsonl, or pkl selects a local reader even when a file has a different extension. Per-split train_dir, valid_dir, and test_dir remain supported. For a Hugging Face dataset, dev is mapped to its validation split.

All EasyTPP benchmark datasets are published under the EasyTPP Hugging Face organization. Set all three paths to a dataset identifier such as easytpp/taxi; the loader selects train, validation, and test automatically:

data:
  taxi:
    data_format: json
    train_dir: easytpp/taxi
    valid_dir: easytpp/taxi
    test_dir: easytpp/taxi
    data_specs:
      num_event_types: 10
      pad_token_id: 10
      padding_side: right
      truncation_side: right

Internally, either input format becomes time_seqs (from time_since_start), time_delta_seqs (from time_since_last_event), and type_seqs (from type_event).

Time rescaling#

Temporal encodings are not scale-invariant, so rescaling is recommended for datasets whose raw inter-event times are large. rescale_time is a boolean and defaults to false. When enabled, both absolute event times and inter-event times are divided by a single scale:

  • if time_scale is supplied, its floating-point value is the divisor;

  • otherwise the divisor is the mean of the training inter-event times after the first entry of each sequence, making the mean training interval approximately 1.

Time predictions and their labels are converted back to the original units before metrics such as RMSE are computed. The resolved divisor is also copied to model_config.time_scale so the model configuration used by the run retains the scale. Training reads training data to compute inter-event statistics. Evaluation and generation can restore statistics and the time scale from a checkpoint without the training split. Reuse the training rescale_time settings and checkpoint sidecar files. Without saved statistics, IntensityFree may need the training data; without a resolved scale, rescaling also needs it.

data:
  taxi:
    data_format: json
    train_dir: easytpp/taxi
    valid_dir: easytpp/taxi
    test_dir: easytpp/taxi
    data_specs:
      num_event_types: 10
      pad_token_id: 10
      padding_side: right
      truncation_side: right
      rescale_time: true
      # time_scale: 3600.0  # optional explicit divisor

Data processing#

The data processing follows the similar pipeline as in official code of AttNHP. We name it the process of event tokenize.

Sequence padding#

By default, time_seqs, time_delta_seqs, and type_seqs are padded to the longest sequence in each batch. Setting padding_strategy to max_length uses the configured max_len instead.

input: raw event sequence (e_0, e_1, e_2, e_3) and max_len=6 # the max length among all data seqs

output:

        index:    0,          1,         2,         3,      4         5
        dtimes:   0,     t_1-t_0,    t_2-t_1,   t_3-t_2, time_pad, time_pad
        types:    e_0,      e_1,        e_2,       e_3,  type_pad, type_pad

By default, we set the value of time_pad and type_pad to be the num_event_types (because we assume the event type index starts from 0, therefore the integer value of num_event_types is unused).

Sequence masking#

After padding, we generate two masks for the event sequences:

  1. seq_non_pad_mask: True for real events and False for padding.

  2. attention_mask: True blocks attention to future events and padding; an event can attend to itself and earlier real events.

Each BatchEncoding contains five named inputs: time_seqs, time_delta_seqs, type_seqs, seq_non_pad_mask, and attention_mask. Models accept these as keyword arguments, for example loss, num_events = model.loglike_loss(**batch). BaseModel.resolve_batch_inputs also accepts batch_non_pad_mask as an alias; positional tuple batches are deprecated. The padding mechanism is implemented in event_tokenizer.

An example#

We take a real event sequence for example. Assume we have an input sequence $[ 1, 9, 5, 0]$ with num_event_types=11 and max_len=6.

Then the padded time_seqs, time_delta_seqs and type_seqs become

# time_seqs
[ 0.0000,  0.8252,  1.3806,  1.8349, 11.0000, 11.0000]

# time_delta_seqs
[ 0.0000,  0.8252,  0.5554,  0.4542, 11.0000, 11.0000]

# type_seqs
[ 1,  9,  5,  0, 11, 11]

The mask sequences are

# seq_non_pad_mask
[ True,  True,  True,  True, False, False]

# attention_mask
[[False, True,  True,  True,  True,  True],
[False, False, True,  True,  True,  True],
[False, False, False, True,  True,  True],
[False, False, False, False, True,  True],
[False, False, False, False,  True,  True],
[False, False, False, False,  True,  True]]

The runnable examples of constructing and iterating the dataset object can be found at examples/event_tokenizer.py

See Datasets for the dataset catalog and Simulation to create synthetic data.