Views
No views yet
1import re
2
3from transformers import pipeline
4
5qa = pipeline(
6 "question-answering", model="raphaelsty/carbonblog", tokenizer="raphaelsty/carbonblog"
7)
8
9def clean(document):
10 """Pre-process the document."""
11 document = re.sub("[^a-zA-Z0-9 \n\.]", " ", document)
12 document = re.sub("\s\s+", " ", document)
13 # [NONE] allows the model to handle missing components.
14 document = f"[NONE] {document.lower()}"
15 return documentdocument = clean("body: 83% nylon 17% spandex; lace: 86% nylon 14% spandex")qa({"question": "What is the 1 component ?", "context": document}){"score": 0.9999976754188538, "start": 32, "end": 36, "answer": "lace"}