File size: 5,294 Bytes
328f2b7
 
9c489e6
 
 
 
 
 
328f2b7
 
 
 
917f929
328f2b7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8fd92ee
328f2b7
 
8fd92ee
 
 
 
328f2b7
 
 
8fd92ee
 
 
328f2b7
8fd92ee
328f2b7
 
8fd92ee
 
 
 
 
 
 
 
 
 
 
328f2b7
 
8fd92ee
 
 
 
328f2b7
8fd92ee
328f2b7
8fd92ee
 
 
328f2b7
8fd92ee
 
328f2b7
8fd92ee
328f2b7
 
8fd92ee
328f2b7
 
 
 
8fd92ee
 
 
328f2b7
 
8fd92ee
328f2b7
 
 
8fd92ee
328f2b7
 
 
 
8fd92ee
328f2b7
 
 
 
 
8fd92ee
 
 
 
 
 
328f2b7
8fd92ee
 
 
 
 
328f2b7
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
---
license: gemma
language:
- ja
- en
base_model:
- google/gemma-3-4b-it
pipeline_tag: text-generation
---
# DataPilot/ArrowMint-Gemma3-4B-ChocoMint-instruct-v0.2 モデルカード

**モデルリポジトリ**: [DataPilot/ArrowMint-Gemma3-4B-ChocoMint-instruct-v0.2](https://huggingface.co/DataPilot/ArrowMint-Gemma3-4B-ChocoMint-instruct-v0.2)

**ベースモデル**: [google/gemma-3-4b-it](https://huggingface.co/google/gemma-3-4b-it)

## Overview

`DataPilot/ArrowMint-Gemma3-4B-ChocoMint-instruct-v0.2`は、Googleによって開発された強力なマルチモーダルモデルである`google/gemma-3-4b-it`をベースとしてファインチューニングされた指示応答モデルです。

このモデルは、[Unsloth](https://github.com/unslothai/unsloth)ライブラリと高品質な合成データセットを用いてトレーニングされました。主な目的は、ベースモデルの持つ能力を維持・強化しつつ、特に**プロンプト(指示)への追従能力****マルチターン対話における性能**を向上させることです。

Gemma 3ファミリーと同様に、テキスト入力と画像入力の両方に対応し、テキスト出力を生成することができます。

## How to use

このモデルを使用するには、Transformersライブラリ (バージョン 4.50.0 以降) が必要です。

```bash
pip install -U transformers accelerate Pillow requests torch
```

### 画像付き推論

```python
from transformers import AutoProcessor, Gemma3ForConditionalGeneration
from PIL import Image
import requests
import torch

model_id = "DataPilot/ArrowMint-Gemma3-4B-ChocoMint-instruct-v0.2"

model = Gemma3ForConditionalGeneration.from_pretrained(
    model_id, device_map="auto"
).eval()

processor = AutoProcessor.from_pretrained(model_id)

messages = [
    {
        "role": "system",
        "content": [{"type": "text", "text": "あなたは素晴らしい日本語アシスタントです。"}]
    },
    {
        "role": "user",
        "content": [
            {"type": "image", "image": "https://cs.stanford.edu/people/rak248/VG_100K_2/2399540.jpg"},
            {"type": "text", "text": "この画像を説明してください。"}
        ]
    }
]

inputs = processor.apply_chat_template(
    messages, add_generation_prompt=True, tokenize=True,
    return_dict=True, return_tensors="pt"
).to(model.device, dtype=torch.bfloat16)

input_len = inputs["input_ids"].shape[-1]

with torch.inference_mode():
    generation = model.generate(**inputs, max_new_tokens=100, do_sample=False)
    generation = generation[0][input_len:]

decoded = processor.decode(generation, skip_special_tokens=True)
print(decoded)
```
### 画像無し推論

```python
from transformers import AutoProcessor, Gemma3ForConditionalGeneration
import torch

model_id = "DataPilot/ArrowMint-Gemma3-4B-ChocoMint-instruct-v0.2"

model = Gemma3ForConditionalGeneration.from_pretrained(
    model_id, device_map="auto"
).eval()

processor = AutoProcessor.from_pretrained(model_id)

messages = [
    {
        "role": "system",
        "content": [{"type": "text", "text": "あなたは素晴らしい日本語アシスタントです。"}]
    },
    {
        "role": "user",
        "content": [
            {"type": "text", "text": "AI言語モデルであるLaMDAが意識があることを主張して弁護士を呼んだとのことです。LaMDAには意識があると思いますか?"}
        ]
    }
]

inputs = processor.apply_chat_template(
    messages, add_generation_prompt=True, tokenize=True,
    return_dict=True, return_tensors="pt"
).to(model.device, dtype=torch.bfloat16)

input_len = inputs["input_ids"].shape[-1]

with torch.inference_mode():
    generation = model.generate(**inputs, max_new_tokens=100, do_sample=False)
    generation = generation[0][input_len:]

decoded = processor.decode(generation, skip_special_tokens=True)
print(decoded)
```

**注意点:**

*   Gemma 3モデルは比較的大きなメモリを必要とします。特に4Bモデルでは、十分なVRAMを持つGPUが必要です。`torch_dtype=torch.bfloat16``device_map="auto"` を使用してメモリ使用量を削減・分散することを推奨します。
*   Gemma 3モデルはリモートコードの実行を要求する場合があります (`trust_remote_code=True`)。信頼できるソースからモデルをロードしていることを確認してください。
*   プロンプトの形式はモデルの性能に大きく影響します。ベースモデルである `google/gemma-3-4b-it` のチャットテンプレートに従うことを推奨します。上記コード例では `apply_chat_template` がこれを自動的に処理します。

## License

このモデルは、ベースモデルである `google/gemma-3-4b-it` のライセンスに基づいています。詳細については、[Gemma Terms of Use](https://ai.google.dev/gemma/terms) を参照してください。

派生モデルである `DataPilot/ArrowMint-Gemma3-4B-ChocoMint-instruct-v0.2` の利用にあたっては、ベースモデルのライセンス条件、特に利用制限([Gemma Prohibited Use Policy](https://ai.google.dev/gemma/prohibited_use_policy))に従う必要があります。