Example: Question Answering
Last updated
Last updated
Question answering models can retrieve the answer to a question from a given text, which is useful for searching for an answer in a document.
Throughout the guide, we will use a simple question answering model based on 🤗 HuggingFace
This downloads a default pretrained model and tokenizer for Questioning Answering. Now you can use the qa_model
on your target question / context:
To extract embeddings from the model, we'll first need to do two things:
Pass output_hidden_states=True
to our model params.
When we call pipeline(...)
it does a lot of things for us - preprocessing, inference, and postprocessing. We'll need to break all this, so we can interfere in the middle and get embeddings 😉
In other words:
And finally, to extract embeddings for this prediction:
The next step would be to store your predictions in a data store, including the embeddings themselves. For more information on storing your predictions, please check out the Storing Your Predictions section.
For example, you could use a Parquet file on S3 or a Postgres table that looks like this:
Now let’s add some monitoring to this model 🚀 To monitor this model in Aporia, the first step is to create a model version:
Next, we can log predictions directly to Aporia:
Alternatively, connect Aporia to a data source. For more information, see Data Sources - Overview:
Your model should now be integrated to Aporia! 🎉
id | question | context | embeddings | answer | score | timestamp |
---|---|---|---|---|---|---|
1
Where are the best cookies?
The best cookies are in...
[0.77, 0.87, 0.94, ...]
Aporia's Office
0.982
2021-11-20 13:41:00
2
Where is the best hummus?
The best hummus is in...
[0.97, 0.82, 0.13, ...]
Another Place
0.881
2021-11-20 13:45:00
3
Where is the best burger?
The best burger is in...
[0.14, 0.55, 0.66, ...]
Blablabla
0.925
2021-11-20 13:49:00