adaptnlp
adaptnlp copied to clipboard
Save context in QuestionAnswering and re-use it
I notices when we run any code snippet, it convert the text to vectors or some similar thing. For example in this code snippet
from adaptnlp import EasyQuestionAnswering
from pprint import pprint
## Example Query and Context
query = "What is the meaning of life?"
context = "Machine Learning is the meaning of life."
top_n = 5
## Load the QA module and run inference on results
qa = EasyQuestionAnswering()
best_answer, best_n_answers = qa.predict_qa(query=query, context=context, n_best_size=top_n, mini_batch_size=1, model_name_or_path="distilbert-base-uncased-distilled-squad")
## Output top answer as well as top 5 answers
print(best_answer)
pprint(best_n_answers)
It convert both query and context to vectors first. What if we have very long context and we have a lot of queries, each time it will convert the context to vector. I think there should be a way to save context vector and re-use it instead of creating again and again.
This scenario is valid if we can feed length of context greater than Bert max sequence length. Can we?