vinayakdev commited on
Commit
9bc33fc
1 Parent(s): f769cbe

Ran locally

Browse files
Files changed (1) hide show
  1. generator.py +14 -13
generator.py CHANGED
@@ -1,4 +1,3 @@
1
-
2
  import transformers
3
  from transformers import (
4
  # Text2TextGenerationPipeline,
@@ -37,16 +36,16 @@ import streamlit as st
37
  def load_model():
38
  hfm = pickle.load(open('t5_model.sav','rb'))
39
  hft = T5TokenizerFast.from_pretrained("t5-base")
40
- # tok = att.from_pretrained("mrm8488/elect")
41
  model = pickle.load(open('electra_model.sav','rb'))
 
42
  # return hfm, hft,tok, model
43
- return hfm, hft, model
44
 
45
- hfmodel, hftokenizer, model = load_model()
46
 
47
  def run_model(input_string, **generator_args):
48
  generator_args = {
49
- "max_model_length": 256,
50
  "num_beams": 4,
51
  "length_penalty": 1.5,
52
  "no_repeat_ngram_size": 2,
@@ -61,8 +60,8 @@ def run_model(input_string, **generator_args):
61
 
62
  res = hfmodel.generate(input_ids=inputs['input_ids'], attention_mask=inputs['attention_mask'], **generator_args)
63
  output = hftokenizer.decode(res[0], skip_special_tokens=True)
64
- output = [item.split("<sep>") for item in output]
65
- output = [o.strip() for o in output[:-1]]
66
  return output
67
 
68
 
@@ -127,17 +126,19 @@ def read_file(filepath_name):
127
 
128
  def create_string_for_generator(context):
129
  gen_list = gen_question(context)
130
- return (gen_list[0][0]).split('? ')
131
 
132
  def creator(context):
133
  questions = create_string_for_generator(context)
 
134
  pairs = []
135
  for ques in questions:
136
- # if ques[-1] != '?':
137
- # ques = ques + '?'
138
  pair = QA(ques,context)
 
139
  pairs.append(pair)
140
  return pairs
141
-
142
- # sentences = main_text.split('.')
143
- # creator(sent)
 
 
1
  import transformers
2
  from transformers import (
3
  # Text2TextGenerationPipeline,
 
36
  def load_model():
37
  hfm = pickle.load(open('t5_model.sav','rb'))
38
  hft = T5TokenizerFast.from_pretrained("t5-base")
 
39
  model = pickle.load(open('electra_model.sav','rb'))
40
+ tok = et.from_pretrained("mrm8488/electra-small-finetuned-squadv2")
41
  # return hfm, hft,tok, model
42
+ return hfm, hft,tok, model
43
 
44
+ hfmodel, hftokenizer,tok, model = load_model()
45
 
46
  def run_model(input_string, **generator_args):
47
  generator_args = {
48
+ "max_length": 256,
49
  "num_beams": 4,
50
  "length_penalty": 1.5,
51
  "no_repeat_ngram_size": 2,
 
60
 
61
  res = hfmodel.generate(input_ids=inputs['input_ids'], attention_mask=inputs['attention_mask'], **generator_args)
62
  output = hftokenizer.decode(res[0], skip_special_tokens=True)
63
+ # output = output.split('</sep>')
64
+ # output = [o.strip() for o in output[:-1]]
65
  return output
66
 
67
 
 
126
 
127
  def create_string_for_generator(context):
128
  gen_list = gen_question(context)
129
+ return gen_list
130
 
131
  def creator(context):
132
  questions = create_string_for_generator(context)
133
+ questions = questions.split('?')
134
  pairs = []
135
  for ques in questions:
136
+ if ques[-1] != '?':
137
+ ques = ques + '?'
138
  pair = QA(ques,context)
139
+ print(pair)
140
  pairs.append(pair)
141
  return pairs
142
+ # creator(""""Hello, World!" program by Brian Kernighan (1978).
143
+ # A "Hello, World!" program is generally a computer program that ignores any input and outputs or displays a message similar to "Hello, World!". A small piece of code in most general-purpose programming languages, this program is used to illustrate a language's basic syntax. "Hello, World!" programs are often the first a student learns to write in a given language,[1] and they can also be used as a sanity check to ensure computer software intended to compile or run source code is correctly installed, and that its operator understands how to use it.
144
+ # """)