Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow tokenization for gzipped json files in datapreprocess #285

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions open_lm/datapreprocess/make_2048.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import argparse
from pathlib import Path
from transformers import GPTNeoXTokenizerFast

import smart_open

# ========================================
# = Global variables =
Expand Down Expand Up @@ -52,10 +52,17 @@ def upload_to_s3_and_remove(fname):

@contextmanager
def get_item_reader(file_name):
"""Creates iterator for reading .jsonl files or Zstd compressed .jsonl files"""
"""
Creates iterator for reading .jsonl files, gzip compressed,
or Zstd compressed .jsonl files
"""
if file_name.endswith(".jsonl"):
with jsonlines.open(file_name) as reader:
yield reader
elif file_name.endswith((".jsonl.gz", ".json.gz")):
with smart_open.open(file_name, "r") as f:
with jsonlines.Reader(f) as reader:
yield reader
else:
dctx = zstd.ZstdDecompressor()
with open(file_name, "rb") as compressed_file:
Expand Down