Spaces:
Running
Running
File size: 591 Bytes
8906342 8e724ea 8906342 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
from transformers import AutoTokenizer, AutoModelForCausalLM
model_name = "roneneldan/TinyStories-1M"
def load():
global model
global tokenizer
model = AutoModelForCausalLM.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
def generate(input_text):
input_ids = tokenizer.encode(input_text, return_tensors="pt")
output_ids = model.generate(
input_ids,
no_repeat_ngram_size=2,
max_new_tokens=200,
eos_token_id=tokenizer.eos_token_id,
temperature=0.2
)
return tokenizer.decode(output_ids[0], skip_special_tokens=True) |