Views
No views yet
main,
then install Transformers libray and copy this code to code editor and run it:1# Load model directly
2from transformers import AutoModel, AutoTokenizer
3
4tokenizer = AutoTokenizer.from_pretrained("microsoft/dialoGPT-small") # do not change, gpt-nano is an pretrained dialogpt and it needs this tokenizer
5model = AutoModel.from_pretrained("path/to/ai")
6
7# ask ai
8input_text = "What is the capital of France?"
9input_ids = tokenizer.encode(input_text, return_tensors="pt")
10
11output = model.generate(
12 input_ids,
13 max_length=50, # You can adjust the max_length as needed
14 num_return_sequences=1,
15 no_repeat_ngram_size=2,
16 do_sample=True,
17 top_k=50,
18 top_p=0.95,
19 temperature=0.7
20)
21
22generated_text = tokenizer.decode(output[0], skip_special_tokens=True)
23print(generated_text)