-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_data.py
56 lines (35 loc) · 1.12 KB
/
get_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Use the loaded pickled model to make predictions
import joblib
import spacy
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.svm import LinearSVC
from spacy.lang.en.stop_words import STOP_WORDS
from spacy.symbols import punct
#Tokenization
import string
punct = string.punctuation
print(punct)
nlp = spacy.load("en")
stopwords = list(STOP_WORDS)
def text_data_cleaning(sentence):
doc = nlp(sentence)
tokens = []
for token in doc:
if token.lemma_ != '-PRON-':
temp = token.lemma_.lower().strip()
else:
temp = token.lower_
tokens.append(temp)
cleaned_tokens = []
for token in tokens:
if token not in list(STOP_WORDS) and token not in punct:
cleaned_tokens.append(token)
return cleaned_tokens
text = '‘MS Dhoni at No. 3 would have broken most records’: Gautam Gambhir'
def predictdata(text):
tfidf = TfidfVectorizer(tokenizer=text_data_cleaning)
joblib_LR_model = joblib.load('news_classifier.pkl')
print(joblib_LR_model)
pred = joblib_LR_model.predict([text])
print(pred)
return pred