Train a transformer model with the command line
Project description
easy sequence classification training and inference with transformers
\
Overview
The sequifier package enables:
- the extraction of sequences for training
- the configuration and training of a transformer classification model
- inference on data with a trained model
Complete example how to build and apply a transformer sequence classifier with sequifier
- create a conda environment, activate and run
pip install sequifier
- create a new project folder (at a path referred to as
PROJECT PATH
later) and a "configs" subfolder - copy default configs from repository for preprocessing, training and inference and name them
preprocess.yaml
,train.yaml
andinfer.yaml
- adapt preprocess config to take the path to the data you want to preprocess
- run
sequifier --preprocess --config_path=[PROJECT PATH]/configs/preprocess.yaml --project_path=[PROJECT PATH]
- the 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 the dd_config parameter in train.yaml and infer.yaml in to the path[PROJECT PATH]/configs/ddconfigs/[FILE NAME]
- run
sequifier --train --on-preprocessed --config_path=[PROJECT PATH]/configs/train.yaml --project_path=[PROJECT PATH]
- adapt inference_data_path in infer.yaml
- run
sequifier --infer --config_path=[PROJECT PATH]/configs/infer.yaml --project_path=[PROJECT PATH]
- find your predictions at
[PROJECT PATH]/outputs/predictions/sequifier-default-best_predictions.csv
More detailed explanations of the three steps
Preprocessing of data into sequences for training
The 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 at documentation/example_inputs/preprocessing_input.csv
The 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] --project_path=[PROJECT 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/default.yaml
Configuring and training the sequence classification model
The training step is executed with the command:
sequifier --train --config_path=[CONFIG PATH] --project_path=[PROJECT PATH]
If the data on which the model is trained comes from the preprocessing step, the flag
--on-preprocessed
should 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 at documentation/example_inputs/training_input.csv
The training step is configured using the config. The two default configs can be found here:
configs/train/default-on-preprocessed.yaml
depending on whether the preprocessing step was executed.
Inferring on test data using the trained model
Inference is done using the command:
sequifier --infer --config_path=[CONFIG PATH] --project_path=[PROJECT PATH]
and configured using a config file. The default version can be found here:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for sequifier-0.2.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a15343249dfb8affa7407ee670955a1cd3f6e85c17e59ce17819b51ba31bd8cf |
|
MD5 | 82d4f555326216664629f1e1dac6db25 |
|
BLAKE2b-256 | c4afb722e5be17b10044ea1341001c7f24672718c9d1f98690b3a7893ccf87a0 |