Repository navigation
kev-finetune: split JSONL on LF only so U+2028, U+2029 and U+0085 stay one record - #277
Draft
jaredpalmer wants to merge 1 commit into
Draft
jaredpalmer wants to merge 1 commit into
jaredpalmer wants to merge 1 commit into
Conversation
…y one record str.splitlines() also breaks on those characters, which json.dumps leaves raw inside a string. split_data, convert_data, generate_data, and the kev_modal record count now split on "\n" only, matching kev.suite.read_jsonl. Co-authored-by: Jared Palmer <hello@jaredpalmer.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
split_data.py,convert_data.py, andgenerate_data.pyread JSONL withstr.splitlines(). Python also breaks a line on U+2028, U+2029, and U+0085.json.dumpswithensure_ascii=Falsewrites those characters raw inside a string, and the line is still valid JSON.split_data.pyreports both halves asnot JSON, drops the record, and exits 0. Each of those characters also pushes every later line number up by one. On a JSONL file,convert_data.pyraisesJSONDecodeError.generate_data.pyraises the same error when it reads records already in--out, and when it reads--examples.kev.train --dataaccepts the file.kev.suite.read_jsonlhas split on"\n"only since #101.The skill scripts now split on
"\n"only, the separator they write.generate_data.pyreads--outand--examplesthrough one function,read_jsonl.upload_datainkev_modal.pycounted lines with the samesplitlines()call, so one record became two in the count printed before training. That count splits on"\n"as well. The upload was not run.The scripts are standard library only, so each reader copies the
read_jsonlsplit. The file is assumed to use LF endings. The scripts write LF. A CRLF row still parses, becausejson.loadstreats the leftover carriage return as whitespace.The second
convert_data.pyin the issue's repro exits 1 with2 rows skipped. That file is already Kev records, and it has nodepartmentcolumn for the label map. A flat JSONL file, the inputconvert_data.pymaps, converts and keeps the character.extract_workload.pystill usessplitlines(), because it numbers source lines.Fixes #276. Reported by @luc-pimentel, with the repro and the diagnosis.
Test plan
test_jsonl_readers_keep_unicode_line_separatorsfailed before the change withread_recordsreturning[], and passes after. It covers U+2028, U+2029, and U+0085, the line number of a following broken line,convert_data.rows_from,existing_records,--examplesvia--dry-run,upload_data's count withbatch_uploadreplaced, and a CRLF row.skills/kev-finetune. CSV convert writes 2 records.split_data.pyprintsinvalid: line 1andinvalid: line 2,1 valid records, exit 0. JSONL convert,existing_records, and--examplesraiseJSONDecodeError: Unterminated string. U+2029 and U+0085 match. A followingnot jsonline is reported as line 4. The count expression on that file is 3.split_data.pyprints2 valid records (0 invalid lines...), exit 0.existing_recordsreturns 2.--examplesexits 0 and the prompt contains U+2028. U+2029 and U+0085 read as 2 records. The following broken line is line 3. Flat JSONL with one record per character converts to 3 records. The count expression is 2.python3 -m pytest tests/test_skill_scripts.py -q: 58 passed.