HachiML commited on
Commit
5eb2254
·
verified ·
1 Parent(s): 1ed37fc

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +92 -75
README.md CHANGED
@@ -1,93 +1,110 @@
1
  ---
 
2
  library_name: transformers
3
  tags:
4
- - SkillTree
5
  - mistral
6
- license: apache-2.0
7
  ---
8
 
9
- # SkillTree Model Collection
10
-
11
- Applying a skill to your model with SkillTree is akin to unlocking a new ability in a video game's skill tree. Just as you would enhance your character's capabilities by selecting and activating specific skills, you can augment your model's abilities by integrating specialized skills. Follow these steps to imbue your model with new prowess, enhancing its performance and versatility in a straightforward and intuitive manner.
12
- **Please note that SkillTree abilities may not function in all cases. To determine whether a specific skill is operational, refer to the Functionality Status.**
13
 
14
- ## What is SkillTree?
15
 
16
- SkillTree represents a set of model weights derived from further pre-training or fine-tuning Large Language Models (LLMs) to extract specific capabilities, such as code generation or chatting abilities. These extracted "skills" can be combined with a specific LLM base model to enhance its capabilities. The concept is inspired by [ChatVector](https://arxiv.org/abs/2310.04799), aiming to modularize and transfer distinct skills across models.
17
 
18
- ## SkillTree Details
19
 
 
 
 
20
  - **Functionality Status:** **Functional** / Non-Functional / Not Verified
21
- - **Base Model:** [mistralai/Mistral-7B-v0.1](https://huggingface.co/mistralai/Mistral-7B-v0.1)
22
- - **Skill Model:** [ibm/merlinite-7b](https://huggingface.co/ibm/merlinite-7b)
23
- - **Enhanced Model(optional):** [HachiML/Swallow-MS-7b-v0.1-ChatSkill-LAB](https://huggingface.co/HachiML/Swallow-MS-7b-v0.1-ChatSkill-LAB)
24
- - **Skill type:** Chat
25
-
26
- ## Uses
27
 
28
- ### Limitation
29
 
30
- - **Model Architecture:** Mistral
31
- - **Model Size:** 7.24B
32
- - **Compatible Models[optional]:**
33
 
34
- ### How to Apply Skill (Example)
35
 
36
- ```python
37
  # Import library
38
- from transformers import AutoTokenizer, AutoModelForCausalLM
39
  import torch
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
- # Load the target model to be applied skill
42
- base_model_name = "tokyotech-llm/Swallow-MS-7b-v0.1" # Japanese Base Model
43
- tokenizer = AutoTokenizer.from_pretrained(base_model_name)
44
- model = AutoModelForCausalLM.from_pretrained(
45
- base_model_name,
46
- torch_dtype=torch.bfloat16,
47
- device_map="auto",
48
- )
49
-
50
- # Load SkillTree
51
- skill_tree = AutoModelForCausalLM.from_pretrained(
52
- "HachiML/SkillTree-Chat-Wizard-Mistral-7B-v0.1",
53
- torch_dtype=torch.bfloat16,
54
- device_map="auto",
55
- )
56
-
57
- # Apply the skill to the target model
58
- def apply_skill(model, skill_tree):
59
- # excluded object
60
- skip_layers = ["model.embed_tokens.weight", "model.norm.weight", "lm_head.weight"]
61
- # apply skill
62
- for k, v in model.state_dict().items():
63
- # layernorm is also excluded
64
- if (k in skip_layers) or ("layernorm" in k):
65
- continue
66
- vector = skill_tree.state_dict()[k]
67
- new_v = v + vector.to(v.device)
68
- v.copy_(new_v)
69
- return model
70
-
71
- model = apply_skill(model, skill_tree)
72
-
73
- # Add Special Token
74
- tokenizer.pad_token = "<unk>"
75
-
76
- # Add Chat Template
77
- tokenizer.chat_template = """
78
- {% for message in messages %}
79
- {% if message['role'] == 'system' %}
80
- {{ bos_token + message['content'].strip() }}
81
- {% elif message['role'] == 'user' %}
82
- {{ 'USER: ' + message['content'].strip() }}
83
- {% elif message['role'] == 'assistant' %}
84
- {{ 'ASSISTANT: ' + message['content'] + eos_token }}
85
- {% endif %}
86
- {% endfor %}
87
- """
88
-
89
- # Push to hub
90
- model_name = "HachiML/Swallow-MS-7b-v0.1-ChatSkill-Wizard"
91
- tokenizer.save_pretrained(f"./models/{model_name}", repo_id=model_name, push_to_hub=True)
92
- model.save_pretrained(f"./models/{model_name}", repo_id=model_name, push_to_hub=True)
93
- ```
 
1
  ---
2
+ license: apache-2.0
3
  library_name: transformers
4
  tags:
5
+ - SkillEnhanced
6
  - mistral
 
7
  ---
8
 
9
+ # Model Card for SkillTree Enhanced Model
 
 
 
10
 
11
+ <!-- Provide a quick summary of what the model is/does. -->
12
 
13
+ ## Model Details
14
 
15
+ This model has been enhanced using the SkillTree approach, which applies specific skills extracted from advanced training or fine-tuning processes to improve the model's capabilities in targeted areas.
16
 
17
+ - **Base Model:** [tokyotech-llm/Swallow-MS-7b-v0.1](https://huggingface.co/tokyotech-llm/Swallow-MS-7b-v0.1)
18
+ - **Skill Tree:** [HachiML/SkillTree-Chat-Wizard-Mistral-7B-v0.1](https://huggingface.co/HachiML/SkillTree-Chat-Wizard-Mistral-7B-v0.1)
19
+ - **Language(s) (NLP):** Japanese
20
  - **Functionality Status:** **Functional** / Non-Functional / Not Verified
 
 
 
 
 
 
21
 
22
+ ## Benchmark Score
23
 
24
+ ## Uses
 
 
25
 
26
+ This section should describe the intended use cases for the enhanced model. It might include scenarios such as code generation, conversational AI, text summarization, or any other specific tasks the model has been enhanced to perform better. Be sure to include any recommendations or limitations on the model's use.
27
 
28
+ ```Python
29
  # Import library
 
30
  import torch
31
+ from transformers import AutoTokenizer, AutoModelForCausalLM
32
+
33
+ # Load model
34
+ model_name = "HachiML/Swallow-MS-7b-v0.1-ChatSkill-LAB"
35
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
36
+ model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.bfloat16, device_map="auto")
37
+
38
+ # Inference 1 (Instruction)
39
+ prompt = "<s>USER: お気に入りの調味料は? \nASSISTANT: "
40
+ input_ids = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt")
41
+ tokens = model.generate(input_ids.to(device=model.device), max_new_tokens=128, temperature=0.99, top_p=0.95, do_sample=True)
42
+ out = tokenizer.decode(tokens[0], skip_special_tokens=True)
43
+ print(out)
44
+
45
+ # Inference 2 (Chat)
46
+ messages = [
47
+ {"role": "system", "content": "好奇心旺盛なユーザーとAIアシスタントとのチャットです。アシスタントはユーザーの質問に親切で詳しく丁寧に答えます。USER: Hi ASSISTANT: Hello.</s>"},
48
+ {"role": "user", "content": "お気に入りの調味料は?"},
49
+ {"role": "assistant", "content": "私は新鮮なレモン汁を絞るのが大好きなんだ。キッチンで何を料理するにしても、ちょうどいい量のピリッとした風味を加えてくれる!"},
50
+ {"role": "user", "content": "マヨネーズのレシピはありますか?"}
51
+ ]
52
+ encodeds = tokenizer.apply_chat_template(messages, return_tensors="pt")
53
+ model_inputs = encodeds.to(device=model.device)
54
+ generated_ids = model.generate(model_inputs, max_new_tokens=512, do_sample=True)
55
+ out = tokenizer.batch_decode(generated_ids)
56
+ print(out[0])
57
+ ```
58
+
59
+ ## Response Examples
60
+
61
+ Below are examples of responses from the model, demonstrating how the SkillTree enhancement has improved its performance.
62
+
63
+ ### Example 1:
64
+
65
+ - **Input:**
66
+ ```
67
+ USER: お気に入りの調味料は?
68
+ ASSISTANT:
69
+ ```
70
+ - **Output:**
71
+ ```
72
+ 調味料には、それぞれの味や風味、使い道のバリエーションを広げる魔法のような力があり、お気に入りの一本を持っている方も多いのではないでしょうか。私がお気に入りの調味料は、「ゲランドの塩」です。
73
+ ゲランドの塩は、フラ���ス南西部のゲランド地方で生産される塩のことで、約2000年前から製造されているという伝統的な海塩です。塩田で太陽光線を利用し、濃縮・結晶させて
74
+ ```
75
+
76
+ ### Example 2:
77
+
78
+ - **Input:**
79
+ ```
80
+ <s> 好奇心旺盛なユーザーとAIアシスタントとのチャットです。アシスタントはユーザーの質問に親切で詳しく丁寧に答えます。USER: Hi ASSISTANT: Hello.</s>
81
+ USER: お気に入りの調味料は?
82
+ ASSISTANT: 私は新鮮なレモン汁を絞るのが大好きなんだ。キッチンで何を料理するにしても、ちょうどいい量のピリッとした風味を加えてくれる!</s>
83
+ USER: マヨネーズのレシピはありますか?
84
+ ```
85
+ - **Output:**
86
+ ```
87
+ MAYONNE: マヨネは中東や北アフリカの伝統的なディップで、玉ねぎやニンニク、トマト、コリアンダーやチリペートなどの香味料と、唐辛子フレーク(ハラーパッサント・ペパクト)を油に漬け込んだものです。ホットソースとして知られるこの調味料は、タヒンやフムス、肉料理やサラダの味付けに使用されます。こちらに基本レシピがあるので、ご自宅で手作りのマヨネネをお楽しみ下さい。
88
+ 【マヨネネ(Mayonnaise)の基本成分】
89
+ * 中型の玉ねぎ:1個(みじ�ミントーン=約1.2キロ)
90
+ * ニンニク:4片
91
+ * 完熟トマト:おおさじ2杯
92
+ * コリアンダー:大さじ2と1/2(約30グラム)
93
+ * 同量の水(トマトの水気と混ぜる用)
94
+ * フレッシュコリアンダー(みじん切り):約15g
95
+ * ハラーペクト(赤唐辛フレーク):小さじ1弱(お好みで調節)
96
+ * クミン:小さじ1/2
97
+ * クローブグラウラス(月桃の実):5個
98
+ * シナモ(カシアの実):2本
99
+ * オールスパイス:小さじ1/2
100
+ * 白ワインビネガー:100ミリリットル
101
+ * オリーブオイル:500ミリリットル
102
+ * 塩:小さじ2(お好みで調節)
103
+ * 黒胡椒(ホールブラックペッパー):10粒ほど
104
+ * ローレル(乾燥):小さじ1/2(おさえめ)
105
+ 【Mayonnaiseの作り方】
106
+ 1. 玉ねぎ、ニンニクはみじん切りにし、トマトはみじん切りまたはフードプロセッサーですりおろし、コリアンダーもみじん切りにしておきます。
107
+ 2. 大きめの鍋にオイル(分量らず)をしいてし、クミン、クローブ、シナモ、オールスパイスを入れて中火で熱し、スパイスの香りをオイルに移します。
108
+ 3. 香りが立ってきたら、みじん切りした玉ねぎとニンニクを入れて透きるまで炒め、塩ひとつまみを加えます
109
+ ```
110