-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WIP] Support encoding and decoding JSONL datasets
Signed-off-by: Juan Cruz Viotti <[email protected]>
- Loading branch information
Showing
5 changed files
with
125 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/bin/sh | ||
|
||
set -o errexit | ||
set -o nounset | ||
|
||
TMP="$(mktemp -d)" | ||
clean() { rm -rf "$TMP"; } | ||
trap clean EXIT | ||
|
||
cat << 'EOF' > "$TMP/document.jsonl" | ||
{ "count": 1 } | ||
{ "count": 2 } | ||
{ "count": 3 } | ||
{ "count": 4 } | ||
{ "count": 5 } | ||
EOF | ||
|
||
"$1" encode "$TMP/document.jsonl" "$TMP/output.binpack" > "$TMP/output.txt" 2>&1 | ||
xxd "$TMP/output.binpack" > "$TMP/output.hex" | ||
|
||
cat << 'EOF' > "$TMP/expected.txt" | ||
00000000: 1306 636f 756e 7415 1300 091d 1300 0525 ..count........% | ||
00000010: 1300 052d 1300 0535 ...-...5 | ||
EOF | ||
|
||
cat << 'EOF' > "$TMP/expected-output.txt" | ||
original file size: 75 bytes | ||
encoded file size: 24 bytes | ||
compression ratio: 32% | ||
EOF | ||
|
||
diff "$TMP/expected.txt" "$TMP/output.hex" | ||
diff "$TMP/output.txt" "$TMP/expected-output.txt" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/bin/sh | ||
|
||
set -o errexit | ||
set -o nounset | ||
|
||
TMP="$(mktemp -d)" | ||
clean() { rm -rf "$TMP"; } | ||
trap clean EXIT | ||
|
||
cat << 'EOF' > "$TMP/document.jsonl" | ||
{ "count": 1 } | ||
{ "count": 2 } | ||
{ "count": 3 } | ||
{ "count": 4 } | ||
{ "count": 5 } | ||
EOF | ||
|
||
"$1" encode "$TMP/document.jsonl" "$TMP/output.binpack" --verbose > "$TMP/output.txt" 2>&1 | ||
xxd "$TMP/output.binpack" > "$TMP/output.hex" | ||
|
||
cat << 'EOF' > "$TMP/expected.txt" | ||
00000000: 1306 636f 756e 7415 1300 091d 1300 0525 ..count........% | ||
00000010: 1300 052d 1300 0535 ...-...5 | ||
EOF | ||
|
||
cat << EOF > "$TMP/expected-output.txt" | ||
original file size: 75 bytes | ||
Interpreting input as JSONL: $(realpath "$TMP")/document.jsonl | ||
Encoding entry #0 | ||
Encoding entry #1 | ||
Encoding entry #2 | ||
Encoding entry #3 | ||
Encoding entry #4 | ||
encoded file size: 24 bytes | ||
compression ratio: 32% | ||
EOF | ||
|
||
diff "$TMP/expected.txt" "$TMP/output.hex" | ||
diff "$TMP/output.txt" "$TMP/expected-output.txt" |