Update README.md
Browse files
README.md
CHANGED
|
@@ -21,49 +21,65 @@ as well as Philosophy in Arabic.
|
|
| 21 |
For more details, check out our [example.com](paper)
|
| 22 |
|
| 23 |
|
| 24 |
-
|
|
|
|
| 25 |
|
| 26 |
```python
|
| 27 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
|
|
|
|
| 28 |
tokenizer = AutoTokenizer.from_pretrained("dru-acrps/ArGTClass")
|
| 29 |
model = AutoModelForSequenceClassification.from_pretrained("dru-acrps/ArGTClass", device_map = 'auto')
|
| 30 |
|
| 31 |
-
classifier = pipeline("text-classification", model=model, tokenizer= tokenizer)
|
| 32 |
-
|
| 33 |
text = " .قصفت إسرائيل مستشفى المعمداني في مدينة غزة، والذي خلف مئات الشهداء والجرحى"
|
| 34 |
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
```
|
| 38 |
|
| 39 |
|
| 40 |
-
### Pipeline example
|
| 41 |
|
| 42 |
```python
|
| 43 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
|
| 44 |
tokenizer = AutoTokenizer.from_pretrained("dru-acrps/ArGTClass")
|
| 45 |
model = AutoModelForSequenceClassification.from_pretrained("dru-acrps/ArGTClass", device_map = 'auto')
|
| 46 |
|
| 47 |
-
classifier = pipeline("text-classification", model=model, tokenizer= tokenizer
|
| 48 |
|
| 49 |
text = " .قصفت إسرائيل مستشفى المعمداني في مدينة غزة، والذي خلف مئات الشهداء والجرحى"
|
| 50 |
|
| 51 |
classifier(text)
|
| 52 |
```
|
| 53 |
|
| 54 |
-
|
|
|
|
| 55 |
|
| 56 |
```python
|
| 57 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
|
| 58 |
-
|
| 59 |
tokenizer = AutoTokenizer.from_pretrained("dru-acrps/ArGTClass")
|
| 60 |
model = AutoModelForSequenceClassification.from_pretrained("dru-acrps/ArGTClass", device_map = 'auto')
|
| 61 |
|
|
|
|
|
|
|
| 62 |
text = " .قصفت إسرائيل مستشفى المعمداني في مدينة غزة، والذي خلف مئات الشهداء والجرحى"
|
| 63 |
|
| 64 |
-
|
| 65 |
-
outputs = model(**inputs)
|
| 66 |
-
ind = outputs.logits.argmax(dim=-1)[0]
|
| 67 |
-
predicted_class = model.config.id2label[ind.item()]
|
| 68 |
```
|
| 69 |
-
|
|
|
|
| 21 |
For more details, check out our [example.com](paper)
|
| 22 |
|
| 23 |
|
| 24 |
+
|
| 25 |
+
### Full classification example
|
| 26 |
|
| 27 |
```python
|
| 28 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
|
| 29 |
+
|
| 30 |
tokenizer = AutoTokenizer.from_pretrained("dru-acrps/ArGTClass")
|
| 31 |
model = AutoModelForSequenceClassification.from_pretrained("dru-acrps/ArGTClass", device_map = 'auto')
|
| 32 |
|
|
|
|
|
|
|
| 33 |
text = " .قصفت إسرائيل مستشفى المعمداني في مدينة غزة، والذي خلف مئات الشهداء والجرحى"
|
| 34 |
|
| 35 |
+
inputs = tokenizer(text, return_tensors= 'pt')
|
| 36 |
+
outputs = model(**inputs)
|
| 37 |
+
ind = outputs.logits.argmax(dim=-1)[0]
|
| 38 |
+
predicted_class = model.config.id2label[ind.item()]
|
| 39 |
+
```
|
| 40 |
+
|
| 41 |
+
### Full classification example (GPU)
|
| 42 |
+
|
| 43 |
+
```python
|
| 44 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
|
| 45 |
+
|
| 46 |
+
tokenizer = AutoTokenizer.from_pretrained("dru-acrps/ArGTClass")
|
| 47 |
+
model = AutoModelForSequenceClassification.from_pretrained("dru-acrps/ArGTClass", device_map = 'auto')
|
| 48 |
+
|
| 49 |
+
text = " .قصفت إسرائيل مستشفى المعمداني في مدينة غزة، والذي خلف مئات الشهداء والجرحى"
|
| 50 |
|
| 51 |
+
inputs = tokenizer(text, return_tensors= 'pt')
|
| 52 |
+
outputs = model(**inputs)
|
| 53 |
+
ind = outputs.logits.argmax(dim=-1)[0]
|
| 54 |
+
predicted_class = model.config.id2label[ind.item()]
|
| 55 |
```
|
| 56 |
|
| 57 |
|
| 58 |
+
### Pipeline example
|
| 59 |
|
| 60 |
```python
|
| 61 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
|
| 62 |
tokenizer = AutoTokenizer.from_pretrained("dru-acrps/ArGTClass")
|
| 63 |
model = AutoModelForSequenceClassification.from_pretrained("dru-acrps/ArGTClass", device_map = 'auto')
|
| 64 |
|
| 65 |
+
classifier = pipeline("text-classification", model=model, tokenizer= tokenizer)
|
| 66 |
|
| 67 |
text = " .قصفت إسرائيل مستشفى المعمداني في مدينة غزة، والذي خلف مئات الشهداء والجرحى"
|
| 68 |
|
| 69 |
classifier(text)
|
| 70 |
```
|
| 71 |
|
| 72 |
+
|
| 73 |
+
### Pipeline example (GPU)
|
| 74 |
|
| 75 |
```python
|
| 76 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
|
|
|
|
| 77 |
tokenizer = AutoTokenizer.from_pretrained("dru-acrps/ArGTClass")
|
| 78 |
model = AutoModelForSequenceClassification.from_pretrained("dru-acrps/ArGTClass", device_map = 'auto')
|
| 79 |
|
| 80 |
+
classifier = pipeline("text-classification", model=model, tokenizer= tokenizer, device="cuda:0")
|
| 81 |
+
|
| 82 |
text = " .قصفت إسرائيل مستشفى المعمداني في مدينة غزة، والذي خلف مئات الشهداء والجرحى"
|
| 83 |
|
| 84 |
+
classifier(text)
|
|
|
|
|
|
|
|
|
|
| 85 |
```
|
|
|