Working with Hugging Face
Jacob H. Marquez
Lead Data Engineer
Question: "What are the action steps?"
Question: "What type of animal is in this picture?"
from transformers import pipeline dqa = pipeline( task="document-question-answering", model="naver-clova-ix/donut-base-finetuned-docvqa")
document_image = "memo.jpg" question_text = "What is this memo about?"
results = dqa(document_image, question_text)
print(results)
{
"score": 0.789,
"start": 1,
"end": 2,
"answer": "distribution",
"words": [102]
}
dqa(image=image,
question=question,
max_answer_len=15)
score
is the probability of the answeranswer
is the answer to the questionstart
is the start word index of the answerend
is the last word index of the answerwords
is a list of all indices for each word in the answer
from transformers import pipeline
vqa = pipeline(
task="visual-question-answering",
model="dandelin/vilt-b32-finetuned-vqa"
)
result = vqa(
image="image.jpeg",
question="what's the person wearing?")
print(result)
[
{'score': 0.9795706272125244,
'answer': 'hat'
},
...,
{'score': 0.02153933234512806,
'answer': 'hoodie'
}
]
label
label identified by the modelscore
probability of the label from the modelWorking with Hugging Face