curtpond commited on
Commit
e3527b4
1 Parent(s): d142413

Rolled back changes.

Browse files
Files changed (1) hide show
  1. app.py +27 -13
app.py CHANGED
@@ -12,11 +12,11 @@ from sklearn.feature_extraction.text import TfidfVectorizer
12
  from flair.data import Sentence
13
  from flair.models import SequenceTagger
14
 
15
- # Load pickled model and vectorizer
16
- model = 'lr_021823.pkl'
17
- model_loaded = pickle.load(open(model, 'rb'))
18
- vectorizer = 'vectorizer_021823.pkl'
19
- vectorizer_loaded = pickle.load(open(vectorizer, 'rb'))
20
 
21
 
22
  # Process input text, including removing stopwords, converting to lowercase, and removing punctuation
@@ -30,19 +30,33 @@ def process_text(text):
30
  text = " ".join(text.split())
31
  return text
32
 
33
- # Vectorize text
 
 
34
  def vectorize_text(text):
35
- text = process_text(text)
36
- text = vectorizer_loaded.transform([text])
37
- return text
 
38
 
39
  # Valid input for the model so number of features match
40
- def class_predict(text):
 
 
 
 
41
  text = process_text(text)
42
- vec = vectorizer_loaded.transform([text])
43
- prediction = model_loaded.predict(vec)
44
  return prediction
45
 
 
 
 
 
 
 
 
 
46
  # Specify NER model
47
  tagger = SequenceTagger.load('best-model.pt') # SequenceTagger.load('best-model.pt')
48
 
@@ -57,7 +71,7 @@ def run_ner(input_text):
57
 
58
  # Run both models, and return a tuple of their results
59
  def run_models(input_text):
60
- prediction = class_predict(input_text)
61
  entities = run_ner(input_text)
62
  return prediction, entities
63
 
 
12
  from flair.data import Sentence
13
  from flair.models import SequenceTagger
14
 
15
+ # file name
16
+ #lr_filename = 'lr_021223.pkl'
17
+
18
+ # Load model from pickle file
19
+ # model = pickle.load(open(lr_filename, 'rb'))
20
 
21
 
22
  # Process input text, including removing stopwords, converting to lowercase, and removing punctuation
 
30
  text = " ".join(text.split())
31
  return text
32
 
33
+ # Vectorize input text
34
+ vec = CountVectorizer()
35
+ '''
36
  def vectorize_text(text):
37
+ #text = process_text(text)
38
+ #text = vectorizer.fit_transform([text])
39
+ #return text
40
+ '''
41
 
42
  # Valid input for the model so number of features match
43
+ def predict(text):
44
+ # Load the pickled model
45
+ filename = 'lr_021223.pkl'
46
+ loaded_model = pickle.load(open(filename, 'rb'))
47
+ text = vec.transform([text])
48
  text = process_text(text)
49
+ prediction = loaded_model.predict(text)
 
50
  return prediction
51
 
52
+ '''
53
+ Prediction function
54
+ #def predict(text):
55
+ #text = vectorize_text(text)
56
+ #prediction = model.predict(text)
57
+ #return prediction
58
+ '''
59
+
60
  # Specify NER model
61
  tagger = SequenceTagger.load('best-model.pt') # SequenceTagger.load('best-model.pt')
62
 
 
71
 
72
  # Run both models, and return a tuple of their results
73
  def run_models(input_text):
74
+ prediction = 0 # This "0" is a placeholder to avoid errors; once the LR model is working, use this instead: prediction = predict(input_text)
75
  entities = run_ner(input_text)
76
  return prediction, entities
77