### Project Dependency Installation Source: https://context7.com/votruongdanh/sentiment/llms.txt Installs all necessary Python packages for the project using pip. It provides commands to install from a requirements file or individually list key dependencies like pandas, transformers, torch, and streamlit. ```bash # Install from requirements.txt pip install -r src/requirements.txt # Or install individually: pip install pandas>=2.0.0 pip install numpy>=1.24.0 pip install transformers>=4.30.0 pip install torch>=2.0.0 pip install tqdm>=4.65.0 pip install streamlit>=1.28.0 pip install plotly>=5.0.0 pip install matplotlib>=3.7.0 pip install seaborn>=0.12.0 # Optional: Gemini API support pip install google-generativeai ``` -------------------------------- ### Launch Streamlit Web Application Source: https://context7.com/votruongdanh/sentiment/llms.txt Starts the Streamlit web interface for interactive sentiment analysis. The application allows file uploads, real-time analysis, data visualization (bar and pie charts), and configuration of analysis parameters like model selection and batch size. ```bash # Start the web application streamlit run src/app.py # Or with custom port streamlit run src/app.py --server.port 8080 # The web app provides: # - File upload interface for CSV files # - Real-time sentiment analysis with progress tracking # - Interactive data tables with filtering # - Sentiment distribution charts (bar + pie) # - Example positive/negative comments display # - Settings panel for model selection and batch size # - CSV export of analyzed results ``` -------------------------------- ### Analyze Text Sentiment with SentimentAnalyzer (Python) Source: https://context7.com/votruongdanh/sentiment/llms.txt Shows how to use the analyze_text method of the SentimentAnalyzer class to classify the sentiment of individual text strings. It provides examples for positive, negative, and neutral sentiments, including analysis of Vietnamese text. ```python from sentiment_analyzer import SentimentAnalyzer analyzer = SentimentAnalyzer() # Analyze individual comments result = analyzer.analyze_text("This video is amazing! Love it!") print(result) # Output: 1 (positive) result = analyzer.analyze_text("Terrible quality, waste of time") print(result) # Output: -1 (negative) result = analyzer.analyze_text("What time was this posted?") print(result) # Output: 0 (neutral) # Works with Vietnamese text result = analyzer.analyze_text("Xinh quá, thích lắm!") print(result) # Output: 1 (positive) result = analyzer.analyze_text("Tẩy chay thôi, chịu không nổi") print(result) # Output: -1 (negative) ``` -------------------------------- ### Batch Text Sentiment Analysis with SentimentAnalyzer (Python) Source: https://context7.com/votruongdanh/sentiment/llms.txt Demonstrates the analyze_batch method for efficient sentiment analysis of multiple text inputs using batch processing. It includes examples of processing a pandas Series and implementing a progress callback for UI integration. ```python from sentiment_analyzer import SentimentAnalyzer import pandas as pd import numpy as np analyzer = SentimentAnalyzer() # Analyze a list of comments texts = pd.Series([ "Great content!", "Not impressed at all", "When was this filmed?", "Absolutely love this creator!", "Worst video I've seen" ]) # Process in batches (default batch_size=32) results = analyzer.analyze_batch(texts, batch_size=16) print(results) # Output: array([ 1, -1, 0, 1, -1]) # With progress callback for UI integration def update_progress(current, total): print(f"Processing batch {current}/{total}") results = analyzer.analyze_batch( texts, batch_size=8, progress_callback=update_progress ) ``` -------------------------------- ### Initialize SentimentAnalyzer with Different Models (Python) Source: https://context7.com/votruongdanh/sentiment/llms.txt Demonstrates how to initialize the SentimentAnalyzer class using different backend models. It shows initialization with the default RoBERTa model, a multilingual BERT model from HuggingFace, and the Google Gemini API, including API key configuration. ```python from sentiment_analyzer import SentimentAnalyzer # Initialize with default RoBERTa model (fast) analyzer = SentimentAnalyzer() # Initialize with multilingual BERT model (more accurate) analyzer = SentimentAnalyzer( model_name='nlptown/bert-base-multilingual-uncased-sentiment' ) # Initialize with Gemini API (highest accuracy, requires API key) analyzer = SentimentAnalyzer( use_gemini=True, gemini_api_key='YOUR_GEMINI_API_KEY' ) # Or set via environment variable import os os.environ['GEMINI_API_KEY'] = 'YOUR_KEY' analyzer = SentimentAnalyzer(use_gemini=True) ``` -------------------------------- ### Command Line Sentiment Analysis Source: https://context7.com/votruongdanh/sentiment/llms.txt Executes sentiment analysis from the command line using a Python script. Supports specifying input/output files, choosing different analysis models (e.g., multilingual BERT), adjusting batch size, and customizing column names in the input CSV. ```bash # Basic usage - analyze default file python src/sentiment_analyzer.py # Specify input file python src/sentiment_analyzer.py --input my_comments.csv # Specify output file (default: overwrites input) python src/sentiment_analyzer.py --input comments.csv --output results.csv # Use more accurate multilingual model python src/sentiment_analyzer.py \ --model nlptown/bert-base-multilingual-uncased-sentiment \ --input comments.csv # Adjust batch size for memory/speed tradeoff python src/sentiment_analyzer.py \ --batch-size 64 \ --input large_dataset.csv # Custom column names python src/sentiment_analyzer.py \ --text-column comment_text \ --trust-column sentiment_score \ --input custom_format.csv # Quick run script (interactive) python src/run_sentiment.py # Data analysis script python src/run_analysis.py ``` -------------------------------- ### Process CSV for Sentiment Analysis with SentimentAnalyzer (Python) Source: https://context7.com/votruongdanh/sentiment/llms.txt Illustrates the process_csv method for reading a CSV file, performing sentiment analysis on a specified text column, and saving the results. It covers options for overwriting the input file or specifying a separate output file, and how the results are added to the DataFrame. ```python from sentiment_analyzer import SentimentAnalyzer analyzer = SentimentAnalyzer( model_name='nlptown/bert-base-multilingual-uncased-sentiment' ) # Process CSV file (overwrites input with results) df = analyzer.process_csv( input_file='tiktok_comments.csv', text_column='text', # Column containing comments trust_column='sentiment', # Output column name batch_size=32 ) # Process with separate output file df = analyzer.process_csv( input_file='input_comments.csv', output_file='analyzed_comments.csv', text_column='text', trust_column='sentiment', batch_size=64 ) # Result DataFrame contains original data plus 'sentiment' column print(df[['text', 'sentiment']].head()) # Output: # text sentiment # 0 Love this video! 1 # 1 So boring... -1 # 2 What song is this? 0 ``` -------------------------------- ### Gemini API Integration for Sentiment Analysis Source: https://context7.com/votruongdanh/sentiment/llms.txt Integrates Google's Gemini API for enhanced sentiment analysis, particularly for complex text, sarcasm, and idioms. The integration can be done by passing the API key directly or via an environment variable. It supports batch processing for efficiency. ```python from sentiment_analyzer import SentimentAnalyzer import os # Option 1: Pass API key directly analyzer = SentimentAnalyzer( use_gemini=True, gemini_api_key='YOUR_GEMINI_API_KEY' ) # Option 2: Use environment variable os.environ['GEMINI_API_KEY'] = 'YOUR_GEMINI_API_KEY' analyzer = SentimentAnalyzer(use_gemini=True) # Gemini handles complex cases better: # - Sarcasm detection: "Great job =))" -> -1 (detects sarcasm) # - Vietnamese idioms: "Đi vào lòng đất" -> -1 (understands context) # - Mixed sentiment: Long comments with nuanced emotions # Batch processing uses optimized API calls texts = pd.Series(['comment1', 'comment2', 'comment3']) results = analyzer.analyze_batch(texts, batch_size=20) # Max 20 per API call ``` -------------------------------- ### Process Pandas DataFrame Directly for Sentiment Analysis (Python) Source: https://context7.com/votruongdanh/sentiment/llms.txt Explains how to use the process_csv_dataframe method to perform sentiment analysis directly on a pandas DataFrame, bypassing file I/O. This is useful for integrating sentiment analysis within web applications like Streamlit. ```python from sentiment_analyzer import SentimentAnalyzer import pandas as pd analyzer = SentimentAnalyzer() # Create or load DataFrame df = pd.DataFrame({ 'text': [ 'Amazing content creator!', 'Terrible editing', 'What filter is this?', 'Best video ever!!' ], 'user': ['user1', 'user2', 'user3', 'user4'] }) # Process DataFrame directly results_df = analyzer.process_csv_dataframe( df, text_column='text', trust_column='sentiment', batch_size=32 ) print(results_df) # Output: ``` -------------------------------- ### TikTok Data Analysis with Python Class Source: https://context7.com/votruongdanh/sentiment/llms.txt Utilizes the TikTokDataAnalyzer class to load, analyze, and visualize TikTok comment data. It supports various analyses including sentiment, engagement, time-based patterns, user activity, and text statistics. The class generates image files for visualizations and a JSON report. ```python from data_analysis import TikTokDataAnalyzer # Initialize analyzer with CSV file analyzer = TikTokDataAnalyzer('tiktok_comments.csv') # Load the data df = analyzer.load_data() # Run individual analyses basic_info = analyzer.basic_info() # Dataset overview sentiment_stats = analyzer.sentiment_analysis() # Sentiment distribution engagement_stats = analyzer.engagement_analysis() # Likes, replies analysis time_stats = analyzer.time_analysis() # Time-based patterns user_stats = analyzer.user_analysis() # User activity analysis video_stats = analyzer.video_analysis() # Per-video analysis text_stats = analyzer.text_analysis() # Text length statistics correlation = analyzer.correlation_analysis() # Feature correlations # Or run full analysis (generates all charts and JSON report) results = analyzer.run_full_analysis() # Output files created in 'analysis_results/' directory: # - sentiment_distribution.png # - engagement_distribution.png # - time_analysis.png # - correlation_heatmap.png # - analysis_report.json ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.