File size: 907 Bytes
0749dcb 56c445e 0749dcb 56c445e |
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 |
---
pipeline_tag: question-answering
tags:
- feature-extraction
language:
- en
license: afl-3.0
---
[Extractive Question Answering application.](https://raphaelsty.github.io/blog/template/)
```python
import re
from transformers import pipeline
qa = pipeline(
"question-answering", model="raphaelsty/carbonblog", tokenizer="raphaelsty/carbonblog"
)
def clean(document):
"""Pre-process the document."""
document = re.sub("[^a-zA-Z0-9 \n\.]", " ", document)
document = re.sub("\s\s+", " ", document)
# [NONE] allows the model to handle missing components.
document = f"[NONE] {document.lower()}"
return document
```
```python
document = clean("body: 83% nylon 17% spandex; lace: 86% nylon 14% spandex")
```
```python
qa({"question": "What is the 1 component ?", "context": document})
```
```json
{"score": 0.9999976754188538, "start": 32, "end": 36, "answer": "lace"}
```
|