CoolFace
Apppublic

muffin2006/document-classification-env

sourceHugging Faceupdated 6mo agoView on Hugging Face
1likes
App README

๐Ÿ“„ Document Classification Environment

OpenEnv submission for Meta x PyTorch Hackathon

An interactive Gymnasium-compatible environment where AI agents learn to classify and route customer support tickets to the correct department.


๐ŸŽฏ Real-World Task

Customer support teams receive hundreds of tickets daily โ€” billing issues, technical bugs, HR complaints, legal queries. This environment simulates that routing challenge, training agents to read a document and instantly decide which department should handle it.

Why this matters: Misrouted tickets waste time and frustrate customers. A well-trained agent can reduce misrouting by 80%+.


๐Ÿ—๏ธ Environment Design

DocumentClassificationEnv(task_difficulty="hard", seed=42)
โ”œโ”€โ”€ observation_space: Dict
โ”‚   โ”œโ”€โ”€ content: Text (the document)
โ”‚   โ”œโ”€โ”€ document_id: Text
โ”‚   โ”œโ”€โ”€ word_count: Box(1,)
โ”‚   โ”œโ”€โ”€ has_urgency_markers: MultiBinary(1)
โ”‚   โ”œโ”€โ”€ features: Box(100,)  โ† TF-IDF features
โ”‚   โ”œโ”€โ”€ document_index: Box(1,)
โ”‚   โ””โ”€โ”€ total_documents: Box(1,)
โ””โ”€โ”€ action_space: Discrete(N)  โ† N = num categories

API

python
from environment import DocumentClassificationEnv

env = DocumentClassificationEnv(task_difficulty="hard", seed=42)
obs, info = env.reset()

while True:
    action = your_agent(obs)          # int: category index
    obs, reward, done, _, info = env.step(action)
    print(f"Reward: {reward:.3f}, Correct: {info['is_correct']}")
    if done:
        print(info["episode_summary"])
        break

๐Ÿ“Š Three Progressive Tasks

TaskCategoriesDocumentsTime LimitTarget Score
Easy5100None0.85
Medium105002 sec0.75
Hard2210001 sec0.75

Categories (Hard Mode โ€” 22 total)

General Billing Billing-Dispute Billing-Refund Support Support-Urgent Support-Normal Technical Technical-Bug Technical-Feature HR HR-Payroll HR-Benefits HR-Complaint Legal Legal-Contract Legal-Compliance Executive Executive-Strategic Finance Marketing Operations


๐Ÿ† Reward Function

python
reward = accuracy_reward + speed_bonus

# accuracy_reward:
#   +1.0 for correct classification
#   -0.5 for wrong classification

# speed_bonus (difficulty-dependent):
#   Easy:   +0.10 if < 100ms
#   Medium: +0.15 if < 200ms, +0.10 if < 500ms
#   Hard:   +0.20 if < 100ms, +0.10 if < 300ms

Partial credit via speed bonus encourages efficient inference, not just accuracy.


๐Ÿ“ˆ Baseline Results (Keyword Agent)

TaskScoreNotes
EASY0.77Simple keyword matching
MEDIUM0.89Priority-ordered keywords
HARD0.16522 categories, harder to distinguish

Better agents (TF-IDF similarity, fine-tuned LLM) can significantly beat baseline.


๐Ÿš€ Quick Start

bash
git clone https://huggingface.co/spaces/TanujInsane/document-classification-env
cd document-classification-env
pip install -r requirements.txt

# Run baseline
python baseline_inference.py --task all --output results.json

# Launch UI
python app.py

๐Ÿ“ File Structure

โ”œโ”€โ”€ environment.py          # Main Gymnasium environment
โ”œโ”€โ”€ tasks.py               # Document generation + TF-IDF features
โ”œโ”€โ”€ grading.py             # Scoring logic (0.0 - 1.0)
โ”œโ”€โ”€ baseline_inference.py  # Keyword-based baseline agent
โ”œโ”€โ”€ app.py                 # Gradio interactive demo
โ”œโ”€โ”€ test_environment.py    # 5 unit tests (all passing โœ…)
โ”œโ”€โ”€ openenv.yaml           # OpenEnv specification
โ”œโ”€โ”€ Dockerfile             # Container deployment
โ””โ”€โ”€ requirements.txt       # Dependencies

๐Ÿ”ฌ Reproducibility

  • โ€”Seed-controlled document generation
  • โ€”Fixed test sets for fair grading
  • โ€”Deterministic reward calculation
  • โ€”Docker containerization for consistent deployment

๐Ÿ’ก Improving Beyond Baseline

python
# Example: TF-IDF similarity agent (beats keyword matching)
from sklearn.metrics.pairwise import cosine_similarity

class TFIDFAgent:
    def __init__(self, difficulty):
        self.env = DocumentClassificationEnv(difficulty)
        # Pre-compute category centroid vectors
        # Use cosine similarity at inference time
        ...

Built for Meta x PyTorch OpenEnv Hackathon | Gymnasium-compatible | Docker deployed