Skip to content

Instantly share code, notes, and snippets.

@GenevieveBuckley
GenevieveBuckley / test_monkeypatch.py
Last active December 12, 2023 18:57
Monkeypatching user input with pytest
from io import StringIO
def double():
x = input("Enter an integer: ")
return int(x) * 2
def adding():
x = float(input('Enter the first number'))
@grantcooksey
grantcooksey / stubber.py
Last active February 8, 2023 11:21
Mocking an S3 bucket using Stubber
import io
import json
import botocore.session
from botocore.stub import Stubber
from botocore.response import StreamingBody
expected_message = {
'message': 'readme'
}
@KevinLiao159
KevinLiao159 / tune_als.py
Created November 11, 2018 02:08
A function for ALS hyper-param tuning
from pyspark.ml.recommendation import ALS
def tune_ALS(train_data, validation_data, maxIter, regParams, ranks):
"""
grid search function to select the best model based on RMSE of
validation data
Parameters
----------
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@cbaziotis
cbaziotis / AttentionWithContext.py
Last active April 25, 2022 14:37
Keras Layer that implements an Attention mechanism, with a context/query vector, for temporal data. Supports Masking. Follows the work of Yang et al. [https://www.cs.cmu.edu/~diyiy/docs/naacl16.pdf] "Hierarchical Attention Networks for Document Classification"
def dot_product(x, kernel):
"""
Wrapper for dot product operation, in order to be compatible with both
Theano and Tensorflow
Args:
x (): input
kernel (): weights
Returns:
"""
if K.backend() == 'tensorflow':