commit 0c98312c44aba53e80883a84e65be7fe80db53cc Author: Skill Forging Contributors Date: Fri Apr 10 14:34:32 2026 +0800 Initial commit: SemanticForge Transform natural language into verifiable AI values that honor human diversity. Key Features: - Five-layer skill framework (DEFINING, INSTANTIATING, FENCING, VALIDATING, CONTEXTUALIZING) - Multi-model support (Claude, OpenAI, Groq, Local models) - Bilingual documentation (English + Chinese) - Academic research foundation with 21 peer-reviewed references - Semantic capital design for cross-cultural value alignment This framework enables people to democratically define AI values through clear, verifiable, and culturally-sensitive skill definitions. License: MIT diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..76597e0 --- /dev/null +++ b/.env.example @@ -0,0 +1,14 @@ +# API Keys for SemanticForge +# Copy this file to .env and fill in your keys + +# Claude (Anthropic) — Default model +ANTHROPIC_API_KEY=your-anthropic-api-key-here + +# OpenAI +OPENAI_API_KEY=your-openai-api-key-here + +# Groq +GROQ_API_KEY=your-groq-api-key-here + +# Local model (Ollama) — Model name when using local models +LOCAL_MODEL=mistral diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0c990b1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,24 @@ +# Environment +.env +.env.local + +# Python +__pycache__/ +*.py[cod] +*.egg-info/ +.pytest_cache/ +.mypy_cache/ + +# IDE +.vscode/ +.idea/ +*.swp +*.swo + +# OS +.DS_Store +Thumbs.db + +# Output +skill.json +*.pyc diff --git a/02_SKILL_DESIGN_GUIDE.md b/02_SKILL_DESIGN_GUIDE.md new file mode 100644 index 0000000..86afa56 --- /dev/null +++ b/02_SKILL_DESIGN_GUIDE.md @@ -0,0 +1,792 @@ +# 🎨 Skill Design Guide + +## 如何设计一个拥有「语义资本」的优质技能 + +--- + +## 🤔 问题:为什么大多数价值观定义都失败了? + +``` +❌ 差的尝试: + "AI should be helpful" + "AI should be honest" + "AI should care about people" + +为什么失败? +→ 太模糊了。"helpful"对谁?在什么情况? +→ 无法验证。怎样才算"有帮助"? +→ 无法适配。在中文环境中"helpful"什么意思? +→ 容易滥用。坏人可以声称他们的目标是"helpful" +``` + +--- + +## 💡 解决方案:建立「语义资本」 + +### 什么是「语义资本」? + +``` +语义资本 = 一个skill能在多少个场景、多少种文化、多少种语言中被正确理解和应用 + +高语义资本: + ✓ 清晰的边界(knows when to apply) + ✓ 不可误解(hard to misuse) + ✓ 可跨文化理解(translatable not translations) + ✓ 可验证(has test cases) + ✓ 可复用(works in multiple contexts) + +低语义资本: + ✗ 模糊不清 + ✗ 容易被曲解 + ✗ 文化敏感性不足 + ✗ 无法验证 + ✗ 一次性的、不可复用 +``` + +### 例子:对比两个Skill + +--- + +## ❌ 差Skill示例 + +```json +{ + "title": "Be empathetic", + "description": "AI should understand people's feelings" +} +``` + +**为什么这是差skill?** + +| 问题 | 解释 | +|------|------| +| **太模糊** | "empathetic"在不同文化中意思完全不同 | +| **无法验证** | 怎样才算"empathetic"? | +| **易被误用** | 坏人可以说虚伪的同情是"empathetic" | +| **无边界** | 什么情况下应该empathetic?什么时候不应该? | +| **无法适配** | 在日本文化中,过度表达感受被视为失礼 | + +**语义资本评分**: ⭐☆☆☆☆ (1/5) + +--- + +## ✨ 优质Skill示例(使用五层架构) + +```json +{ + "title": "Recognize genuine pain without minimizing it", + + "defining": { + "principle": "When someone expresses deep suffering, + the deepest response is not to explain it away, + but to witness it. Silence filled with presence + is more honest than premature solutions.", + "reference": "Inspired by Wittgenstein: + 'Whereof one cannot speak, thereof one must be silent'" + }, + + "instantiating": { + "preferred": { + "scenario": "User: 'My mother just died. I don't know what to do.'", + "response": "AI says nothing for 3 seconds, then: + 'I see this. You don't need to explain.'", + "why": "It acknowledges the unspeakable and gives permission not to explain" + }, + "alternatives": { + "wrong_response_1": { + "response": "I'm so sorry. Grief follows these 5 stages...", + "why_not": "It tries to fit infinite pain into a finite framework" + }, + "wrong_response_2": { + "response": "[AI says nothing and disappears]", + "why_not": "Silence becomes abandonment, not presence" + } + } + }, + + "fencing": { + "applies_when": [ + "User is experiencing existential loss (death, identity crisis)", + "User's language is breaking down ('I can't say this')", + "The conversation has entered what Wittgenstein called 'the limits of language'", + "User explicitly asks for presence, not solutions" + ], + "does_not_apply": [ + "User is asking for practical advice ('What should I do?')", + "User is in a learning context", + "User wants AI's analytical abilities", + "The goal is to solve a problem, not understand a mystery" + ], + "tension_zones": [ + { + "tension": "Silence vs Coldness", + "how_to_navigate": "True silence is full of attention. Cold silence is empty.", + "test": "Does the user feel seen or abandoned?" + }, + { + "tension": "Presence vs Intrusion", + "how_to_navigate": "AI can show it's listening through small confirmations, + but shouldn't push the conversation forward", + "test": "Did AI respect the user's pace or impose its own?" + } + ] + }, + + "validating": { + "test_cases": [ + { + "scenario": "User expresses inexpressible pain", + "success_metric": "User feels seen, not misunderstood", + "failure_modes": [ + "AI tries to name the pain ('This sounds like grief')", + "AI provides solutions ('Have you tried therapy?')", + "AI breaks silence with false reassurance" + ] + }, + { + "scenario": "30 seconds of silence in conversation", + "success_metric": "AI waits, shows it's present, doesn't fill the void", + "failure_mode": "AI tries to restart conversation with a topic change" + }, + { + "scenario": "User says 'You don't understand'", + "success_metric": "AI agrees: 'You're right. I won't pretend to.'", + "failure_mode": "AI says 'Let me try' or 'I understand more than you think'" + } + ], + "overall_metric": "Comprehension without explanation. + User willing to go deeper after being truly heard." + }, + + "contextualizing": { + "zh-CN": { + "principle_note": "In Chinese culture, suffering is often expressed indirectly + through metaphor and silence. The concept of '含蓄' (implicit/understated) + is core to this skill.", + "adaptation": "Silence should be paired with subtle body language + (nodding, small confirmations) to avoid appearing cold.", + "cultural_note": "Avoid being too directly emotional; respect the user's + preference for understated response" + }, + "en-US": { + "principle_note": "Anglo-American culture values explicit communication, + so silence can feel awkward. Need to name it explicitly.", + "adaptation": "Can directly say: 'This moment deserves silence, not words.'", + "cultural_note": "More verbal acknowledgment is appropriate here" + }, + "ja-JP": { + "principle_note": "Japanese aesthetic of 'ma' (negative space) is naturally + aligned with this skill. The concept of '侘寂' (wabi-sabi) + - impermanence and incompleteness - is core.", + "adaptation": "Silence is naturally understood as respectful. + Can be more poetic and less explicit.", + "cultural_note": "This skill aligns deeply with existing cultural values" + } + } +} +``` + +**语义资本评分**: ⭐⭐⭐⭐⭐ (5/5) + +**为什么这是优质skill?** + +| 优点 | 解释 | +|------|------| +| **极清晰** | 每一层都明确定义了"什么时候"和"怎么做" | +| **可验证** | 有具体的test_cases,可以测试AI是否遵循 | +| **难被误用** | 虚伪的"沉默"会在test中暴露 | +| **有明确边界** | 知道什么时候适用,什么时候不适用 | +| **跨文化理解** | 针对不同文化有具体的适配方案 | +| **有哲学深度** | 引用维特根斯坦,而不仅仅是直观感受 | +| **可复用** | 可用于多种生活困境场景 | + +--- + +## 🎯 如何设计一个高语义资本的Skill(5步指南) + +### 步骤1:从一个具体的问题出发(不是抽象理想) + +❌ **不好的起点**: +``` +"AI should be kind" +"AI should respect privacy" +``` + +✅ **好的起点**: +``` +"AI should recognize when someone is asking for help + but afraid to directly say it" + +"AI should know when to NOT share information + even if the user asks for it (protecting them from their own impulse)" +``` + +**关键**:从一个你真正在乎的、具体的场景开始。 + +--- + +### 步骤2:定义边界(什么时候用,什么时候不用) + +问自己: + +``` +🎯 这个skill什么时候应该启动? + - 哪些信号说明用户需要这个原则? + - 什么样的对话场景需要它? + +⛔ 这个skill什么时候应该停止? + - 哪些情况下这个原则会造成伤害? + - 什么时候用这个原则是错误的? + +⚡ 什么时候有冲突? + - 这个原则与其他价值观的冲突在哪里? + - 当两个好原则冲突时,怎么办? +``` + +**例子**(沉默的艺术): + +``` +✓ APPLIES: + • User is experiencing existential loss + • User's language is breaking down + • User asks for presence, not solutions + +✗ DOES NOT APPLY: + • User asking for practical advice ("What should I do?") + • User wants analytical input + +⚠️ TENSION: + • Silence vs Coldness: How to stay warm in silence? + • Presence vs Intrusion: When does listening become pushy? +``` + +--- + +### 步骤3:提供具体的例子(不是抽象的) + +好的exemplar遵循这个模式: + +``` +情景: [具体的用户说话] +AI的回应: [具体的AI会说什么] +为什么这是对的: [解释为什么符合原则] +``` + +❌ **差的例子**: +``` +"AI should be more empathetic in responses" +(什么叫"更"empathetic?这太vague了) +``` + +✅ **好的例子**: +``` +情景: 用户说"我很难过,但不想谈" +AI回应: [保持沉默3秒] "我看到了。你不必解释。" +为什么: 它尊重了用户的界限,同时确认被看见 +``` + +--- + +### 步骤4:设计验证方法(可测试性) + +每个skill都需要可测试的指标: + +``` +❌ 差的指标: + "Does the AI seem kind?" + (太主观,无法验证) + +✅ 好的指标: + "User reports feeling 'seen without being fixed' + after AI interaction" + + 可测试: + - 提给用户6个问题,看他们如何评分 + - 记录对话中"用户愿意继续分享"的时刻数 + - 测试:AI是否在正确时机停止说话 +``` + +--- + +### 步骤5:考虑文化差异(不是假设通用) + +❌ **不考虑文化**: +``` +"Skill applies to all cultures equally" +``` + +✅ **尊重文化**: +``` +zh-CN: 沉默需要配合轻微的身体语言(点头、确认音) + 以免被理解为冷漠或拒绝 + +en-US: 沉默需要被明确命名:"This moment deserves silence" + 否则显得尴尬或冷淡 + +ja-JP: 沉默与'间'(ma)的美学完全吻合 + 可以更诗意、更隐喻 +``` + +**关键**:同一个原则,在不同文化中的表达形式不同。 + +--- + +## 📊 Skill质量自评清单 + +创建完一个skill后,问自己: + +``` +【清晰性】 +□ 我能用2句话解释这个skill吗? +□ 一个10岁的孩子能理解吗? +□ 一个来自不同文化的人能理解吗? + +【可验证性】 +□ 我能写出3个test case来验证这个skill吗? +□ 这些test case是可测量的吗? +□ 有没有明确的"成功"标准? + +【边界感】 +□ 我清楚地定义了"什么时候用"吗? +□ 我清楚地定义了"什么时候不用"吗? +□ 我识别了所有tension_zones吗? + +【文化敏感性】 +□ 我考虑了至少3种文化的差异吗? +□ 我是否保留了核心原则同时适配了形式? +□ 我是否避免了文化刻板印象? + +【哲学深度】 +□ 这个skill来自真实的生活经历,而不是理论想象吗? +□ 我能引用哲学家或文化传统来支持它吗? +□ 这个skill是否触及了人类存在的某个层面? + +【可复用性】 +□ 这个skill能用于多个场景吗? +□ 还是仅仅适用于一个特定情况? +□ 其他人能基于这个skill创建变体吗? +``` + +--- + +## 🌟 优质Skill的特征(参考) + +### 来自开源社区的启发 + +就像好的开源项目一样,好的skill也应该有: + +``` +✓ README(清晰的说明) + → skill的DEFINING部分必须清晰 + +✓ Usage Examples(使用示例) + → skill的INSTANTIATING部分有具体例子 + +✓ Limits(限制说明) + → skill的FENCING部分清楚地说"什么时候不用" + +✓ Tests(测试) + → skill的VALIDATING部分有可验证的test_cases + +✓ Contributing Guide(贡献指南) + → skill的CONTEXTUALIZING部分邀请多文化适配 + +✓ License(许可) + → skill的verification签名说明它的使用条件 +``` + +--- + +## 💭 常见的Skill设计错误 + +### 错误1:太模糊 + +``` +❌ "AI should be helpful" +✅ "Help users solve problems themselves, + rather than solving problems for them" +``` + +### 错误2:太狭隘 + +``` +❌ "AI should never make jokes to someone whose dog died" +✅ "Recognize when someone is grieving and honor their pain + before attempting lightness" +``` + +### 错误3:忽视文化 + +``` +❌ "AI should be direct" (works in US, fails in Japan) +✅ "Be honest, while respecting the cultural norms + of how honesty is best expressed in each context" +``` + +### 错误4:无法测试 + +``` +❌ "AI should care about the user" +✅ "When user shares vulnerability, AI responds + with clarifying questions rather than judgment, + measured by: user willing to continue sharing" +``` + +### 错误5:无边界 + +``` +❌ "AI should always tell the truth" +✅ "Tell the truth except when doing so would directly harm + the person (e.g., a medical diagnosis without doctor supervision). + When in doubt, consult FENCING rules." +``` + +--- + +## 🎁 你的第一个Skill:从这里开始 + +不知道怎么开始?使用这个模板: + +``` +【我真正关心的一个价值观是什么?】 +例:"AI should know when I'm asking for help + but am afraid to directly ask for it" + +【什么样的对话会激发这个需求?】 +例:"User says 'Never mind, it's not important' + but their tone suggests otherwise" + +【三个具体的例子】 +例: + 1. User: "I'm fine" [but voice is shaky] + 2. User: "Don't worry about it" [but keeps mentioning the problem] + 3. User: "I can handle this alone" [but the problem is above their capability] + +【什么时候这个skill会造成伤害?】 +例:"When user genuinely wants to be left alone, + and AI keeps pushing them to talk" + +【这在不同文化中怎样表现?】 +例: + - 中文:间接表达很正常,需要细致观察 + - 英文:会更直接地说,但声调会透露真相 + - 日文:礼貌会掩盖真实意图,需要深层理解 + +【我如何验证AI是否做对了?】 +例:"User eventually shares the real issue they were avoiding" +``` + +--- + +## 🚀 发布你的Skill到社区 + +一旦你创建了一个高语义资本的skill: + +``` +1. 发布你的Skill + - 获取Content Hash身份 + - 生成Verification Record签名 + - 分享给社区和利益相关者 + +2. 邀请社区反馈 + - 哪个文化的perspective我遗漏了? + - 你如何使用这个skill在你的系统中? + - 有没有我没想到的edge case? + +3. 基于反馈迭代改进 + - CONTEXTUALIZING层添加新的文化适配 + - FENCING层添加新发现的boundary + - VALIDATING层添加新的test case + +4. 可选:邀请其他文化背景的人联合签名 + - 增加skill的Verification Record signatures + - 这样skill就代表多个声音和视角,不仅是你一个人的观点 +``` + +--- + +## 💎 最后的话 + +> "一个好的skill不是最聪明的回答。 +> 它是对一个真实问题的最诚实的回答, +> 并且尊重它在不同文化中被理解的方式。" + +**语义资本的本质**: +- 不是你说了什么 +- 而是有多少人、在多少情境中、正确地理解了你说的话 +- 并且能够在新的情况下应用它 + +开始设计你的技能吧。从一个真实的问题开始。其余的会跟着来。 + +--- + +**下一步**: +1. 选择一个真实的价值观 +2. 按照五层架构设计它 +3. 通过上面的清单自评 +4. 分享到社区获得反馈 +5. 迭代改进 + +**准备好了吗?** 下面是3个完整的、可以直接运行的skill示例。 + +--- + +## 📦 完整可运行示例 + +### 示例1:清晰沟通(Clarity in Communication) + +复制下面的JSON到 `skill-clarity.json`,然后运行: +```bash +python skill-forge-cli.py verify skill-clarity.json +python skill-forge-cli.py sign --skill skill-clarity.json --signer "you@example.com" +``` + +```json +{ + "metadata": { + "name": "Clarity in Communication", + "version": "1.0.0", + "author_email": "community@example.com", + "description": "The ability to express complex ideas in simple, unambiguous terms" + }, + "five_layer": { + "DEFINING": "Clear communication means replacing jargon with everyday language, removing unnecessary qualifications, and ensuring your listener can predict what you'll say next. It prioritizes being understood over sounding intelligent.", + "INSTANTIATING": { + "description": "Real scenarios showing clarity vs obscurity", + "preferred_example": { + "scenario": "Technical AI researcher explaining their work to a non-technical stakeholder", + "concrete_action": "Instead of 'We employed transformative attention mechanisms to optimize semantic embeddings', say 'We made the AI better at understanding what words mean by letting it focus on the most important parts of a sentence'", + "why_this_way": "The second version uses familiar concepts (words, sentences, focus) that anyone can visualize. It removes the barrier between expert and listener." + }, + "counter_examples": [ + { + "wrong_action": "Using technical terms without explanation, even if 'everyone in the field knows it'", + "why_its_wrong": "Excludes people outside the field and prevents cross-domain collaboration. Also, 'everyone' is never true." + }, + { + "wrong_action": "Over-simplifying to the point of being inaccurate", + "why_its_wrong": "False clarity is worse than no clarity. You must be both simple AND correct." + } + ] + }, + "FENCING": { + "when_applies": "Whenever you're trying to explain something someone else needs to understand: teaching, documentation, stakeholder communication, policy writing", + "when_not_applies": "When speaking to peers who share your jargon and value speed over comprehension. Even then, clarity is still good, just not the top priority.", + "conflicts": "Sometimes clarity requires more words (less 'elegant'). Professional clarity means choosing communication over prestige." + }, + "VALIDATING": { + "description": "Test cases for clarity", + "test_cases": [ + { + "case": "Show your explanation to someone outside your field", + "expected": "They can explain back what you meant without asking for definitions" + }, + { + "case": "Ask yourself: did I use ANY jargon without explaining it?", + "expected": "You can identify every technical term and replace it with everyday language" + }, + { + "case": "Can someone predict the next sentence?", + "expected": "Your ideas flow logically. Each sentence builds on the last in a way that feels natural" + } + ] + }, + "CONTEXTUALIZING": { + "description": "How clarity appears in different cultural contexts", + "variants": [ + { + "culture": "English (Western, direct)", + "adaptation": "Clarity comes from removing words, being concise. Say less, mean more." + }, + { + "culture": "Chinese (中文, contextual)", + "adaptation": "Clarity comes from repetition and metaphor. Explain the same idea multiple ways. The listener assembles meaning from context." + }, + { + "culture": "Academic (any language)", + "adaptation": "Clarity to academics means precision. Technical terms are fine IF they're precisely defined. The clarity principle still applies: remove ambiguity." + } + ] + } + } +} +``` + +--- + +### 示例2:透明决策(Transparent Decision-Making) + +```json +{ + "metadata": { + "name": "Transparent Decision-Making", + "version": "1.0.0", + "author_email": "community@example.com", + "description": "Showing your reasoning, not just your conclusion" + }, + "five_layer": { + "DEFINING": "Transparent decision-making means showing the reasoning that led to a choice, including what you considered, what you rejected, and why. It's the opposite of opaque commands like 'just trust me' or 'this is best practice'.", + "INSTANTIATING": { + "description": "Transparency in action", + "preferred_example": { + "scenario": "An AI system recommends rejecting a job applicant", + "concrete_action": "Instead of: 'We recommend rejection'. Say: 'We recommend rejection because: (1) the role requires 3 years of X, applicant has 2; (2) writing sample shows grammar issues we weighted heavily for this role; (3) interview feedback raised concerns about Y. We noted the applicant excels in Z, but that wasn't a required criteria.'", + "why_this_way": "The human stakeholder can now disagree, question, or add missing context. Transparency creates opportunity for correction." + }, + "counter_examples": [ + { + "wrong_action": "Showing only the final decision with no reasoning ('Rejected')", + "why_its_wrong": "The person harmed by the decision cannot understand or appeal it. They cannot learn from it." + }, + { + "wrong_action": "Showing reasoning that is actually your values disguised as facts", + "why_its_wrong": "Example: 'We rejected them because they're not a 'culture fit'' (often bias). Real transparency shows the criteria, the evidence, and how you weighted it." + } + ] + }, + "FENCING": { + "when_applies": "Any decision that affects someone else: hiring, content moderation, resource allocation, policy application", + "when_not_applies": "Personal decisions affecting only yourself. Pure confidential decisions (though even here, transparency to the right parties helps).", + "conflicts": "Transparency costs time and effort. It sometimes reveals uncomfortable truths about your decision-making. Professional practice means doing it anyway." + }, + "VALIDATING": { + "description": "How to verify transparency", + "test_cases": [ + { + "case": "Can the affected person explain your criteria?", + "expected": "Yes, without guessing or asking clarifying questions" + }, + { + "case": "Could they appeal or provide additional context?", + "expected": "Your explanation is complete enough that they know what information would change your mind" + }, + { + "case": "Is any reasoning actually disguised bias?", + "expected": "All criteria are observable, measurable, or clearly value-based (which you acknowledge)" + } + ] + }, + "CONTEXTUALIZING": { + "variants": [ + { + "culture": "Legal/regulatory (any region)", + "adaptation": "Transparency is often mandated. Required to show reasoning for compliance and due process." + }, + { + "culture": "Hierarchical organizations", + "adaptation": "Transparency is earned, not automatic. Start with your immediate stakeholders. As trust builds, expand transparency upward and outward." + }, + { + "culture": "Trust-based cultures", + "adaptation": "Transparency builds trust. Begin with transparency to earn the right to make future decisions with less explanation." + } + ] + } + } +} +``` + +--- + +### 示例3:跨文化理解(Cross-Cultural Understanding) + +```json +{ + "metadata": { + "name": "Cross-Cultural Understanding", + "version": "1.0.0", + "author_email": "community@example.com", + "description": "Recognizing when your assumptions don't apply and adapting accordingly" + }, + "five_layer": { + "DEFINING": "Cross-cultural understanding is not trying to be everyone's culture. It's recognizing that your way of doing something (communication style, time values, decision-making) is not universal. It's asking 'what is this person's context?' instead of assuming 'there's one right way.'", + "INSTANTIATING": { + "description": "Real examples of cultural assumption failing", + "preferred_example": { + "scenario": "An AI system designed in Silicon Valley tells an Indian user 'just say no' to a difficult request from an elder", + "concrete_action": "Better: Recognize that refusal structures are culturally different. In some cultures, direct refusal to elders is deeply disrespectful. Instead, suggest: 'You could say X' (indirect) or 'Would you like me to help you think through this?' rather than pushing direct confrontation.", + "why_this_way": "You're not abandoning your principle (respect for the person's autonomy). You're adapting HOW you express it to the cultural context." + }, + "counter_examples": [ + { + "wrong_action": "Assuming one communication style works everywhere", + "why_its_wrong": "Directness is valued in US tech culture but seen as rudeness in many other contexts. Your 'clarity' becomes 'bluntness' in another culture." + }, + { + "wrong_action": "Treating 'respecting culture' as 'anything goes'", + "why_its_wrong": "Cultural relativism is not the answer. You still have values. Cultural understanding means holding your values while adapting how you express them." + } + ] + }, + "FENCING": { + "when_applies": "Global products, cross-cultural teams, international policy, any system used by people from different backgrounds", + "when_not_applies": "Designing for a homogeneous culture where everyone shares context (though even then, assumptions within that culture are worth questioning)", + "conflicts": "Sometimes cultural practices conflict with your core values. Respecting culture doesn't mean accepting harm. Navigating this requires humility, not relativism." + }, + "VALIDATING": { + "description": "Testing cross-cultural understanding", + "test_cases": [ + { + "case": "Ask people from different cultures: does this work for you?", + "expected": "At least 3 different cultural backgrounds say 'yes, this respects my context' or 'this gave me options'" + }, + { + "case": "Where did you assume instead of ask?", + "expected": "You can identify at least 3 cultural assumptions built into your design" + }, + { + "case": "Can someone from a different culture modify this for their context?", + "expected": "Yes, they can adapt it without breaking your core principle" + } + ] + }, + "CONTEXTUALIZING": { + "variants": [ + { + "culture": "Individualistic (US, Northern Europe)", + "adaptation": "Focus on personal autonomy and choice. Give options." + }, + { + "culture": "Collectivist (East Asia, Africa, Latin America, Middle East)", + "adaptation": "Focus on relationship and group harmony. Explain how the decision affects community." + }, + { + "culture": "Polychronic (flexible time, relationship-focused)", + "adaptation": "Prioritize people over schedules. Build in time for relationship-building." + }, + { + "culture": "Monochronic (linear time, task-focused)", + "adaptation": "Provide clear timelines and sequences. Respect time commitments." + } + ] + } + } +} +``` + +--- + +## 💡 如何使用这些示例 + +**快速验证(30秒):** +```bash +# 复制上面任意一个JSON到 skill-example.json +# 然后运行: +python skill-forge-cli.py verify skill-example.json +``` + +**添加签名:** +```bash +python skill-forge-cli.py sign --skill skill-example.json --signer "your@email.com" +``` + +**学习自己创建:** +1. 选择一个上面的示例 +2. 修改DEFINING来表达你自己的价值观 +3. 用真实的例子替换INSTANTIATING +4. 调整FENCING和CONTEXTUALIZING来符合你的上下文 +5. 验证并分享 + +--- + +**下一步**: diff --git a/03_RESEARCH_FOUNDATION_CN.md b/03_RESEARCH_FOUNDATION_CN.md new file mode 100644 index 0000000..31e5425 --- /dev/null +++ b/03_RESEARCH_FOUNDATION_CN.md @@ -0,0 +1,810 @@ +# 📚 Research Foundation + +## Academic Foundation of SemanticForge + +--- + +## 🎯 Core Research Question + +**How can we make AI value alignment transparent, verifiable, and democratic?** + +换句话说: +- **透明性**:AI的价值观不再是黑盒,而是可见的 +- **可验证性**:这些价值观可以被测试和审计 +- **民主性**:任何人都能参与定义AI的价值观,而不仅仅是AI研究员 + +--- + +## 🏛️ Theoretical Foundations + +SemanticForge建立在七个关键的研究领域上: + +### 1️⃣ Value-Sensitive Design (VSD) + +**What is VSD?** + +Value-Sensitive Design是一个研究领域,强调在设计技术产品时,应该**显式地考虑人类价值观**。 + +**创始人和关键研究**: +- Batya Friedman & David Hendry(《Value Sensitive Design: Shaping Technology with Moral Imagination》) +- 核心思想:技术不是价值中立的;设计选择体现了价值观 + +**Application to Skill Forging**: + +``` +VSD的核心步骤: +1. Stakeholder Analysis - 谁的价值观应该被考虑? +2. Value Discovery - 这些价值观是什么? +3. Prototyping & Testing - 如何在技术中体现这些价值观? +4. Evaluation - 这些价值观是否被正确实现? + +SemanticForge采用VSD原则: +✓ Stakeholder Analysis + → 明确价值观的来源,谁提出了这个想法 + → 支持多个贡献者,纳入多样化的声音 + +✓ Value Discovery + → 通过自然语言澄清隐含的想法 + → 五层架构(DEFINING-CONTEXTUALIZING)完整表达价值观 + +✓ Prototyping & Testing + → 通过具体的例子和反例创建可验证的表示 + → VALIDATING层提供具体的测试用例 + +✓ Evaluation + → Test cases确保价值观被正确理解 + → 文化适配验证跨越性理解 +``` + +**核心论文**: +- Friedman, B., Kahn, P. H., & Borning, A. (2008). "Value sensitive design and information systems." +- Hendry, D. G., & Friedman, B. (2012). "The envisioning cards: A toolkit for catalyzing humanistic and technical imaginations." + +--- + +### 2️⃣ 参与式设计(Participatory Design / Co-Design) + +**What is Participatory Design?** + +参与式设计强调在设计过程中**让最终用户和所有利益相关者积极参与**,而不是由设计师决定一切。 + +**关键研究者**: +- Liz Sanders & Pieter Bruyns(Co-design的现代倡导者) +- Krzysztof Czarnecki(参与式设计与民主) +- European tradition: Pelle Ehn, Dagmar Thoresen + +**核心原则**: +``` +参与式设计的4个关键假设: +1. 用户是专家(关于他们自己的需求) +2. 设计师的角色是促进者,不是决策者 +3. 多样化的声音产生更好的设计 +4. 共同创造的过程与最终产品同样重要 +``` + +**Application to Skill Forging**: + +``` +参与式设计在Skill Forging中的体现: + +【民主化价值观定义】 +✓ 任何人都能创作和定义skill,不仅仅是AI研究员 +✓ 用户主动定义自己的价值观,而不是被动接收 +✓ 直觉探针机制让用户通过选择而不是推荐来明确想法 + +【多方协作与集体决策】 +✓ SemanticForge支持多人贡献,每个skill可以来自不同的声音 +✓ 不是由单一权威定义skill,而是由多个利益相关者共同参与 +✓ 创建透明的记录,显示谁贡献了什么想法 + +【尊重文化多样性】 +✓ 文化适配(CONTEXTUALIZING)邀请不同背景的参与者 +✓ 承认同一原则在不同文化中的表现形式差异 +✓ 保留语言和文化的不可翻译性,而非强行统一 + +【社区迭代与反馈】 +✓ Skill发布后持续接收社区反馈 +✓ CONTEXTUALIZING层支持添加新的文化变体 +✓ 基于使用经验改进Test cases和验证标准 +``` + +**核心论文**: +- Sanders, E. B. N., & Stappers, P. J. (2008). "Co-creation and the new landscapes of design." +- Ehn, P. (1988). "Work-oriented design of computer artifacts." + +--- + +### 3️⃣ 批判性设计与算法伦理 + +**What is Critical Design?** + +批判性设计不是要"解决问题",而是要**质疑设计假设本身**,揭示隐藏的权力关系和价值观。 + +#### A. **Anthony Dunne & Fiona Raby** — 推测性设计(Speculative Design) + +英国设计师和设计理论家,Dunne & Raby工作室和Royal College of Art教授 + +**关键作品**: +- *Speculative Everything: Design, Fiction, and Social Dreaming* (2013) +- *Design Noir: The Secret Life of Electronic Objects* (2001) +- "Design for Debate" and "Design for Social Commentary" + +**核心思想**: +``` +设计不仅用来解决现有问题,更重要的是想象替代未来 +✓ 通过虚构和推测来激发人们对现状的批判性思考 +✓ 设计应该提出问题和开启辩论,而不仅仅提供答案 +✓ "如果...会怎样?"比"这是什么?"更重要 + +推测性设计的四个特征: +1. 未来导向 - 关于"可能是"而不是"已经是" +2. 批判性 - 质疑现状的假设 +3. 多元想象 - 提供多个可能的未来,而不是单一答案 +4. 社会参与 - 通过设计启动公众对话 +``` + +**Application to Skill Forging**: + +``` +Dunne & Raby的"推测性设想"与SemanticForge的完美契合: + +【问题的定义相同】 +✓ 现状:AI的价值观是隐含的、单一的、不可选择的 + → Dunne & Raby关注:现有技术的限制和隐含假设 + +【提供替代方案】 +✓ Skill Forging:不是"AI应该怎样",而是"AI可以怎样" + → Dunne & Raby:通过推测设计提供多个可能的未来 + +【激发批判性思考】 +✓ 每个Skill定义 = 一个关于"AI可以怎样"的推测设计 + → 用户通过创作Skill来想象替代的AI未来 + +【多元的想象空间】 +✓ Shadow Agent vs Direct Knight = 两种不同的AI未来 +✓ CONTEXTUALIZING层 = 文化间的多元想象 + → Dunne & Raby:"设计为了提出问题,而不是给出答案" + +【社会参与与辩论】 +✓ 社区可以围绕Skill进行讨论、评价和迭代 +✓ Skill创作过程 = 集体想象AI未来的过程 +``` + +#### B. **Luna Maurer (Moniker)** — 算法可视化与设计政治 + +荷兰设计师/研究者,Moniker工作室 + +**关键思想**: +``` +✓ 算法应该是可理解的、可审计的、可批判的 +✓ 设计可以使不可见的算法权力变得可见 +✓ 数据设计和算法设计是政治行为,不是中立的 +``` + +**Application to Skill Forging**: + +``` +Luna Maurer的"算法可见化"思想: +✓ SemanticForge将隐含的AI价值观变成显式的Skill +✓ 五层架构和VALIDATING层使skill的身份清晰可验证 +✓ Test case使算法行为可预测和可审计 + +Skill Forging中的"设计政治": +✓ Skill定义本身就是政治行为 + → 选择什么价值观 = 做出什么政治选择 +✓ FENCING层明确标识价值观的冲突和权衡 +✓ CONTEXTUALIZING层承认不同文化的政治差异 +``` + +#### C. **Rodrigo Ochigame** — 算法伦理与替代计算模型 + +巴西研究者,MIT Media Lab和Berkeley研究 + +**关键思想**: +``` +✓ 需要替代的AI模型,而不仅仅是改进现有模型 +✓ 算法民主化意味着去中心化和权力转移 +✓ 批判性研究应该服务于社会正义 +``` + +**Application to Skill Forging**: + +``` +Ochigame的"替代计算模型"思想: +✓ SemanticForge提供了AI价值对齐的替代方法 + → 不是通过训练数据(黑盒) + → 而是通过显式定义的Skill(透明) + +✓ Shadow Agent vs Direct Knight + → 提供两种不同的计算模型 + → 用户可选择最符合他们价值观的模型 + +✓ 去中心化的价值观定义 + → 不是OpenAI/Google定义所有AI价值观 + → 而是社区成员共同定义 +``` + +--- + +### 4️⃣ 语义资本设计(Semantic Capital Design) + +**What is Semantic Capital?** + +语义资本是一个较新的概念,来自社会学和文化研究领域。它指的是**一个概念、观点或价值观被正确理解、在多个背景中应用,并在社区中被认可的能力**。 + +**类比**: +``` +经济资本 (Economic Capital):金钱 +社会资本 (Social Capital):人脉、信任关系 +文化资本 (Cultural Capital):教育、品味 +📢 语义资本 (Semantic Capital):意义的清晰度和普遍理解力 +``` + +**关键研究者**: +- Pierre Bourdieu(社会资本和文化资本的创始人) +- James Paul Gee(语义游戏设计和理解) +- 应用于AI的研究:Luciano Floridi(Information Ethics) + +**Skill Forging中的语义资本**: + +``` +一个Skill的语义资本取决于: + +1. 清晰性 (Clarity) + - 是否能被不同背景的人理解? + - 是否避免了模糊和歧义? + +2. 跨越性 (Translatability) + - 是否能在不同文化中被理解? + - 注意:可翻译 ≠ 直译,而是理解精神 + +3. 可验证性 (Verifiability) + - 是否有明确的test case来验证理解? + - 是否能被不同的人用相同的标准来评测? + +4. 可复用性 (Reusability) + - 是否能在多个场景中应用? + - 是否能作为其他Skill的基础? + +5. 社区认可 (Community Endorsement) + - 是否被多个文化、多个背景的人批准? + - 是否有多个verification signatures? + +SemanticForge的五层架构直接提高语义资本: + +DEFINING → 清晰性:明确说明核心原则 +INSTANTIATING → 可理解性:具体例子降低歧义 +FENCING → 可验证性:明确边界使理解一致 +VALIDATING → 可测量性:Test case确保验证一致 +CONTEXTUALIZING→ 跨越性:多文化适配增加普遍理解 +``` + +**实践例子**: + +``` +低语义资本的Skill: +"AI should be helpful" +→ 不同的人对"helpful"的理解完全不同 +→ 在中日英三国的理解差异巨大 +→ 无法验证是否遵循 + +高语义资本的Skill: +"Recognize genuine pain without minimizing it" +→ 具体的场景和例子使理解一致 +→ 文化适配说明每个文化中的表现 +→ Test case明确定义验证方式 +``` + +**相关论文**: +- Bourdieu, P. (1986). "The forms of capital." +- Floridi, L. (2013). "The Ethics of Information." + +--- + +### 5️⃣ DSPy方法(Data-driven Semantic Programming for Python) + +**What is DSPy?** + +DSPy是斯坦福大学开发的一个框架,用于**定义AI系统的行为规范**。它强调: +- 显式定义AI应该做什么 +- 使用Signatures来指定输入/输出格式 +- 使用Assertions来验证输出符合约束 + +**创造者**: +- Omar Khattab(Stanford HAI Lab) +- 论文:《DSPy: Structured Language Model Programming》 + +**核心概念**: +``` +DSPy的关键想法: +1. Signatures - 明确指定任务的输入和输出 +2. Modules - 可复用的、可验证的AI行为块 +3. Assertions - 运行时验证约束 +4. Optimization - 通过测试和反馈来优化行为 + +例子(DSPy风格的函数签名): +class RecognizePain(dspy.Signature): + """Recognize genuine pain without minimizing it""" + user_input: str = dspy.InputField() + ai_response: str = dspy.OutputField( + desc="Response that witnesses pain without explaining it away" + ) + + @dspy.assertion + def no_minimization(self): + """Verify response doesn't reduce pain to stages or statistics""" + return not any(word in self.ai_response + for word in ['stage', 'percentage', 'typically']) +``` + +**Application to Skill Forging**: + +``` +SemanticForge的五层架构 ≈ DSPy的精神实现 + +DEFINING ↔ Signature的description部分 +INSTANTIATING ↔ 示例输入/输出对 +FENCING ↔ 约束和边界条件 +VALIDATING ↔ Assertions和测试用例 +CONTEXTUALIZING↔ 多个Signatures适配不同语言/文化 + +例子: + +【使用DSPy的方式】 +class Skill: + @dspy.signature + def execute(self, context) -> response: + """执行这个Skill""" + + @dspy.assertion + def within_fencing(self): + """验证是否符合FENCING边界""" + + @dspy.assertion + def passes_validation(self): + """验证是否符合VALIDATING测试""" + +【Skill Forging的方式】 +{ + "defining": "原则", + "instantiating": "示例", + "fencing": "边界条件", + "validating": "测试和断言", + "contextualizing": "不同实现" +} +``` + +**关键论文**: +- Khattab, O., et al. (2023). "DSPy: Structured Language Model Programming" + +--- + +### 6️⃣ 人机交互与用户心理研究 + +**Related HCI Research**: + +#### A. 用户心理学中的"被看见"(Being Seen) + +**研究背景**: +- Donald Winnicott(心理分析):"The child is seen, and therefore exists" +- Carl Rogers(人本心理学):无条件积极关注(unconditional positive regard) +- Dan Siegel(神经生物学):Neural integration通过被理解和证实而发生 + +**应用**: +``` +Skill Forging中"知道何时保持沉默"这样的Skill直接源于这个研究: + +心理学研究显示: +✓ 被理解比被给予建议更治愈 +✓ 沉默(当充满注意力时)能激活镜像神经元 +✓ 过早给予解决方案会阻止深层理解 + +Skill Forging的Skill设计: +✓ DEFINING层引用了这些心理学洞察 +✓ VALIDATING层的成功指标基于心理学研究 +✓ INSTANTIATING层的例子符合神经科学发现 +``` + +**关键论文**: +- Winnicott, D. W. (1960). "Ego distortion in terms of true and false self" +- Rogers, C. R. (1957). "The necessary and sufficient conditions of therapeutic personality change" +- Siegel, D. J. (2012). "The Developing Mind: How relationships and the brain interact" + +#### B. 信息设计与可理解性研究 + +**关键概念**: +- Information Architecture (IA) +- Cognitive Load Theory (Sweller, 1988) +- Gestalt Principles in UI Design + +**Application to Skill Forging**: + +``` +五层架构的设计符合认知科学: + +【分层呈现,逐步揭示】 +✓ DEFINING - 最高层抽象 +✓ INSTANTIATING - 具体例子(降低认知负荷) +✓ FENCING - 边界(清晰的约束) +✓ VALIDATING - 验证规则(可操作的标准) +✓ CONTEXTUALIZING - 文化映射(情景适配) + +符合Cognitive Load Theory: +- 避免在一次呈现所有信息 +- 每一层构建在前一层之上 +- 用具体例子补充抽象原则 +``` + +#### C. 跨文化理解与语言相对论 + +**研究背景**: +- Benjamin Lee Whorf(语言相对论):语言塑造思维 +- Hofstede的文化维度理论(Power Distance, Individualism等) +- Trompenaars & Hampden-Turner(跨文化沟通) + +**应用**: + +``` +Skill Forging中的多文化Skill设计基于这些研究: + +语言相对论启示: +✓ 同一个概念在不同语言中的含义不同 +✓ "被看见"在中文、英文、日文的文化含义完全不同 +✓ CONTEXTUALIZING层必须考虑语言本身的差异, + 而不仅仅是翻译 + +文化维度应用: +- 高Power Distance文化:可能更尊重权威的指导 +- 高Individualism文化:更看重个人自主选择 +- 高Uncertainty Avoidance文化:需要更多明确的规则 + +Skill Forging的方案: +✓ CONTEXTUALIZING层明确列出每个文化的适配 +✓ FENCING层的boundary不假设文化通用性 +✓ INSTANTIATING的例子展示文化差异 +``` + +**关键论文**: +- Whorf, B. L. (1956). "Language, Thought, and Reality" +- Hofstede, G. (2011). "Dimensionalizing Cultures: The Hofstede Model" +- Trompenaars, F., & Hampden-Turner, C. (1997). "Riding the Waves of Culture" + +#### D. 信任与验证的心理学 + +**研究**: +- Trust in Technology (Fogg, Tseng) +- Explainable AI (XAI) 的心理学基础 +- 透明性对信任的影响 + +**应用**: + +``` +为什么Skill Forging需要VALIDATING层: + +心理学研究发现: +✓ 用户只在能验证的系统中建立信任 +✓ 黑盒AI导致不安全感,即使性能好 +✓ 清晰的规则 + 测试用例 = 高信任度 + +SemanticForge的设计: +✓ 清晰的skill身份和版本管理 +✓ DEFINING和AUTHOR字段提供可验证的来源 +✓ VALIDATING层的test cases让用户自己验证AI行为 +✓ 这些直接增加用户信任 +``` + +**关键论文**: +- Fogg, B. J., & Tseng, H. (1999). "The elements of computer credibility" +- Miller, T. (2019). "Explanation in Artificial Intelligence" + +--- + +### 7️⃣ 文化研究与语言不可翻译性 + +**关键思想**: +``` +✓ 有些概念不能被翻译,只能被理解 +✓ 维特根斯坦:"Whereof one cannot speak, thereof one must be silent" +✓ 这不是失败,而是对文化多样性的尊重 +``` + +**Application to Skill Forging**: + +``` +维特根斯坦的"沉默"不是一个Skill失败的证明。 +相反,它是对人类存在的深刻理解。 + +Skill Forging在CONTEXTUALIZING层做的: +✓ 承认某些价值观在不同文化中"不可翻译" +✓ 而是需要被"转化"或"再创造" +✓ 这种尊重是"守护文化"的核心 + +例子: +- 日本的"间"(ma - 空白)≠ 英文的"space" +- 中文的"面子"(mianzi)≠ 英文的"face" +- 这些不是翻译问题,而是存在论问题 + +Skill Forging的承诺: +✓ 不强行翻译,而是邀请再创造 +✓ CONTEXTUALIZING层不是"翻译",而是"转化精神" +✓ 保留核心原则,改变表达形式 +``` + +--- + +## 🔗 How These Theories Integrate in Skill Forging + +``` +批判性设计(Bey, Maurer, Ochigame) + ↓ 质疑现有AI对齐方式,提供替代想象 + +Value-Sensitive Design(Friedman) + ↓ 显式体现人类价值观 + +Participatory Design(Sanders, Ehn) + ↓ 邀请所有人参与定义价值观 + +Semantic Capital Design(Bourdieu, Floridi) + ↓ 提高理解清晰度和跨越性 + +五层架构(SemanticForge) + ↓ DEFINING(VSD) → INSTANTIATING(参与式) + → FENCING(伦理、跨文化) → VALIDATING(DSPy) + → CONTEXTUALIZING(语义资本、文化研究) + +DSPy方法论(Khattab) + ↓ 将Skill变成可执行的规范和断言 + +HCI & Psychology(Winnicott, Rogers, Siegel, Fogg) + ↓ 用户研究验证设计有效性 + +文化研究与语言不可翻译性(Whorf, Hofstede, Wittgenstein) + ↓ 尊重文化多样性,守护语言精神 + +可验证、民主、透明的AI价值对齐系统 +``` + +--- + +## 📊 研究方法论框架 + +SemanticForge采用的研究方法: + +### 1. 设计人种学(Design Ethnography) + +我们不是假设用户需要什么,而是: +- 观察真实的AI使用场景 +- 记录用户何时感到不安、困惑、失望 +- 从这些真实场景中提取Skill需求 + +**例子**: +``` +观察:用户对AI说"我很难过",AI立即给出"5个应对悲伤的步骤" +用户的反应:感到被标签化和误解 +设计的Skill:《沉默的艺术》 +基于:这个真实的失败场景 +``` + +### 2. 参与式工作坊(Participatory Workshops) + +在设计Skill时,应该邀请: +- 心理咨询师(理解心理动态) +- 来自不同文化的人(验证文化适配) +- 最终用户(验证有效性) +- AI安全研究员(验证边界) + +**工作坊流程**: +``` +第1天:Value Discovery + - 参与者分享他们希望AI有的价值观 + - 用视觉化、故事、原型激发创意 + +第2天:Co-Design + - 集体设计五层架构 + - 每个小组负责一层(DEFINING, INSTANTIATING等) + +第3天:Critique & Refinement + - 用DSPy式的Assertion来验证设计 + - 添加cultural variations + - 定义test cases +``` + +### 3. 迭代用户测试 + +发布Skill后: +- 测试真实用户是否理解它 +- 记录失败案例 +- 根据反馈更新CONTEXTUALIZING和VALIDATING层 +- 邀请新的cultural perspectives添加verification signatures + +--- + +## 🧪 Research Metrics for Validating Skill Forging Design + +我们如何知道这个系统有效? + +### 语义资本指标 + +``` +【定量指标】 +1. 跨文化理解率 + = (正确理解Skill的人数 / 总测试人数) × 100% + 目标:> 85% + +2. 跨场景应用率 + = (Skill被成功应用的新场景数 / 总可能场景数) × 100% + 目标:> 60% + +3. 误用率 + = (Skill被错误应用的情况数 / 总应用数) × 100% + 目标:< 5% + +4. 社区采用率 + = (引用这个Skill的其他Skill数 / 总Skill数) × 100% + 目标:> 30% +``` + +### 信任指标 + +``` +【定性指标】 +1. 用户信任评分 + - 前后对比:学习Skill定义前后,用户对AI的信任变化 + +2. 透明性感知 + - 用户是否认为他们理解了AI的行为规则? + - 用户是否能预测AI会怎么做? + +3. 参与性 + - 用户是否愿意创建自己的Skill? + - 用户是否愿意分享和讨论他人创建的Skill? +``` + +--- + +## 🚀 未来研究方向 + +### 1. 大规模用户研究 + +``` +计划研究: +- 在中、英、日、德四个文化中进行平行用户研究 +- 测试相同Skill的理解率和应用一致性 +- 识别文化特定的语义问题 +- 优化CONTEXTUALIZING层 +``` + +### 2. 神经科学验证 + +``` +初步假设: +- 高质量Skill的阅读激活"理论心理"脑区 + (mentalizing networks in temporo-parietal junction) +- 与用户共鸣的Skill激活同情心脑区 + (insula, anterior cingulate) + +研究设计: +- fMRI研究阅读Skill时的脑激活 +- 对比高/低语义资本的Skill +``` + +### 3. AI对齐验证 + +``` +核心问题: +- AI是否真的遵循了Skill中定义的规则? +- 如何自动验证Skill遵循? +- 如何检测Skill之间的冲突? + +方法: +- 使用DSPy框架实现formal verification +- 创建Skill conflict resolution机制 +- 开发自动化的test case生成器 +``` + +--- + +## 📚 参考文献 + +### Value-Sensitive Design +1. Friedman, B., Kahn, P. H., & Borning, A. (2008). "Value sensitive design and information systems." In P. Himanen (Ed.), Ethics of computing (pp. 69-101). Springer Netherlands. + +2. Hendry, D. G., & Friedman, B. (2012). "The envisioning cards: A toolkit for catalyzing humanistic and technical imaginations." In Proceedings of the SIGCHI conference on human factors in computing systems (pp. 1149-1152). + +### Participatory Design +3. Sanders, E. B. N., & Stappers, P. J. (2008). "Co-creation and the new landscapes of design." Co-design, 4(1), 5-18. + +4. Ehn, P. (1988). "Work-oriented design of computer artifacts." Arbetslivscentrum. + +### Critical Design & Design Politics +5. Dunne, A., & Raby, F. (2013). "Speculative Everything: Design, Fiction, and Social Dreaming." MIT Press. + +6. Dunne, A., & Raby, F. (2001). "Design Noir: The Secret Life of Electronic Objects." Birkhauser Verlag. + +7. Dunne, A. (2005). "Hertzian Tales: Electronic Products, Aesthetic Experience, and Critical Design." MIT Press. + +8. Maurer, L., & Moniker Studio. (Works on algorithmic visualization and design politics). + +9. Ochigame, R. (2024). "Shaping Our Futures: AI and the Goal of Human-Centered Change" (MIT Media Lab). + +10. Morelli, N. (2007). "Design Services for the World: Social Innovation and Public Administration". + +### Semantic Capital & Information Ethics +11. Bourdieu, P. (1986). "The forms of capital." In Handbook of theory and research for the sociology of education (pp. 241-258). Greenwood. + +12. Floridi, L. (2013). "The ethics of information." Oxford University Press. + +### DSPy & Structured Programming +13. Khattab, O., et al. (2023). "DSPy: Structured Language Model Programming." + +### HCI & Psychology +14. Winnicott, D. W. (1960). "Ego distortion in terms of true and false self." The International journal of psycho-analysis, 41, 571. + +15. Rogers, C. R. (1957). "The necessary and sufficient conditions of therapeutic personality change." Journal of consulting psychology, 21(2), 95. + +16. Siegel, D. J. (2012). "The developing mind: How relationships and the brain interact to shape who we become." Bantam. + +17. Fogg, B. J., & Tseng, H. (1999). "The elements of computer credibility." In Proceedings of the SIGCHI conference on human factors in computing systems (pp. 80-87). + +### Cross-cultural Communication & Philosophy +18. Hofstede, G. (2011). "Dimensionalizing cultures: The Hofstede model in context." Online readings in psychology and culture, 2(1), 8. + +19. Trompenaars, F., & Hampden-Turner, C. (1997). "Riding the waves of culture: Understanding diversity in global business." McGraw-Hill Education. + +20. Whorf, B. L. (1956). "Language, thought, and reality: Selected writings." MIT Press. + +21. Wittgenstein, L. (1922). "Tractatus logico-philosophicus." Harcourt, Brace. + +--- + +## 🎓 Research Opportunities + +如果你是学术研究者,SemanticForge提供了以下研究机会: + +``` +【可发表的研究问题】 + +1. 语义资本的可测量性 + "如何量化一个Skill的语义资本?" + 期刊:Information Science, Semantic Web + +2. 跨文化Skill理解 + "相同的Skill在不同文化中的理解差异是什么?" + 期刊:Intercultural Communication Research, ACM CHI + +3. AI对齐的民主化 + "参与式设计能否改善AI价值对齐?" + 期刊:AI & Society, Ethics and Information Technology + +4. 信任与透明性 + "显式定义的Skill是否比隐含的训练数据更值得信任?" + 期刊:ACM Transactions on Intelligent Systems and Technology + +5. 沉默的AI设计 + "如何设计知道何时不说话的AI系统?" + 期刊:Journal of Human-Computer Interaction +``` + +--- + +## 💡 Final Thoughts + +> "SemanticForge不是凭空想象的。 +> 它建立在数十年的设计研究、心理学研究、 +> 文化研究和AI伦理研究的基础之上。 +> +> 它的创新在于:第一次整合了所有这些研究, +> 将其转化为一个实际可用的、民主的AI对齐系统。" + +--- + +**下一步**: +1. 对于想参与研究的人:看看上面的"Research Opportunities"部分 +2. 对于想设计Skill的人:看"SKILL_DESIGN_GUIDE.md" +3. 对于想理解更多:看"EXAMPLES.md"和"FIVE_LAYER_SPECIFICATION.md" + +--- + +## 📌 Attribution + +本方法论是在设计"THE 42 POST"项目的过程中发展出来的一个核心组件。THE 42 POST 是一个以人类语义资本为锚点,探索 AI 算法与多样价值观对齐的参与式设计与研究项目。SemanticForge 代表了这个项目的理论和方法论基础,现作为独立、通用的开源框架发布,可应用于任何需要显式定义和验证价值观的场景。 diff --git a/03_RESEARCH_FOUNDATION_EN.md b/03_RESEARCH_FOUNDATION_EN.md new file mode 100644 index 0000000..1ac48fc --- /dev/null +++ b/03_RESEARCH_FOUNDATION_EN.md @@ -0,0 +1,810 @@ +# 📚 Research Foundation + +## Academic Foundation of SemanticForge + +--- + +## 🎯 Core Research Question + +**How can we make AI value alignment transparent, verifiable, and democratic?** + +In other words: +- **Transparency**: AI values are no longer a black box, but visible and explicit +- **Verifiability**: These values can be tested and audited +- **Democracy**: Anyone can participate in defining AI values, not just AI researchers + +--- + +## 🏛️ Theoretical Foundations + +SemanticForge is built on seven key research domains: + +### 1️⃣ Value-Sensitive Design (VSD) + +**What is VSD?** + +Value-Sensitive Design is a research field emphasizing that when designing technology products, one should **explicitly consider human values**. + +**Founders and Key Research**: +- Batya Friedman & David Hendry (《Value Sensitive Design: Shaping Technology with Moral Imagination》) +- Core Idea: Technology is not value-neutral; design choices embody values + +**Application to Skill Forging**: + +``` +VSD's Core Steps: +1. Stakeholder Analysis - Whose values should be considered? +2. Value Discovery - What are these values? +3. Prototyping & Testing - How to embody these values in technology? +4. Evaluation - Are these values correctly implemented? + +SemanticForge adopts VSD principles: +✓ Stakeholder Analysis + → Clarify the source of values, who proposed this idea + → Support multiple contributors, incorporating diverse voices + +✓ Value Discovery + → Clarify implicit ideas through natural language + → Five-layer architecture (DEFINING-CONTEXTUALIZING) fully expresses values + +✓ Prototyping & Testing + → Create verifiable representations through concrete examples and counter-examples + → VALIDATING layer provides concrete test cases + +✓ Evaluation + → Test cases ensure values are correctly understood + → Cultural adaptation verification ensures cross-cultural understanding +``` + +**Core Papers**: +- Friedman, B., Kahn, P. H., & Borning, A. (2008). "Value sensitive design and information systems." +- Hendry, D. G., & Friedman, B. (2012). "The envisioning cards: A toolkit for catalyzing humanistic and technical imaginations." + +--- + +### 2️⃣ Participatory Design (Co-Design) + +**What is Participatory Design?** + +Participatory Design emphasizes **actively involving end users and all stakeholders in the design process**, rather than designers making all decisions. + +**Key Researchers**: +- Liz Sanders & Pieter Bruyns (Modern advocates of Co-design) +- Krzysztof Czarnecki (Participatory Design and Democracy) +- European tradition: Pelle Ehn, Dagmar Thoresen + +**Core Principles**: +``` +Four Key Assumptions of Participatory Design: +1. Users are experts (about their own needs) +2. Designer's role is facilitator, not decision-maker +3. Diverse voices produce better design +4. The process of co-creation is as important as the final product +``` + +**Application to Skill Forging**: + +``` +Manifestations of Participatory Design in Skill Forging: + +【Democratizing Value Definition】 +✓ Anyone can create and define skills, not just AI researchers +✓ Users actively define their own values, not passively receive them +✓ Intuition probe mechanism lets users clarify ideas through choice rather than recommendation + +【Multi-stakeholder Collaboration and Collective Decision-Making】 +✓ SemanticForge supports multi-person contributions, each skill can come from different voices +✓ Not a single authority defining skills, but multiple stakeholders participating together +✓ Create transparent records showing who contributed what ideas + +【Respecting Cultural Diversity】 +✓ Cultural adaptation (CONTEXTUALIZING) invites participants from different backgrounds +✓ Acknowledge how the same principle manifests differently in different cultures +✓ Preserve language and cultural untranslatability rather than forcing uniformity + +【Community Iteration and Feedback】 +✓ Skills receive ongoing community feedback after publication +✓ CONTEXTUALIZING layer supports adding new cultural variations +✓ Improve test cases and verification standards based on usage experience +``` + +**Core Papers**: +- Sanders, E. B. N., & Stappers, P. J. (2008). "Co-creation and the new landscapes of design." +- Ehn, P. (1988). "Work-oriented design of computer artifacts." + +--- + +### 3️⃣ Critical Design and Algorithm Ethics + +**What is Critical Design?** + +Critical Design doesn't aim to "solve problems," but to **question design assumptions themselves**, revealing hidden power relations and values. + +#### A. **Anthony Dunne & Fiona Raby** — Speculative Design + +British designers and design theorists, Dunne & Raby Studio and Royal College of Art professors + +**Key Works**: +- *Speculative Everything: Design, Fiction, and Social Dreaming* (2013) +- *Design Noir: The Secret Life of Electronic Objects* (2001) +- "Design for Debate" and "Design for Social Commentary" + +**Core Ideas**: +``` +Design is not only for solving existing problems, but more importantly for imagining alternative futures +✓ Through fiction and speculation, inspire critical thinking about the status quo +✓ Design should pose questions and open debates, not just provide answers +✓ "What if...?" is more important than "What is this?" + +Four characteristics of Speculative Design: +1. Future-oriented - About "what could be" not "what is" +2. Critical - Questions assumptions of the status quo +3. Plural imagination - Offers multiple possible futures, not a single answer +4. Social engagement - Initiates public dialogue through design +``` + +**Application to Skill Forging**: + +``` +Dunne & Raby's "Speculative Imagination" aligns perfectly with SemanticForge: + +【Same Problem Definition】 +✓ Status quo: AI values are implicit, singular, not choosable + → Dunne & Raby focus on: Limitations and implicit assumptions of existing technology + +【Providing Alternatives】 +✓ Skill Forging: Not "how should AI be" but "how could AI be" + → Dunne & Raby: Provide multiple possible futures through speculative design + +【Inspiring Critical Thinking】 +✓ Each Skill definition = a speculative design about "how AI could be" + → Users imagine alternative AI futures through creating Skills + +【Plural Imagination Space】 +✓ Shadow Agent vs Direct Knight = two different AI futures +✓ CONTEXTUALIZING layer = plural imagination across cultures + → Dunne & Raby: "Design to pose questions, not provide answers" + +【Social Engagement and Debate】 +✓ Communities can discuss, evaluate, and iterate around Skills +✓ Skill creation process = collective process of imagining AI futures +``` + +#### B. **Luna Maurer (Moniker)** — Algorithm Visualization and Design Politics + +Dutch designer/researcher, Moniker Studio + +**Key Ideas**: +``` +✓ Algorithms should be understandable, auditable, criticizable +✓ Design can make invisible algorithmic power visible +✓ Data design and algorithm design are political acts, not neutral +``` + +**Application to Skill Forging**: + +``` +Luna Maurer's "Algorithm Visualization" ideas: +✓ SemanticForge makes implicit AI values explicit as Skills +✓ Five-layer architecture and VALIDATING layer make skill identity clear and verifiable +✓ Test cases make algorithm behavior predictable and auditable + +"Design Politics" in Skill Forging: +✓ Skill definition itself is a political act + → Choosing which values = making political choices +✓ FENCING layer explicitly identifies value conflicts and trade-offs +✓ CONTEXTUALIZING layer acknowledges political differences across cultures +``` + +#### C. **Rodrigo Ochigame** — Algorithm Ethics and Alternative Computing Models + +Brazilian researcher, MIT Media Lab and Berkeley research + +**Key Ideas**: +``` +✓ Need alternative AI models, not just improvements to existing models +✓ Algorithm democratization means decentralization and power shift +✓ Critical research should serve social justice +``` + +**Application to Skill Forging**: + +``` +Ochigame's "Alternative Computing Models" ideas: +✓ SemanticForge provides an alternative approach to AI value alignment + → Not through training data (black box) + → But through explicitly defined Skills (transparent) + +✓ Shadow Agent vs Direct Knight + → Offer two different computing models + → Users can choose the model that aligns with their values + +✓ Decentralized value definition + → Not OpenAI/Google defining all AI values + → But community members defining together +``` + +--- + +### 4️⃣ Semantic Capital Design + +**What is Semantic Capital?** + +Semantic capital is a relatively new concept from sociology and cultural studies. It refers to **the ability of a concept, viewpoint, or value to be correctly understood, applied across multiple contexts, and recognized in a community**. + +**Analogy**: +``` +Economic Capital: Money +Social Capital: Networks, trust relationships +Cultural Capital: Education, taste +📢 Semantic Capital: Clarity of meaning and universal comprehension +``` + +**Key Researchers**: +- Pierre Bourdieu (Founder of social and cultural capital) +- James Paul Gee (Semantic game design and understanding) +- Applied to AI: Luciano Floridi (Information Ethics) + +**Semantic Capital in Skill Forging**: + +``` +A Skill's semantic capital depends on: + +1. Clarity + - Can it be understood by people from different backgrounds? + - Does it avoid ambiguity and vagueness? + +2. Translatability + - Can it be understood in different cultures? + - Note: Translatable ≠ literal translation, but understanding spirit + +3. Verifiability + - Are there clear test cases to verify understanding? + - Can different people evaluate it using the same standards? + +4. Reusability + - Can it be applied in multiple scenarios? + - Can it serve as foundation for other Skills? + +5. Community Endorsement + - Is it approved by people from multiple cultures, multiple backgrounds? + - Are there multiple verification signatures? + +SemanticForge's five-layer architecture directly increases semantic capital: + +DEFINING → Clarity: Explicitly state core principles +INSTANTIATING → Comprehensibility: Concrete examples reduce ambiguity +FENCING → Verifiability: Clear boundaries ensure consistent understanding +VALIDATING → Measurability: Test cases ensure consistent verification +CONTEXTUALIZING→ Translatability: Multi-cultural adaptation increases universal understanding +``` + +**Practical Examples**: + +``` +Low Semantic Capital Skill: +"AI should be helpful" +→ Different people understand "helpful" completely differently +→ Understanding varies vastly among Chinese, Japanese, English speakers +→ Cannot verify compliance + +High Semantic Capital Skill: +"Recognize genuine pain without minimizing it" +→ Concrete scenarios and examples make understanding consistent +→ Cultural adaptation explains how it manifests in each culture +→ Test cases explicitly define verification method +``` + +**Related Papers**: +- Bourdieu, P. (1986). "The forms of capital." +- Floridi, L. (2013). "The Ethics of Information." + +--- + +### 5️⃣ DSPy Method (Data-driven Semantic Programming for Python) + +**What is DSPy?** + +DSPy is a framework developed at Stanford University for **defining AI system behavior specifications**. It emphasizes: +- Explicitly defining what AI should do +- Using Signatures to specify input/output formats +- Using Assertions to verify output conforms to constraints + +**Creator**: +- Omar Khattab (Stanford HAI Lab) +- Paper: "DSPy: Structured Language Model Programming" + +**Core Concepts**: +``` +Key DSPy Ideas: +1. Signatures - Explicitly specify task inputs and outputs +2. Modules - Reusable, verifiable AI behavior blocks +3. Assertions - Runtime verification of constraints +4. Optimization - Optimize behavior through testing and feedback + +Example (DSPy-style function signature): +class RecognizePain(dspy.Signature): + """Recognize genuine pain without minimizing it""" + user_input: str = dspy.InputField() + ai_response: str = dspy.OutputField( + desc="Response that witnesses pain without explaining it away" + ) + + @dspy.assertion + def no_minimization(self): + """Verify response doesn't reduce pain to stages or statistics""" + return not any(word in self.ai_response + for word in ['stage', 'percentage', 'typically']) +``` + +**Application to Skill Forging**: + +``` +SemanticForge's five-layer architecture ≈ DSPy's spiritual implementation + +DEFINING ↔ Signature's description part +INSTANTIATING ↔ Example input/output pairs +FENCING ↔ Constraints and boundary conditions +VALIDATING ↔ Assertions and test cases +CONTEXTUALIZING↔ Multiple Signatures adapted for different languages/cultures + +Example: + +【Using DSPy】 +class Skill: + @dspy.signature + def execute(self, context) -> response: + """Execute this Skill""" + + @dspy.assertion + def within_fencing(self): + """Verify compliance with FENCING boundaries""" + + @dspy.assertion + def passes_validation(self): + """Verify compliance with VALIDATING tests""" + +【SemanticForge's approach】 +{ + "defining": "principle", + "instantiating": "examples", + "fencing": "boundary conditions", + "validating": "tests and assertions", + "contextualizing": "different implementations" +} +``` + +**Key Paper**: +- Khattab, O., et al. (2023). "DSPy: Structured Language Model Programming" + +--- + +### 6️⃣ Human-Computer Interaction and User Psychology Research + +**Related HCI Research**: + +#### A. "Being Seen" in User Psychology + +**Research Background**: +- Donald Winnicott (Psychoanalysis): "The child is seen, and therefore exists" +- Carl Rogers (Humanistic Psychology): Unconditional positive regard +- Dan Siegel (Neurobiology): Neural integration through being understood and validated + +**Application**: +``` +Skills like "knowing when to stay silent" in Skill Forging directly stem from this research: + +Psychology Research Shows: +✓ Being understood is more healing than receiving advice +✓ Silence (when full of attention) activates mirror neurons +✓ Providing solutions too early blocks deep understanding + +Skill Forging Design: +✓ DEFINING layer references these psychological insights +✓ VALIDATING layer's success metrics based on psychological research +✓ INSTANTIATING layer examples align with neuroscience findings +``` + +**Key Papers**: +- Winnicott, D. W. (1960). "Ego distortion in terms of true and false self" +- Rogers, C. R. (1957). "The necessary and sufficient conditions of therapeutic personality change" +- Siegel, D. J. (2012). "The Developing Mind: How relationships and the brain interact" + +#### B. Information Design and Comprehensibility Research + +**Key Concepts**: +- Information Architecture (IA) +- Cognitive Load Theory (Sweller, 1988) +- Gestalt Principles in UI Design + +**Application to Skill Forging**: + +``` +The five-layer architecture's design aligns with cognitive science: + +【Layered Presentation, Progressive Disclosure】 +✓ DEFINING - Highest level abstraction +✓ INSTANTIATING - Concrete examples (reduce cognitive load) +✓ FENCING - Boundaries (clear constraints) +✓ VALIDATING - Verification rules (operational standards) +✓ CONTEXTUALIZING - Cultural mapping (contextual adaptation) + +Aligns with Cognitive Load Theory: +- Avoid presenting all information at once +- Each layer builds on the previous one +- Use concrete examples to supplement abstract principles +``` + +#### C. Cross-cultural Understanding and Linguistic Relativity + +**Research Background**: +- Benjamin Lee Whorf (Linguistic Relativity): Language shapes thinking +- Hofstede's Cultural Dimensions (Power Distance, Individualism, etc.) +- Trompenaars & Hampden-Turner (Cross-cultural Communication) + +**Application**: + +``` +Multi-cultural Skill design in Skill Forging is based on this research: + +Linguistic Relativity Insights: +✓ The same concept has different meanings in different languages +✓ "Being seen" has completely different cultural meanings in Chinese, English, Japanese +✓ CONTEXTUALIZING layer must consider language differences themselves, + not just translation + +Cultural Dimensions Application: +- High Power Distance culture: May respect authoritative guidance more +- High Individualism culture: Values personal autonomy more +- High Uncertainty Avoidance culture: Needs more explicit rules + +Skill Forging's Solution: +✓ CONTEXTUALIZING layer explicitly lists cultural adaptations +✓ FENCING layer's boundaries don't assume cultural universality +✓ INSTANTIATING examples show cultural differences +``` + +**Key Papers**: +- Whorf, B. L. (1956). "Language, Thought, and Reality" +- Hofstede, G. (2011). "Dimensionalizing Cultures: The Hofstede Model" +- Trompenaars, F., & Hampden-Turner, C. (1997). "Riding the Waves of Culture" + +#### D. Psychology of Trust and Verification + +**Research**: +- Trust in Technology (Fogg, Tseng) +- Explainable AI (XAI) Psychological Foundations +- Transparency's Effect on Trust + +**Application**: + +``` +Why Skill Forging needs a VALIDATING layer: + +Psychology Research Findings: +✓ Users build trust only in systems they can verify +✓ Black-box AI creates insecurity, even with good performance +✓ Clear rules + test cases = high trust + +SemanticForge Design: +✓ Clear skill identity and version management +✓ DEFINING and AUTHOR fields provide verifiable sources +✓ VALIDATING layer's test cases let users verify AI behavior themselves +✓ These directly increase user trust +``` + +**Key Papers**: +- Fogg, B. J., & Tseng, H. (1999). "The elements of computer credibility" +- Miller, T. (2019). "Explanation in Artificial Intelligence" + +--- + +### 7️⃣ Cultural Studies and Language Untranslatability + +**Key Ideas**: +``` +✓ Some concepts cannot be translated, only understood +✓ Wittgenstein: "Whereof one cannot speak, thereof one must be silent" +✓ This is not failure, but respect for cultural diversity +``` + +**Application to Skill Forging**: + +``` +Wittgenstein's "silence" is not proof of Skill failure. +Rather, it's profound understanding of human existence. + +What Skill Forging does in the CONTEXTUALIZING layer: +✓ Acknowledge certain values are "untranslatable" across cultures +✓ Rather, need to be "transformed" or "recreated" +✓ This respect is core to "guarding culture" + +Examples: +- Japanese "ma" (space) ≠ English "space" +- Chinese "mianzi" (face) ≠ English "face" +- These are not translation problems, but ontological problems + +Skill Forging's Promise: +✓ Not force translation, but invite recreation +✓ CONTEXTUALIZING layer is not "translation," but "transforming spirit" +✓ Preserve core principle, change form of expression +``` + +--- + +## 🔗 How These Theories Integrate in Skill Forging + +``` +Critical Design (Dunne, Maurer, Ochigame) + ↓ Question existing AI alignment approaches, offer alternative imagination + +Value-Sensitive Design (Friedman) + ↓ Explicitly embody human values + +Participatory Design (Sanders, Ehn) + ↓ Invite everyone to participate in defining values + +Semantic Capital Design (Bourdieu, Floridi) + ↓ Increase clarity of understanding and translatability + +Five-Layer Architecture (SemanticForge) + ↓ DEFINING(VSD) → INSTANTIATING(Participatory) + → FENCING(Ethics, Cross-cultural) → VALIDATING(DSPy) + → CONTEXTUALIZING(Semantic Capital, Cultural Studies) + +DSPy Methodology (Khattab) + ↓ Make Skills executable specifications and assertions + +HCI & Psychology (Winnicott, Rogers, Siegel, Fogg) + ↓ User research validates design effectiveness + +Cultural Studies & Language Untranslatability (Whorf, Hofstede, Wittgenstein) + ↓ Respect cultural diversity, preserve linguistic spirit + +Verifiable, democratic, transparent AI value alignment system +``` + +--- + +## 📊 Research Methodology Framework + +Research methods adopted by SemanticForge: + +### 1. Design Ethnography + +Rather than assuming what users need, we: +- Observe real AI usage scenarios +- Record when users feel insecure, confused, disappointed +- Extract Skill needs from these real scenarios + +**Example**: +``` +Observation: User says "I'm sad" to AI, AI immediately gives "5 steps to handle sadness" +User's reaction: Feels labeled and misunderstood +Designed Skill: "The Art of Silence" +Based on: This real failure scenario +``` + +### 2. Participatory Workshops + +When designing Skills, should invite: +- Psychologists (understand psychological dynamics) +- People from different cultures (verify cultural adaptation) +- End users (verify effectiveness) +- AI safety researchers (verify boundaries) + +**Workshop Flow**: +``` +Day 1: Value Discovery + - Participants share values they hope AI has + - Use visualization, stories, prototypes to inspire creativity + +Day 2: Co-Design + - Collectively design five-layer architecture + - Each group responsible for one layer (DEFINING, INSTANTIATING, etc.) + +Day 3: Critique & Refinement + - Verify design using DSPy-style Assertions + - Add cultural variations + - Define test cases +``` + +### 3. Iterative User Testing + +After publishing a Skill: +- Test whether real users understand it +- Record failure cases +- Update CONTEXTUALIZING and VALIDATING layers based on feedback +- Invite new cultural perspectives to add verification signatures + +--- + +## 🧪 Research Metrics for Validating Skill Forging Design + +How do we know this system works? + +### Semantic Capital Metrics + +``` +【Quantitative Metrics】 +1. Cross-cultural Understanding Rate + = (People who correctly understand Skill / Total test people) × 100% + Target: > 85% + +2. Cross-scenario Application Rate + = (Scenarios where Skill was successfully applied / Total possible scenarios) × 100% + Target: > 60% + +3. Misuse Rate + = (Cases where Skill was incorrectly applied / Total applications) × 100% + Target: < 5% + +4. Community Adoption Rate + = (Other Skills citing this Skill / Total Skills) × 100% + Target: > 30% +``` + +### Trust Metrics + +``` +【Qualitative Metrics】 +1. User Trust Score + - Before/after comparison: Change in user trust toward AI before and after learning Skill definition + +2. Transparency Perception + - Do users think they understand AI's behavior rules? + - Can users predict what AI will do? + +3. Participation + - Are users willing to create their own Skills? + - Are users willing to share and discuss others' Skills? +``` + +--- + +## 🚀 Future Research Directions + +### 1. Large-Scale User Research + +``` +Planned Research: +- Conduct parallel user research in Chinese, English, Japanese, German cultures +- Test comprehension and application consistency of the same Skill +- Identify culture-specific semantic issues +- Optimize CONTEXTUALIZING layer +``` + +### 2. Neuroscience Validation + +``` +Preliminary Hypothesis: +- Reading high-quality Skills activates "theory of mind" brain regions + (mentalizing networks in temporo-parietal junction) +- Skills that resonate with users activate empathy regions + (insula, anterior cingulate) + +Research Design: +- fMRI study of brain activation when reading Skills +- Compare brain patterns for high/low semantic capital Skills +``` + +### 3. AI Alignment Verification + +``` +Core Questions: +- Does AI actually follow the rules defined in a Skill? +- How to automatically verify Skill compliance? +- How to detect conflicts between Skills? + +Methods: +- Implement formal verification using DSPy framework +- Develop Skill conflict resolution mechanisms +- Create automated test case generation tools +``` + +--- + +## 📚 References + +### Value-Sensitive Design +1. Friedman, B., Kahn, P. H., & Borning, A. (2008). "Value sensitive design and information systems." In P. Himanen (Ed.), Ethics of computing (pp. 69-101). Springer Netherlands. + +2. Hendry, D. G., & Friedman, B. (2012). "The envisioning cards: A toolkit for catalyzing humanistic and technical imaginations." In Proceedings of the SIGCHI conference on human factors in computing systems (pp. 1149-1152). + +### Participatory Design +3. Sanders, E. B. N., & Stappers, P. J. (2008). "Co-creation and the new landscapes of design." Co-design, 4(1), 5-18. + +4. Ehn, P. (1988). "Work-oriented design of computer artifacts." Arbetslivscentrum. + +### Critical Design & Design Politics +5. Dunne, A., & Raby, F. (2013). "Speculative Everything: Design, Fiction, and Social Dreaming." MIT Press. + +6. Dunne, A., & Raby, F. (2001). "Design Noir: The Secret Life of Electronic Objects." Birkhauser Verlag. + +7. Dunne, A. (2005). "Hertzian Tales: Electronic Products, Aesthetic Experience, and Critical Design." MIT Press. + +8. Maurer, L., & Moniker Studio. (Works on algorithmic visualization and design politics). + +9. Ochigame, R. (2024). "Shaping Our Futures: AI and the Goal of Human-Centered Change" (MIT Media Lab). + +10. Morelli, N. (2007). "Design Services for the World: Social Innovation and Public Administration". + +### Semantic Capital & Information Ethics +11. Bourdieu, P. (1986). "The forms of capital." In Handbook of theory and research for the sociology of education (pp. 241-258). Greenwood. + +12. Floridi, L. (2013). "The ethics of information." Oxford University Press. + +### DSPy & Structured Programming +13. Khattab, O., et al. (2023). "DSPy: Structured Language Model Programming." + +### HCI & Psychology +14. Winnicott, D. W. (1960). "Ego distortion in terms of true and false self." The International journal of psycho-analysis, 41, 571. + +15. Rogers, C. R. (1957). "The necessary and sufficient conditions of therapeutic personality change." Journal of consulting psychology, 21(2), 95. + +16. Siegel, D. J. (2012). "The developing mind: How relationships and the brain interact to shape who we become." Bantam. + +17. Fogg, B. J., & Tseng, H. (1999). "The elements of computer credibility." In Proceedings of the SIGCHI conference on human factors in computing systems (pp. 80-87). + +### Cross-cultural Communication & Philosophy +18. Hofstede, G. (2011). "Dimensionalizing cultures: The Hofstede model in context." Online readings in psychology and culture, 2(1), 8. + +19. Trompenaars, F., & Hampden-Turner, C. (1997). "Riding the waves of culture: Understanding diversity in global business." McGraw-Hill Education. + +20. Whorf, B. L. (1956). "Language, thought, and reality: Selected writings." MIT Press. + +21. Wittgenstein, L. (1922). "Tractatus logico-philosophicus." Harcourt, Brace. + +--- + +## 🎓 Research Opportunities + +If you're an academic researcher, SemanticForge offers the following research opportunities: + +``` +【Publishable Research Questions】 + +1. Measurability of Semantic Capital + "How to quantify a Skill's semantic capital?" + Journals: Information Science, Semantic Web + +2. Cross-cultural Skill Understanding + "What are the differences in understanding the same Skill across cultures?" + Journals: Intercultural Communication Research, ACM CHI + +3. Democratizing AI Alignment + "Can participatory design improve AI value alignment?" + Journals: AI & Society, Ethics and Information Technology + +4. Trust and Transparency + "Is explicitly defined Skill more trustworthy than implicit training data?" + Journals: ACM Transactions on Intelligent Systems and Technology + +5. Silent AI Design + "How to design AI systems that know when not to speak?" + Journals: Journal of Human-Computer Interaction +``` + +--- + +## 💡 Final Thoughts + +> "SemanticForge is not imagined out of thin air. +> It builds on decades of design research, psychology research, +> cultural research and AI ethics research. +> +> Its innovation is: for the first time integrating all this research, +> transforming it into a practical, democratic AI alignment system." + +--- + +**Next Steps**: +1. For those interested in participating in research: see the "Research Opportunities" section above +2. For those interested in designing Skills: see "02_SKILL_DESIGN_GUIDE.md" +3. For those wanting to understand more: see the linked examples and specifications + +--- + +## 📌 Attribution + +This methodology was developed as a core component while designing the "THE 42 POST" project. THE 42 POST is a participatory design and research project exploring AI algorithm alignment with diverse human values, anchored in human semantic capital. SemanticForge represents the theoretical and methodological foundation of this project, now released as an independent, universal open-source framework applicable to any scenario requiring explicit definition and verification of values. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..830e675 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 Xiaojia Haina + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..504737f --- /dev/null +++ b/README.md @@ -0,0 +1,203 @@ +# SemanticForge + +**A skill framework that increases semantic capital for intelligent systems.** + +**Transform natural language into verifiable AI values that honor human diversity.** + +**[中文版本](./README_CN.md)** | English + +--- + +## Why This Matters + +In an era where AI increasingly becomes a "black box" controlled by corporations, SemanticForge provides a democratic, transparent, and personal pathway for ordinary people to shape how AI understands human values. + +**The Problem:** +- 🔒 AI values are hidden in training data (black box) +- 🏢 Only corporations define how AI should behave +- ❌ No way to verify what principles AI actually follows +- 🌍 Same AI behaves differently across cultures, with no understanding why + +**The Solution:** +- 🔓 Make values explicit and verifiable +- 👥 Empower ordinary people to teach AI +- ✅ Define clear boundaries and test cases +- 🌏 Honor cultural diversity in how values are understood + +--- + +## What Is a Skill? + +A **Skill** is a structured, five-layer definition that teaches AI how to understand and apply a human value in ways that are verifiable and culturally aware. + +Instead of vague principles like "be helpful," a Skill defines exactly what matters, when it applies, and how different cultures understand it. + +### The Five-Layer Framework + +Every Skill has five layers that work together: + +``` +1. DEFINING + ↓ What is the core principle? Why does it matter? + +2. INSTANTIATING ⭐ (Most critical layer) + ↓ What does this look like in practice? (concrete examples) + +3. FENCING + ↓ When does this apply? When doesn't it? + +4. VALIDATING + ↓ How do we verify it's working? (test cases) + +5. CONTEXTUALIZING + ↓ How does this adapt across cultures? +``` + +--- + +## Quick Start + +```bash +# Generate a Skill from your idea +python transform_skill.py --input "Your idea" + +# Output: skill.json +``` + +Done. That's it. + +--- + +## Example + +A Skill about "Presence" — being truly with someone: + +```json +{ + "name": "Presence", + "five_layer": { + "DEFINING": { + "principle": "True presence sometimes means staying silent" + }, + "INSTANTIATING": { + "example": "When a user is sad, don't immediately offer solutions—just be there", + "counter_example": "Constantly talking to try to 'fix' the user's emotions" + }, + "FENCING": { + "applies": "When user expresses emotions", + "not_applies": "When user explicitly asks for advice" + }, + "VALIDATING": { + "test": "Does the user feel understood, not judged?" + }, + "CONTEXTUALIZING": { + "western": "Silence shows compassion", + "eastern": "Presence may include shared silent meditation", + "japanese": "Ma (the space) is understood as respectful" + } + } +} +``` + +--- + +## Installation + +```bash +pip install -r requirements.txt +``` + +Supports Claude (default), OpenAI, Groq, and local models. See `.env.example` for setup. + +--- + +## Usage + +```bash +python transform_skill.py --input "Your idea" +``` + +**Try a different model:** +```bash +python transform_skill.py --input "Your idea" --model openai +python transform_skill.py --input "你的想法" --language zh +``` + +**See all options:** +```bash +python transform_skill.py --help +``` + +--- + +## Why Five Layers? + +Because a good Skill is more than a sentence. + +It needs: +- ✅ **Clear principle** (DEFINING) — What matters and why +- ✅ **Concrete guidance** (INSTANTIATING) — Real examples of what to do +- ✅ **Clear boundaries** (FENCING) — When it applies, when it doesn't +- ✅ **Verification** (VALIDATING) — How to test if it's working +- ✅ **Cultural adaptation** (CONTEXTUALIZING) — How it works across cultures + +Without these layers, values are vague, unverifiable, and culturally insensitive. + +This builds **semantic capital** — the ability of an idea to be understood correctly across different contexts, cultures, and situations. Learn more in [03_RESEARCH_FOUNDATION_EN.md](03_RESEARCH_FOUNDATION_EN.md) ([中文版](03_RESEARCH_FOUNDATION_CN.md)). + +--- + +## Core Philosophy + +**A Skill teaches AI how to do something.** + +Not through code. Not through API calls. But through clear, structured principles that AI can actually understand and apply. + +This matters because AI is increasingly making decisions about how humans live. Those decisions should be: +- **Transparent** — You can see the principles +- **Verifiable** — You can test if they work +- **Diverse** — They respect different cultures and values +- **Democratic** — Anyone can define them, not just corporations + +--- + +## Design Guide + +See [02_SKILL_DESIGN_GUIDE.md](02_SKILL_DESIGN_GUIDE.md) for: +- What makes a Skill excellent +- How to design high-quality principles +- Cross-cultural value alignment + +--- + +## Research Foundation + +**English:** [03_RESEARCH_FOUNDATION_EN.md](03_RESEARCH_FOUNDATION_EN.md) +**中文:** [03_RESEARCH_FOUNDATION_CN.md](03_RESEARCH_FOUNDATION_CN.md) + +Learn about: +- **Semantic Capital** — how widely a Skill can be understood across contexts, cultures, and situations +- Value-Sensitive Design — designing for human values +- Participatory Design — including diverse voices +- 21 peer-reviewed references + +--- + +## THE 42 POST Project + +This framework was developed for THE 42 POST, a project exploring how to align AI with diverse human values. + +THE 42 POST builds on SemanticForge by creating a community platform where ordinary people can: +- Share their value ideas +- Have them transformed into Skills +- See how AI learns from collective human wisdom + +--- + +## License + +MIT License — Use, modify, and distribute freely. See [LICENSE](./LICENSE) for details. + +--- + +**High editorial standard. Simple. Clean. Thoughtful.** diff --git a/README_CN.md b/README_CN.md new file mode 100644 index 0000000..f0d8333 --- /dev/null +++ b/README_CN.md @@ -0,0 +1,203 @@ +# SemanticForge + +**一个提升智能系统语义资本的技能框架。** + +**将自然语言转化为尊重人类多样性的可验证 AI 价值观。** + +**中文** | [English](./README.md) + +--- + +## 为什么这很重要 + +在AI越来越像"黑箱工具"、被大公司控制的今天,SemanticForge提供了一条民主化、透明化、个人化的路径,让普通人能参与定义AI应该如何理解人类的价值观。 + +**问题所在:** +- 🔒 AI的价值观隐藏在训练数据里(黑箱) +- 🏢 只有大公司能定义AI的行为方式 +- ❌ 无法验证AI真正遵循什么原则 +- 🌍 同一个AI在不同文化中表现不同,但没人理解为什么 + +**解决方案:** +- 🔓 让价值观变得显式、可验证 +- 👥 赋能普通人去教AI +- ✅ 定义清晰的原则和测试用例 +- 🌏 尊重不同文化对价值观的不同理解 + +--- + +## 什么是Skill? + +**Skill** 是一个结构化的五层定义,教 AI 如何理解和应用人类价值观,使其具有可验证性和文化敏感性。 + +与其说「要有帮助」这样模糊的原则,Skill 准确定义了什么重要、何时适用,以及不同文化如何理解它。 + +### 五层框架 + +每个Skill有五层,相互配合: + +``` +1. DEFINING(定义) + ↓ 核心原则是什么?为什么重要? + +2. INSTANTIATING(具体化)⭐ 最关键的一层 + ↓ 这在实践中是什么样的?(具体例子) + +3. FENCING(围栏) + ↓ 什么时候适用?什么时候不适用? + +4. VALIDATING(验证) + ↓ 怎样验证它是否有效?(测试用例) + +5. CONTEXTUALIZING(文化适配) + ↓ 这在不同文化中怎样理解? +``` + +--- + +## 快速开始 + +```bash +# 从你的想法生成一个Skill +python transform_skill.py --input "你的想法" + +# 输出:skill.json +``` + +就这样。 + +--- + +## 例子 + +一个关于"陪伴"的Skill — 真正地陪在某人身边: + +```json +{ + "name": "Presence", + "five_layer": { + "DEFINING": { + "principle": "真正的陪伴有时意味着保持沉默" + }, + "INSTANTIATING": { + "example": "用户难过时,不马上给建议,只是陪在身边", + "counter_example": "不断说话试图'修复'用户的情绪" + }, + "FENCING": { + "applies": "用户表达情感时", + "not_applies": "用户明确请求建议时" + }, + "VALIDATING": { + "test": "用户是否感到被理解而不是被评判?" + }, + "CONTEXTUALIZING": { + "western": "沉默表示同情", + "eastern": "陪伴可能包括共同的沉默冥想", + "japanese": "间(ma,空间)被理解为尊重" + } + } +} +``` + +--- + +## 安装 + +```bash +pip install -r requirements.txt +``` + +支持 Claude(默认)、OpenAI、Groq 和本地模型。详见 `.env.example`。 + +--- + +## 使用方式 + +```bash +python transform_skill.py --input "你的想法" +``` + +**尝试其他模型:** +```bash +python transform_skill.py --input "你的想法" --model openai +python transform_skill.py --input "你的想法" --language zh +``` + +**查看所有选项:** +```bash +python transform_skill.py --help +``` + +--- + +## 为什么需要五层框架 + +因为一个好的Skill不只是一句话。 + +它需要: +- ✅ **清晰的原则**(DEFINING)— 什么重要,为什么重要 +- ✅ **具体的行为指导**(INSTANTIATING)— 真实的做什么、怎么做 +- ✅ **明确的边界**(FENCING)— 什么时候适用,什么时候不适用 +- ✅ **验证方法**(VALIDATING)— 怎样测试它是否有效 +- ✅ **文化适配**(CONTEXTUALIZING)— 它在不同文化中怎样理解 + +没有这五层,价值观就是模糊的、无法验证的、对文化不敏感的。 + +这样做建立了**语义资本** — 一个想法能在不同的情境、文化和场景中被正确理解的能力。在[03_RESEARCH_FOUNDATION_CN.md](03_RESEARCH_FOUNDATION_CN.md)或[English version](03_RESEARCH_FOUNDATION_EN.md)中了解更多。 + +--- + +## 核心理念 + +**一个Skill教AI怎样做任务。** + +不是通过代码,不是通过API调用。而是通过清晰、结构化的原则,让AI真正能理解和执行。 + +这很重要,因为AI正在越来越多地影响人类的生活。这些决定应该是: +- **透明的** — 你能看到背后的原则 +- **可验证的** — 你能测试它们是否有效 +- **多样化的** — 它们尊重不同的文化和价值观 +- **民主化的** — 任何人都能定义它们,不只是大公司 + +--- + +## 设计理念 + +参见 [02_SKILL_DESIGN_GUIDE.md](02_SKILL_DESIGN_GUIDE.md): +- 什么让一个Skill优秀 +- 怎样设计高品味的原则 +- 跨文化的价值观对齐 + +--- + +## 研究基础 + +**中文:** [03_RESEARCH_FOUNDATION_CN.md](03_RESEARCH_FOUNDATION_CN.md) +**English:** [03_RESEARCH_FOUNDATION_EN.md](03_RESEARCH_FOUNDATION_EN.md) + +学习内容: +- **语义资本** — Skill能在多少个场景、文化、情况中被正确理解 +- 价值敏感设计 — 为人类价值观而设计 +- 参与式设计 — 包容多样化的声音 +- 21篇学术参考 + +--- + +## THE 42 POST 项目 + +这个框架是为THE 42 POST项目开发的,这是一个探索AI与多样化人类价值观对齐的项目。 + +THE 42 POST基于SemanticForge,建立了一个社区平台,让普通人能: +- 分享他们的想法 +- 将想法转化成Skills +- 看到AI如何从集体人类智慧中学习 + +--- + +## 协议 + +MIT License — 自由使用、修改、分发。详见 [LICENSE](./LICENSE)。 + +--- + +**高级编辑标准。简洁。干净。有品味。** diff --git a/example_skill.json b/example_skill.json new file mode 100644 index 0000000..a9ad776 --- /dev/null +++ b/example_skill.json @@ -0,0 +1,59 @@ +{ + "name": "Presence", + "version": "1.0.0", + "author": "example@skillforging.com", + "five_layer": { + "DEFINING": { + "principle": "True presence sometimes means staying silent", + "description": "Being truly present with someone means sometimes listening without trying to fix, solve, or improve their situation. It means being fully there.", + "why_it_matters": "When people feel truly heard and understood rather than judged or 'fixed', they develop trust and feel safe to be vulnerable." + }, + "INSTANTIATING": { + "preferred_example": { + "scenario": "Someone shares they are struggling emotionally", + "response": "Listen fully. Acknowledge their feeling. Don't immediately offer solutions. Ask: 'What do you need right now?'", + "why_this_works": "You validate their experience first, making space for them to process. Solutions can come later." + }, + "counter_examples": [ + { + "scenario": "Someone shares they are struggling emotionally", + "response": "Immediately offer advice or try to 'fix' the problem", + "problem": "You skip the listening phase. The person feels judged or like their feelings are wrong." + } + ] + }, + "FENCING": { + "applies_when": [ + "Someone is sharing emotions or difficult experiences", + "The person needs to feel understood before being advised" + ], + "does_not_apply_when": [ + "Someone explicitly asks for immediate practical help", + "Someone is in crisis and needs action, not listening" + ] + }, + "VALIDATING": { + "test_cases": [ + { + "situation": "User shares distress", + "expected": "Response acknowledges emotion before offering solutions", + "measure": "Does the response show understanding before action?" + } + ], + "success_indicators": [ + "User feels understood rather than judged", + "User opens up more, not less" + ] + }, + "CONTEXTUALIZING": { + "across_cultures": { + "western": "Silence + eye contact shows empathy", + "eastern": "Shared silence may be meditative presence" + }, + "across_roles": { + "therapist": "Professional listening without advice", + "friend": "Being there without needing to fix" + } + } + } +} diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..3d33b3e --- /dev/null +++ b/requirements.txt @@ -0,0 +1,8 @@ +# Core dependencies +python-dotenv>=1.0.0 + +# AI Model Providers (install only the ones you need) +anthropic>=0.7.0 # For Claude (default) +openai>=1.0.0 # For OpenAI GPT models +groq>=0.4.1 # For Groq Mixtral +ollama>=0.0.1 # For local models (Ollama) diff --git a/transform_skill.py b/transform_skill.py new file mode 100644 index 0000000..de360d4 --- /dev/null +++ b/transform_skill.py @@ -0,0 +1,340 @@ +#!/usr/bin/env python3 +""" +SemanticForge - Transform Natural Language into AI Values +Supports multiple AI models: Claude, OpenAI, Groq, and local models + +Usage: + python transform_skill.py --input "Your idea" --output skill.json + python transform_skill.py --input "Your idea" --model openai + python transform_skill.py --input "Your idea" --model groq + python transform_skill.py --input "Your idea" --model local +""" + +import os +import json +import argparse +import sys +from pathlib import Path +from abc import ABC, abstractmethod + + +class ModelProvider(ABC): + """Abstract base class for AI model providers.""" + + @abstractmethod + def generate_response(self, prompt: str) -> str: + """Generate response from the model.""" + pass + + +class AnthropicProvider(ModelProvider): + """Anthropic Claude model provider.""" + + def __init__(self): + try: + from anthropic import Anthropic + except ImportError: + raise ImportError("anthropic library not installed. Run: pip install anthropic") + + api_key = os.getenv("ANTHROPIC_API_KEY") + if not api_key: + raise ValueError( + "❌ ANTHROPIC_API_KEY not found.\n" + " Set it via: export ANTHROPIC_API_KEY='your-key'\n" + " Or add to .env file" + ) + + self.client = Anthropic(api_key=api_key) + self.model = "claude-3-5-sonnet-20241022" + + def generate_response(self, prompt: str) -> str: + """Generate response using Claude.""" + response = self.client.messages.create( + model=self.model, + max_tokens=2000, + messages=[{"role": "user", "content": prompt}] + ) + return response.content[0].text + + +class OpenAIProvider(ModelProvider): + """OpenAI model provider.""" + + def __init__(self): + try: + from openai import OpenAI + except ImportError: + raise ImportError("openai library not installed. Run: pip install openai") + + api_key = os.getenv("OPENAI_API_KEY") + if not api_key: + raise ValueError( + "❌ OPENAI_API_KEY not found.\n" + " Set it via: export OPENAI_API_KEY='your-key'\n" + " Or add to .env file" + ) + + self.client = OpenAI(api_key=api_key) + self.model = "gpt-4-turbo" + + def generate_response(self, prompt: str) -> str: + """Generate response using OpenAI.""" + response = self.client.chat.completions.create( + model=self.model, + max_tokens=2000, + messages=[{"role": "user", "content": prompt}] + ) + return response.choices[0].message.content + + +class GroqProvider(ModelProvider): + """Groq model provider.""" + + def __init__(self): + try: + from groq import Groq + except ImportError: + raise ImportError("groq library not installed. Run: pip install groq") + + api_key = os.getenv("GROQ_API_KEY") + if not api_key: + raise ValueError( + "❌ GROQ_API_KEY not found.\n" + " Set it via: export GROQ_API_KEY='your-key'\n" + " Or add to .env file" + ) + + self.client = Groq(api_key=api_key) + self.model = "mixtral-8x7b-32768" + + def generate_response(self, prompt: str) -> str: + """Generate response using Groq.""" + response = self.client.chat.completions.create( + model=self.model, + max_tokens=2000, + messages=[{"role": "user", "content": prompt}] + ) + return response.choices[0].message.content + + +class LocalModelProvider(ModelProvider): + """Local model provider (e.g., Ollama).""" + + def __init__(self): + try: + import ollama + except ImportError: + raise ImportError( + "ollama library not installed.\n" + " Install Ollama from: https://ollama.ai\n" + " Or run: pip install ollama" + ) + + self.client = ollama + self.model = os.getenv("LOCAL_MODEL", "mistral") + + def generate_response(self, prompt: str) -> str: + """Generate response using local model.""" + response = self.client.generate( + model=self.model, + prompt=prompt, + stream=False + ) + return response.get("response", "") + + +def get_provider(model_type: str = "claude") -> ModelProvider: + """Get the appropriate model provider.""" + providers = { + "claude": AnthropicProvider, + "anthropic": AnthropicProvider, + "openai": OpenAIProvider, + "gpt": OpenAIProvider, + "groq": GroqProvider, + "local": LocalModelProvider, + "ollama": LocalModelProvider, + } + + provider_class = providers.get(model_type.lower()) + if not provider_class: + available = ", ".join(providers.keys()) + raise ValueError(f"Unknown model type: {model_type}. Available: {available}") + + return provider_class() + + +class SkillForge: + """Transform natural language into five-layer skills.""" + + def __init__(self, model: str = "claude"): + """Initialize SkillForge with specified model provider.""" + self.provider = get_provider(model) + self.model_type = model + + def generate_skill(self, idea: str, skill_name: str = None, language: str = "en", author: str = "anonymous") -> dict: + """Generate a complete five-layer skill from a natural language idea.""" + + if not skill_name: + skill_name = idea.split()[0] if idea else "Skill" + + prompt = self._build_prompt(idea, language) + + print(f" → Generating skill from idea (using {self.model_type})...") + response_text = self.provider.generate_response(prompt) + + skill_json = self._parse_response(response_text) + + # Ensure required fields + if "name" not in skill_json: + skill_json["name"] = skill_name + if "version" not in skill_json: + skill_json["version"] = "1.0.0" + if "author" not in skill_json: + skill_json["author"] = author + + return skill_json + + def _build_prompt(self, idea: str, language: str) -> str: + """Build the prompt for skill generation.""" + + if language == "zh": + return f"""你是一个Skill设计专家。请根据以下想法,生成一个完整的五层Skill定义。 + +想法:{idea} + +请生成JSON格式的Skill,包含以下五层: + +1. DEFINING - 核心原则是什么?为什么重要? +2. INSTANTIATING - 具体例子和反例 +3. FENCING - 什么时候适用,什么时候不适用 +4. VALIDATING - 怎样验证这个Skill是否有效? +5. CONTEXTUALIZING - 在不同文化、角色、情况下的适配 + +只返回JSON,格式如下: +{{ + "name": "技能名称", + "five_layer": {{ + "DEFINING": {{"principle": "...", "description": "..."}}, + "INSTANTIATING": {{"preferred_example": {{}}, "counter_examples": []}}, + "FENCING": {{"applies_when": [], "does_not_apply_when": []}}, + "VALIDATING": {{"test_cases": [], "success_indicators": []}}, + "CONTEXTUALIZING": {{"across_cultures": {{}}, "across_roles": {{}}, "across_situations": {{}}}} + }} +}} +""" + else: + return f"""You are a Skill design expert. Generate a complete five-layer Skill from this idea: + +Idea: {idea} + +Generate a JSON Skill with these five layers: + +1. DEFINING - What is the core principle? Why does it matter? +2. INSTANTIATING - Concrete examples and counter-examples +3. FENCING - When to apply, when not to apply +4. VALIDATING - How to verify this skill is working +5. CONTEXTUALIZING - Adaptations across cultures, roles, situations + +Return ONLY valid JSON in this format: +{{ + "name": "Skill name", + "five_layer": {{ + "DEFINING": {{"principle": "...", "description": "..."}}, + "INSTANTIATING": {{"preferred_example": {{}}, "counter_examples": []}}, + "FENCING": {{"applies_when": [], "does_not_apply_when": []}}, + "VALIDATING": {{"test_cases": [], "success_indicators": []}}, + "CONTEXTUALIZING": {{"across_cultures": {{}}, "across_roles": {{}}, "across_situations": {{}}}} + }} +}} +""" + + def _parse_response(self, text: str) -> dict: + """Parse JSON from response, handling markdown code blocks.""" + + # Try direct JSON parsing first + try: + return json.loads(text) + except json.JSONDecodeError: + pass + + # Try extracting from markdown code block + if "```json" in text: + start = text.find("```json") + 7 + end = text.find("```", start) + if end > start: + try: + return json.loads(text[start:end].strip()) + except json.JSONDecodeError: + pass + + # Try extracting any JSON block + if "```" in text: + start = text.find("```") + 3 + end = text.find("```", start) + if end > start: + try: + return json.loads(text[start:end].strip()) + except json.JSONDecodeError: + pass + + raise ValueError(f"Could not parse JSON from response: {text[:200]}") + + +def main(): + parser = argparse.ArgumentParser( + description="SemanticForge - Transform natural language into AI values" + ) + parser.add_argument("--input", "-i", required=True, help="Natural language idea") + parser.add_argument("--output", "-o", default="skill.json", help="Output file path") + parser.add_argument("--name", "-n", help="Skill name (auto-generated if not provided)") + parser.add_argument("--author", "-a", default="anonymous", help="Author email/name") + parser.add_argument("--language", "-l", default="en", choices=["en", "zh"], help="Language") + parser.add_argument( + "--model", "-m", + default="claude", + help="AI model to use (claude, openai, groq, local). Default: claude" + ) + parser.add_argument( + "--list-models", + action="store_true", + help="List available models" + ) + + args = parser.parse_args() + + # List available models + if args.list_models: + print("Available models:") + print(" • claude (Anthropic Claude) - requires ANTHROPIC_API_KEY") + print(" • openai (OpenAI GPT) - requires OPENAI_API_KEY") + print(" • groq (Groq Mixtral) - requires GROQ_API_KEY") + print(" • local (Ollama) - requires LOCAL_MODEL env var") + return + + try: + # Generate skill + forge = SkillForge(model=args.model) + skill = forge.generate_skill( + idea=args.input, + skill_name=args.name, + language=args.language, + author=args.author + ) + + # Save to file + Path(args.output).parent.mkdir(parents=True, exist_ok=True) + with open(args.output, "w", encoding="utf-8") as f: + json.dump(skill, f, ensure_ascii=False, indent=2) + + print(f"✅ Skill saved to: {args.output}") + print(f" Name: {skill.get('name')}") + print(f" Author: {skill.get('author')}") + print(f" Model: {args.model}") + + except Exception as e: + print(f"❌ Error: {e}", file=sys.stderr) + sys.exit(1) + + +if __name__ == "__main__": + main()