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
| [email protected] | |
| [email protected] | |
| [email protected] | |
| [email protected] | |
| [email protected] | |
| [email protected] | |
| [email protected] | |
| [email protected] | |
| [email protected] | |
| [email protected] |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
| """ | |
| Here is a dice loss for keras which is smoothed to approximate a linear (L1) loss. | |
| It ranges from 1 to 0 (no error), and returns results similar to binary crossentropy | |
| """ | |
| # define custom loss and metric functions | |
| from keras import backend as K | |
| def dice_coef(y_true, y_pred, smooth=1): |
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
| """ | |
| A weighted version of categorical_crossentropy for keras (2.0.6). This lets you apply a weight to unbalanced classes. | |
| @url: https://gist.github.com/wassname/ce364fddfc8a025bfab4348cf5de852d | |
| @author: wassname | |
| """ | |
| from keras import backend as K | |
| def weighted_categorical_crossentropy(weights): | |
| """ | |
| A weighted version of keras.objectives.categorical_crossentropy | |
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 cmudict/CMU Pronouncing Dictionary as a dataset for keras | |
| author: wassname | |
| url : https://gist.github.com/wassname/ce0ac72c50832b0a27e67bd97ba36080 | |
| """ | |
| from keras.utils.data_utils import get_file | |
| from sklearn.model_selection import train_test_split | |
| import numpy as np |
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
| """ | |
| A keras attention layer that wraps RNN layers. | |
| Based on tensorflows [attention_decoder](https://github.com/tensorflow/tensorflow/blob/c8a45a8e236776bed1d14fd71f3b6755bd63cc58/tensorflow/python/ops/seq2seq.py#L506) | |
| and [Grammar as a Foreign Language](https://arxiv.org/abs/1412.7449). | |
| date: 20161101 | |
| author: wassname | |
| url: https://gist.github.com/wassname/5292f95000e409e239b9dc973295327a | |
| """ |
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
| """ | |
| Url: https://gist.github.com/wassname/1393c4a57cfcbf03641dbc31886123b8 | |
| """ | |
| import unicodedata | |
| import string | |
| valid_filename_chars = "-_.() %s%s" % (string.ascii_letters, string.digits) | |
| char_limit = 255 | |
| def clean_filename(filename, whitelist=valid_filename_chars, replace=' '): |
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
| from io import StringIO | |
| import pandas as pd | |
| import numpy as np | |
| import sklearn | |
| def parse_classification_report(classification_report): | |
| """Parses sklearn classification report into a pandas dataframe.""" | |
| return pd.read_fwf(StringIO(classification_report),lineterminator='\n', index_col=0, colspecs=[(0,12),(12,22),(22,32),(32,42),(42,52)]).dropna() | |
| target_names['leak','no leak'] |
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
| # from https://gist.github.com/wassname/00b94dc7eb7220c136685fce782be3a4 | |
| from io import StringIO | |
| import pandas as pd | |
| import numpy as np | |
| from sklearn import metrics | |
| import sklearn | |
| def parse_classification_report(classification_report): | |
| """Parse a sklearn classification report to a dict.""" | |
| return pd.read_fwf( |