Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evaluation does not work for RelationNet #3

Open
MrigankRaman opened this issue Jul 4, 2020 · 1 comment
Open

Evaluation does not work for RelationNet #3

MrigankRaman opened this issue Jul 4, 2020 · 1 comment
Assignees

Comments

@MrigankRaman
Copy link

The evaluation function was not implemented in the code. So, I implemented it but I get a CUDA error which I traced back to transformers. I am hereby attaching the screenshot of the error. So for context I trained the relationNet using roberta as the encoder and then when I try to evaluate the trained model, I get this error.
Screenshot (20)

@MrigankRaman
Copy link
Author

To reproduce the error just add the below code in the eval(args) function of rn.py file and run the script in eval mode.

model_path = os.path.join(args.save_dir, 'model.pt')

if 'lm' in args.ent_emb:
    print('Using contextualized embeddings for concepts')
    use_contextualized, cp_emb = True, None
else:
    use_contextualized = False
# cp_emb = [np.load(path) for path in args.ent_emb_paths]
# cp_emb = torch.tensor(np.concatenate(cp_emb, 1))

# concept_num, concept_dim = cp_emb.size(0), cp_emb.size(1)

# rel_emb = np.load(args.rel_emb_path)
# rel_emb = np.concatenate((rel_emb, -rel_emb), 0)
# rel_emb = cal_2hop_rel_emb(rel_emb)
# rel_emb = torch.tensor(rel_emb)
# relation_num, relation_dim = rel_emb.size(0), rel_emb.size(1)
device = torch.device("cuda:0" if torch.cuda.is_available() and args.cuda else "cpu")
model, old_args = torch.load(model_path, map_location = device)
model.to(device)
model.eval() 
dataset = LMRelationNetDataLoader(old_args.train_statements, args.train_rel_paths,
                                  old_args.dev_statements, args.dev_rel_paths,
                                  old_args.test_statements, args.test_rel_paths,
                                  batch_size=args.batch_size, eval_batch_size=args.eval_batch_size, device=device,
                                  model_name=args.encoder,
                                  max_tuple_num=args.max_tuple_num, max_seq_length=args.max_seq_len,
                                  is_inhouse=args.inhouse, inhouse_train_qids_path=args.inhouse_train_qids,
                                  use_contextualized=use_contextualized,
                                  train_adj_path=args.train_adj, dev_adj_path=args.dev_adj, test_adj_path=args.test_adj,
                                  train_node_features_path=args.train_node_features, dev_node_features_path=args.dev_node_features,
                                  test_node_features_path=args.test_node_features, node_feature_type=args.node_feature_type,
                                  format=args.format)
print()
print("***** runing evaluation *****")
print(f'| dataset: {old_args.dataset} | num_dev: {dataset.dev_size()} | num_test: {dataset.test_size()} | save_dir: {args.save_dir} |')
dev_acc = evaluate_accuracy(dataset.dev(), model)
test_acc = evaluate_accuracy(dataset.test(), model) if dataset.test_size() else 0.0
print("***** evaluation done *****")
print()
print(f'| dev_accuracy: {dev_acc} | test_acc: {test_acc} |')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants