-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #597 from CMU-IDeeL/f23_PrettyMeng
rec8
- Loading branch information
Showing
7 changed files
with
124,511 additions
and
9 deletions.
There are no files selected for viewing
Binary file renamed
BIN
+1.52 MB
...ion8/IDL_S23_Recitation_8__RNN_Basics.pdf → ...n/Recitation8/Fall2023-RNN-Recitation.pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import argparse | ||
import os | ||
import sys | ||
|
||
import numpy as np | ||
|
||
|
||
def read_corpus(): | ||
filename = 't8.shakespeare.txt' | ||
lines = [] | ||
with open(filename, 'r') as f: | ||
for pos, line in enumerate(f): | ||
if 243 < pos < 124440: | ||
if len(line.strip()) > 0: | ||
lines.append(line) | ||
corpus = " ".join(lines) | ||
return corpus | ||
|
||
|
||
def get_charmap(corpus): | ||
chars = list(set(corpus)) | ||
chars.sort() | ||
charmap = {c: i for i, c in enumerate(chars)} | ||
return chars, charmap | ||
|
||
|
||
def map_corpus(corpus, charmap): | ||
return np.array([charmap[c] for c in corpus], dtype=np.int64) | ||
|
||
|
||
def to_text(line, charset): | ||
return "".join([charset[c] for c in line]) | ||
|
||
|
||
def main(argv): | ||
|
||
# Read and process data | ||
corpus = read_corpus() | ||
print("Corpus: {}...{}".format(corpus[:50], corpus[-50:])) | ||
print("Total character count: {}".format(len(corpus))) | ||
chars, charmap = get_charmap(corpus) | ||
charcount = len(chars) | ||
print("Unique character count: {}".format(len(chars))) | ||
array = map_corpus(corpus, charmap) | ||
|
||
|
||
if __name__ == '__main__': | ||
main(sys.argv[1:]) |
Oops, something went wrong.