JakeTurner616 commited on
Commit
9e559ec
·
verified ·
1 Parent(s): 30a69c1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -4
app.py CHANGED
@@ -5,19 +5,24 @@ def generate_text(prompt, max_length, temperature, top_p, repetition_penalty):
5
  tokenizer = GPT2TokenizerFast.from_pretrained("JakeTurner616/Adonalsium-gpt-neo-1.3B")
6
  model = GPTNeoForCausalLM.from_pretrained("JakeTurner616/Adonalsium-gpt-neo-1.3B")
7
 
8
- # Check if tokenizer has a padding token, if not, set it to eos_token
9
  if tokenizer.pad_token is None:
10
  tokenizer.pad_token = tokenizer.eos_token
11
- model.resize_token_embeddings(len(tokenizer))
12
 
13
- inputs = tokenizer(prompt, return_tensors="pt", padding=True)
 
 
 
14
  outputs = model.generate(
15
  input_ids=inputs["input_ids"],
 
16
  max_length=max_length,
17
  temperature=temperature,
18
  top_p=top_p,
19
  repetition_penalty=repetition_penalty,
20
- no_repeat_ngram_size=2
 
 
21
  )
22
 
23
  generated_texts = [tokenizer.decode(output, skip_special_tokens=True) for output in outputs]
 
5
  tokenizer = GPT2TokenizerFast.from_pretrained("JakeTurner616/Adonalsium-gpt-neo-1.3B")
6
  model = GPTNeoForCausalLM.from_pretrained("JakeTurner616/Adonalsium-gpt-neo-1.3B")
7
 
8
+ # Set pad token
9
  if tokenizer.pad_token is None:
10
  tokenizer.pad_token = tokenizer.eos_token
 
11
 
12
+ inputs = tokenizer(prompt, return_tensors="pt", padding=True, truncation=True)
13
+ # Ensure that pad_token_id is set for the model
14
+ model.config.pad_token_id = tokenizer.pad_token_id
15
+
16
  outputs = model.generate(
17
  input_ids=inputs["input_ids"],
18
+ attention_mask=inputs["attention_mask"], # Explicitly pass attention mask
19
  max_length=max_length,
20
  temperature=temperature,
21
  top_p=top_p,
22
  repetition_penalty=repetition_penalty,
23
+ no_repeat_ngram_size=2, # Correctly specify the no_repeat_ngram_size
24
+ do_sample=True, # Ensure sampling is enabled for temperature and top_p to take effect
25
+ pad_token_id=tokenizer.pad_token_id
26
  )
27
 
28
  generated_texts = [tokenizer.decode(output, skip_special_tokens=True) for output in outputs]