This model is a fine-tuned version of the GPT-2 base model, fine-tuned on a dataset consisting of works by William Shakespeare to generate text in his tone and style. The model is designed to generate coherent and contextually relevant text, mimicking the unique style and phrasing found in the dataset.
1from transformers import GPT2LMHeadModel, GPT2Tokenizer
2
3# Load the fine-tuned model and tokenizer
4model_name = "sartajbhuvaji/gpt2_B_Shakespeare"
5model = GPT2LMHeadModel.from_pretrained(model_name)
6tokenizer = GPT2Tokenizer.from_pretrained(model_name)
7
8# Prepare input text
9input_text = "To be, or not to be, that is the question:"
10input_ids = tokenizer.encode(input_text, return_tensors="pt")
11
12# Generate text
13output = model.generate(
14 input_ids,
15 max_length=200,
16 num_return_sequences=1,
17 no_repeat_ngram_size=2,
18 do_sample=True,
19 top_k=50,
20 top_p=0.95
21)
22
23# Decode the generated text
24generated_text = tokenizer.decode(output[0], skip_special_tokens=True)
25print(generated_text)
26
This model has been trained on a specific dataset, and its responses will reflect the content and style of that dataset.
The model may generate text that reflects the biases present in the original data.
This model is not suitable for generating factual information or for use cases requiring highly accurate and unbiased outputs.
Use this model responsibly. The text generated by the model should not be used for misleading or harmful purposes.
Note that this model might reflect historical biases inherent in the original text sources.
Acknowledgments
This model is based on the GPT-2 architecture by OpenAI and has been fine-tuned using the Hugging Face transformers library.