Downloads · 30 days
23
19% of all-time downloads
prithivMLmods/Gpt2-Wikitext-9180
Gpt2-Wikitext-9180 is a text generation model from prithivMLmods. Use it when you need the model to write or continue text. It is set up for transformers. The card lists the license as apache-2.0.
Gpt2-Wikitext-9180, fine-tuned from GPT-2, is a Transformer-based language model trained on a large English corpus (WikiText) using self-supervised learning. This means it was trained on raw, unlabeled text data, usin…
Downloads · 30 days
23
19% of all-time downloads
All-time downloads
120
Public
Parameters
124M
28.4 GB on disk
Likes
0
Public
Click a slice to open those files.
.pt37.8 GB · 65%
From the Hugging Face model README
Gpt2-Wikitext-9180, fine-tuned from GPT-2, is a Transformer-based language model trained on a large English corpus (WikiText) using self-supervised learning. This means it was trained on raw, unlabeled text data, using an automated process to create inputs and labels by predicting the next word in a sentence. No manual annotation was involved, allowing the model to leverage a vast amount of publicly available data.
pip install transformers
import torch
from transformers import GPT2LMHeadModel, GPT2Tokenizer
# Loading pre-trained GPT-2 model and tokenizer
model_name = "prithivMLmods/Gpt2-Wikitext-9180"
tokenizer = GPT2Tokenizer.from_pretrained(model_name)
model = GPT2LMHeadModel.from_pretrained(model_name)
# Set the model to evaluation mode
model.eval()
def generate_text(prompt, max_length=100, temperature=0.8, top_k=50):
input_ids = tokenizer.encode(prompt, return_tensors="pt")
output = model.generate(
input_ids,
max_length=max_length,
temperature=temperature,
top_k=top_k,
pad_token_id=tokenizer.eos_token_id,
do_sample=True
)
generated_text = tokenizer.decode(output[0], skip_special_tokens=True)
return generated_text
# Example prompt
prompt = "Once upon a time"
generated_text = generate_text(prompt, max_length=68)
# Print the generated text
print(generated_text)