Spaces:
Sleeping
Sleeping
add probability feature
Browse files
app.py
CHANGED
@@ -21,22 +21,31 @@ def lemmatize(s: str) -> iter:
|
|
21 |
# lemmatize
|
22 |
return map(lambda token: token.lemma_.lower(), tokens)
|
23 |
|
24 |
-
def predict(title: str , post: str):
|
25 |
text = title + " " + post
|
26 |
lemmes = np.array([' '.join(list(lemmatize(text)))])
|
27 |
|
28 |
X = tfidf.transform(lemmes)
|
29 |
|
30 |
-
|
31 |
-
|
|
|
32 |
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
demo = gr.Interface(
|
36 |
fn=predict,
|
37 |
inputs=[
|
38 |
-
gr.Textbox(lines=1, placeholder="Title..."),
|
39 |
-
gr.Textbox(lines=10, placeholder="Post...")
|
|
|
40 |
outputs=gr.Textbox(lines=10))
|
41 |
|
42 |
demo.launch()
|
|
|
21 |
# lemmatize
|
22 |
return map(lambda token: token.lemma_.lower(), tokens)
|
23 |
|
24 |
+
def predict(title: str , post: str, predict_proba: bool):
|
25 |
text = title + " " + post
|
26 |
lemmes = np.array([' '.join(list(lemmatize(text)))])
|
27 |
|
28 |
X = tfidf.transform(lemmes)
|
29 |
|
30 |
+
if predict_proba:
|
31 |
+
y_proba = model.predict_proba(X)[0]
|
32 |
+
tags = list(dict(sorted(tags_binarizer.ts.count.items())).keys())
|
33 |
|
34 |
+
result = list(zip(tags, y_proba))
|
35 |
+
else:
|
36 |
+
y_bin = model.predict(X)
|
37 |
+
y_tags = tags_binarizer.inverse_transform(y_bin)
|
38 |
+
|
39 |
+
result = y_tags
|
40 |
+
|
41 |
+
return result
|
42 |
|
43 |
demo = gr.Interface(
|
44 |
fn=predict,
|
45 |
inputs=[
|
46 |
+
gr.Textbox(label="Title", lines=1, placeholder="Title..."),
|
47 |
+
gr.Textbox(label="Post", lines=10, placeholder="Post..."),
|
48 |
+
gr.Checkbox(label="Proba?")],
|
49 |
outputs=gr.Textbox(lines=10))
|
50 |
|
51 |
demo.launch()
|