Update README.md
Browse files
README.md
CHANGED
@@ -30,6 +30,55 @@ It achieves the following results on the evaluation set:
|
|
30 |
- Validation F1 Score (macro): 0.8105
|
31 |
- Validation F1 Score (weighted): 0.8551
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
## Model Details
|
34 |
|
35 |
### Model Description
|
|
|
30 |
- Validation F1 Score (macro): 0.8105
|
31 |
- Validation F1 Score (weighted): 0.8551
|
32 |
|
33 |
+
## How to use
|
34 |
+
|
35 |
+
You can use this model with a pipeline for text classification.
|
36 |
+
But first, you need to install the `peft` library like so:
|
37 |
+
|
38 |
+
```console
|
39 |
+
pip install peft
|
40 |
+
```
|
41 |
+
|
42 |
+
Then, you can run the following code.
|
43 |
+
|
44 |
+
```python
|
45 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
|
46 |
+
|
47 |
+
model_id = "xlm-roberta-base"
|
48 |
+
peft_model_id = "rasyosef/xlm-roberta-base-lora-amharic-news-classification"
|
49 |
+
|
50 |
+
categories = ['ሀገር አቀፍ ዜና', 'መዝናኛ', 'ስፖርት', 'ቢዝነስ', 'ዓለም አቀፍ ዜና', 'ፖለቲካ']
|
51 |
+
id2label = {i: lbl for i, lbl in enumerate(categories)}
|
52 |
+
label2id = {lbl: i for i, lbl in enumerate(categories)}
|
53 |
+
|
54 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
55 |
+
|
56 |
+
model = AutoModelForSequenceClassification.from_pretrained(
|
57 |
+
model_id,
|
58 |
+
num_labels=len(categories), # 6
|
59 |
+
id2label=id2label,
|
60 |
+
label2id=label2id
|
61 |
+
)
|
62 |
+
|
63 |
+
model.load_adapter(peft_model_id)
|
64 |
+
|
65 |
+
classifier = pipeline("text-classification", model=model, tokenizer=tokenizer)
|
66 |
+
|
67 |
+
classifier([
|
68 |
+
"""ቅርሶቹን ለመታደግ የተጀመረው የሙዚዬም ግንባታም በበጀት ምክንያት ተቋርጧል።
|
69 |
+
|
70 |
+
በአፄ ቴዎድሮስ የንግስና ቦታ ደረስጌ ማሪያም ተጀምሮ የቆመው የሙዚየሙ ግንባታ ተጠናቀቆ ስራ
|
71 |
+
እንዲጀምር ነዋሪዎች ጠይቀዋል። ዘመነ መሳፍንት መቋጫ ያገኘባት የኢትዮጵያ አንድነት የታወጀባት ዳግማዊ
|
72 |
+
አፄ ቴዎድሮስ ከመንገሳቸው በፊት ደጃች ውቤን ቧሂት ከሚባል ቦታ ድል አድርገው ደጃች ውቤ ለንግስና ባዘጋጁት የንግስና ቦታና
|
73 |
+
እቃዎች ንጉሰ ነገስት ዘኢትዮጵያ ተብለው የነገሱባት ቦታ ናት።""", # 'ሀገር አቀፍ ዜና'
|
74 |
+
])
|
75 |
+
```
|
76 |
+
|
77 |
+
Output:
|
78 |
+
```python
|
79 |
+
[{'label': 'ሀገር አቀፍ ዜና', 'score': 0.977573037147522}]
|
80 |
+
```
|
81 |
+
|
82 |
## Model Details
|
83 |
|
84 |
### Model Description
|