--- 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 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 # Function that applies sigmoid to a score def sigmoid(x): return 1 / (1 + np.exp(-x)) 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 HeCross 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}, } ```