This file contains 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
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: |
This file contains 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 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) |
This file contains 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 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() |
NewerOlder