Views
No views yet
1from transformers import AutoModelForSequenceClassification, AutoTokenizer
2
3# load model
4model = AutoModelForSequenceClassification.from_pretrained('dmrau/bow-bert')
5# load tokenizer
6tokenizer = AutoTokenizer.from_pretrained('bert-base-uncased')
7
8# tokenize query and passage and concatenate them
9inp = tokenizer(['this is a query','query a is this'], ['this is a passage', 'passage a is this'], return_tensors='pt')
10# get estimated score
11print('score', model(**inp).logits[:, 1])
12
13### outputs identical scores for different
14### word orders as the model is order invariant:
15# scores: [-2.9463, -2.9463]@article{rau2022role,
title={The Role of Complex NLP in Transformers for Text Ranking?},
author={Rau, David and Kamps, Jaap},
journal={arXiv preprint arXiv:2207.02522},
year={2022}
}