
Product
Introducing Scala and Kotlin Support in Socket
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
A Python library for sentiment analysis of Persian (Farsi) text, capable of classifying opinions as "recommended", "not_recommended", or "no_idea".
pip install persian-sentiment-analyzer
Python 3.6+
hazm
gensim
scikit-learn
numpy
pandas
from persian_sentiment_analyzer import SentimentAnalyzer
# Initialize with a pre-trained model
analyzer = SentimentAnalyzer(model_path="path/to/pretrained_model")
# Predict sentiment
result = analyzer.predict("این محصول بسیار عالی است")
print(result) # Output: 'recommended'
from persian_sentiment_analyzer import SentimentAnalyzer
import pandas as pd
# Load your dataset
data = pd.read_csv("persian_reviews.csv")
texts = data['text'].tolist()
labels = data['label'].values # 0: not_recommended, 1: recommended, 2: no_idea
# Initialize analyzer
analyzer = SentimentAnalyzer()
# Preprocess and tokenize texts
tokenized_texts = [analyzer.preprocessor.preprocess_text(text) for text in texts]
# Train Word2Vec model
analyzer.train_word2vec(tokenized_texts, vector_size=100)
# Prepare feature vectors
X = np.array([analyzer.sentence_vector(tokens) for tokens in tokenized_texts])
# Train classifier
analyzer.train_classifier(X, labels)
# Save the trained model
analyzer.save_model("my_persian_model")
from persian_sentiment_analyzer import predict_sentiments_for_file
# Process a CSV file containing Persian comments
results_summary = predict_sentiments_for_file(
analyzer,
input_file="comments.csv",
output_file="results.csv",
summary_file="summary.csv"
)
print(results_summary)
1- Text Preprocessing:
Normalization (Hazm)
Tokenization
Stemming
Stopword removal
2- Feature Extraction:
Word2Vec embeddings (100 dimensions)
Sentence vectors (average of word vectors)
3- Classification:
The pre-trained model achieves the following performance on our test set:
Metric Value Accuracy 85.2% Precision 84.7% Recall 85.0% F1-score 84.8%
License This project is licensed under the MIT License - see the LICENSE file for details
Github : RezaGooner
FAQs
Persian Sentiment Analysis Toolkit
We found that persian-sentiment demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
Application Security
/Security News
Socket CEO Feross Aboukhadijeh and a16z partner Joel de la Garza discuss vibe coding, AI-driven software development, and how the rise of LLMs, despite their risks, still points toward a more secure and innovative future.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.