Spaces:
Sleeping
Sleeping
Create models/text_model.py
Browse files- models/text_model.py +17 -0
models/text_model.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
+
|
| 3 |
+
# Public, stable model that works on Spaces
|
| 4 |
+
text_model = pipeline(
|
| 5 |
+
task="text-classification",
|
| 6 |
+
model="distilbert-base-uncased-finetuned-sst-2-english", # sentiment model used as a placeholder for "credibility"
|
| 7 |
+
device=-1 # CPU
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
# Map a variety of possible raw labels to friendly names.
|
| 11 |
+
# Different transformers versions may return NEGATIVE/POSITIVE or LABEL_0/LABEL_1.
|
| 12 |
+
TEXT_FRIENDLY_MAP = {
|
| 13 |
+
"NEGATIVE": "Fake / Not Credible",
|
| 14 |
+
"LABEL_0": "Fake / Not Credible",
|
| 15 |
+
"POSITIVE": "Real / Credible",
|
| 16 |
+
"LABEL_1": "Real / Credible",
|
| 17 |
+
}
|