nomadic07 commited on
Commit
ae2f2e1
·
verified ·
1 Parent(s): ee7bc44

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -3
app.py CHANGED
@@ -26,7 +26,7 @@ def get_question(context, answer):
26
  return tokenizer.decode(outs[0], skip_special_tokens=True).replace("question:", "").strip()
27
 
28
  # Function to get similar words using Sense2Vec
29
- def sense2vec_get_words(word, max_similarity=0.3):
30
  word = word.lower().replace(" ", "_") # Prepare word for Sense2Vec
31
  sense = s2v.get_best_sense(word) # Get best sense (e.g., 'apple|NOUN')
32
  if not sense:
@@ -36,7 +36,7 @@ def sense2vec_get_words(word, max_similarity=0.3):
36
  return [
37
  each_word[0].split("|")[0].replace("_", " ").title()
38
  for each_word in s2v.most_similar(sense, n=20)
39
- if each_word[0].split("|")[0] != word and each_word[1] >= max_similarity
40
  ]
41
 
42
  # Generate multiple questions and return as DataFrame
@@ -46,7 +46,7 @@ def generate_questions(context, num_questions=5):
46
  distractors = sense2vec_get_words(answer.capitalize())
47
  if distractors:
48
  question = get_question(context, answer)
49
- options = [answer.capitalize()] + distractors[:3]
50
  question_dict = {
51
  "Question": question,
52
  "Answer": answer.capitalize(),
 
26
  return tokenizer.decode(outs[0], skip_special_tokens=True).replace("question:", "").strip()
27
 
28
  # Function to get similar words using Sense2Vec
29
+ def sense2vec_get_words(word):
30
  word = word.lower().replace(" ", "_") # Prepare word for Sense2Vec
31
  sense = s2v.get_best_sense(word) # Get best sense (e.g., 'apple|NOUN')
32
  if not sense:
 
36
  return [
37
  each_word[0].split("|")[0].replace("_", " ").title()
38
  for each_word in s2v.most_similar(sense, n=20)
39
+ if each_word[0].split("|")[0] != word
40
  ]
41
 
42
  # Generate multiple questions and return as DataFrame
 
46
  distractors = sense2vec_get_words(answer.capitalize())
47
  if distractors:
48
  question = get_question(context, answer)
49
+ options = [answer.capitalize()] + distractors[-3:]
50
  question_dict = {
51
  "Question": question,
52
  "Answer": answer.capitalize(),