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.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PerSent
3
- Version: 0.1.4
3
+ Version: 0.1.5
4
4
  Summary: Persian Sentiment Analysis Toolkit
5
5
  Home-page: https://github.com/RezaGooner/PerSent
6
6
  Author: RezaGooner
@@ -1,4 +1,4 @@
1
1
  from .analyzer import PersianSentimentAnalyzer
2
2
 
3
- __version__ = "0.1.4"
3
+ __version__ = "0.1.5"
4
4
  __all__ = ['PersianSentimentAnalyzer']
@@ -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
- processed_text = self._preprocess_text(text, for_emotion=True)
87
- results = self.emotion_analyzer(processed_text)[0]
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
- item['label']: round(float(item['score']), 4)
91
- for item in results
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)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PerSent
3
- Version: 0.1.4
3
+ Version: 0.1.5
4
4
  Summary: Persian Sentiment Analysis Toolkit
5
5
  Home-page: https://github.com/RezaGooner/PerSent
6
6
  Author: RezaGooner
@@ -5,7 +5,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
5
5
 
6
6
  setup(
7
7
  name="PerSent",
8
- version="0.1.4",
8
+ version="0.1.5",
9
9
  author="RezaGooner",
10
10
  author_email="RezaAsadiProgrammer@Gmail.com",
11
11
  description="Persian Sentiment Analysis Toolkit",
File without changes
File without changes
File without changes
File without changes