File size: 1,338 Bytes
9ef4b27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c0fcbfe
9ef4b27
72ccc70
9ef4b27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
eb48395
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
# MT5-Small Fine-tuned on Arabic Question Answering

This model is a fine-tuned version of MT5-Small for question answering tasks in Arabic.


## Training and evaluation data

The model was trained on the tydiqa-goldp dataset for Arabic.

## Training procedure

The model was fine-tuned using the Hugging Face Transformers library.

## How to use

You can use this model with the Transformers pipeline for question answering:

```python
import torch
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM

model_name = "HozRifai/mt5-ar-qa-v0"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model.to(device)

def generate_answer(question, context, max_length=64):
    input_text = f"question: {question} context: {context}"
    inputs = tokenizer(input_text, return_tensors="pt", max_length=max_length, truncation=True, padding="max_length").to(device)
    
    outputs = model.generate(
        **inputs,
        max_length=max_length,
        num_beams=4,
        length_penalty=2.0,
        early_stopping=True
    )
    
    return tokenizer.decode(outputs[0], skip_special_tokens=True)

context = ""
question = ""

answer = generate_answer(question, context)
print("Answer is: ", answer)
```