Package: sequifier
easy sequence classification training and inference with transformers\OverviewThe sequifier package enables:the extraction of sequences for trainingthe configuration and training of a transformer classification modelinference on data with a trained modelOther materialsIf you want to first get a more specific understanding of the transformer architecture, have a look at
theWikipedia article.If you want to see a benchmark on a small synthetic dataset with 10k cases, agains a random forest,
an xgboost model and a logistic regression, check outthis notebook.Complete example how to build and apply a transformer sequence classifier with sequifiercreate a conda environment with python 3.9.12, activate and runpip install sequifiercreate a new project folder (at a path referred to asPROJECT PATHlater) and aconfigssubfoldercopy default configs from repository for preprocessing, training and inferenceadapt preprocess config to take the path to the data you want to preprocess and setproject_pathtoPROJECT PATHrunsequifier --preprocess --config_path=[PROJECT PATH]/configs/preprocess.yamlthe preprocessing step outputs a "data driven config" at[PROJECT PATH]/configs/ddconfigs/[FILE NAME]. It contains the number of classes found in the data, a map of classes to indices and the oaths to train, validation and test splits of data. Adapt thedd_configparameter intrain-on-preprocessed.yamlandinfer.yamlin to the path[PROJECT PATH]/configs/ddconfigs/[FILE NAME]and setproject_pathtoPROJECT PATHin both configsrunsequifier --train --on-preprocessed --config_path=[PROJECT PATH]/configs/train-on-preprocessed.yamladaptinference_data_pathininfer.yamlrunsequifier --infer --config_path=[PROJECT PATH]/configs/infer.yamlfind your predictions at[PROJECT PATH]/outputs/predictions/sequifier-default-best_predictions.csvMore detailed explanations of the three stepsPreprocessing of data into sequences for trainingThe preprocessing step is designed for scenarios where for long series
of events, the prediction of the next event from the previous N events  is of interest.
In cases of sequences where only the last item is a valid target, the preprocessing
step should not be executed.This step presupposes input data with three columns: "sequenceId", "itemId" and "timesort".
"sequenceId" and "itemId" identify sequence and item, and the timesort column must
provide values that enable sequential sorting. Often this will simply be a timestamp.
You can find an example of the preprocessing input data atdocumentation/example_inputs/preprocessing_input.csvThe data can then be processed and split into training, validation and testing datasets of all
valid subsequences in the original data with the command:sequifier --preprocess --config_path=[CONFIG PATH]The config path specifies the path to the preprocessing config and the project
path the path to the (preferably empty) folder the output files of the different
steps are written to.The default config can be found on this path:configs/preprocess.yamlConfiguring and training the sequence classification modelThe training step is executed with the command:sequifier --train --config_path=[CONFIG PATH]If the data on which the model is trained comes from the preprocessing step, the flag--on-preprocessedshould also be added.If the training data does not come from the preprocessing step, both train and validation
data have to take the form of a csv file with the columns "sequenceId", [SEQ LENGTH], [SEQ LENGTH - 1],...,"1", "target".
You can find an example of the preprocessing input data atdocumentation/example_inputs/training_input.csvThe training step is configured using the config. The two default configs can be found here:configs/train.yamlconfigs/train-on-preprocessed.yamldepending on whether the preprocessing step was executed.Inferring on test data using the trained modelInference is done using the command:sequifier --infer --config_path=[CONFIG PATH]and configured using a config file. The default version can be found here:configs/infer.yaml