Downloads · 30 days
24
2% of all-time downloads
XBOT-RK/distilgpt2-wiki-qa
distilgpt2-wiki-qa is a text generation model from XBOT-RK. Use it when you need the model to write or continue text. It is set up for transformers. The card lists the license as mit.
This Question-Answering model was fine-tuned & trained from a generative, left-to-right transformer in the style of GPT-2, the distilgpt2 model. This model was trained on Wiki-QA dataset from Microsoft.
Downloads · 30 days
24
2% of all-time downloads
All-time downloads
1.1K
Public
Parameters
88.2M
668 MB on disk
Likes
1
Public
Click a slice to open those files.
.bin334 MB · 50%
How the weights are stored.
F3281.9M · 93%
From the Hugging Face model README
This Question-Answering model was fine-tuned & trained from a generative, left-to-right transformer in the style of GPT-2, the distilgpt2 model. This model was trained on Wiki-QA dataset from Microsoft.
The following code shows how to use the Distil-GPT2-Wiki-QA checkpoint and Transformers to generate Answers.
from transformers import GPT2LMHeadModel, GPT2Tokenizer
import torch
import re
tokenizer = GPT2Tokenizer.from_pretrained("XBOT-RK/distilgpt2-wiki-qa")
model = GPT2LMHeadModel.from_pretrained("XBOT-RK/distilgpt2-wiki-qa")
device = "cuda" if torch.cuda.is_available() else "cpu"
def infer(question):
generated_tensor = model.generate(**tokenizer(question, return_tensors="pt").to(device), max_new_tokens = 50)
generated_text = tokenizer.decode(generated_tensor[0])
return generated_text
def processAnswer(question, result):
answer = result.replace(question, '').strip()
if "<bot>:" in answer:
answer = re.search('<bot>:(.*)', answer).group(1).strip()
if "<endofstring>" in answer:
answer = re.search('(.*)<endofstring>', answer).group(1).strip()
return answer
question = "What is a tropical cyclone?"
result = infer(question)
answer = processAnswer(question, result)
print('Question: ', question)
print('Answer: ', answer)
# Output
"Question: What is a tropical cyclone?"
"Answer: The cyclone is named after the climber Edmond Halley, who described it as the 'most powerful cyclone of the Atlantic'."