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

Simplify monoT5 and monoBERT boilerplate #80

Closed
lintool opened this issue Sep 9, 2020 · 3 comments · Fixed by #83
Closed

Simplify monoT5 and monoBERT boilerplate #80

lintool opened this issue Sep 9, 2020 · 3 comments · Fixed by #83

Comments

@lintool
Copy link
Member

lintool commented Sep 9, 2020

There's a lot of boilerplate here: https://github.com/castorini/pygaggle#a-simple-reranking-example

Can we fold all of that into the constructor of the class? E.g., so we're left with:

reranker =  monoT5()

or

reranker =  monoBERT()

Make model_name, tokenizer_name, etc. configurable with sensical defaults.

So simple reranking gets boiled down to

from pyserini.search import SimpleSearcher
from pygaggle.rerank.base import hits_to_texts

query = Query('who proposed the geocentric theory')
searcher = SimpleSearcher('/path/to/msmarco/index/')
reranker = monoBERT()

hits = searcher.search(query.text)
reranked = reranker.rerank(query, hits_to_texts(hits))
reranked.sort(key=lambda x: x.score, reverse=True)

@rodrigonogueira4 @rodrigonogueira4 thoughts?

@ronakice
Copy link
Member

ronakice commented Sep 9, 2020

Yeah, I think we should do that!

@rodrigonogueira4
Copy link
Member

I agree!

@yuxuan-ji
Copy link
Contributor

yuxuan-ji commented Sep 10, 2020

EDIT: Outdated comment

I'm a bit confused by the naming of this, is the goal to have a set of predefined rerankers w/ defaults
ex:

from pyaggle.rerank.pretrained import monoBERT, monoT5
reranker = monoBERT() or monoT5() -> Reranker # defaults to castorini/monobert-large-msmarco and castorini/monot5-base-msmarco

# similar to how huggingface transformers has:
AutoModel.from_pretrained('monoBERT')

or just to create general constructors for each reranker similar to what's in:
https://github.com/castorini/pygaggle/blob/master/pygaggle/run/evaluate_document_ranker.py#L103
i.e.

def construct_seq_class_transformer(options: DocumentRankingEvaluationOptions
                                    ) -> Reranker:
    model = AutoModelForSequenceClassification.from_pretrained(options.model, from_tf=options.from_tf)
    device = torch.device(options.device)
    model = model.to(device).eval()
    tokenizer = AutoTokenizer.from_pretrained(options.tokenizer_name)
    return SequenceClassificationTransformerReranker(model, tokenizer)

TLDR why name monoBERT vs construct_seq_class_transformer

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.

4 participants