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 keras.backend as K | |
dtype='float16' | |
K.set_floatx(dtype) | |
# default is 1e-7 which is too small for float16. Without adjusting the epsilon, we will get NaN predictions because of divide by zero problems | |
K.set_epsilon(1e-4) |
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 math | |
import matplotlib | |
import matplotlib.pyplot as plt | |
from matplotlib.ticker import PercentFormatter | |
# x is a vector representing a sentence. Sentence is an vector of integers. | |
# this method returns a matrix Z of size number_of_tokens_in_sentence * number_of_tokens_in_sentence | |
# st that z[i][j] == x[j] except when i==j, z[i][j] == 0. ie the token is blanked out with the padding indicator | |
def create_occlusion_batch(x): | |
number_tokens_in_sentence=x.shape[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
def make_random_input_sentence(sequence_length=300): | |
import random | |
input_words=list() | |
input_sentence=list() | |
for i in range(0,sequence_length): | |
word=random.choice(list(sg.wv.vocab.keys())) | |
input_words.append(word) | |
vector=sg[word] | |
input_sentence.append(vector) | |
disease_token_bit=np.zeros((sequence_length,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
np.random.normal(loc=0.0, scale=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
def make_random_input_sentence(sequence_length=300,word2vec): | |
import random | |
input_words=list() | |
input_sentence=list() | |
for i in range(0,sequence_length): | |
word=random.choice(list(sg.wv.vocab.keys())) | |
input_words.append(word) | |
vector=word2vec[word] | |
input_sentence.append(vector) | |
input_sentence=np.array(input_sentence) |
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
# converts array of embedding intergers to a list of tokens that those integers represent | |
# the disease token is shown in upper case | |
# x_1 = array of embedding integers | |
# x_2 = array of disease phrase indicators | |
def embeddings_to_tokens(x_1,x_2,retain_null=True): | |
tokens=list([embedding_to_token_map[embedding_id] for embedding_id in x_1]) | |
for i in range(0,x_2.shape[0]): | |
if x_2[i]==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
public interface IQueryString { | |
Option<string> GetValue(string key); | |
} |
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
public abstract partial class Either<T, U> {...} | |
//here are some business rules | |
public Either<LoanDeclinedReason, LoanRequest> CheckCustomerCredit(LoanRequest request) { | |
if (request.Customer.CreditScore > 8) return Either.Right(request); | |
return Either.Left(LoanDeclinedReason.InsufficientCreditScore); | |
} | |
public Either<LoanDeclinedReason, LoanRequest> CheckGoldPrerequisiteCustomer(LoanRequest request) { | |
if (request.Value < 10000) return Either.Right(request); //dont need gold status for less than 10,000 | |
if (request.Customer.GoldCustomer) return Either.Right(request); |
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
public static decimal GetTaxes(decimal salary) | |
{ | |
var taxBands = new[] | |
{ | |
new Tuple<Decimal, Decimal, Decimal>(0, 5070, 0.1m), | |
new Tuple<Decimal, Decimal, Decimal>(5070, 8660, 0.14m), | |
new Tuple<Decimal, Decimal, Decimal>(8660, 14070, 0.23m), | |
new Tuple<Decimal, Decimal, Decimal>(14070, 21240, 0.3m), | |
new Tuple<Decimal, Decimal, Decimal>(21240, 40230, 0.33m), | |
new Tuple<Decimal, Decimal, Decimal>(40230, Decimal.MaxValue, 0.45m) |
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 JsonpViewRenderer extends JsonViewRenderer { | |
var nameOfCallbackParameter = "callback" | |
private def jsonWithPadding(renderJson: => Unit, request: Request, response: Response) = { | |
val callbackOption = request.getStringParameter(nameOfCallbackParameter) | |
callbackOption match { | |
case None => renderJson | |
case Some(callback) => { | |
response.getWriter.write(callback + "(") |