SantanuBanerjee commited on
Commit
480770e
·
verified ·
1 Parent(s): db2900b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -8
app.py CHANGED
@@ -356,40 +356,49 @@ def create_cluster_dataframes(processed_df):
356
 
357
 
358
 
359
-
360
  from transformers import GPTNeoForCausalLM, GPT2Tokenizer
361
  def generate_project_proposal(prompt): # Generate the proposal
362
  # model_Name = "EleutherAI/gpt-neo-2.7B"
 
 
363
  model_Name = "EleutherAI/gpt-neo-1.3B"
 
364
 
365
  consoleMessage_and_Print(f"Trying to access {model_Name} model. The Prompt is: \n{prompt}")
366
 
367
  model = GPTNeoForCausalLM.from_pretrained(model_Name)
368
  tokenizer = GPT2Tokenizer.from_pretrained(model_Name)
369
- model_max_token_limit = 2048
370
 
371
  try:
372
  # input_ids = tokenizer.encode(prompt, return_tensors="pt")
373
  # Truncate the prompt to fit within the model's input limits
374
  # Adjust as per your model's limit
375
- input_ids = tokenizer.encode(prompt, return_tensors="pt", truncation=True, max_length = model_max_token_limit/2)
376
 
377
 
378
  print("Input IDs shape:", input_ids.shape)
 
 
 
 
379
  # Generate the output
380
  output = model.generate(
381
  input_ids,
 
382
  max_new_tokens = model_max_token_limit,
383
  num_return_sequences=1,
384
  no_repeat_ngram_size=2,
385
- temperature=0.5,
386
- pad_token_id=tokenizer.eos_token_id # Ensure padding with EOS token
 
387
  )
388
  print("Output shape:", output.shape)
389
 
390
 
391
  # Decode the output to text
392
- full_returned_segment = tokenizer.decode(output[0], skip_special_tokens=True)
393
 
394
  # Slice off the input part if the input length is known
395
  input_length = input_ids.shape[1]
@@ -410,10 +419,9 @@ def generate_project_proposal(prompt): # Generate the proposal
410
 
411
 
412
 
413
- import copy
414
-
415
 
416
 
 
417
  def create_project_proposals(budget_cluster_df, problem_cluster_df, location_clusters, problem_clusters):
418
  consoleMessage_and_Print("\n Starting function: create_project_proposals")
419
  proposals = {}
 
356
 
357
 
358
 
359
+ from random import uniform
360
  from transformers import GPTNeoForCausalLM, GPT2Tokenizer
361
  def generate_project_proposal(prompt): # Generate the proposal
362
  # model_Name = "EleutherAI/gpt-neo-2.7B"
363
+ # tempareCHUR = uniform(0.3,0.6)
364
+
365
  model_Name = "EleutherAI/gpt-neo-1.3B"
366
+ tempareCHUR = uniform(0.5,0.8)
367
 
368
  consoleMessage_and_Print(f"Trying to access {model_Name} model. The Prompt is: \n{prompt}")
369
 
370
  model = GPTNeoForCausalLM.from_pretrained(model_Name)
371
  tokenizer = GPT2Tokenizer.from_pretrained(model_Name)
372
+ model_max_token_limit = 2047
373
 
374
  try:
375
  # input_ids = tokenizer.encode(prompt, return_tensors="pt")
376
  # Truncate the prompt to fit within the model's input limits
377
  # Adjust as per your model's limit
378
+ input_ids = tokenizer.encode(prompt, return_tensors="pt", truncation=True, max_length = int(model_max_token_limit/2) )
379
 
380
 
381
  print("Input IDs shape:", input_ids.shape)
382
+
383
+ pad_tokenId = tokenizer.pad_token_id if tokenizer.pad_token_id is not None else tokenizer.eos_token_id # Padding with EOS token may always be great
384
+ attentionMask = input_ids.ne(pad_tokenId).long()
385
+
386
  # Generate the output
387
  output = model.generate(
388
  input_ids,
389
+ min_length = int(model_max_token_limit/3), # minimum length of the generated output
390
  max_new_tokens = model_max_token_limit,
391
  num_return_sequences=1,
392
  no_repeat_ngram_size=2,
393
+ temperature=tempareCHUR,
394
+ attention_mask=attentionMask, # This was previously not being used
395
+ pad_token_id=pad_tokenId
396
  )
397
  print("Output shape:", output.shape)
398
 
399
 
400
  # Decode the output to text
401
+ # full_returned_segment = tokenizer.decode(output[0], skip_special_tokens=True)
402
 
403
  # Slice off the input part if the input length is known
404
  input_length = input_ids.shape[1]
 
419
 
420
 
421
 
 
 
422
 
423
 
424
+ import copy
425
  def create_project_proposals(budget_cluster_df, problem_cluster_df, location_clusters, problem_clusters):
426
  consoleMessage_and_Print("\n Starting function: create_project_proposals")
427
  proposals = {}