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

How to get the actual rank using trainer.predict()? #136

Open
littlewine opened this issue Mar 25, 2020 · 3 comments
Open

How to get the actual rank using trainer.predict()? #136

littlewine opened this issue Mar 25, 2020 · 3 comments
Labels
question Further information is requested

Comments

@littlewine
Copy link

Describe the Question

I am trying to get the rank out of a trained model (using trainer). However, when I do trainer.predict() I get back a numpy array of shape num_qids x 1. The number of query ids .predict returns is depending on the dataloader dl passed on trainer.predict(dl).

In other words, as I understand I get a score (probably the first metric I've defined on metrics?) for each query id. However, what I need is a ranked list of documents for each query id, rather than a single score.

How can I get that? I could find no solution through the tutorials.

My code looks like:


    trainer.run()

    # Evaluation
    print('Validation results:')
    print(trainer.evaluate(valid_dl))
    print('Test results:')
    print(trainer.evaluate(test_dl))


    val_preds = trainer.predict(valid_dl)
    test_preds = trainer.predict(train_dl)

val_preds.shape
>> Out[18]: (150, 1)
valid_dl.label.shape
>> Out[19]: (150,)

@littlewine littlewine added the question Further information is requested label Mar 25, 2020
@arita37
Copy link

arita37 commented Apr 26, 2020

Having more details on evaluate, it would be useful

@shimengfeng
Copy link

I think when you use .predict, you will get a list of scores. You can sort on those scores and then get the order of it using np.argsort. Then you can get the corresponding document using the order you obtained. This is my understanding and hopefully it is helpful.

@littlewine
Copy link
Author

littlewine commented Jun 18, 2020 via email

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

No branches or pull requests

3 participants