Views
No views yet
1from transformers import pipeline
2
3nlp = pipeline("text2text-generation", model='khhuang/zerofec-daqa-t5-base', tokenizer='khhuang/zerofec-daqa-t5-base')
4
5QUESTION = "What is Night of the Living Dead?"
6CONTEXT = "Night of the Living Dead is a 1968 American independent horror film , directed by George A."
7
8def format_inputs(context: str, question: str):
9 return f"{question} \n {context}"
10
11text = format_inputs(CONTEXT, QUESTION)
12
13nlp(text)
14# should output [{'generated_text': 'a 1968 american independent horror film'}]1from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
2
3tokenizer = AutoTokenizer.from_pretrained('khhuang/zerofec-daqa-t5-base')
4model = AutoModelForSeq2SeqLM.from_pretrained('khhuang/zerofec-daqa-t5-base')
5
6QUESTION = "What is Night of the Living Dead?"
7CONTEXT = "Night of the Living Dead is a 1968 American independent horror film , directed by George A."
8
9def format_inputs(context: str, question: str):
10 return f"{question} \n {context}"
11
12text = format_inputs(CONTEXT, QUESTION)
13
14
15input_ids = tokenizer(text, return_tensors="pt").input_ids
16generated_ids = model.generate(input_ids, max_length=32, num_beams=4)
17output = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)
18print(output)
19# should output "a 1968 american independent horror film"@inproceedings{huang-etal-2023-zero,
title = "Zero-shot Faithful Factual Error Correction",
author = "Huang, Kung-Hsiang and
Chan, Hou Pong and
Ji, Heng",
booktitle = "Proceedings of the 61st Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers)",
month = jul,
year = "2023",
address = "Toronto, Canada",
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/2023.acl-long.311",
doi = "10.18653/v1/2023.acl-long.311",
pages = "5660--5676",
}