-
Notifications
You must be signed in to change notification settings - Fork 10
/
gpt_2_processor.py
53 lines (40 loc) · 1.04 KB
/
gpt_2_processor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""Dataset processor for GPT-2.
Reformats The Beatles' lyrics dataset and writes it out to a file. For each
song, the title is written on the first line, the writers on the second, then
the lyrics on the next N lines. Finally, two blank lines are written before
the start of the next song. E.g.:
<Song 1 Title>
<Song 1 Writer(s)>
<Song 1 Lyrics>
<Song 1 Lyrics>
...
<Song 1 Lyrics>
<Song 2 Title>
<Song 2 Writer(s)>
<Song 2 Lyrics>
<Song 2 Lyrics>
...
<Song 1 Lyrics>
...
...
...
<Song m Title>
<Song m Writer(s)>
<Song m Lyrics>
<Song m Lyrics>
<Song m Lyrics>
"""
if __name__ == '__main__':
with open('dataset.txt', 'r') as file_:
songs = file_.readlines()
dataset = ''
for song in songs:
song = song.strip()
title, author, song = song.split('\t')
dataset += "{}\n{}\n".format(title, author)
lyrics = song.split('\\')
for lyric in lyrics:
dataset += lyric + '\n'
dataset += '\n\n'
with open('gpt_2_dataset.txt', 'w') as file_:
file_.write(dataset)