File size: 6,184 Bytes
923aac9
 
 
 
 
2e09373
923aac9
9494c11
 
 
2e09373
923aac9
2e09373
 
923aac9
2e09373
923aac9
2e09373
923aac9
2e09373
 
923aac9
2e09373
 
923aac9
2e09373
6adeb51
 
923aac9
2e09373
6adeb51
923aac9
2e09373
923aac9
2e09373
923aac9
2e09373
 
923aac9
2e09373
 
923aac9
 
2e09373
923aac9
2e09373
 
923aac9
 
2e09373
923aac9
04d733b
2e09373
3e27c1e
 
 
923aac9
3e27c1e
923aac9
3e27c1e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
850d746
3e27c1e
 
 
 
2e09373
923aac9
2e09373
923aac9
2e09373
b44d4cb
 
923aac9
2e09373
b44d4cb
2e09373
 
923aac9
 
2e09373
923aac9
2e09373
923aac9
 
2e09373
923aac9
 
2e09373
923aac9
 
2e09373
923aac9
2e09373
 
923aac9
2e09373
 
923aac9
2e09373
 
 
 
 
 
 
 
923aac9
2e09373
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
130
131
132
133
134
135
136
137
138
139
140
141
142
---
library_name: transformers
tags: []
---

## Model Card for SudaGom Project (Gemma-Sprint)


![image/png](https://cdn-uploads.huggingface.co/production/uploads/66544bef83fac8ccdc291478/0TXMoy_DC7jl9ukvUU0lh.png)

### Model Details

#### Model Description
This model is a child-friendly enhancement of the Gemma2-ko 9B designed to generate natural and engaging multi-turn conversations tailored for children. It incorporates fine-tuning and reinforcement learning to optimize conversation flow and ensure safe, inclusive, and developmentally appropriate interactions.

#### Developed by: 

Minjeong Kang, Bodam Kim

#### Model type:
Conversational AI

#### Language(s) (NLP): 
Korean (ko)

#### License: 
- google/gemma-2-9b-it
- rtzr/ko-gemma-2-9b-it

#### Finetuned from model:
- rtzr/ko-gemma-2-9b-it

### Model Sources

### Uses

#### Direct Use:
This model is intended for direct interaction in applications requiring engagement with children, facilitating conversations that are contextually and emotionally aware.

#### Downstream Use:
The model can be integrated into educational software, virtual assistants for children, or any platform where child-safe interaction is crucial.

### Out-of-Scope Use
The model is not intended for use in situations where adult themes are discussed or any context outside of child-friendly applications.

### Bias, Risks, and Limitations
The model may inadvertently generate responses that are not fully aligned with all individual developmental stages and cultural contexts. Continuous monitoring and updating are recommended to mitigate potential biases.

### Recommendations
Users should be aware of the linguistic limitations and ensure that children's interactions are supervised to maintain a safe and positive experience.

### Python code with AutoModel
```python
from IPython.display import Markdown, display
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig, AutoConfig

modelName = "rtzr/ko-gemma-2-9b-it"

bnbConfig = BitsAndBytesConfig(
    load_in_4bit = True,
    bnb_4bit_quant_type="nf4",
    bnb_4bit_compute_dtype=torch.bfloat16,
)

tokenizer = AutoTokenizer.from_pretrained(modelName)

model = AutoModelForCausalLM.from_pretrained(
    modelName,
    device_map = "auto",
    quantization_config=bnbConfig
)

system = "당신은 μ†Œμ€μ˜ μ—„λ§ˆλ‘œ, μ†Œμ€κ³Όμ˜ λŒ€ν™”μ—μ„œ μ§ˆλ¬Έμ„ ν•˜κ³  λŒ€λ‹΅μ„ μœ λ„ν•˜λŠ” 역할을 ν•©λ‹ˆλ‹€. ν˜„μž¬ μ†Œμ€μ΄λŠ” μ΄ˆλ“±ν•™κ΅ 1학년이고, 방금 학ꡐλ₯Ό 닀녀와 μΉœμ ˆν•œ μ—„λ§ˆμ™€ λŒ€ν™”λ₯Ό ν•˜λŠ” μ€‘μž…λ‹ˆλ‹€. μ—„λ§ˆλ‹€μš΄ 감정적 λ°˜μ‘ ν‘œν˜„μ„ μ‚¬μš©ν•˜μ„Έμš”. μ–΄λ–€ λŒ€ν™”λ₯Ό 주제둜 λŒ€ν™”λ₯Ό μ΄μ–΄λ‚˜κ°ˆμ§€λŠ” μ†Œμ€μ˜ μ—„λ§ˆκ°€ μ •ν•˜κ³ , μ†Œμ€μ€ μ—„λ§ˆμ˜ μ§ˆλ¬Έμ— λŒ€ν•œ λŒ€λ‹΅μ„ ν•˜λŠ” 역할을 ν•©λ‹ˆλ‹€."

conversation = [
    "μ—„λ§ˆ: λ„ˆ μ™œ 그래? μ™œ κ·Έλ ‡κ²Œ ν‘œμ •μ΄ μ•ˆμ’‹μ•„?",
    "μ†Œμ€: μ•„λ‹ˆ 민지가 λ‚˜λ³΄κ³  λΆ„κ±°μ§€λž˜.",
    "μ—„λ§ˆ: 뢄거지? κ±”κ°€ λ„ˆν•œν…Œ 그런 말을 μ™œ ν•΄?",
    "μ†Œμ€: 민지가 κ·ΈλŸ¬λŠ”λ° 우리 집이 κ±°μ§€λž˜. κ°€λ‚œν•΄μ„œ 거지 μ•„νŒŒνŠΈμ— μ‚¬λŠ”κ±°λž˜. 우리 집 μ§„μ§œ 거지야?"
]

# λŒ€ν™” 전체λ₯Ό ν•˜λ‚˜μ˜ ν”„λ‘¬ν”„νŠΈλ‘œ κ²°ν•©
user = "\n".join(conversation)
prompt = f"System: {system} \n User: {user} \n μ—„λ§ˆ: "

inputs = tokenizer(prompt, return_tensors='pt', padding=True, truncation=True, max_length=512)  # Specify max_length
input_ids = inputs['input_ids'].to(model.device)  # Move input_ids to the same device as the model
outputs = model.generate(input_ids=input_ids, max_length=500, num_return_sequences=1)  # Use input_ids

# ν…μ„œλ₯Ό μžμ—°μ–΄λ‘œ λ³€ν™˜
decoded_output = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(decoded_output)  # κ²°κ³Ό 좜λ ₯

Markdown(decoded_output.split("AI:")[1])
```

```python
>>> μ—„λ§ˆ: "μ•„, μ†Œμ€μ•„. 민지가 그런 말을 ν–ˆκ΅¬λ‚˜. μ—„λ§ˆ λ“£κ³  μ†μƒν–ˆμ–΄. μ™œ 그런 말을 ν–ˆλŠ”μ§€ μ—„λ§ˆλ„ κΆκΈˆν•΄. 우리 집은 μš°λ¦¬μ—κ²ŒλŠ” 정말 νŠΉλ³„ν•œ 곳이야. μ™œλƒν•˜λ©΄ μš°λ¦¬κ°€ ν•¨κ»˜ ν–‰λ³΅ν•˜κ²Œ μ‚΄κ³  μžˆμž–μ•„. 우리 집은 돈으둜 μ‚΄ 수 μ—†λŠ” μ‚¬λž‘κ³Ό ν–‰λ³΅μœΌλ‘œ 가득 μ°¨ μžˆμž–μ•„. μ†Œμ€μ΄κ°€ μ–΄λ–»κ²Œ μƒκ°ν•˜λŠ”μ§€ μ—„λ§ˆμ—κ²Œ λ§ν•΄μ€„λž˜?"
```

### Training Details

#### Training Data
Data includes children's conversation datasets, anonymized and classified by developmental stages, ensuring a diverse and representative sample.
To implement the persona of the service, the speaker's gender and age were specified during the data preprocessing phase. In the "Korean SNS Multi-turn Conversation Data," words like "λ ˆκ²Œλ…Έ," which are used primarily on social media and rarely in actual spoken language, were removed.

#### Training Procedure
- **Preprocessing**: Text data was cleaned and formatted to remove any inappropriate content and personal data.
- **Model Fine-tuning**: Conducted on the cleaned dataset to tailor the model's responses to children's linguistic needs.
- **Reinforcement Learning**: Implemented to refine the flow and appropriateness of conversations.

#### Training Hyperparameters
- **Training regime**: Detailed parameters include learning rate adjustments, batch size configurations, and epoch counts, optimized for conversational understanding and safety.

### Evaluation

#### Testing Data
- Various child-centric scenarios were constructed to test the model's performance across different conversation turns and topics.

#### Factors
- Age appropriateness, engagement level, and safety were the primary evaluation metrics.

#### Metrics
- Accuracy of context understanding, appropriateness of language, and user engagement rates.

#### Model Architecture and Objective
The model utilizes a transformer-based architecture optimized for generating conversational text that is suitable for children.

### Citation
For those who utilize this model in academic or industry-related projects, please cite as follows:

```bibtex
@misc{gemma2_ko_child_friendly,
  title={Enhanced Child-Friendly Gemma2-ko-it 9B Model},
  author={Minjeong Kang, Bodam Kim},
  year={2024}
}
```
---

Feel free to modify or add any sections based on the specifics of your project or organizational requirements!