Spaces:
Sleeping
Sleeping
Updated pickel files and app.py.
Browse files
app.py
CHANGED
|
@@ -12,12 +12,11 @@ from sklearn.feature_extraction.text import TfidfVectorizer
|
|
| 12 |
from flair.data import Sentence
|
| 13 |
from flair.models import SequenceTagger
|
| 14 |
|
| 15 |
-
#
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
|
| 22 |
# Process input text, including removing stopwords, converting to lowercase, and removing punctuation
|
| 23 |
stop = stopwords.words('english')
|
|
@@ -30,32 +29,19 @@ def process_text(text):
|
|
| 30 |
text = " ".join(text.split())
|
| 31 |
return text
|
| 32 |
|
| 33 |
-
# Vectorize
|
| 34 |
-
vec = CountVectorizer()
|
| 35 |
-
'''
|
| 36 |
def vectorize_text(text):
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
'''
|
| 41 |
|
| 42 |
# Valid input for the model so number of features match
|
| 43 |
-
def
|
| 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 |
-
|
|
|
|
| 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')
|
|
@@ -71,7 +57,7 @@ def run_ner(input_text):
|
|
| 71 |
|
| 72 |
# Run both models, and return a tuple of their results
|
| 73 |
def run_models(input_text):
|
| 74 |
-
prediction =
|
| 75 |
entities = run_ner(input_text)
|
| 76 |
return prediction, entities
|
| 77 |
|
|
|
|
| 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 |
# Process input text, including removing stopwords, converting to lowercase, and removing punctuation
|
| 22 |
stop = stopwords.words('english')
|
|
|
|
| 29 |
text = " ".join(text.split())
|
| 30 |
return text
|
| 31 |
|
| 32 |
+
# Vectorize text
|
|
|
|
|
|
|
| 33 |
def vectorize_text(text):
|
| 34 |
+
text = process_text(text)
|
| 35 |
+
text = vectorizer_loaded.transform([text])
|
| 36 |
+
return text
|
|
|
|
| 37 |
|
| 38 |
# Valid input for the model so number of features match
|
| 39 |
+
def class_predict(text):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
text = process_text(text)
|
| 41 |
+
vec = vectorizer_loaded.transform([text])
|
| 42 |
+
prediction = model_loaded.predict(vec)
|
| 43 |
return prediction
|
| 44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
# Specify NER model
|
| 47 |
tagger = SequenceTagger.load('best-model.pt') # SequenceTagger.load('best-model.pt')
|
|
|
|
| 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 |
|