Update app.py
Browse files
app.py
CHANGED
|
@@ -17,7 +17,7 @@ class_names = ['Negative', 'Neutral', 'Positive']
|
|
| 17 |
|
| 18 |
# ২. প্রেডিক্টর ফাংশন (Internal use for LIME and Real-time)
|
| 19 |
def predictor(texts):
|
| 20 |
-
inputs = tokenizer(texts, return_tensors="pt", padding=
|
| 21 |
with torch.no_grad():
|
| 22 |
outputs = model(**inputs)
|
| 23 |
probs = torch.nn.functional.softmax(outputs.logits, dim=-1)
|
|
@@ -88,10 +88,9 @@ def get_explanation(text):
|
|
| 88 |
label_idx = np.argmax(probs)
|
| 89 |
label_name = class_names[label_idx]
|
| 90 |
|
| 91 |
-
|
| 92 |
-
explainer = LimeTextExplainer(class_names=class_names)
|
| 93 |
# লাইভ মোডে যাতে স্লো না হয়, তাই স্যাম্পল সংখ্যা ১০০০ রাখা হয়েছে
|
| 94 |
-
exp = explainer.explain_instance(text, predictor, num_features=10, labels=(label_idx,), num_samples=
|
| 95 |
weights = OrderedDict(exp.as_list(label=label_idx))
|
| 96 |
|
| 97 |
lime_weights = pd.DataFrame({'words': list(weights.keys()), 'weights': list(weights.values())})
|
|
|
|
| 17 |
|
| 18 |
# ২. প্রেডিক্টর ফাংশন (Internal use for LIME and Real-time)
|
| 19 |
def predictor(texts):
|
| 20 |
+
inputs = tokenizer(texts, return_tensors="pt", padding=True, truncation=True, max_length=64)
|
| 21 |
with torch.no_grad():
|
| 22 |
outputs = model(**inputs)
|
| 23 |
probs = torch.nn.functional.softmax(outputs.logits, dim=-1)
|
|
|
|
| 88 |
label_idx = np.argmax(probs)
|
| 89 |
label_name = class_names[label_idx]
|
| 90 |
|
| 91 |
+
explainer = LimeTextExplainer(class_names=class_names, split_expression=r'\s+')
|
|
|
|
| 92 |
# লাইভ মোডে যাতে স্লো না হয়, তাই স্যাম্পল সংখ্যা ১০০০ রাখা হয়েছে
|
| 93 |
+
exp = explainer.explain_instance(text, predictor, num_features=10, labels=(label_idx,), num_samples=1000)
|
| 94 |
weights = OrderedDict(exp.as_list(label=label_idx))
|
| 95 |
|
| 96 |
lime_weights = pd.DataFrame({'words': list(weights.keys()), 'weights': list(weights.values())})
|