Jsevisal commited on
Commit
d49ebb9
·
verified ·
1 Parent(s): 16be28e

Add usage examples to README.md

Browse files
Files changed (1) hide show
  1. README.md +30 -0
README.md CHANGED
@@ -29,6 +29,36 @@ It achieves the following results on the evaluation set:
29
  - F1 Score: 0.9322
30
 
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  ## Training procedure
33
 
34
  ### Training hyperparameters
 
29
  - F1 Score: 0.9322
30
 
31
 
32
+ ## Usage
33
+
34
+ Pre-trained models can be used like this:
35
+ ```python
36
+ from sentence_transformers import CrossEncoder
37
+ model = CrossEncoder('Jsevisal/CrossEncoder-ModernBERT-base-qnli')
38
+ scores = model.predict([('Query1', 'Paragraph1'), ('Query2', 'Paragraph2')])
39
+
40
+ #e.g.
41
+ scores = model.predict([('How many people live in Berlin?', 'Berlin had a population of 3,520,031 registered inhabitants in an area of 891.82 square kilometers.'), ('What is the size of New York?', 'New York City is famous for the Metropolitan Museum of Art.')])
42
+ ```
43
+
44
+ ## Usage with Transformers AutoModel
45
+ You can use the model also directly with Transformers library (without SentenceTransformers library):
46
+ ```python
47
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
48
+ import torch
49
+
50
+ model = AutoModelForSequenceClassification.from_pretrained('Jsevisal/CrossEncoder-ModernBERT-base-qnli')
51
+ tokenizer = AutoTokenizer.from_pretrained('Jsevisal/CrossEncoder-ModernBERT-base-qnli')
52
+
53
+ features = tokenizer(['How many people live in Berlin?', 'What is the size of New York?'], ['Berlin had a population of 3,520,031 registered inhabitants in an area of 891.82 square kilometers.', 'New York City is famous for the Metropolitan Museum of Art.'], padding=True, truncation=True, return_tensors="pt")
54
+
55
+ model.eval()
56
+ with torch.no_grad():
57
+ scores = torch.nn.functional.sigmoid(model(**features).logits)
58
+ print(scores)
59
+ ```
60
+
61
+
62
  ## Training procedure
63
 
64
  ### Training hyperparameters