Created
August 20, 2018 18:32
-
-
Save ImadDabbura/3f2b8c42465b6d6a2fcb37673d457160 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| # Load names | |
| data = open("../data/names.txt", "r").read() | |
| # Convert characters to lower case | |
| data = data.lower() | |
| # Construct vocabulary using unique characters, sort it in ascending order, | |
| # then construct two dictionaries that maps character to index and index to | |
| # characters. | |
| chars = list(sorted(set(data))) | |
| chars_to_idx = {ch:i for i, ch in enumerate(chars)} | |
| idx_to_chars = {i:ch for ch, i in chars_to_idx.items()} | |
| # Get the size of the data and vocab size | |
| data_size = len(data) | |
| vocab_size = len(chars_to_idx) | |
| print(f"There are {data_size} characters and {vocab_size} unique characters.") | |
| # Fitting the model | |
| parameters, loss = model("../data/names.txt", chars_to_idx, idx_to_chars, 100, vocab_size, 100, 0.01) | |
| # Plotting the loss | |
| plt.plot(range(len(loss)), loss) | |
| plt.xlabel("Epochs") | |
| plt.ylabel("Smoothed loss"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment