Views
No views yet
pip install -U sentence-transformers1from sentence_transformers import CrossEncoder
2
3# Download from the 🤗 Hub
4model = CrossEncoder("BSC-NLP4BIA/Distemist-CE-Reranker")
5# Get scores for pairs of texts
6pairs = [
7 ['How many calories in an egg', 'There are on average between 55 and 80 calories in an egg depending on its size.'],
8 ['How many calories in an egg', 'Egg whites are very low in calories, have no fat, no cholesterol, and are loaded with protein.'],
9 ['How many calories in an egg', 'Most of the calories in an egg come from the yellow yolk in the center.'],
10]
11scores = model.predict(pairs)
12print(scores.shape)
13# (3,)
14
15# Or rank different texts based on similarity to a single text
16ranks = model.rank(
17 'How many calories in an egg',
18 [
19 'There are on average between 55 and 80 calories in an egg depending on its size.',
20 'Egg whites are very low in calories, have no fat, no cholesterol, and are loaded with protein.',
21 'Most of the calories in an egg come from the yellow yolk in the center.',
22 ]
23)
24# [{'corpus_id': ..., 'score': ...}, {'corpus_id': ..., 'score': ...}, ...]