Commit
路
56c445e
1
Parent(s):
e38f108
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,42 @@
|
|
| 1 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
license: afl-3.0
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
pipeline_tag: question-answering
|
| 3 |
+
tags:
|
| 4 |
+
- feature-extraction
|
| 5 |
+
language:
|
| 6 |
+
- en
|
| 7 |
license: afl-3.0
|
| 8 |
---
|
| 9 |
+
|
| 10 |
+
[Extractive Question Answering application.](https://raphaelsty.github.io/blog/template/)
|
| 11 |
+
|
| 12 |
+
```python
|
| 13 |
+
import re
|
| 14 |
+
|
| 15 |
+
from transformers import pipeline
|
| 16 |
+
|
| 17 |
+
qa = pipeline(
|
| 18 |
+
"question-answering", model="raphaelsty/carbonblog", tokenizer="raphaelsty/carbonblog"
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
def clean(document):
|
| 22 |
+
"""Pre-process the document."""
|
| 23 |
+
document = re.sub("[^a-zA-Z0-9 \n\.]", " ", document)
|
| 24 |
+
document = re.sub("\s\s+", " ", document)
|
| 25 |
+
# [NONE] allows the model to handle missing components.
|
| 26 |
+
document = f"[NONE] {document.lower()}"
|
| 27 |
+
return document
|
| 28 |
+
```
|
| 29 |
+
|
| 30 |
+
```python
|
| 31 |
+
document = clean("body: 83% nylon 17% spandex; lace: 86% nylon 14% spandex")
|
| 32 |
+
```
|
| 33 |
+
|
| 34 |
+
```python
|
| 35 |
+
qa({"question": "What is the 1 component ?", "context": document})
|
| 36 |
+
```
|
| 37 |
+
|
| 38 |
+
```json
|
| 39 |
+
{"score": 0.9999976754188538, "start": 32, "end": 36, "answer": "lace"}
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
|