File size: 2,441 Bytes
e34c175
492f0d3
 
e34c175
 
492f0d3
e34c175
 
 
01a12c9
e34c175
 
 
 
d0e2ffe
 
 
 
 
 
 
e34c175
d0e2ffe
00ec0fb
 
d0e2ffe
 
 
 
 
 
 
 
 
 
dd77a1f
 
 
d0e2ffe
 
 
 
e34c175
 
 
 
 
 
d0e2ffe
 
 
e34c175
 
d0e2ffe
01a12c9
492f0d3
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
---
language:
- he
pipeline_tag: zero-shot-classification
datasets:
- HeTree/MevakerConcTree
license: apache-2.0
---

# Hebrew Cross-Encoder Model

## Usage
```python
from sentence_transformers import CrossEncoder
import numpy as np

# Function that applies sigmoid to a score
def sigmoid(x):
    return 1 / (1 + np.exp(-x))

model = CrossEncoder('HeTree/HeCross')

# Scores (already after sigmoid)
scores = model.predict([('כמה אנשים חיים בברלין?', 'ברלין מונה 3,520,031 תושבים רשומים בשטח של 891.82 קמ"ר.'), 
                        ('כמה אנשים חיים בברלין?', 'העיר ניו יורק מפורסמת בזכות מוזיאון המטרופוליטן לאומנות.')])
print(scores)
```

## Usage with Transformers AutoModel
You can use the model also directly with Transformers library (without SentenceTransformers library):
```python
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
model = AutoModelForSequenceClassification.from_pretrained('HeTree/HeCross')
tokenizer = AutoTokenizer.from_pretrained('HeTree/HeCross')
features = tokenizer(['כמה אנשים חיים בברלין?', 'כמה אנשים חיים בברלין?'],
                     ['ברלין מונה 3,520,031 תושבים רשומים בשטח של 891.82 קמ"ר.', 'העיר ניו יורק מפורסמת בזכות מוזיאון המטרופוליטן לאומנות.'],
                     padding=True, truncation=True, return_tensors="pt")
model.eval()
with torch.no_grad():
    scores = sigmoid(model(**features).logits)
    print(scores)
```

## Zero-Shot Classification
This model can also be used for zero-shot-classification:
```python
from transformers import pipeline
classifier = pipeline("zero-shot-classification", model='HeTree/HeCross')
sent = "בשבוע שעבר שדרגתי את גרסת  הטלפון שלי ."
candidate_labels = ["נייד לשיחות", "אתר", "חיוב חשבון", "גישה לחשבון בנק"]
res = classifier(sent, candidate_labels)
print(res)
``` 

### Citing

If you use HeConE in your research, please cite [HeRo: RoBERTa and Longformer Hebrew Language Models](http://arxiv.org/abs/2304.11077).
```
@article{shalumov2023hero,
      title={HeRo: RoBERTa and Longformer Hebrew Language Models}, 
      author={Vitaly Shalumov and Harel Haskey},
      year={2023},
      journal={arXiv:2304.11077},
}