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

Return best n categories when predicting #60

Open
sadrasabouri opened this issue Mar 13, 2022 · 2 comments · May be fixed by #61
Open

Return best n categories when predicting #60

sadrasabouri opened this issue Mar 13, 2022 · 2 comments · May be fixed by #61

Comments

@sadrasabouri
Copy link

Is your feature request related to a problem? Please describe.
In my case (using PLDA for information retrieval) it'd better to predict [let's say] best n options instead of the best one for a given query.
I figured out that the predict method does not support this feature. But it can be done using calc_logp_pp_categories method.

Describe the solution you'd like
My fast solution for solving this was to use bellow code:

def predict_doc_at(query, k=1):
    """
    Predict which document is matched to the given query.

    :param query: input query
    :type query: str (or list of strs)
    :param k: number of returning docs
    :type k: int 
    :return: return the document name
    """
    query_embedding = get_embeddings(query)
    data = PLDA_classifier.model.transform(query_embedding,
                                           from_space='D',
                                           to_space='U_model')
    logpps_k, K = PLDA_classifier.calc_logp_pp_categories(data,
                                                          False)
    best_k_idx = logpps_k.argsort()[::-1][:k]
    predictions = K[best_k_idx]
    return accuracy, predictions
@RaviSoji
Copy link
Owner

Thank you for writing this solution!

Would you mind making a pull request with the updated code and updating the Jupyter notebook with an example? I am happy to incorporate this.

Thanks again!
Ravi B. Sojitra

@sadrasabouri
Copy link
Author

Sure you can assign me this issue and I'll take care of if ASAP.

sadrasabouri added a commit to sadrasabouri/plda that referenced this issue Mar 28, 2022
@sadrasabouri sadrasabouri linked a pull request Mar 28, 2022 that will close this issue
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

Successfully merging a pull request may close this issue.

2 participants