Skip to content

Instantly share code, notes, and snippets.

View BalazsHoranyi's full-sized avatar
🤖

Balazs Horanyi BalazsHoranyi

🤖
View GitHub Profile
interactions = da.from_npy_stack('interactions')
users = interactions[:,0]
items = interactions[:,1]
slicer = 10000000
for i in tqdm(range(math.ceil((len(interactions))/slicer))):
if i == 0:
user_set = set(users[i*slicer: (i+1)*slicer].compute())
else:
def to_dask_array(df):
# https://stackoverflow.com/questions/37444943/dask-array-from-dataframe?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
partitions = df.to_delayed()
shapes = [part.values.shape for part in partitions]
dtypes = partitions[0].dtypes
results = compute(dtypes, *shapes) # trigger computation to find shape
dtypes, shapes = results[0], results[1:]
chunks = [da.from_delayed(part.values, shape, dtypes)
def bpr_loss(positive_predictions, negative_predictions):
"""
Bayesian Personalised Ranking pairwise loss function. Original Implementation: https://github.com/maciejkula/spotlight
"""
loss = (1.0 - F.sigmoid(positive_predictions -
negative_predictions))
return loss.mean()