Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
167 changes: 167 additions & 0 deletions configs/train/siren_train_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
{
"experiment_name": "siren_ml1m_test",
"dataset": {
"type": "negative_ratings_graph",
"positive_domain": "positive",
"graph_dir_path": "../data/ml-1m",
"dataset": {
"type": "negative_rating",
"positive_domain": "positive",
"negative_domain": "negative",
"path_to_data_dir": "../data",
"name": "ml-1m",
"max_sequence_length": 50,
"samplers": {
"num_negatives_val": 100,
"type": "negative_ratings_next_item_prediction",
"negative_sampler_type": "negative_ratings_negative_sampler",
"negative_sampler_type_graph": "random",
"positive_domain": "positive",
"offset": 4
}
}
},
"dataloader": {
"train": {
"type": "torch",
"batch_size": 256,
"batch_processor": {
"type": "negative_batch"
},
"drop_last": true,
"shuffle": true
},
"validation": {
"type": "torch",
"batch_size": 256,
"batch_processor": {
"type": "negative_batch"
},
"drop_last": false,
"shuffle": false
}
},
"model": {
"type": "siren",
"user_prefix": "user.graph",
"positive_prefix": "positive.graph",
"negative_prefix": "negative.graph",
"candidate_prefix": "candidates.graph",
"mlp_layers": 2,
"embedding_dim": 64,
"num_layers": 3,
"dropout": 0.5,
"initializer_range": 0.02
},
"optimizer": {
"type": "basic",
"optimizer": {
"type": "adam",
"lr": 0.001
}
},
"loss": {
"type": "composite",
"losses": [
{
"type": "bpr",
"positive_prefix": "positive_scores",
"negative_prefix": "negative_scores",
"output_prefix": "lightgcn_downstream_loss"
},
{
"type": "regularization",
"prefix": [
"item_embeddings"
],
"weight": 1e-2,
"output_prefix": "lightgcn_regularization_loss"
}
],
"output_prefix": "lightgcn_loss"
},
"callback": {
"type": "composite",
"callbacks": [
{
"type": "metric",
"on_step": 1,
"loss_prefix": "lightgcn_loss"
},
{
"type": "metric",
"on_step": 1,
"loss_prefix": "lightgcn_downstream_loss"
},
{
"type": "metric",
"on_step": 1,
"loss_prefix": "lightgcn_regularization_loss"
},
{
"type": "validation",
"on_step": 64,
"pred_prefix": "logits",
"labels_prefix": "labels.graph",
"metrics": {
"ndcg@5": {
"type": "ndcg",
"k": 5
},
"ndcg@10": {
"type": "ndcg",
"k": 10
},
"ndcg@20": {
"type": "ndcg",
"k": 20
},
"recall@5": {
"type": "recall",
"k": 5
},
"recall@10": {
"type": "recall",
"k": 10
},
"recall@20": {
"type": "recall",
"k": 20
}
}
},
{
"type": "eval",
"on_step": 256,
"pred_prefix": "logits",
"labels_prefix": "labels.graph",
"metrics": {
"ndcg@5": {
"type": "ndcg",
"k": 5
},
"ndcg@10": {
"type": "ndcg",
"k": 10
},
"ndcg@20": {
"type": "ndcg",
"k": 20
},
"recall@5": {
"type": "recall",
"k": 5
},
"recall@10": {
"type": "recall",
"k": 10
},
"recall@20": {
"type": "recall",
"k": 20
}
}
}
]
}
}
2 changes: 1 addition & 1 deletion modeling/callbacks/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .base import BaseCallback, CompositeCallback, EvalCallback
from .base import BaseCallback, CompositeCallback, EvalCallback, ValidationCallback
29 changes: 29 additions & 0 deletions modeling/dataloader/batch_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,32 @@ def __call__(self, batch):
processed_batch[part] = torch.tensor(values, dtype=torch.long)

return processed_batch


class NegativeBatchProcessor(BaseBatchProcessor, config_name='negative_batch'):

def __call__(self, batch):
processed_batch = {}

for key in batch[0].keys():
if key.endswith('.ids'):
# prefix = key.split('.')[0]
prefix = key[:-4]
assert '{}.length'.format(prefix) in batch[0]

processed_batch[f'{prefix}.ids'] = []
processed_batch[f'{prefix}.length'] = []

for sample in batch:
# Тк item.negative_domain.ids может не быть из-за отсутствия негативных взаимодействий пользователя
if f'{prefix}.ids' in sample:
processed_batch[f'{prefix}.ids'].extend(sample[f'{prefix}.ids'])
processed_batch[f'{prefix}.length'].append(sample[f'{prefix}.length'])

for part, values in processed_batch.items():
if part == 'ratings.ids':
processed_batch[part] = torch.tensor(values, dtype=torch.float)
else:
processed_batch[part] = torch.tensor(values, dtype=torch.long)

return processed_batch
Loading