vinayakdev commited on
Commit
bef439a
1 Parent(s): d8ef29e

Happy Hugging Face!

Browse files
Files changed (2) hide show
  1. .DS_Store +0 -0
  2. generator.py +14 -17
.DS_Store CHANGED
Binary files a/.DS_Store and b/.DS_Store differ
 
generator.py CHANGED
@@ -2,10 +2,10 @@
2
  import transformers
3
  from transformers import (
4
  # Text2TextGenerationPipeline,
5
- TFAutoModelForSeq2SeqLM as alwm,
6
  # TokenClassificationPipeline,
7
  # AutoModelForTokenClassification,
8
- TFAutoModelForQuestionAnswering as amqa,
9
  AutoTokenizer as att,
10
  # BertTokenizer,
11
  # AlbertTokenizer,
@@ -20,7 +20,6 @@ from transformers import (
20
  # ElectraForQuestionAnswering
21
  )
22
  import torch
23
- import tensorflow
24
  import string
25
  import numpy as np
26
  from transformers import pipeline
@@ -30,11 +29,9 @@ import pickle
30
  # sq_tokenizer = att.from_pretrained("mrm8488/t5-base-finetuned-question-generation-ap")
31
  # sq_model = alwm.from_pretrained("mrm8488/t5-base-finetuned-question-generation-ap")
32
  # text= "The abolition of feudal privileges by the National Constituent Assembly on 4 August 1789 and the Declaration \\nof the Rights of Man and of the Citizen (La Déclaration des Droits de l'Homme et du Citoyen), drafted by Lafayette \\nwith the help of Thomas Jefferson and adopted on 26 August, paved the way to a Constitutional Monarchy \\n(4 September 1791 – 21 September 1792). Despite these dramatic changes, life at the court continued, while the situation \\nin Paris was becoming critical because of bread shortages in September. On 5 October 1789, a crowd from Paris descended upon Versailles \\nand forced the royal family to move to the Tuileries Palace in Paris, where they lived under a form of house arrest under \\nthe watch of Lafayette's Garde Nationale, while the Comte de Provence and his wife were allowed to reside in the \\nPetit Luxembourg, where they remained until they went into exile on 20 June 1791."
33
- # hftokenizer = pickle.load(open('models/hftokenizer.sav', 'rb'))
34
- # hfmodel = pickle.load(open('models/hfmodel.sav', 'rb'))
35
- hfmodel = alwm.from_pretrained("valhalla/t5-small-e2e-qg")
36
 
37
- hftokenizer = T5TokenizerFast.from_pretrained("t5-small")
38
  def run_model(input_string, **generator_args):
39
  generator_args = {
40
  "max_length": 256,
@@ -50,22 +47,20 @@ def run_model(input_string, **generator_args):
50
  output = hftokenizer.batch_decode(res, skip_special_tokens=True)
51
  output = [item.split("<sep>") for item in output]
52
  return output
53
- al_tokenizer = att.from_pretrained("deepset/electra-base-squad2")
54
- al_model = amqa.from_pretrained("deepset/electra-base-squad2")
55
-
56
- # al_model = pickle.load(open('models/al_model.sav', 'rb'))
57
- # al_tokenizer = pickle.load(open('models/al_tokenizer.sav', 'rb'))
58
  def QA(question, context):
59
  # model_name="deepset/electra-base-squad2"
60
  nlp = pipeline("question-answering",model=al_model,tokenizer=al_tokenizer)
61
  format = {
62
  'question':question,
63
  'context':context
64
- }
65
  res = nlp(format)
66
  output = f"{question}\n{string.capwords(res['answer'])}\tscore : [{res['score']}] \n"
67
  return output
68
- # inputs = tokenizer(question, context, return_tensors="pt")
69
  # # Run the model, the deepset way
70
  # with torch.no_grad():
71
  # output = model(**inputs)
@@ -83,8 +78,10 @@ def QA(question, context):
83
  # QA("What was the first C program","The first prgram written in C was Hello World")
84
 
85
  def gen_question(inputs):
86
- questions = run_model(inputs)
87
- return questions
 
 
88
 
89
  # string_query = "Hello World"
90
  # gen_question(f"answer: {string_query} context: The first C program said {string_query} "). #The format of the query to generate questions
@@ -97,7 +94,7 @@ def read_file(filepath_name):
97
  return context
98
 
99
  def create_string_for_generator(context):
100
- gen_list = gen_question(context)
101
  return (gen_list[0][0]).split('? ')
102
 
103
  def creator(context):
 
2
  import transformers
3
  from transformers import (
4
  # Text2TextGenerationPipeline,
5
+ AutoModelForSeq2SeqLM as alwm,
6
  # TokenClassificationPipeline,
7
  # AutoModelForTokenClassification,
8
+ AutoModelForQuestionAnswering as amqa,
9
  AutoTokenizer as att,
10
  # BertTokenizer,
11
  # AlbertTokenizer,
 
20
  # ElectraForQuestionAnswering
21
  )
22
  import torch
 
23
  import string
24
  import numpy as np
25
  from transformers import pipeline
 
29
  # sq_tokenizer = att.from_pretrained("mrm8488/t5-base-finetuned-question-generation-ap")
30
  # sq_model = alwm.from_pretrained("mrm8488/t5-base-finetuned-question-generation-ap")
31
  # text= "The abolition of feudal privileges by the National Constituent Assembly on 4 August 1789 and the Declaration \\nof the Rights of Man and of the Citizen (La Déclaration des Droits de l'Homme et du Citoyen), drafted by Lafayette \\nwith the help of Thomas Jefferson and adopted on 26 August, paved the way to a Constitutional Monarchy \\n(4 September 1791 – 21 September 1792). Despite these dramatic changes, life at the court continued, while the situation \\nin Paris was becoming critical because of bread shortages in September. On 5 October 1789, a crowd from Paris descended upon Versailles \\nand forced the royal family to move to the Tuileries Palace in Paris, where they lived under a form of house arrest under \\nthe watch of Lafayette's Garde Nationale, while the Comte de Provence and his wife were allowed to reside in the \\nPetit Luxembourg, where they remained until they went into exile on 20 June 1791."
32
+ hftokenizer = pickle.load(open('models/hftokenizer.sav', 'rb'))
33
+ hfmodel = pickle.load(open('models/hfmodel.sav', 'rb'))
 
34
 
 
35
  def run_model(input_string, **generator_args):
36
  generator_args = {
37
  "max_length": 256,
 
47
  output = hftokenizer.batch_decode(res, skip_special_tokens=True)
48
  output = [item.split("<sep>") for item in output]
49
  return output
50
+
51
+ al_model = pickle.load(open('models/al_model.sav', 'rb'))
52
+ al_tokenizer = pickle.load(open('models/al_tokenizer.sav', 'rb'))
 
 
53
  def QA(question, context):
54
  # model_name="deepset/electra-base-squad2"
55
  nlp = pipeline("question-answering",model=al_model,tokenizer=al_tokenizer)
56
  format = {
57
  'question':question,
58
  'context':context
59
+ }
60
  res = nlp(format)
61
  output = f"{question}\n{string.capwords(res['answer'])}\tscore : [{res['score']}] \n"
62
  return output
63
+ # inputs = tokenizer(question, context, return_tensors="pt")
64
  # # Run the model, the deepset way
65
  # with torch.no_grad():
66
  # output = model(**inputs)
 
78
  # QA("What was the first C program","The first prgram written in C was Hello World")
79
 
80
  def gen_question(inputs):
81
+
82
+ questions = run_model(inputs)
83
+
84
+ return questions
85
 
86
  # string_query = "Hello World"
87
  # gen_question(f"answer: {string_query} context: The first C program said {string_query} "). #The format of the query to generate questions
 
94
  return context
95
 
96
  def create_string_for_generator(context):
97
+ gen_list = gen_question(context)
98
  return (gen_list[0][0]).split('? ')
99
 
100
  def creator(context):