UCIFastReader vs. CNTKTextFormatReader for Tabular Data
I am working with 10K rows of tabular data, with 24 feature columns (F1-24) and 4 classification labels (LEHP, LELP, SEHP, SELP) for the test and training dataset as follows using the UCIFastReader:
LEHP F1 F2 F3 F4 . . .
LELP F1 F2 F3 F4 . . .
SEHP F1 F2 F3 F4 . . .
SELP F1 F2 F3 F4 . . .
Of course I listed the string classification labels (LEHP, LELP, SEHP, SELP) in the simple mapping dataset. This works well, but I also want to embed some reference data (e.g. date/time) not to be used in the modeling within each record and thought I could use the “start = 2” to skip this these fields:
01/15/2016 12:41:23.234 LEHP F1 F2 F3 F4 . . .
01/16/2016 10:01:33.345 LELP F1 F2 F3 F4 . . .
01/17/2016 09:36:25.567 SEHP F1 F2 F3 F4 . . .
01/18/2016 14:21:53.890 SELP F1 F2 F3 F4 . . .
Using the reader block:
reader = [
readerType = "UCIFastReader"
file = "Train-UCIFastReader.txt"
labels=[
start = 2
dim = 1
labelDim=4
labelMappingFile = "SimpleMapping-DLT.txt"
]
features=[
start = 3
dim = 24
]
]
But found I could not skip over it without it reading into the next line and throwing an error.
EXCEPTION occurred: label found in data not specified in label mapping file: 01/15/2016
So I tried the new CNTKTextFormatReader thinking I could do this:
01/15/2016 12:41:23.234 |LEHP |F F1 F2 F3 F4 . . .
01/16/2016 10:01:33.345 |LELP |F F1 F2 F3 F4 . . .
01/17/2016 09:36:25.567 |SEHP |F F1 F2 F3 F4 . . .
01/18/2016 14:21:53.890 |SELP |F F1 F2 F3 F4 . . .
But found I would also need to turn the string labels into a numeric vector which requires more reprocessing and the sequence ID must be numeric and therefore has limited use to retain reference data.
|L 1 0 0 0 |F F1 F2 F3 F4 . . .
|L 0 1 0 0 |F F1 F2 F3 F4 . . .
|L 0 0 1 0 |F F1 F2 F3 F4 . . .
|L 0 0 0 1 |F F1 F2 F3 F4 . . .
I’ve also noticed in the wiki the UCIFastReader is to be deprecated in favor of the new CNTKTextFormatReader which is a bit concerning given the former works well for tabular data although not ideal for other types of data input. Looking for guidance on how best to accommodate reference data in the input record in one of the readers.
Thanks
(small sample datafile attached) Train-UCIFastReader.txt
As far as the tabular data go, CNTKTextFormatReader should be at parity with UCIFastReader.
Unfortunately, it's not possible to make UCIFast skip over columns in the input. In this particular case, each time it sees a value that's not a number, it decides that it must be a label (start and dim only help to tell numerical labels apart from features).
While neither reader natively supports reference data, your best shot at it is to use CNTKTest format with explicit sequence ids and map them externally to reference data:
input.txt:
1 |L 1 0 0 0 |F F1 F2 F3 F4 . . .
2 |L 0 1 0 0 |F F1 F2 F3 F4 . . .
3 |L 0 0 1 0 |F F1 F2 F3 F4 . . .
4 |L 0 0 0 1 |F F1 F2 F3 F4 . . .
id-to-reference-map.txt:
1 01/15/2016 12:41:23.234
2 01/16/2016 10:01:33.345
3 01/17/2016 09:36:25.567
4 01/18/2016 14:21:53.890
FWIW, there's a converter from UCI to CNTKText format, which can take care of reprocessing:
python path_to_converter\uci_to_cntk_text_format_converter.py -in Train-UCIFastReader.txt -fs 3 -fd 24 -ls 2 -ld 1 -nl 4 --mapping_file SimpleMapping-DLT.txt -out Train-CNTKText.txt
It won't add sequence ids though, but that's easy to fix.
Thanks raaaar, I too was thinking in the absence of a skip-over feature, I could use the unique sequence ID as a match key for the reference data.
I also wondered if I could just concatenate the reference items with underscore separator but then in the Text Reader only reference the "L" and "F" aliases, if that would skip the reference data. Haven't tried it yet nor walked the code.
|R_01/15/2016_12:41:23.234 0 |L 1 0 0 0 |F F1 F2 F3 F4 . . .
|R_01/16/2016_10:01:33.345 0 |L 0 1 0 0 |F F1 F2 F3 F4 . . .
|R_01/17/2016_09:36:25.567 0 |L 0 0 1 0 |F F1 F2 F3 F4 . . .
|R_01/18/2016_14:21:53.890 0 |L 0 0 0 1 |F F1 F2 F3 F4 . . .
Nope, this won't work, the reader will complain that all identifiers in the first column are different. What will work is leaving ref data in the first column without any adornments and adding the following options to the reader config:
skipSequenceIds=true
traceLevel=0
maxErrors=10000 # == number of lines in the input
The last two basically tell the reader to swallow errors whenever it sees something unusual in the input. However, this is an extremely hacky approach and it should be used with caution.
Might you consider an enhancement whereby "|#", or something similar, would ignore all contents until the next "|" is encountered? Even if "|#" had to start in position zero. Then any type of reference data can be included, space delimited or not.
One could have "|#" to ignore the column (provided it is tab-separated), or just "#" to ignore until rest of line.
Not sure if introducing another special character ('#') is a good idea. That said, double-pipe ('||') can be used as an escape sequence ( = skip everything until the next column or the end of row).
So, is it used for skipping to the next column, or till the end of the row? I would prefer |# / # since this is more self explanatory (it introduces comments in most scripting languages)
Thanks @raaaar for adding '|#' and other improvements to the CNTKTextFormatReader. I did a quick test on the following with reference DateTime info in the beginning of the record and it worked as expected.
|# 04/04/2014 10:26:27 |F 1.0 0.4350 2.0000 0.6471 0.4412 0.8182 0.2059 0.5588 1.8866 0.0244 0.0519 0.5968 0.0275 1.0519 0.5313 0.4437 0.5428 0.4837 0.5933 0.7529 1.3273 1.2427 0.6323 1.0449 |L 0 1 0 0