Views
No views yet
OLMo-1B-Base-Shakespeare is a fine-tuned version of the allenai/OLMo-1B-0724-hf model, retrained on the complete collection of novels by William Shakespeare. The model aims to generate text in the style of Shakespeare's works and has been optimized to capture the linguistic and stylistic nuances present in the original text.transformers library installed:pip install transformers1from transformers import AutoModelForCausalLM, AutoTokenizer
2import torch
3
4torch.random.manual_seed(0)
5
6model_name = 'sartajbhuvaji/OLMo-1B-Base-Shakespeare'
7tokenizer = AutoTokenizer.from_pretrained(model_name)
8model = AutoModelForCausalLM.from_pretrained(
9 model_name,
10 device_map="cuda",
11 torch_dtype="auto",
12 trust_remote_code=True,
13)
14model.to('cuda')
15
16input_text = 'Hello how are you?'
17input_ids = tokenizer.encode(input_text, return_tensors='pt').to('cuda')
18
19output = model.generate(input_ids, max_length=100, num_return_sequences=1, no_repeat_ngram_size=2)
20generated_text = tokenizer.decode(output[0], skip_special_tokens=True)
21print(generated_text)
22'''
23Hello how are you?
24 SECOND GENTLEMAN. I am a gentleman.
25 The Duke, my lord, and all the court are yours.
26
27 Enter a MESSENGER
28
29 THIRD GENTSLE MAN. Here's a messenger. What news? What's the news,
30 sir? How doth your lady? Is she well? Or is she
31 hears'd, beaten, or slain? The news is, sir
32'''