Note
To use this tutorial, you need to install unitxt.
Dynamic Data Processing For Inference¶
Unitxt can be used to process data dynamically and generate model-ready inputs on the fly, based on a given task recipe.
First define a recipe:
recipe = "card=cards.wnli,template=templates.classification.multi_class.relation.default,demos_pool_size=5,num_demos=2"
Second, prepare an python dictionary object in the exact schema of the task used in that recipe:
instance = {
"label": "?",
"text_a": "It works perfectly",
"text_b": "It works!",
"classes": ["entailment", "not entailment"],
"type_of_relation": "entailment",
"text_a_type": "premise",
"text_b_type": "hypothesis",
}
Then you can produce the model-ready input data with the produce function:
from unitxt import produce
result = produce([instance], recipe)
Then you have the formatted instance in the result. If you print(result[0][“source”]) you will get:
Given a premise and hypothesis classify the entailment of the hypothesis to one of entailment, not entailment.
premise: When Tatyana reached the cabin, her mother was sleeping. She was careful not to disturb her, undressing and climbing back into her berth., hypothesis: mother was careful not to disturb her, undressing and climbing back into her berth.
The entailment class is entailment
premise: The police arrested all of the gang members. They were trying to stop the drug trade in the neighborhood., hypothesis: The police were trying to stop the drug trade in the neighborhood.
The entailment class is not entailment
premise: It works perfectly, hypothesis: It works!
The entailment class is