Update README.md
Browse files
README.md
CHANGED
|
@@ -11,4 +11,38 @@ base_model:
|
|
| 11 |
- aubmindlab/bert-base-arabertv02
|
| 12 |
pipeline_tag: text-classification
|
| 13 |
library_name: transformers
|
| 14 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
- aubmindlab/bert-base-arabertv02
|
| 12 |
pipeline_tag: text-classification
|
| 13 |
library_name: transformers
|
| 14 |
+
---
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
model loading:
|
| 19 |
+
```py
|
| 20 |
+
import torch
|
| 21 |
+
from transformers import (
|
| 22 |
+
AutoTokenizer,
|
| 23 |
+
AutoModelForSequenceClassification,
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
model_name = "AyaHazem61/araBERT-For-Hate-Speech-Detection"
|
| 27 |
+
|
| 28 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 29 |
+
model = AutoModelForSequenceClassification.from_pretrained(
|
| 30 |
+
model_name,
|
| 31 |
+
num_labels=2
|
| 32 |
+
)
|
| 33 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 34 |
+
model.to(device)
|
| 35 |
+
```
|
| 36 |
+
|
| 37 |
+
model predicting:
|
| 38 |
+
```py
|
| 39 |
+
texts = ["السلام عليكم و رحمة الله و بركاته"]
|
| 40 |
+
inputs = tokenizer(texts , return_tensors="pt", padding="max_length", truncation=True, max_length=512)
|
| 41 |
+
|
| 42 |
+
model .eval()
|
| 43 |
+
with torch.no_grad():
|
| 44 |
+
outputs = model (**inputs)
|
| 45 |
+
|
| 46 |
+
logits = outputs.logits
|
| 47 |
+
|
| 48 |
+
```
|