Skip to content

Load dataset from huggingface instead of dead S3 instance #11

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
21 changes: 10 additions & 11 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@
except NameError:
pass ## we're still good
"""
import functools
from functools import partial
import urllib
import zipfile
import os

import torch
import torch.nn.functional as F
from torch import nn
import datasets

# This seems like one of the best choices right now for a fast/lightweight/simple tokenizer.
import tiktoken
Expand Down Expand Up @@ -94,20 +92,21 @@
if not os.path.exists(hyp['misc']['data_location']):
print("downloading data and tokenizing (1-2 min)")

raw_data_source = 'https://s3.amazonaws.com/research.metamind.io/wikitext/wikitext-103-raw-v1.zip'
raw_data_cache = './data_raw/' # where to cache the data after downloading

if not os.path.isfile(raw_data_cache):
os.makedirs(raw_data_cache, exist_ok=True)
urllib.request.urlretrieve(raw_data_source, raw_data_cache+'data.zip')

with zipfile.ZipFile('data_raw/data.zip', 'r') as zip_ref:
zip_ref.extractall('data_raw/')

with open('data_raw/wikitext-103-raw/wiki.train.raw', 'r', encoding="utf8") as data_file:
wikitext_train = datasets.load_dataset('wikitext', 'wikitext-103-raw-v1', cache_dir=raw_data_cache, split="train")
wikitext_eval = datasets.load_dataset('wikitext', 'wikitext-103-raw-v1', cache_dir=raw_data_cache, split="validation")
with open(raw_data_cache+'wiki.train.txt', 'w', encoding="utf8") as data_file:
data_file.write("".join(wikitext_train['text']))
with open(raw_data_cache+'wiki.valid.txt', 'w', encoding="utf8") as data_file:
data_file.write("".join(wikitext_eval['text']))

with open('data_raw/wiki.train.txt', 'r', encoding="utf8") as data_file:
raw_train_data = data_file.read()

with open('data_raw/wikitext-103-raw/wiki.valid.raw', 'r', encoding="utf8") as data_file:
with open('data_raw/wiki.valid.txt', 'r', encoding="utf8") as data_file:
raw_eval_data = data_file.read()

tokenizer = tiktoken.get_encoding("gpt2")
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
torch
torchvision
tiktoken
tiktoken
datasets