from openmind import pipeline
from openmind import is_torch_npu_available
import torch
import argparse
import torch.nn.functional as F
import time
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument(
"--model_name_or_path",
type=str,
help="Path to model",
default="zhouhui/t5-small-qg-hl",
)
args = parser.parse_args()
return args
def main():
args = parse_args()
model_path = args.model_name_or_path
if is_torch_npu_available():
device = "npu:0"
else:
device = "cpu"
#device = "cpu"
start_time = time.time()
generator = pipeline('text2text-generation', model= model_path , device=device,trust_remote_code=True)
output = generator("who are you?", do_sample=True, min_length=50)
print(f">>>output={output}")
end_time = time.time()
print(f"硬件环境:{device},推理执行时间:{end_time - start_time}秒")
if __name__ == "__main__":
main()This is t5-small model trained for answer aware question generation task. The answer spans are highlighted within the text with special highlight tokens.
You can play with the model using the inference API, just highlight the answer spans with <hl> tokens and end the text with </s>. For example
<hl> 42 <hl> is the answer to life, the universe and everything. </s>
For more deatils see this repo.
You'll need to clone the repo.
from pipelines import pipeline
nlp = pipeline("question-generation")
nlp("42 is the answer to life, universe and everything.")
=> [{'answer': '42', 'question': 'What is the answer to life, universe and everything?'}]