RonanKMcGovern
commited on
Commit
•
5a223ff
1
Parent(s):
a47738e
data set complete
Browse files
README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1 |
|
2 |
# Data source
|
3 |
-
|
4 |
-
|
5 |
-
|
|
|
|
|
|
|
|
1 |
|
2 |
# Data source
|
3 |
+
Downloaded via Andrej Karpathy's nanogpt repo from this [link](https://raw.githubusercontent.com/karpathy/char-rnn/master/data/tinyshakespeare/input.txt)
|
4 |
+
|
5 |
+
# Data Format
|
6 |
+
- The entire dataset is split into train (90%) and test (10%).
|
7 |
+
- All rows are at most 1024 tokens, using the Llama 2 tokenizer.
|
8 |
+
- All rows are split cleanly so that sentences are whole and unbroken.
|
create_dataset.py
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import csv
|
2 |
+
from transformers import AutoTokenizer
|
3 |
+
|
4 |
+
# Initialize the tokenizer
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained("TheBloke/Yarn-Llama-2-7B-128K-GPTQ", use_fast=True)
|
6 |
+
|
7 |
+
# Read the input data
|
8 |
+
with open('input.txt', 'r') as f:
|
9 |
+
data = f.readlines()
|
10 |
+
|
11 |
+
# Initialize variables
|
12 |
+
train_data = []
|
13 |
+
test_data = []
|
14 |
+
current_row = ""
|
15 |
+
current_token_count = 0
|
16 |
+
carry_over = ""
|
17 |
+
|
18 |
+
# Iterate over each line and add to train or test data
|
19 |
+
for i, line in enumerate(data):
|
20 |
+
line_to_add = carry_over + line.strip()
|
21 |
+
carry_over = ""
|
22 |
+
|
23 |
+
# Tokenize the line to count tokens
|
24 |
+
tokens = tokenizer(line_to_add)['input_ids']
|
25 |
+
num_tokens = len(tokens)
|
26 |
+
|
27 |
+
# Check if adding the line would exceed the token limit
|
28 |
+
if current_token_count + num_tokens > 1024:
|
29 |
+
# Find the last period followed by a space in the current row
|
30 |
+
last_period_idx = current_row.rfind('. ')
|
31 |
+
|
32 |
+
if last_period_idx != -1:
|
33 |
+
# Carry over the content after the last period
|
34 |
+
carry_over = current_row[last_period_idx+2:].strip() + "\n"
|
35 |
+
current_row = current_row[:last_period_idx+1]
|
36 |
+
|
37 |
+
if i < len(data) * 0.9:
|
38 |
+
train_data.append(current_row.strip())
|
39 |
+
else:
|
40 |
+
test_data.append(current_row.strip())
|
41 |
+
|
42 |
+
current_row = carry_over
|
43 |
+
current_token_count = len(tokenizer(current_row.strip())['input_ids'])
|
44 |
+
|
45 |
+
# Add the line to the current row
|
46 |
+
current_row += (line_to_add + "\n") if current_row else (line_to_add + "\n")
|
47 |
+
current_token_count += num_tokens
|
48 |
+
|
49 |
+
# Save as train.csv and test.csv
|
50 |
+
with open('train.csv', 'w', newline='') as f:
|
51 |
+
writer = csv.writer(f)
|
52 |
+
writer.writerow(['Text'])
|
53 |
+
for row in train_data:
|
54 |
+
writer.writerow([row])
|
55 |
+
|
56 |
+
with open('test.csv', 'w', newline='') as f:
|
57 |
+
writer = csv.writer(f)
|
58 |
+
writer.writerow(['Text'])
|
59 |
+
for row in test_data:
|
60 |
+
writer.writerow([row])
|
test.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
train.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|