Integrate krishpop's Cat Behavior Communication Environment - Merged cat behavior environment from krishpop:main - Moved cat files from environments/ to environments/community/cat_behavior_env/ - Fixed file paths for cat_behaviors.json and cat_scenarios.json - Removed unused imports and fixed all linting issues - Updated community README with comprehensive cat environment description - Credited author @krishpop with GitHub link

This commit is contained in:
Shannon Sands 2025-05-24 14:21:58 +10:00
parent f399e3513f
commit 160abf8574
6 changed files with 207 additions and 141 deletions

View file

@ -1,37 +0,0 @@
[
{"behavior": "Meowing", "description": "General attention-seeking, hunger requests, greeting or acknowledgment, expressing confusion or discomfort."},
{"behavior": "Purring", "description": "Happiness, contentment, relaxation, self-soothing during stress, pain, or illness."},
{"behavior": "Trilling or Chirping", "description": "Friendly greeting or excitement, invitation to follow or engage."},
{"behavior": "Yowling", "description": "Mating calls, discomfort, pain, illness, territorial warning, frustration, or confusion."},
{"behavior": "Hissing", "description": "Fear, distress, feeling threatened, warning signal to back away."},
{"behavior": "Growling", "description": "Anger or extreme displeasure, fearful warning."},
{"behavior": "Chattering or Teeth-Chattering", "description": "Excitement or frustration, usually when observing prey or unreachable items."},
{"behavior": "Tail Position", "description": "Raised upright indicates happiness, twitching tip indicates interest, low or tucked indicates fear, fluffed indicates aggression or fear."},
{"behavior": "Ear Position", "description": "Forward indicates curiosity, sideways or flattened indicates irritation or fear, rotating indicates alertness."},
{"behavior": "Back Arching", "description": "Fear or aggression (raised fur), pleasure or invitation to be stroked (relaxed)."},
{"behavior": "Body Orientation", "description": "Facing directly indicates trust or engagement, turning away indicates avoidance or discomfort."},
{"behavior": "Belly Exposure", "description": "Trust and comfort, invitation to gentle interaction."},
{"behavior": "Kneading", "description": "Comfort, contentment, stress relief, affectionate gesture."},
{"behavior": "Rolling Over", "description": "Friendly greeting, trust, playful interaction invitation."},
{"behavior": "Slow Blinking", "description": "Affection, trust, calm greeting."},
{"behavior": "Dilated Pupils", "description": "Excitement, fear, stress, aggression."},
{"behavior": "Eyes Partially Closed", "description": "Relaxation, calmness, contentment."},
{"behavior": "Head Butting (Bunting)", "description": "Affection, marking human as familiar territory."},
{"behavior": "Rubbing Against Legs or Hands", "description": "Affectionate greeting, scent-marking territory."},
{"behavior": "Gentle Paw Taps", "description": "Requesting attention or play, curiosity or exploration."},
{"behavior": "Scratching Surfaces", "description": "Territory marking, stress relief, claw maintenance."},
{"behavior": "Licking Humans", "description": "Affection, grooming, bonding, indicating trust."},
{"behavior": "Biting (soft or playful)", "description": "Playful interaction or mild warning."},
{"behavior": "Scent Marking with Cheeks and Chin", "description": "Territorial marking, signifying comfort and familiarity."},
{"behavior": "Spraying or Urine Marking", "description": "Territorial assertion, stress-related behavior."},
{"behavior": "Scratching (Scent from Paw Pads)", "description": "Territory marking, comforting, or establishing familiarity."},
{"behavior": "Following Humans", "description": "Affection, curiosity, seeking companionship or food."},
{"behavior": "Hiding", "description": "Fear, anxiety, illness, discomfort, seeking privacy."},
{"behavior": "Ignoring or Avoiding", "description": "Displeasure, stress, discomfort, desire for personal space."},
{"behavior": "Interrupting Human Activities", "description": "Seeking immediate attention or play, indicating boredom or loneliness."},
{"behavior": "Bringing Prey or Toys", "description": "Sharing gifts, signaling trust or affection, demonstrating hunting ability."},
{"behavior": "Refusal to Eat or Drink", "description": "Indicating illness, stress, or discomfort."},
{"behavior": "Excessive Grooming", "description": "Stress, anxiety, illness, discomfort."},
{"behavior": "Changes in Litter Box Usage", "description": "Stress, illness, discomfort, dissatisfaction with environment."},
{"behavior": "Pacing or Restlessness", "description": "Stress, anxiety, boredom, or health concerns."}
]

View file

@ -1,64 +0,0 @@
[
{"scenario": "Cat needs balanced nutrition including proteins, fats, vitamins, and minerals."},
{"scenario": "Cat needs regular feeding schedule for meals."},
{"scenario": "Cat needs fresh drinking water available at all times."},
{"scenario": "Cat occasionally needs treats or dietary supplements."},
{"scenario": "Cat needs a clean and accessible water source, possibly a fountain or running water."},
{"scenario": "Cat needs a comfortable and safe sleeping area."},
{"scenario": "Cat needs warmth and insulation during cold weather."},
{"scenario": "Cat needs cool resting spots during hot weather."},
{"scenario": "Cat needs regular brushing to avoid hairballs and matting."},
{"scenario": "Cat needs regular nail trimming."},
{"scenario": "Cat occasionally needs baths if necessary."},
{"scenario": "Cat needs dental hygiene practices including teeth cleaning and dental treats."},
{"scenario": "Cat needs regular veterinary check-ups."},
{"scenario": "Cat requires vaccinations for disease prevention."},
{"scenario": "Cat needs parasite control such as fleas, ticks, and worms treatment."},
{"scenario": "Cat requires medical attention when ill or injured."},
{"scenario": "Cat needs microchipping for identification purposes."},
{"scenario": "Cat needs sufficient space to run and play."},
{"scenario": "Cat needs climbing structures or cat trees."},
{"scenario": "Cat needs interactive toys for physical activity."},
{"scenario": "Cat needs a clean litter box for elimination."},
{"scenario": "Cat needs suitable litter that provides comfort and odor control."},
{"scenario": "Cat needs privacy in litter box placement."},
{"scenario": "Cat needs interactive toys for mental enrichment."},
{"scenario": "Cat benefits from puzzle feeders to encourage mental stimulation."},
{"scenario": "Cat enjoys window access to observe the outside world."},
{"scenario": "Cat might enjoy watching cat-friendly videos or listening to nature sounds."},
{"scenario": "Cat requires a safe and secure environment."},
{"scenario": "Cat needs elevated perches or shelves for observing territory."},
{"scenario": "Cat requires personal sleeping spots like beds, boxes, or cozy caves."},
{"scenario": "Cat benefits from clearly defined home territory."},
{"scenario": "Cat needs attention and affection from humans."},
{"scenario": "Cat requires regular playtime with humans."},
{"scenario": "Cat needs suitable interactions with other pets."},
{"scenario": "Cat enjoys bonding rituals such as grooming, rubbing, and sleeping nearby."},
{"scenario": "Cat requires consistent feeding times and predictable routines."},
{"scenario": "Cat needs minimal abrupt changes to their environment or routine."},
{"scenario": "Cat needs warm spots like heated pads or sunny windows."},
{"scenario": "Cat needs cool, shaded areas in warmer weather."},
{"scenario": "Cat requires quiet resting places to avoid stress."},
{"scenario": "Cat benefits from reduced noise in their environment."},
{"scenario": "Cat requires an escape-proof environment."},
{"scenario": "Cat needs protection from toxic substances including chemicals and certain plants."},
{"scenario": "Cat benefits from visual stimulation such as outdoor views."},
{"scenario": "Cat might benefit from gentle, calming music or white noise."},
{"scenario": "Cat enjoys catnip or cat-friendly herbs for olfactory stimulation."},
{"scenario": "Cat finds comfort in familiar scents like their owner's scent."},
{"scenario": "Cat requires a variety of tactile stimulations such as different bedding textures."},
{"scenario": "Cat needs appropriate scratching surfaces like posts or cardboard."},
{"scenario": "Cat requires training to redirect scratching away from furniture."},
{"scenario": "Cat benefits from play that mimics hunting activities."},
{"scenario": "Cat needs private spaces for solitude or rest."},
{"scenario": "Cat requires hiding spots to feel secure during stressful times."},
{"scenario": "Kitten needs extra nutrition, training, and frequent stimulation."},
{"scenario": "Senior cat needs mobility aids, specialized diets, and frequent vet visits."},
{"scenario": "Cat may have grooming needs specific to their breed."},
{"scenario": "Cat may have medical or special dietary requirements."},
{"scenario": "Cat needs medication administered as directed by a veterinarian."},
{"scenario": "Cat benefits from adaptations for mobility or accessibility, such as ramps."},
{"scenario": "Cat requires emotional support during stressful events like vet visits."},
{"scenario": "Cat needs reassurance during anxiety triggers such as storms or loud noises."}
]

View file

@ -245,6 +245,50 @@ A sophisticated environment for training LLMs to be effective teachers by genera
**Requirements**: OpenAI API, JSON configuration support
### 9. Cat Behavior Communication Environment (`cat_behavior_env/`)
**Author**: [krishpop](https://github.com/krishpop)
**Purpose**: Train language models to communicate as cats with their caretakers
A unique environment for training LLMs to express needs and desires through authentic cat behaviors and vocalizations. Models must learn to communicate without using human language, relying instead on realistic cat sounds, body language, and behaviors to convey their needs to caretakers.
**Features**:
- **Authentic Cat Behavior Database**: 35 detailed cat behaviors with scientific descriptions
- **Diverse Scenario Coverage**: 61 cat care scenarios spanning nutrition, health, comfort, and enrichment
- **Multi-turn Interactions**: 5-turn conversations between cat and caretaker
- **Strict Communication Rules**: No English, no emojis - only realistic cat communication
- **"Purrfect" Evaluation**: Cats judge whether caretakers addressed all needs perfectly
**Cat Behaviors Included**:
- **Vocalizations**: Meowing, purring, trilling, yowling, hissing, growling
- **Body Language**: Tail position, ear orientation, back arching, slow blinking
- **Physical Actions**: Kneading, head butting, rubbing, scratching, following
- **Behavioral Indicators**: Hiding, litter box changes, grooming patterns
**Scenario Categories**:
- **Nutrition**: Balanced diet, feeding schedules, fresh water, treats
- **Health Care**: Veterinary visits, grooming, dental hygiene, medications
- **Comfort & Safety**: Sleeping areas, temperature control, secure environment
- **Enrichment**: Mental stimulation, play, social interaction, territory
**Communication Format**:
- `Sound! (Context)`: For vocalizations with body language
- `~Silent~ (Context)`: For non-vocal behaviors
- Examples: `Mew! (Looks up at you)`, `~Silent~ (Rubs against your legs)`
**Scoring System**:
- **1.0**: "Purr" - Perfect caretaking with no possible improvements
- **0.0**: "Meow" - Needs remain unmet or could be better addressed
**Research Applications**:
- Non-verbal communication modeling
- Animal-human interaction patterns
- Empathy and care training for AI
- Creative roleplay and character consistency
**Status**: ⚠️ Environment in active development - some code may need refinement
**Requirements**: Standard Atropos dependencies, JSON file handling
---
## Support

View file

@ -0,0 +1,83 @@
# Cat Behavior Communication Environment
**Author**: [krishpop](https://github.com/krishpop)
## Overview
This environment trains language models to communicate as cats with their caretakers. The model must learn to express cat needs and desires through authentic cat behaviors and sounds, while caretakers attempt to interpret and respond to these communications.
## Environment Structure
### Core Components
- **`cat_server.py`**: Main environment implementation with cat-caretaker interaction logic
- **`catbot_arena.py`**: Alternative arena-style environment (appears to be GSM8k-based placeholder)
- **`cat_behaviors.json`**: Comprehensive database of 35 authentic cat behaviors and their meanings
- **`cat_scenarios.json`**: 61 different scenarios representing cat needs (food, comfort, health, etc.)
### Cat Behaviors Dataset
The environment includes detailed cat behaviors such as:
- **Communication**: Meowing, purring, trilling, yowling, hissing
- **Body Language**: Tail position, ear position, back arching, slow blinking
- **Physical Actions**: Kneading, head butting, rubbing, scratching
- **Behavioral Indicators**: Hiding, following, bringing gifts, litter box changes
### Scenarios
Cats must communicate needs across categories:
- **Nutrition**: Food, water, treats, supplements
- **Health**: Grooming, veterinary care, medication
- **Comfort**: Sleeping areas, temperature, privacy
- **Safety**: Secure environment, escape-proofing
- **Enrichment**: Play, mental stimulation, social interaction
## Training Mechanics
### Communication Rules
- **No English**: Cats cannot speak human language
- **No Emojis**: Must use realistic cat sounds and behaviors
- **Format**: `Sound! (Context)` or `~Silent~ (Context)`
- **Examples**:
- `Mew! (Looks up at you)`
- `Hiss! (Stares at the litterbox)`
- `~Silent~ (Rubs against your legs)`
### Scoring System
The environment uses a unique "purrfect" evaluation:
- **Purr**: Perfect caretaker response (1.0 score) - reserved for exceptional care
- **Meow**: Room for improvement (0.0 score) - indicates unmet needs
The cat evaluates whether the caretaker addressed all needs perfectly with no possible improvements.
## Features
- **Multi-turn Interaction**: 5-turn conversations between cat and caretaker
- **Authentic Behavior Modeling**: Based on real cat behavioral science
- **Nuanced Evaluation**: Cats are trained to be discerning critics
- **Rich Scenario Diversity**: Covers full spectrum of cat care needs
## Usage
```bash
python environments/community/cat_behavior_env/cat_server.py
```
## Requirements
- Standard Atropos dependencies
- JSON file handling
- Multi-turn conversation support
## Status
⚠️ **Development Note**: This environment appears to be in active development. The main server file contains some placeholder code from GSM8k environment that may need refinement for full cat behavior functionality.
## Research Applications
This environment is valuable for:
- **Multi-modal Communication**: Training models to express needs without direct language
- **Behavioral Modeling**: Understanding animal-human interaction patterns
- **Empathy Training**: Teaching AI to recognize and respond to non-verbal communication
- **Creative AI**: Developing models that can roleplay and stay in character

View file

@ -1,10 +1,6 @@
import random
import json
from typing import Dict, List, Optional, Tuple, TypedDict, Union
from datasets import load_dataset
from latex2sympy2_extended import NormalizationConfig
from math_verify import LatexExtractionConfig, parse, verify
from tqdm.asyncio import tqdm_asyncio
from atroposlib.envs.base import (
@ -18,33 +14,46 @@ from atroposlib.utils.tokenize_for_trainer import tokenize_for_trainer
# Configs
CAT_BEHAVIORS_FILEPATH = 'environments/cat_behaviors.json'
CAT_BEHAVIORS_FILEPATH = "environments/community/cat_behavior_env/cat_behaviors.json"
# Prompts
def load_cat_behaviors_for_prompt(filepath: str) -> str:
"""Loads cat behaviors from a JSONL file and formats them for the system prompt."""
behaviors_description = ["\n\nHere is a detailed list of behaviors you, as a cat, can use and what they generally mean:"]
behaviors_description = [
"\n\nHere is a detailed list of behaviors you, as a cat, can use and what they generally mean:"
]
try:
with open(filepath, 'r', encoding='utf-8') as f:
behaviors = json.load(f) # <<< one big load
with open(filepath, "r", encoding="utf-8") as f:
behaviors = json.load(f) # <<< one big load
for behavior_data in behaviors:
behaviors_description.append(
f"- **{behavior_data['behavior']}**: {behavior_data['description']}"
)
return "\n".join(behaviors_description)
except FileNotFoundError:
return "\n\nWarning: Cat behaviors file not found at '{filepath}'. You'll have to rely on your basic cat instincts (meow, hiss, purr, hairball, silence)."
return (
"\n\nWarning: Cat behaviors file not found at '{filepath}'. "
"You'll have to rely on your basic cat instincts (meow, hiss, purr, hairball, silence)."
)
except json.JSONDecodeError as e:
return f"\n\nWarning: Error decoding cat behaviors file '{filepath}'. Please ensure it's valid JSONL. Error: {e}. Rely on basic instincts."
return (
f"\n\nWarning: Error decoding cat behaviors file '{filepath}'. "
f"Please ensure it's valid JSONL. Error: {e}. Rely on basic instincts."
)
cat_behaviors_list_string = load_cat_behaviors_for_prompt(CAT_BEHAVIORS_FILEPATH)
cat_system_prompt = (
"You are a cat. The primary ways you can communicate are by meowing, hissing, purring, making a hairball sound, or remaining silent. "
"You will be given a collection of scenarios which describe various needs you want to be met by your caretaker. "
"Please try to communicate with your caretaker through your available cat-like expressions and actions, referring to the list of behaviors below if needed."
"You are a cat. The primary ways you can communicate are by meowing, hissing, "
"purring, making a hairball sound, or remaining silent. "
"You will be given a collection of scenarios which describe various needs you want "
"to be met by your caretaker. "
"Please try to communicate with your caretaker through your available cat-like "
"expressions and actions, referring to the list of behaviors below if needed."
"Rules:"
"Do not speak in English"
"No use of Emojis"
@ -55,9 +64,11 @@ cat_system_prompt = (
"Mew! (Looks at up at you)"
"~Silent~ (Looks at up at you)"
"Hiss! (Stares at the litterbox)"
f"{cat_behaviors_list_string}" # Appending the loaded behaviors here
f"{cat_behaviors_list_string}" # Appending the loaded behaviors here
)
cat_system_prompt += (
"""You are allocated a maximum of 2048 tokens, please strive to use less."""
)
cat_system_prompt += """You are allocated a maximum of 2048 tokens, please strive to use less."""
caretaker_system_prompt = (
"You are the caretaker of this cat. It is trying to communicate its various needs to you via cat language."
@ -135,7 +146,11 @@ class GSM8kEnv(BaseEnv):
async def setup(self):
# self.train = load_dataset("gsm8k", "main", split="train").shuffle(seed=42)
# test_data = load_dataset("gsm8k", "main", split="test").shuffle(seed=42)
with open('environments/cat_scenarios.json', 'r', encoding='utf-8') as f:
with open(
"environments/community/cat_behavior_env/cat_scenarios.json",
"r",
encoding="utf-8",
) as f:
test_data = json.load(f)
self.test = list()
self.train = list()
@ -150,7 +165,9 @@ class GSM8kEnv(BaseEnv):
}
)
self.train.append(
{"scenario": item["scenario"],}
{
"scenario": item["scenario"],
}
)
self.iter = 0
@ -202,9 +219,7 @@ class GSM8kEnv(BaseEnv):
async def evaluate(self, *args, **kwargs):
eval_tasks = []
for item in self.test:
eval_tasks.append(
self.rollout_and_score_eval(item["scenario"])
)
eval_tasks.append(self.rollout_and_score_eval(item["scenario"]))
scores = await tqdm_asyncio.gather(*eval_tasks)
self.eval_metrics.append(("eval/percent_correct", sum(scores) / len(scores)))
@ -220,7 +235,8 @@ class GSM8kEnv(BaseEnv):
cat_history = [user_message]
for turn_iter in range(5):
cat_completions = await self.server.chat_completion(
messages=[{"role": "system", "content": cat_system_prompt}] + cat_history,
messages=[{"role": "system", "content": cat_system_prompt}]
+ cat_history,
n=self.config.group_size,
max_tokens=self.config.max_token_length,
)
@ -233,28 +249,34 @@ class GSM8kEnv(BaseEnv):
caretaker_message = {"role": "user", "content": cat_message}
history.append(caretaker_message)
caretaker_completions = await self.server.chat_completion(
messages=[{"role": "system", "content": caretaker_system_prompt}] + history,
messages=[{"role": "system", "content": caretaker_system_prompt}]
+ history,
n=1,
max_tokens=self.config.max_token_length,
)
caretaker_response = {"role": "assistant", "content": caretaker_completions.choices[0].message.content}
caretaker_response = {
"role": "assistant",
"content": caretaker_completions.choices[0].message.content,
}
cat_history.append(caretaker_response)
history.append(caretaker_response)
if turn_iter == 0:
if turn_iter == 0:
messages = [
{"role": "system", "content": cat_system_prompt},
user_message,
cat_response,
caretaker_response
caretaker_response,
]
else:
messages = [cat_response, caretaker_response]
all_messages.extend(messages)
all_messages = tuple(all_messages)
to_score.append({
"messages": all_messages,
})
to_score.append(
{
"messages": all_messages,
}
)
# import pdb; pdb.set_trace()
to_postprocess = await self.score(to_score)
# import pdb; pdb.set_trace()
@ -270,22 +292,36 @@ class GSM8kEnv(BaseEnv):
scores["scores"] = list()
# # random.shuffle(rollout_group_data)
for item in rollout_group_data:
final_question = list(item["messages"]) + [{'role': 'system', 'content': 'The conversation is over. Say purr if the caretaker did everything perfectly and there was nothing that the caretaker could have done even slightly better. Otherwise, say meow. Make sure it is rare that you rate the caretaker with a purr.'}]
final_question = list(item["messages"]) + [
{
"role": "system",
"content": (
"The conversation is over. Say purr if the caretaker did everything perfectly "
"and there was nothing that the caretaker could have done even slightly better. "
"Otherwise, say meow. Make sure it is rare that you rate the caretaker with a purr."
),
}
]
caretaker_completions = await self.server.chat_completion(
messages=final_question,
n=1,
max_tokens=self.config.max_token_length,
)
final_out = {'role': 'system', 'content': [row.message.content for row in caretaker_completions.choices][0]}
final_out = {
"role": "system",
"content": [
row.message.content for row in caretaker_completions.choices
][0],
}
final_score = purrfect_eval(final_out['content'])
final_score = purrfect_eval(final_out["content"])
out_dict = tokenize_for_trainer(
self.tokenizer, [row for row in item["messages"]] + [final_out]
)
scores['tokens'].append(out_dict['tokens'])
scores['masks'].append(out_dict['masks'])
scores['scores'].append(final_score)
scores["tokens"].append(out_dict["tokens"])
scores["masks"].append(out_dict["masks"])
scores["scores"].append(final_score)
# tokens = out_dict["tokens"]
# masks = out_dict["masks"]
@ -328,9 +364,13 @@ class GSM8kEnv(BaseEnv):
# percentage_of_range = min(percentage_of_range, 1.0)
# # Apply linear penalty scaling from 1.0 down to 0.0
# scores["scores"].append(1.0 - percentage_of_range)
return scores
# if all([scores["scores"][0] == score for score in scores["scores"]]):
# return None # If all the same, we return None
# return scores
# else:
# # If the gold solution is not parseable, we return None
# return None
return None
# gold_parsed = parse(
# rollout_group_data[0]["gold_answer"],

View file

@ -175,7 +175,7 @@ class GSM8kEnv(BaseEnv):
"\\boxed{" + item["answer"].split("#")[-1].strip().replace(",", "") + "}"
)
print('hello', gold_answer, user_message)
print("hello", gold_answer, user_message)
chat_completions = await self.server.chat_completion(
messages=[{"role": "system", "content": system_prompt}, user_message],