Views
No views yet
1from transformers import AutoModelForCausalLM, AutoTokenizer
2
3# Load the model and tokenizer
4model_name = "kmack/DetectiveTales-DistilGPT2"
5tokenizer = AutoTokenizer.from_pretrained(model_name)
6model = AutoModelForCausalLM.from_pretrained(model_name)
7
8# Define your prompt
9prompt = "It all started with the murder of the chief. This is the type of case that Sherlock likes and gets off on"
10
11# Tokenize the input
12input_ids = tokenizer.encode(prompt, return_tensors="pt")
13
14# Generate output
15output = model.generate(
16 input_ids,
17 max_length=100, # Adjust the length as needed
18 num_return_sequences=1, # Number of generated outputs
19 no_repeat_ngram_size=2, # Avoid repeating phrases
20 top_k=50, # Use top-k sampling
21 top_p=0.95, # Use nucleus sampling
22 temperature=0.7, # Adjust creativity
23 do_sample=True # Enable sampling
24)
25
26# Decode and print the generated text
27generated_text = tokenizer.decode(output[0], skip_special_tokens=True)
28print(generated_text)
29
30# Output:
31# It all started with the murder of the chief. This is the type of case that Sherlock likes and gets off on. It only lasts a few days at last. He would say that Holmes's actions were not criminal. I assure you that if you knew his intentions and how he wasabout this,you probablywouldn't havehad him so far, Watson. Of course that is, then, but in any event, it isthe sort of case you know to follow closely. He is the one who has sent the letters from London to Madrid. He has sent every letter that I say, and if there are no objections you can take them out as you will. This is the type of cases where our Lady Watson will decide to get out of such a situation.We made a case for his protection,and he came out as the best possible one. We were all so ready so that he could not have waited for me to meet me again. The whole affairwas very unusual. It was a little dark on the night before. He gave me the order.