Project03

Musk-Tweets

Gallery
Architecture Diagram
Training Pipeline
Results Chart
System Overview

LLM-based Social Media Intelligence — not a tweet generator.

Overview

Musk-Tweets is a social media intelligence system that analyzes, understands, and generates contextually-aware tweets in the style of specific public figures. It is designed for research and analysis applications, not content generation — the focus is on understanding how language patterns encode identity, sentiment, and intent in social media.

Problem

Social media text carries rich information about author identity, emotional state, and social context. Existing tools either focus on sentiment analysis alone or generate content without understanding the underlying linguistic patterns. Musk-Tweets bridges this gap by combining fine-tuned language modeling with structured analysis pipelines.

Architecture

The system consists of three interconnected pipelines:

`

Dataset Cleaning Fine-tuning Generation Evaluation

↓ ↓ ↓ ↓ ↓

Raw Tweets → Normalization → LoRA Fine-tune → Context-Aware → Quality Metrics

Deduplication 7B Parameter Beam Search Human Eval

Bot Filter QLoRA (4-bit) Sampling Perplexity

Normalization PEFT Config Length Control BLEU/ROUGE

`

Dataset Pipeline

Dataset Construction: 500K+ tweets from public Musk posts spanning 2015-2024, paired with metadata including timestamp, engagement metrics, topic labels, and sentiment annotations.

Cleaning Pipeline:

  • URL and mention removal (anonymized, not dropped — preserves structure)
  • Hashtag extraction and normalization (mapped to topic categories)
  • Emoji-to-text conversion (preserves sentiment information)
  • Duplicate detection using MinHash similarity
  • Bot/Spam filtering via heuristics and a lightweight classifier
  • Language detection and filtering (English only)
  • Thread and reply stripping (isolates standalone tweets)
  • Length normalization (padding/truncation to 280 chars)
  • Fine-tuning Pipeline

    Base Model: Llama-3-8B (pre-trained)

    Fine-tuning Method: QLoRA (Quantized Low-Rank Adaptation)

  • 4-bit NF quantization of base weights
  • Rank 64 adaptation matrices
  • Target modules: all attention layers and MLP down-projection
  • LoRA alpha: 16
  • Dropout: 0.05
  • Training Configuration:

    ParameterValue
    ------------------
    Epochs3
    Batch Size64 (gradient accumulation 4 steps)
    Learning Rate2e-4 (cosine schedule)
    Warmup Steps500
    Max Sequence Length512
    Quantization4-bit NF4
    Trainerbitsandbytes + PEFT + TRL

    Generation Pipeline

  • Context Injection: User-provided prompt or topic embedding prepended to input
  • Constrained Decoding: Length constrained to 280 tokens, no special characters
  • Beam Search: Beam width 4 with length penalty 0.6
  • Nucleus Sampling: Top-p = 0.9, temperature = 0.7 as alternative to beam
  • Repetition Penalty: 1.2 to reduce repetitive outputs
  • Post-processing: Grammar correction, emoji consistency check, authenticity scoring
  • Evaluation Framework

    MetricMethodTarget
    ------------------------
    AuthenticityHuman eval (3 annotators, 1-5 scale)3.5+
    CoherencePerplexity on held-out test set< 25
    Style SimilarityBERTScore vs. reference corpus> 0.85
    Topic RelevanceTF-IDF similarity to context> 0.7
    SafetyToxicity classifier (3 models)< 5% flagged

    Training

    The fine-tuning process required careful hyperparameter tuning:

  • Overfitting prevention: Early stopping at 3 epochs with patience of 1 on validation perplexity
  • Catastrophic forgetting mitigation: Elastic weight consolidation on base model layers
  • Data ordering: Curriculum learning — start with simple tweets, progress to complex multi-topic ones
  • Batch composition: Balanced sampling across topics to prevent mode collapse
  • Challenges

    Style Collapse

    The model initially generated generic tweets that lost the distinctive voice of the author. Solution: increased LoRA rank to 64 and added a style classifier loss term that penalizes deviation from the reference style distribution.

    Contextual Coherence

    Long-form consistency across generated tweet threads was poor. Introducing a sliding window context window of 5 previous tweets as input context improved coherence significantly.

    Tokenization Mismatch

    Twitter-specific tokens (handles, hashtags, mentions) caused tokenization fragmentation. Custom tokenizer training on the tweet corpus reduced BPE fragmentation by 40%.

    Safety and Ethics

    The model had to be constrained to prevent generation of harmful or misleading content. Implemented a multi-stage filter: toxicity classifier pre-check, content safety classifier post-generation, and a confidence threshold that blocks low-confidence generations from being returned.

    Optimization

    Memory Optimization

  • QLoRA reduces fine-tuning memory from ~48GB to ~6GB
  • Gradient checkpointing for the LoRA adapters only
  • Gradient accumulation steps traded for effective batch size
  • Optimizer states quantized to 8-bit
  • Inference Optimization

  • vLLM backend for GPU-efficient serving
  • Continuous batching for throughput optimization
  • KV-cache reuse across similar prompts
  • Speculative decoding with a small draft model
  • Results

    MetricValue
    ---------------
    Authenticity Score (Human Eval)3.8 / 5.0
    BERTScore (Style)0.87
    Perplexity (Held-out)22.3
    Safety Flag Rate2.1%
    Inference Latency150ms per tweet
    Fine-tuning Time6 hours (1x A100)
    Model Size (QLoRA adapters)45MB

    Lessons Learned

  • QLoRA is remarkable: 4-bit quantization during fine-tuning preserves quality while reducing memory by 10x.
  • Style is learnable: With enough data and proper regularization, a model can capture an author's linguistic fingerprint.
  • Safety cannot be an afterthought: The pipeline needs filtering at both input and output stages.
  • Evaluation is harder than training: No single metric captures social media text quality — human evaluation remains essential.
  • Tokenization matters: Custom tokenizer training on domain-specific text significantly outperforms generic tokenizers.
  • Future Work

  • Extend to multi-author comparison analysis
  • Add temporal modeling to track how an author's style evolves over time
  • Build anomaly detection to flag potentially unauthorized posts
  • Integrate multimodal analysis (images + text) for deeper social media understanding
  • Create a research API for NLP and social science researchers
  • Source Code

    GitHub Repository

    Sivadeth PS — AI Engineer