PerSent 0.1.4__tar.gz → 0.1.6__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.6}/PKG-INFO +1 -1
- {persent-0.1.4 → persent-0.1.6}/PerSent/__init__.py +1 -1
- {persent-0.1.4 → persent-0.1.6}/PerSent/analyzer.py +38 -9
- {persent-0.1.4 → persent-0.1.6}/PerSent.egg-info/PKG-INFO +1 -1
- {persent-0.1.4 → persent-0.1.6}/setup.py +1 -1
- {persent-0.1.4 → persent-0.1.6}/LICENSE.txt +0 -0
- {persent-0.1.4 → persent-0.1.6}/PerSent.egg-info/SOURCES.txt +0 -0
- {persent-0.1.4 → persent-0.1.6}/PerSent.egg-info/dependency_links.txt +0 -0
- {persent-0.1.4 → persent-0.1.6}/PerSent.egg-info/requires.txt +0 -0
- {persent-0.1.4 → persent-0.1.6}/PerSent.egg-info/top_level.txt +0 -0
- {persent-0.1.4 → persent-0.1.6}/README.md +0 -0
- {persent-0.1.4 → persent-0.1.6}/setup.cfg +0 -0
- {persent-0.1.4 → persent-0.1.6}/tests/test_basic.py +0 -0
|
@@ -39,6 +39,17 @@ class AdvancedPersianSentimentAnalyzer:
|
|
|
39
39
|
'sg': 1 # استفاده از skip-gram
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
# نگاشت برچسبهای احساسات
|
|
43
|
+
self.emotion_labels = {
|
|
44
|
+
'ترس': 'Fear',
|
|
45
|
+
'تعجب': 'Surprise',
|
|
46
|
+
'خشم': 'Anger',
|
|
47
|
+
'تحقیر': 'Contempt',
|
|
48
|
+
'شادی': 'Joy',
|
|
49
|
+
'غم': 'Sadness',
|
|
50
|
+
'انزجار': 'Disgust'
|
|
51
|
+
}
|
|
52
|
+
|
|
42
53
|
os.makedirs(self.model_dir, exist_ok=True)
|
|
43
54
|
|
|
44
55
|
def _preprocess_text(self, text, for_emotion=False):
|
|
@@ -81,19 +92,36 @@ class AdvancedPersianSentimentAnalyzer:
|
|
|
81
92
|
return np.zeros(self.w2v_params['vector_size'])
|
|
82
93
|
|
|
83
94
|
def _emotion_analysis(self, text):
|
|
84
|
-
"""تحلیل احساسات پیشرفته با
|
|
95
|
+
"""تحلیل احساسات پیشرفته با مدل BERT"""
|
|
85
96
|
try:
|
|
97
|
+
# پیشپردازش متن برای تحلیل احساسات
|
|
86
98
|
processed_text = self._preprocess_text(text, for_emotion=True)
|
|
99
|
+
|
|
100
|
+
# تحلیل احساسات
|
|
87
101
|
results = self.emotion_analyzer(processed_text)[0]
|
|
88
102
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
103
|
+
# پردازش نتایج
|
|
104
|
+
emotions = {}
|
|
105
|
+
for item in results:
|
|
106
|
+
fa_label = item['label']
|
|
107
|
+
if fa_label in self.emotion_labels:
|
|
108
|
+
en_label = self.emotion_labels[fa_label]
|
|
109
|
+
score = round(float(item['score']), 4)
|
|
110
|
+
emotions[en_label] = score
|
|
111
|
+
|
|
112
|
+
# اگر همه مقادیر صفر بودند، قویترین احساس را برگردان
|
|
113
|
+
if all(v == 0 for v in emotions.values()) and results:
|
|
114
|
+
top_emotion = max(results, key=lambda x: x['score'])
|
|
115
|
+
fa_label = top_emotion['label']
|
|
116
|
+
if fa_label in self.emotion_labels:
|
|
117
|
+
en_label = self.emotion_labels[fa_label]
|
|
118
|
+
emotions[en_label] = round(float(top_emotion['score']), 4)
|
|
119
|
+
|
|
120
|
+
return emotions
|
|
121
|
+
|
|
94
122
|
except Exception as e:
|
|
95
|
-
print(f"
|
|
96
|
-
return {label: 0.0 for label in
|
|
123
|
+
print(f"خطا در تحلیل احساسات: {str(e)}")
|
|
124
|
+
return {label: 0.0 for label in self.emotion_labels.values()}
|
|
97
125
|
|
|
98
126
|
def train(self, train_csv, test_size=0.2):
|
|
99
127
|
"""آموزش پیشرفته مدل تحلیل توصیه"""
|
|
@@ -151,7 +179,7 @@ class AdvancedPersianSentimentAnalyzer:
|
|
|
151
179
|
'model_params': self.w2v_params
|
|
152
180
|
}
|
|
153
181
|
|
|
154
|
-
def predict(self, text, mode=0, threshold=0.
|
|
182
|
+
def predict(self, text, mode=0, threshold=0.1):
|
|
155
183
|
"""
|
|
156
184
|
پیشبینی پیشرفته با قابلیت تنظیم آستانه
|
|
157
185
|
|
|
@@ -220,3 +248,4 @@ class AdvancedPersianSentimentAnalyzer:
|
|
|
220
248
|
self.vectorizer = Word2Vec.load(
|
|
221
249
|
os.path.join(self.model_dir, f'word2vec_v{version}.model')
|
|
222
250
|
)
|
|
251
|
+
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|