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
| import numpy as np | |
| import math | |
| np.random.seed(423) | |
| # code for the environment | |
| class CartPoleEnv: | |
| def __init__(self): | |
| # Environment parameters | |
| self.gravity = 9.8 | |
| self.masscart = 1.0 |
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
| # inspired by micrograd and tinygrad | |
| import numpy as np | |
| class Tensor: | |
| def __init__(self, data, name=''): | |
| self.data = np.array(data) | |
| self.grad = np.zeros_like(self.data) | |
| self.parents = [] | |
| self.op = '' |
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
| <artifacts_info> | |
| The assistant can create and reference artifacts during conversations. Artifacts are for substantial, self-contained content that users might modify or reuse, displayed in a separate UI window for clarity. | |
| # Good artifacts are... | |
| - Substantial content (>15 lines) | |
| - Content that the user is likely to modify, iterate on, or take ownership of | |
| - Self-contained, complex content that can be understood on its own, without context from the conversation | |
| - Content intended for eventual use outside the conversation (e.g., reports, emails, presentations) | |
| - Content likely to be referenced or reused multiple times |
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
| document.getElementById("editor").addEventListener("keydown", function (event) { | |
| // Check if Enter is pressed without the Ctrl key | |
| if (event.key === "Enter" && !event.ctrlKey) { | |
| event.preventDefault(); | |
| } | |
| // Check if both Ctrl and Enter are pressed | |
| if (event.ctrlKey && event.key === "Enter") { | |
| event.preventDefault(); |
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
| class ProgressBar: | |
| def __init__(self, total, desc='', width=10): | |
| self.total = total | |
| self.width = width | |
| self.header = f"{desc}: " if len(desc) > 0 else '' | |
| self.i = 0 | |
| self.__print_progress() | |
| def __print_progress(self): | |
| p = round((self.i*self.width) / self.total) |
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
| ## | |
| # usage: | |
| # 1. Add '#export' as the first line of the cells you want to export. | |
| # This script will ignore all other cells. | |
| # 2. $python convert_nb_script.py -n sample.ipynb > sample_script.py | |
| # | |
| # You can use other tags to selectively export other cells | |
| # eg. Add tag #test to the cells containing unit tests | |
| # python convert_nb_script.py -n sample.ipynb -t test > unit_tests.py | |
| ## |
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
| def prefix_beam_search(ctc, | |
| alphabet, | |
| blank_token, | |
| end_token, | |
| space_token, | |
| lm, | |
| k=25, | |
| alpha=0.30, | |
| beta=5, | |
| prune=0.001): |
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
| def create_spectrogram(signals): | |
| stfts = tf.signal.stft(signals, fft_length=256) | |
| spectrograms = tf.math.pow(tf.abs(stfts), 0.5) | |
| return spectrograms |
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
| class ASR(tf.keras.Model): | |
| def __init__(self, filters, kernel_size, conv_stride, conv_border, n_lstm_units, n_dense_units): | |
| super(ASR, self).__init__() | |
| self.conv_layer = tf.keras.layers.Conv1D(filters, | |
| kernel_size, | |
| strides=conv_stride, | |
| padding=conv_border, | |
| activation='relu') | |
| self.lstm_layer = tf.keras.layers.LSTM(n_lstm_units, | |
| return_sequences=True, |
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
| class Cache: | |
| ''' | |
| class to cache the probability values while performing prefix beam search | |
| ''' | |
| def __init__(self): | |
| self.data = {} | |
| def add(self, key1, key2, value): | |
| if key1 not in self.data: | |
| self.data[key1] = {} |
NewerOlder