Command-line options
Metarank CLI has a set of command-line options to control its behavior.
To run the main app, download the latest jar file and run the following command:
java -jar metarank-x.x.x.jar __ __
_____ _____/ |______ ____________ ____ | | __
/ \_/ __ \ __\__ \\_ __ \__ \ / \| |/ /
| Y Y \ ___/| | / __ \| | \// __ \| | \ <
|__|_| /\___ >__| (____ /__| (____ /___| /__|_ \
\/ \/ \/ \/ \/ \/ Metarank v:unknown
Usage: metarank <subcommand> <options>
Options:
-h, --help Show help message
-v, --version Show version of this program
Subcommand: import - import historical clickthrough data
-c, --config <arg> path to config file
-d, --data <arg> path to an input file
-f, --format <arg> input file format: json, snowplow, snowplow:tsv,
snowplow:json (optional, default=json)
-o, --offset <arg> offset: earliest, latest, ts=1663171036, last=1h
(optional, default=earliest)
-s, --sort-files-by <arg> how should multiple input files be sorted
(optional, default: name, values:
[name,last-modified]
-v, --validation <arg> should input validation be enabled (optional,
default=false)
-h, --help Show help message
Subcommand: train - train the ML model
-c, --config <arg> path to config file
-m, --model <arg> model name to train
-s, --split <arg> train/test splitting strategy (optional, default:
time=80%, options: random=N%,time=N%,hold_last=N%)
-h, --help Show help message
Subcommand: serve - run the inference API
-c, --config <arg> path to config file
-h, --help Show help message
Subcommand: standalone - import, train and serve at once
-c, --config <arg> path to config file
-d, --data <arg> path to an input file
-f, --format <arg> input file format: json, snowplow, snowplow:tsv,
snowplow:json (optional, default=json)
-o, --offset <arg> offset: earliest, latest, ts=1663171036, last=1h
(optional, default=earliest)
-s, --sort-files-by <arg> how should multiple input files be sorted
(optional, default: name, values:
[name,last-modified]
-v, --validation <arg> should input validation be enabled (optional,
default=false)
-h, --help Show help message
Subcommand: validate - run the input data validation suite
-c, --config <arg> path to config file
-d, --data <arg> path to an input file
-f, --format <arg> input file format: json, snowplow, snowplow:tsv,
snowplow:json (optional, default=json)
-o, --offset <arg> offset: earliest, latest, ts=1663171036, last=1h
(optional, default=earliest)
-s, --sort-files-by <arg> how should multiple input files be sorted
(optional, default: name, values:
[name,last-modified]
-v, --validation <arg> should input validation be enabled (optional,
default=false)
-h, --help Show help message
Subcommand: sort - sort the dataset by timestamp
-d, --data <arg> path to a file/directory with input files
-o, --out <arg> path to an output file
-h, --help Show help message
Subcommand: autofeature - generate reference config based on existing data
-c, --cat-threshold <arg> min threshold of category frequency, when its
considered a catergory (optional, default=0.003)
-d, --data <arg> path to an input file
-f, --format <arg> input file format: json, snowplow, snowplow:tsv,
snowplow:json (optional, default=json)
-o, --offset <arg> offset: earliest, latest, ts=1663171036, last=1h
(optional, default=earliest)
--out <arg> path to an output config file
-r, --ruleset <arg> set of rules to generate config: stable, all
(optional, default=stable, values: [stable, all])
-s, --sort-files-by <arg> how should multiple input files be sorted
(optional, default: name, values:
[name,last-modified]
-v, --validation <arg> should input validation be enabled (optional,
default=false)
-h, --help Show help message
Subcommand: export - export training dataset for hyperparameter optimization
-c, --config <arg> path to config file
-m, --model <arg> model name to export data for
-o, --out <arg> a directory to export model training files
--sample <arg> sampling ratio of exported training click-through events
-s, --split <arg> train/test splitting strategy (optional, default:
time=80%, options: random=N%,time=N%,hold_last=N%)
-h, --help Show help message
Subcommand: termfreq - compute term frequencies for the BM25 field_match extractor
-d, --data <arg> path to an input file
-f, --fields <arg> Comma-separated list of text fields
-l, --language <arg> Language to use for tokenization, stemming and
stopwords
-o, --out <arg> an file to write term-freq dict to
-h, --help Show help message
For all other tricks, consult the docs on https://docs.metarank.aiThe command-line argument structure is:
Running modes
Metarank CLI has a set of different running modes:
import: import and process historical data, writing state to the chosen persistence backend like Redis.train: train the ML model with XGBoost/LightGBM.serve: run the inference API to do realtime rerankingstandalone: runimport,trainandservetasks at once.validate: validates data nd configuration files.sort: pre-sorts the dataset by timestamp.autofeature: automatically generates feature configuration based on your data.export: export the training dataset for further hyperparam optimization.termfreq: compute term frequency dictionary for BM25 field_match extractor
Validation
Metarank CLI provides validate command to validate both your data and configuration file.
You will need to provide both data and configuration files
The above command will output validation checks performed on the files provided and will output information similar to the following:
Historical data sorting
Metarank expects your historical data to be ordered by the timestamp in the ascending order. If for any reason, you cannot generate a sorted file, the sort sub-command can do the job for you.
You can sort both single files and folders with multiple files. In case of folders, sort command will merge all data into one sorted file.
Sorting one file is a simple as
You can do sorting with a folder as well
Auto feature generation
If you don't know what features to include in the configuration file, the autofeature sub-command can generate the configuration for you based on the historical data you have.
Simply run
Check out more about autofeature sub-command in our Automatic feature engineering guide.
Training the model
You can train the underlying ML ranking model:
if the
--model <name>option is not given, then Metarank will train all the defined models sequentially.
While training the model, Metarank will split your data into train/validation datasets with the following supported splitting strategies:
random: shuffle all the training samples and take N% as a training part. May result in an implicit model leakage, when information about the future was leaked in the training set.An example: on Christmas items with Santa are selling much better (and not selling at all afterwards), and leaking this knowledge into your training set will result in better offline scores (as model knows that Christmas is coming). In production, it will behave significantly worse, as there is no way to predict the future out of the training data anymore.
time: sort all training samples by timestamp and pick first N% as training set (the default option).hold_last: group all samples by user, and sort per-user samples by timestamp. N% first samples within each user are picked into the training dataset.Has the same issue with future leaking in the model, but optimizes the train dataset to focus on last user click.
The format of split strategy CLI flag is --strategy name=ratio%. For example:
random with 90% ratio:
--split random=90%random with a default 80% ratio:
--split random
Dataset export
Metarank can emit CSV/LibSVM formatted datasets and corresponding config files for LightGBM and XGBoost, so you can later perform a hyper-parameter optimization using your favourite tool:
Metarank export format is dependent on model backend type:
For XGBoost, we export a LibSVM-encoded train/test files with embedded
qid. This format is not compatible with the LightGBM LibSVM reader implementation (and we were unable to make it work with both). An example:
for LightGBM, we export a CSV-encoded train/test files with header. XGBoost (as for version 1.70) cannot load query information from CSV files, so it cannot be used for LambdaMART. Example:
For both booster implementations Metarank also emits a corresponding config file with all default values filled in. You can just run the lightgbm/xgboost cli tool externally to replicate what's Metarank is doing.
For XGBoost:
For LightGBM:
Metarank supports the same train/test split strategies for export subcommand as for the train one.
BM25 term frequencies dictionary
To use the BM25 score in the field_match, you need to compute a bit of statistics over your textual information.
To do so, run the termfreq subcommand:
With the resulting term-freq.json file you can configure the BM25 score extractor in the following way:
The same dictionary can be used for multiple field_match extractors, for example when you want to have separate BM25 scores for query-title and query-description matches.
Environment variables
Config file can be passed to the Metarank not only as a command-line argument, but also as an environment variable. This is typically used in docker and k8s-based deployments:
METARANK_CONFIG: path to config file, for examples3://bucket/prefix/config.yml
Last updated
Was this helpful?