pratikshahp commited on
Commit
f8e5a6f
·
verified ·
1 Parent(s): 90ba42f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -2
app.py CHANGED
@@ -21,12 +21,18 @@ def generate_mcqs(text, num_questions=5):
21
  model = AutoModelForCausalLM.from_pretrained("openai-community/gpt2-large")
22
 
23
  # Tokenize the input text
24
- inputs = tokenizer(text, return_tensors="pt", max_length=1024, truncation=True)
25
 
26
  mcqs = []
27
  for _ in range(num_questions):
28
  # Generate a single MCQ at a time
29
- output = model.generate(**inputs, max_length=100, temperature=0.7, num_return_sequences=1)
 
 
 
 
 
 
30
 
31
  # Decode the generated sequence
32
  mcq = tokenizer.decode(output[0], skip_special_tokens=True)
 
21
  model = AutoModelForCausalLM.from_pretrained("openai-community/gpt2-large")
22
 
23
  # Tokenize the input text
24
+ inputs = tokenizer(text, return_tensors="pt", max_length=512, truncation=True)
25
 
26
  mcqs = []
27
  for _ in range(num_questions):
28
  # Generate a single MCQ at a time
29
+ output = model.generate(
30
+ **inputs,
31
+ max_length=512, # Adjusted to match the tokenized input length
32
+ max_new_tokens=100, # Limit the number of new tokens added during generation
33
+ temperature=0.7,
34
+ num_return_sequences=1
35
+ )
36
 
37
  # Decode the generated sequence
38
  mcq = tokenizer.decode(output[0], skip_special_tokens=True)