PerSent 0.1.4__tar.gz → 0.1.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of PerSent might be problematic. Click here for more details.
- {persent-0.1.4 → persent-0.1.5}/PKG-INFO +1 -1
- {persent-0.1.4 → persent-0.1.5}/PerSent/__init__.py +1 -1
- {persent-0.1.4 → persent-0.1.5}/PerSent/analyzer.py +24 -8
- {persent-0.1.4 → persent-0.1.5}/PerSent.egg-info/PKG-INFO +1 -1
- {persent-0.1.4 → persent-0.1.5}/setup.py +1 -1
- {persent-0.1.4 → persent-0.1.5}/LICENSE.txt +0 -0
- {persent-0.1.4 → persent-0.1.5}/PerSent.egg-info/SOURCES.txt +0 -0
- {persent-0.1.4 → persent-0.1.5}/PerSent.egg-info/dependency_links.txt +0 -0
- {persent-0.1.4 → persent-0.1.5}/PerSent.egg-info/requires.txt +0 -0
- {persent-0.1.4 → persent-0.1.5}/PerSent.egg-info/top_level.txt +0 -0
- {persent-0.1.4 → persent-0.1.5}/README.md +0 -0
- {persent-0.1.4 → persent-0.1.5}/setup.cfg +0 -0
- {persent-0.1.4 → persent-0.1.5}/tests/test_basic.py +0 -0
|
@@ -81,20 +81,36 @@ class AdvancedPersianSentimentAnalyzer:
|
|
|
81
81
|
return np.zeros(self.w2v_params['vector_size'])
|
|
82
82
|
|
|
83
83
|
def _emotion_analysis(self, text):
|
|
84
|
-
"""تحلیل احساسات
|
|
84
|
+
"""تحلیل احساسات با مدل BERT فارسی"""
|
|
85
85
|
try:
|
|
86
|
-
|
|
87
|
-
|
|
86
|
+
inputs = self.emotion_tokenizer(
|
|
87
|
+
text,
|
|
88
|
+
return_tensors="pt",
|
|
89
|
+
truncation=True,
|
|
90
|
+
padding=True,
|
|
91
|
+
max_length=128
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
with torch.no_grad():
|
|
95
|
+
outputs = self.emotion_model(**inputs)
|
|
96
|
+
|
|
97
|
+
probs = softmax(outputs.logits, dim=1)
|
|
98
|
+
|
|
99
|
+
# Ensure proper conversion to numpy array/list
|
|
100
|
+
if isinstance(probs, torch.Tensor):
|
|
101
|
+
scores = probs.cpu().numpy()[0]
|
|
102
|
+
else:
|
|
103
|
+
scores = probs[0]
|
|
88
104
|
|
|
89
105
|
return {
|
|
90
|
-
|
|
91
|
-
for
|
|
92
|
-
if item['label'] in ['ترس', 'تعجب', 'خشم', 'تحقیر', 'شادی', 'غم', 'انزجار']
|
|
106
|
+
label: round(float(score), 4)
|
|
107
|
+
for label, score in zip(self.emotion_labels, scores)
|
|
93
108
|
}
|
|
94
109
|
except Exception as e:
|
|
95
110
|
print(f"Error in emotion analysis: {str(e)}")
|
|
96
|
-
return {label: 0.0 for label in
|
|
97
|
-
|
|
111
|
+
return {label: 0.0 for label in self.emotion_labels}
|
|
112
|
+
|
|
113
|
+
|
|
98
114
|
def train(self, train_csv, test_size=0.2):
|
|
99
115
|
"""آموزش پیشرفته مدل تحلیل توصیه"""
|
|
100
116
|
df = pd.read_csv(train_csv)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|