Update README.md
Browse files
README.md
CHANGED
@@ -7,6 +7,35 @@ library_name: peft
|
|
7 |
|
8 |
<!-- Provide a quick summary of what the model is/does. -->
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
|
12 |
## Model Details
|
|
|
7 |
|
8 |
<!-- Provide a quick summary of what the model is/does. -->
|
9 |
|
10 |
+
## How to Use
|
11 |
+
|
12 |
+
```python
|
13 |
+
from transformers import AutoTokenizer, AutoModelForQuestionAnswering, pipeline
|
14 |
+
from peft import PeftModel, PeftConfig
|
15 |
+
|
16 |
+
config = PeftConfig.from_pretrained("MohamedShakhsak/bert-qa-squad2_V1")
|
17 |
+
base_model = AutoModelForQuestionAnswering.from_pretrained(config.base_model_name_or_path)
|
18 |
+
model = PeftModel.from_pretrained(base_model, "MohamedShakhsak/bert-qa-squad2_V1")
|
19 |
+
|
20 |
+
tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)
|
21 |
+
qa_pipeline = pipeline("question-answering", model=model, tokenizer=tokenizer)
|
22 |
+
|
23 |
+
examples = [
|
24 |
+
{
|
25 |
+
"question": "What is the capital of France?",
|
26 |
+
"context": "Paris is the capital and most populous city of France."
|
27 |
+
},
|
28 |
+
{
|
29 |
+
"question": "When was the iPhone first released?",
|
30 |
+
"context": "The first iPhone was released by Apple Inc. on June 29, 2007."
|
31 |
+
}
|
32 |
+
]
|
33 |
+
|
34 |
+
for example in examples:
|
35 |
+
answer = qa_pipeline(example)
|
36 |
+
print(f"Q: {example['question']}\nA: {answer}\n")
|
37 |
+
```
|
38 |
+
|
39 |
|
40 |
|
41 |
## Model Details
|