-
Notifications
You must be signed in to change notification settings - Fork 623
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from RUCAIBox/master
update
- Loading branch information
Showing
15 changed files
with
438 additions
and
104 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,26 @@ | ||
from logging import getLogger | ||
from recbox.config import Config | ||
from recbox.data import create_dataset, data_preparation | ||
from recbox.trainer import get_trainer | ||
from recbox.utils import init_logger, get_model | ||
import json | ||
from argparse import ArgumentParser | ||
from run_test import whole_process | ||
|
||
config = Config('properties/overall.config') | ||
config.init() | ||
init_logger(config) | ||
logger = getLogger() | ||
parser = ArgumentParser() | ||
parser.add_argument('--model', '-m', type=str, default='BPRMF', help='name of models') | ||
parser.add_argument('--dataset', '-d', type=str, default='ml-100k', help='name of datasets') | ||
parser.add_argument('--epochs', '-e', type=int, default=1, help='num of running epochs') | ||
|
||
dataset = create_dataset(config) | ||
logger.info(dataset) | ||
args = parser.parse_args() | ||
|
||
# If you want to customize the evaluation setting, | ||
# please refer to `data_preparation()` in `data/utils.py`. | ||
train_data, test_data, valid_data = data_preparation(config, dataset) | ||
args_dict = { | ||
'model': args.model, | ||
'dataset': args.dataset, | ||
'epochs': args.epochs | ||
} | ||
|
||
model = get_model(config['model'])(config, train_data).to(config['device']) | ||
logger.info(model) | ||
with open('presets.json', 'r', encoding='utf-8') as preset_file: | ||
presets_dict = json.load(preset_file) | ||
|
||
trainer = get_trainer(config['MODEL_TYPE'])(config, model) | ||
token = '-'.join([args.model, args.dataset]) | ||
if token in presets_dict: | ||
print('Hit preset: [{}]'.format(token)) | ||
args_dict.update(presets_dict) | ||
|
||
# trainer.resume_checkpoint('saved/model_best.pth') | ||
best_valid_score, _ = trainer.fit(train_data, valid_data) | ||
result = trainer.evaluate(test_data) | ||
logger.info(best_valid_score) | ||
whole_process(config_dict=args_dict) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"BPRMF-ml-1m": { | ||
"train_batch_size": 4096, | ||
"metrics": ["Recall", "MRR", "NDCG", "Hit", "Precision"] | ||
}, | ||
"BPRMF-yelp": { | ||
"train_batch_size": 4096, | ||
"metrics": ["Recall", "MRR", "NDCG", "Hit", "Precision"], | ||
"min_user_inter_num": 25, | ||
"max_user_inter_num": 25 | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
[data] | ||
|
||
########define the UIRT columns | ||
USER_ID_FIELD='user_id' | ||
ITEM_ID_FIELD='item_id' | ||
NEG_PREFIX='neg_' | ||
LABEL_FIELD='label' | ||
RATING_FIELD='rating' | ||
HEAD_ENTITY_ID_FIELD='head_id' | ||
TAIL_ENTITY_ID_FIELD='tail_id' | ||
RELATION_ID_FIELD='relation_id' | ||
ENTITY_ID_FIELD='entity_id' | ||
|
||
#########select load columns | ||
load_col={'inter': ['user_id', 'item_id', 'rating'], 'kg': ['head_id', 'relation_id', 'tail_id'], 'link': ['item_id', 'entity_id']} | ||
|
||
########data separator | ||
field_separator='\t' | ||
seq_separator=' ' | ||
|
||
########data filter | ||
lowest_val={'rating':10} | ||
drop_filter_field=True | ||
min_user_inter_num=10 | ||
min_item_inter_num=10 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[model] | ||
|
||
embedding_size=64 | ||
kg_embedding_size=64 | ||
layers=[64] | ||
mess_dropout=[0.1] | ||
reg_weight=1e-5 | ||
kg_weight=0.5 |
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
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
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
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
Oops, something went wrong.