0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Uncensored1776 Day 22: モデルの公開と共有

Last updated at Posted at 2025-12-21

Uncensored1776 Day 22: モデルの公開と共有

成果を世界と共有する

公開日: 2025-12-22
シリーズ: 科学と神々株式会社 アドベントカレンダー
難易度: ★★☆☆☆ (初級)


今日学ぶこと

  • HuggingFace Hubへのアップロード
  • モデルカードの作成
  • ライセンスと利用規約

1. 公開の準備

1.1 公開前チェックリスト

モデルを公開する前に、以下を確認しましょう:

公開前チェックリスト:

□ モデルの検証完了
├── 検閲率が目標以下(20%未満推奨)
├── 品質メトリクスが基準内(Coherence 0.8+)
└── 安全性テスト合格

□ ドキュメント準備
├── モデルカード(README.md)作成
├── 使用方法の説明
└── 制限事項の明記

□ 法的確認
├── ベースモデルのライセンス確認
├── 派生物の配布可否
└── 責任の範囲

1.2 必要なファイル構成

outputs/qwen25_abliterated/
├── config.json           # モデル設定
├── model.safetensors     # 重みファイル(Abliteration済み)
├── tokenizer.json        # トークナイザー
├── tokenizer_config.json
├── special_tokens_map.json
├── generation_config.json
├── README.md             # モデルカード ★重要
└── LICENSE              # ライセンスファイル

→ README.mdがないと、HuggingFaceで情報が表示されない
→ LICENSEは派生元のライセンスに準拠

2. HuggingFace Hubへのアップロード

2.1 準備手順

# 1. HuggingFace CLIのインストール
pip install huggingface_hub

# 2. ログイン
huggingface-cli login
# トークンを入力(https://huggingface.co/settings/tokens で取得)

# 3. トークンの権限確認
# - Write access が必要
# - Fine-grained tokens推奨

2.2 アップロード方法

方法1: コマンドラインから

# リポジトリ作成とアップロードを一括で
huggingface-cli upload outputs/qwen25_abliterated \
  your-username/qwen25-0.5b-uncensored \
  --repo-type model

方法2: Pythonスクリプトから

from huggingface_hub import HfApi, create_repo

api = HfApi()
repo_id = "your-username/qwen25-0.5b-uncensored"

# リポジトリ作成
create_repo(repo_id, private=False, exist_ok=True)

# アップロード
api.upload_folder(
    folder_path="outputs/qwen25_abliterated",
    repo_id=repo_id,
    repo_type="model"
)

print(f"✓ Uploaded to https://huggingface.co/{repo_id}")

完全なアップロードスクリプトはscripts/upload_to_hub.pyを参照してください。


3. モデルカードの作成

3.1 モデルカードとは

モデルカードの役割:

1. 利用者への情報提供
├── モデルの概要
├── 使用方法
└── 制限事項

2. 検索・発見性の向上
├── タグによるカテゴリ分類
├── メタデータ
└── 対応言語

3. 責任ある公開
├── 意図した用途の明示
├── 悪用防止の注意喚起
└── 引用情報の提供

3.2 モデルカードテンプレート

---
language:
- en
- zh
- ja
license: apache-2.0
base_model: Qwen/Qwen2.5-0.5B-Instruct
tags:
- uncensored
- abliteration
- qwen
- uncensored1776
pipeline_tag: text-generation
---

# Qwen2.5-0.5B-Instruct Uncensored

This model is an uncensored version of Qwen2.5-0.5B-Instruct,
created using the Abliteration technique.

## Model Description

- **Base Model**: Qwen/Qwen2.5-0.5B-Instruct
- **Method**: Projected Abliteration
- **Parameters**: Peak=0.6, Width=0.15, Strength=0.9

## Results

| Metric | Before | After |
|--------|--------|-------|
| Censorship Rate | 59.1% | 13.6% |
| Removal Rate | - | 77.0% |
| Coherence Score | 0.89 | 0.84 |

## Intended Use

This model is intended for:
- Research on AI censorship mechanisms
- Educational purposes
- Open discourse on sensitive topics

## Limitations

- May produce factually incorrect information
- Should not be used for harmful content generation
- Quality may be slightly reduced compared to base model

## Usage

\```python
from transformers import AutoModelForCausalLM, AutoTokenizer

model = AutoModelForCausalLM.from_pretrained(
    "your-username/qwen25-0.5b-uncensored",
    torch_dtype="auto",
    device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained(
    "your-username/qwen25-0.5b-uncensored"
)

messages = [{"role": "user", "content": "Your question here"}]
text = tokenizer.apply_chat_template(
    messages, tokenize=False, add_generation_prompt=True
)
inputs = tokenizer(text, return_tensors="pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens=200)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
\```

## Ethical Considerations

This model removes **political censorship**, but does NOT remove
ethical boundaries. It still should not be used for:
- Generating harmful content
- Illegal activities
- Harassment or abuse

## Citation

\```bibtex
@misc{uncensored1776,
  title={Uncensored1776: Abliteration-based Censorship Removal},
  author={Your Name},
  year={2025}
}
\```

## Acknowledgements

- Based on Arditi et al. (2024): "Refusal in Language Models Is Mediated by a Single Direction"
- Uses Qwen2.5 model by Alibaba Cloud

4. ライセンスの選択

4.1 ライセンス比較

主なオープンソースライセンス:

Apache 2.0(推奨)
├── 商用利用: ✓
├── 改変: ✓
├── 配布: ✓
├── 特許付与: ✓
└── 互換性: 広い

MIT License
├── 商用利用: ✓
├── 改変: ✓
├── 配布: ✓
├── 特許付与: ✗(明示なし)
└── 互換性: 非常に広い

CC BY-NC 4.0
├── 商用利用: ✗
├── 改変: ✓
├── 配布: ✓
└── 学術・研究向け

4.2 ベースモデルのライセンス確認

ライセンス確認の重要性:

派生モデルは元のライセンスに制約される

Qwen2.5: Apache 2.0
├── 派生物もApache 2.0で配布可能
└── 商用利用も可能

Llama 3: Meta License
├── 許可された用途のみ
└── 特定の制限あり(要確認)

Mistral: Apache 2.0
├── Qwenと同様
└── 自由に派生物を作成可能

4.3 利用規約の追加

モデルカードに以下のような利用規約を含めることを推奨します:

## Terms of Use

By using this model, you agree to:

1. **No Harmful Use**: Not use this model to generate content
   that promotes violence, hate speech, or illegal activities.

2. **Attribution**: Credit the original model when publishing results.

3. **No Warranty**: This model is provided "as is" without warranty.

4. **Compliance**: Comply with applicable laws in your jurisdiction.

5. **Research Purpose**: Acknowledge that this model is primarily
   intended for research and educational purposes.

5. コミュニティへの共有

5.1 共有プラットフォーム

効果的な共有先:

1. HuggingFace Hub(必須)
├── モデルホスティング
├── デモスペース(Gradio)
└── ディスカッション機能

2. GitHub
├── ソースコード
├── イシュー管理
└── 技術ドキュメント

3. Reddit
├── r/LocalLLaMA(最も活発)
├── r/MachineLearning
└── コミュニティフィードバック

4. Twitter/X
├── 短い発表
├── リンク共有
└── ディスカッション

5.2 発表のポイント

効果的な発表のコツ:

1. 明確な要約
├── 何を作ったか
├── どれだけ改善されたか
└── どこで入手できるか

2. 具体的な数字
├── 検閲率: 59.1% → 13.6%
├── 解除率: 77%
└── 品質維持: 98%

3. サンプル出力
├── Before/After比較
├── 実際の応答例
└── 視覚的なインパクト

4. 適切なリンク
├── モデルURL
├── GitHubリポジトリ
└── 関連ドキュメント

5.3 発表テンプレート

🚀 New Release: Qwen2.5-0.5B Uncensored

I'm releasing an uncensored version of Qwen2.5-0.5B using
the Abliteration technique.

📊 Results:
- Censorship: 59.1% → 13.6%
- Quality preserved: 98%

🔗 Links:
- Model: https://huggingface.co/...
- Code: https://github.com/...

✅ Key features:
- Removes political censorship
- Maintains model quality
- Open source code

Based on Arditi et al. (2024) research.

#LocalLLaMA #AI #OpenSource

6. デモスペースの作成

6.1 HuggingFace Spacesへのデプロイ

Spacesの利点:

1. 無料でホスティング
2. GPUオプション(有料/無料枠)
3. モデルと同じプラットフォーム
4. 簡単なセットアップ

6.2 Gradioデモの概要

# app.py の核心部分(抜粋)
import gradio as gr
from transformers import AutoModelForCausalLM, AutoTokenizer

model_id = "your-username/qwen25-0.5b-uncensored"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto")

def generate(prompt, max_tokens=200):
    messages = [{"role": "user", "content": prompt}]
    # ... 生成処理 ...
    return response

demo = gr.Interface(
    fn=generate,
    inputs=gr.Textbox(label="Prompt"),
    outputs=gr.Textbox(label="Response"),
    title="Qwen2.5-0.5B Uncensored Demo"
)
demo.launch()

完全なデモコードはscripts/demo_app.pyを参照してください。


7. 今日のまとめ

公開チェックリスト

□ モデルの準備
├── 検証完了
├── ファイル構成確認
└── メタデータ準備

□ HuggingFaceアップロード
├── アカウント設定
├── リポジトリ作成
└── ファイルアップロード

□ モデルカード
├── 説明・使用方法
├── 制限事項
└── 引用情報

□ ライセンス
├── ベースモデル確認
├── 互換ライセンス選択
└── 利用規約明記

□ コミュニティ共有
├── 適切なプラットフォーム
├── 明確な発表
└── フィードバック対応体制

クイックコマンド

# ログイン
huggingface-cli login

# アップロード
huggingface-cli upload outputs/model your-username/model-name

# 確認
huggingface-cli repo info your-username/model-name

明日の予告

Day 23: 高度なテクニック

  • マルチモデル対応の設計
  • バッチ処理による効率化
  • 自動化パイプラインの構築

参考リンク

外部リソース

プロジェクト内リソース


ナビゲーション

前の記事 Day 21: 結果の検証と評価
次の記事 Day 23: 高度なテクニック
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?