from transformers import pipeline
nlp = pipeline("text2text-generation", model='Salesforce/mixqg-large', tokenizer='Salesforce/mixqg-large')
CONTEXT = "In the late 17th century, Robert Boyle proved that air is necessary for combustion."
ANSWER = "Robert Boyle"
def format_inputs(context: str, answer: str):
return f"{answer} \\n {context}"
text = format_inputs(CONTEXT, ANSWER)
nlp(text)
# should output [{'generated_text': 'Who proved that air is necessary for combustion?'}]
Using the pre-trained model directly:
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
tokenizer = AutoTokenizer.from_pretrained('Salesforce/mixqg-large')
model = AutoModelForSeq2SeqLM.from_pretrained('Salesforce/mixqg-large')
CONTEXT = "In the late 17th century, Robert Boyle proved that air is necessary for combustion."
ANSWER = "Robert Boyle"
def format_inputs(context: str, answer: str):
return f"{answer} \\n {context}"
text = format_inputs(CONTEXT, ANSWER)
input_ids = tokenizer(text, return_tensors="pt").input_ids
generated_ids = model.generate(input_ids, max_length=32, num_beams=4)
output = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)
print(output)
# should output "Who proved that air is necessary for combustion?"
Citation
@misc{murakhovska2021mixqg,
title={MixQG: Neural Question Generation with Mixed Answer Types},
author={Lidiya Murakhovs'ka and Chien-Sheng Wu and Tong Niu and Wenhao Liu and Caiming Xiong},
year={2021},
eprint={2110.08175},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
Runs of Salesforce mixqg-large on huggingface.co
106
Total runs
0
24-hour runs
0
3-day runs
-5
7-day runs
83
30-day runs
More Information About mixqg-large huggingface.co Model
mixqg-large huggingface.co
mixqg-large huggingface.co is an AI model on huggingface.co that provides mixqg-large's model effect (), which can be used instantly with this Salesforce mixqg-large model. huggingface.co supports a free trial of the mixqg-large model, and also provides paid use of the mixqg-large. Support call mixqg-large model through api, including Node.js, Python, http.
mixqg-large huggingface.co is an online trial and call api platform, which integrates mixqg-large's modeling effects, including api services, and provides a free online trial of mixqg-large, you can try mixqg-large online for free by clicking the link below.
Salesforce mixqg-large online free url in huggingface.co:
mixqg-large is an open source model from GitHub that offers a free installation service, and any user can find mixqg-large on GitHub to install. At the same time, huggingface.co provides the effect of mixqg-large install, users can directly use mixqg-large installed effect in huggingface.co for debugging and trial. It also supports api for free installation.