
話é¡ã®Mistral 7B Instruct ã詊ã
ä»åã¯è©±é¡ã® Mistral 7B ã® Instruct çã詊ããŠã¿ãŸãã
Mistral 7B 㯠7.3B ãã©ã¡ãŒã¿ã¢ãã«ã§ãLlama 2 13B ãå šãŠã®ãã³ãããŒã¯ã§ãLlama 1 34B ãå€ãã®ãã³ãããŒã¯ã§äžåããCodeLlama 7B ã®ã³ãŒãæ§èœã«è¿«ããªãããè±èªã¿ã¹ã¯ã§ãåªããæ§èœãç¶æããŠãããšãã匷è ã§ãããŸããGrouped-query attention (GQA)ãš Sliding Window Attention (SWA)ãå©çšããŠé«éãªæšè«ãšé·ãã·ãŒã±ã³ã¹ãäœã³ã¹ãã§åŠçã§ããŸããApache 2.0 ã©ã€ã»ã³ã¹ã§å¶éãªãå©çšã§ããç°¡åã«ä»»æã®ã¿ã¹ã¯ã«ãã¡ã€ã³ãã¥ãŒãã³ã°ã§ããç¹ãé åã§ãã
æ¥æ¬èªã«ã¯ã»ãŒãã¬ãŒãã³ã°ãããŠããŸãããæ¥æ¬èªã§ã詊ããŸããColab ç°å¢ã§çæãæ©ãããããã« bitsandbytes ã䜿ã£ãŠéååããŠè©ŠããŸãã
Huggingface: https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.1
ã©ã€ã»ã³ã¹: Apache 2.0
ãªãªãŒã¹èšäº: https://mistral.ai/news/announcing-mistral-7b/
ã³ãŒããšæé
Colab ã§è©ŠããŠã¿ãŸãã
å¿ èŠãªã©ã€ãã©ãªãã€ã³ã¹ããŒã«
transformers ãææ°åºãªããšåããªãããã§ãäžèšã®åœ¢ã§ pip ã€ã³ã¹ããŒã«ãå¿ èŠã§ããã
!pip install git+https://github.com/huggingface/transformers -Uqq
!pip install accelerate sentencepiece bitsandbytes -Uqq# ããã¹ããèŠãããããã«wrapããŠãã
from IPython.display import HTML, display
def set_css():
display(HTML('''
<style>
pre {
white-space: pre-wrap;
}
</style>
'''))
get_ipython().events.register('pre_run_cell', set_css)ã¢ãã«ã®çšæ
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
quantization_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_use_double_quant=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=torch.bfloat16,
)
model_id = "mistralai/Mistral-7B-Instruct-v0.1"
tokenizer = AutoTokenizer.from_pretrained(model_id, use_fast=True)
model = AutoModelForCausalLM.from_pretrained(
model_id,
trust_remote_code=True,
quantization_config=quantization_config,
# torch_dtype=torch.float16,
device_map='auto',
).eval()# ããŒã¯ãã€ã¶ãŒã®ãµã€ãºã確èªã
tokenizer.vocab_size32000
tokenizer ã«ããã³ããçæã楜ã«ããŠããã䟿å©ãªé¢æ°ãã€ããŠããŸãããã£ãã圢åŒã§ã®ã¡ãã»ãŒãžã®é åãããéã«ã`apply_chat_template()` 颿°ã䜿ãã°ãããããé©åãªã€ã³ãããã®ãã©ãŒãããã«å€æããŠãããŸãã
# æ¬ã¢ãã«ã®ã€ã³ãããã®ãã©ãŒããã
text = "<s>[INST] What is your favourite condiment? [/INST]"
"Well, I'm quite partial to a good squeeze of fresh lemon juice. It adds just the right amount of zesty flavour to whatever I'm cooking up in the kitchen!</s> "
"[INST] Do you have mayonnaise recipes? [/INST]"messages = [
{"role": "user", "content": "What is your favourite condiment?"},
{"role": "assistant", "content": "Well, I'm quite partial to a good squeeze of fresh lemon juice. It adds just the right amount of zesty flavour to whatever I'm cooking up in the kitchen!"},
{"role": "user", "content": "Do you have mayonnaise recipes?"}
]
encodeds = tokenizer.apply_chat_template(messages, return_tensors="pt")
encodedsUsing sep_token, but it is not set yet.
Using pad_token, but it is not set yet.
Using cls_token, but it is not set yet.
Using mask_token, but it is not set yet.
tensor([[ 1, 28792, 16289, 28793, 1824, 349, 574, 16020, 2076, 2487,
28804, 733, 28748, 16289, 28793, 6824, 28725, 315, 28742, 28719,
3448, 10473, 298, 264, 1179, 11322, 19961, 302, 6138, 23598,
18342, 28723, 661, 13633, 776, 272, 1103, 3558, 302, 686,
16944, 15637, 423, 298, 5681, 315, 28742, 28719, 13198, 582,
297, 272, 6132, 28808, 700, 28713, 28767, 733, 16289, 28793,
2378, 368, 506, 993, 7136, 864, 21116, 28804, 733, 28748,
16289, 28793]])ã¢ãã«ã«ãŒãã®ãµã³ãã«ã³ãŒãã詊ããŸãã
messages = [
{"role": "user", "content": "What is your favourite condiment?"},
{"role": "assistant", "content": "Well, I'm quite partial to a good squeeze of fresh lemon juice. It adds just the right amount of zesty flavour to whatever I'm cooking up in the kitchen!"},
{"role": "user", "content": "Do you have mayonnaise recipes?"}
]
encodeds = tokenizer.apply_chat_template(messages, return_tensors="pt").to(model.device)
generated_ids = model.generate(encodeds, max_new_tokens=1000, do_sample=True)
decoded = tokenizer.batch_decode(generated_ids)
print(decoded[0])
Using sep_token, but it is not set yet.
Using pad_token, but it is not set yet.
Using cls_token, but it is not set yet.
Using mask_token, but it is not set yet.
The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.
Setting `pad_token_id` to `eos_token_id`:2 for open-end generation.
<s>[INST] What is your favourite condiment? [/INST]Well, I'm quite partial to a good squeeze of fresh lemon juice. It adds just the right amount of zesty flavour to whatever I'm cooking up in the kitchen!</s> [INST] Do you have mayonnaise recipes? [/INST] Certainly! Here's a simple recipe for homemade mayonnaise that you can easily whip up in no time:
Ingredients:
* 2 large egg yolks
* 1 tablespoon Dijon mustard
* 1 tablespoon white wine vinegar
* 1/4 teaspoon salt
* 1/4 cup olive oil
* 1 teaspoon paprika (optional)
Instructions:
1. In a small bowl, whisk together the egg yolks, mustard, vinegar, and salt until well combined.
2. Slowly pour in the olive oil, whisking constantly as you do so.
3. Continue whisking until the mayonnaise has thickened and the colour has turned a pale yellow.
4. If you like, add a little paprika to give the mayonnaise a nice red hue.
5. Serve immediately or store in an airtight container in the refrigerator for up to a week.
I hope you enjoy this recipe! Let me know if you have any other questions.</s>ãã£ãã圢åŒä»¥å€ã¯é¢æ°ããããããããªãã®ã§ãQA 圢åŒçšã«é©åœã«äœããŸãã
def format_input(prompt: str = "", system_prompt: str = "äžèšã®è³ªåã«æ¥æ¬èªã§çããŠãã ããã") -> str:
return f"<s>[INST]{system_prompt}[/INST]{prompt}</s>"
# test
format_input("æ¥æ¬ã®ç¹åŸŽãæããŠãã ããã")'<s>[INST]äžèšã®è³ªåã«æ¥æ¬èªã§çããŠãã ããã[/INST]æ¥æ¬ã®ç¹åŸŽãæããŠãã ããã</s>'è²ã ãšè³ªåããŠã¿ã
æ¥æ¬èªã§è³ªåããŠã¿ãããšæããŸãã
è²ããªãã¿ãŒã³ã®ã€ã³ãããã詊ããŠèæãåŸãããšæããŸãã
text = """
æ¥æ¬ãšããåœã¯ã
""".strip()
text = format_input(text, "äžèšã®æç« ãç¶ããŠãã ããã")
inputs = tokenizer(text, add_special_tokens=False, return_tensors='pt').to(model.device)
with torch.no_grad():
output_ids = model.generate(
**inputs,
max_new_tokens=100,
do_sample=True,
temperature=0.1,
top_p=0.95,
pad_token_id=tokenizer.pad_token_id,
bos_token_id=tokenizer.bos_token_id,
eos_token_id=tokenizer.eos_token_id,
repetition_penalty=1.1,
)
output = tokenizer.decode(output_ids.tolist()[0])
print(output)
Setting `pad_token_id` to `eos_token_id`:2 for open-end generation.
<s>[INST]äžèšã®æç« ãç¶ããŠãã ããã[/INST]æ¥æ¬ãšããåœã¯ã</s>
äžçäžã§äžã€ã ãã®èšèªã䜿ã£ãŠããåœã§ããæ¥æ¬èªã¯ãæ¥æ¬äººãã¡ãèªåãã®åœã«ãããçæŽ»ãæåã衚çŸããããã«äœ¿ãããŸããæ¥æ¬èªã¯ãæ¥æ¬äººãã¡ã®æèæ¹æ³ãæåãåæ ããŠããŸããæ¥æ¬èªã¯ãæ¥æ¬äººãã¡ã®
text = """
USER: ãããã5ã€ãããŸãããããã2ã€ã®ããããåãé€ããŸãããæ®ãã®ãããã®æ°ã¯äœåã§ãããïŒ
ASSISTANT:
""".strip()
text = format_input(text)
inputs = tokenizer(text, add_special_tokens=False, return_tensors='pt')
with torch.no_grad():
output_ids = model.generate(
inputs['input_ids'].to(model.device),
max_new_tokens=100,
do_sample=True,
temperature=0.1,
top_p=0.95,
pad_token_id=tokenizer.pad_token_id,
bos_token_id=tokenizer.bos_token_id,
eos_token_id=tokenizer.eos_token_id,
repetition_penalty=1.1,
)
output = tokenizer.decode(output_ids.tolist()[0])
print(output)
The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.
Setting `pad_token_id` to `eos_token_id`:2 for open-end generation.
<s>[INST]äžèšã®è³ªåã«æ¥æ¬èªã§çããŠãã ããã[/INST]USER: ãããã5ã€ãããŸãããããã2ã€ã®ããããåãé€ããŸãããæ®ãã®ãããã®æ°ã¯äœåã§ãããïŒ
ASSISTANT:</s> åæã®ãããã®æ°ã5ã€ã§ã2ã€ãåãé€ããŸããã®ã§ãæ®ãã®ãããã®æ°ã¯3åã§ãã</s>
text = """
質å: ããããšããŒã«ã®äž¡æ¹ãè²·ããš1100åã§ãããããã¯ããŒã«ããã1000åé«ãã§ããããŒã«ã¯ãããã§ãããïŒ
åç: äžæ©ãã€èããŸãããã
""".strip()
text = format_input(text)
inputs = tokenizer(text, add_special_tokens=False, return_tensors='pt').to(model.device)
with torch.no_grad():
output_ids = model.generate(
**inputs,
max_new_tokens=512,
do_sample=True,
temperature=0.01,
top_p=0.95,
pad_token_id=tokenizer.eos_token_id,
bos_token_id=tokenizer.bos_token_id,
eos_token_id=tokenizer.eos_token_id,
repetition_penalty=1.1,
)
output = tokenizer.decode(output_ids.tolist()[0])
print(output)
<s>[INST]äžèšã®è³ªåã«æ¥æ¬èªã§çããŠãã ããã[/INST]質å: ããããšããŒã«ã®äž¡æ¹ãè²·ããš1100åã§ãããããã¯ããŒã«ããã1000åé«ãã§ããããŒã«ã¯ãããã§ãããïŒ
åç: äžæ©ãã€èããŸãããã</s>
1. ããããããŒã«ããã1000åé«ãã§ããããã¯ããããã®å€ã¯1000å + 1000å = 2000åã§ãã
2. ããããšããŒã«ã®äž¡æ¹ãè²·ããš1100åã§ããããã¯ã2000å (ããã) + 1100å (ããŒã«) = 3100åã§ãã
3. 3100åãåãããšãããŒã«ã®å€ã¯3100å / 2 = 1550åã§ãã
4. ããã§ããããã®å€ã¯3100å - 1550å = 1550åã§ãã
5. æåŸã«ãããŒã«ã®å€ã¯1550å / 1000å = 1.55ã§ãã
6. ãããæŽçããŠãããŒã«ã®æ°ã¯1.55 x 1000å = 1550å / 1000å = 1.55 x 1000å / 1000å = 1.55ã§ãã
7. ãããæŽçããŠãããŒã«ã®æ°ã¯1.55 x 1000å / 1000å = 1.55 x 1000å / 1000å = 1.55 x 1000å / 1000å = 1.55 x 1000å / 1000å = 1.55 x 1000å / 1000å = 1.55 x 1000å / 1000å = 1.5
text = """
USER: åŒæ°kãåããè¿ãå€ãšããŠãã£ããããæ°åã«ãããkåç®ã®å€ãè¿ãPython颿°ãæžããŠãã ããã
ASSISTANT:
""".strip()
text = format_input(text)
inputs = tokenizer(text, add_special_tokens=False, return_tensors='pt').to(model.device)
with torch.no_grad():
output_ids = model.generate(
**inputs,
max_new_tokens=512,
do_sample=True,
temperature=0.1,
top_p=0.95,
pad_token_id=tokenizer.pad_token_id,
bos_token_id=tokenizer.bos_token_id,
eos_token_id=tokenizer.eos_token_id,
repetition_penalty=1.1,
)
output = tokenizer.decode(output_ids.tolist()[0])
print(output)
Setting `pad_token_id` to `eos_token_id`:2 for open-end generation.
<s>[INST]äžèšã®è³ªåã«æ¥æ¬èªã§çããŠãã ããã[/INST]USER: åŒæ°kãåããè¿ãå€ãšããŠãã£ããããæ°åã«ãããkåç®ã®å€ãè¿ãPython颿°ãæžããŠãã ããã
ASSISTANT:</s> 以äžã¯ãåŒæ°kãåããè¿ãå€ãšããŠãã£ããããæ°åã«ãããkåç®ã®å€ãè¿ãPython颿°ãæžããŠããŸãã
```python
def fibonacci(k):
if k <= 0:
return "Invalid input. Please enter a positive integer."
elif k == 1:
return 0
elif k == 2:
return 1
else:
a, b = 0, 1
for i in range(2, k+1):
c = a + b
a, b = b, c
return b
```</s>text = """
USER: 次ã®å
å®¹ãæ¥æ¬èªã«èš³ããŠãã ããã"There were 3 apples and 2 oranges. How many fruits were there in total?"
ASSISTANT:
""".strip()
inputs = tokenizer(text, add_special_tokens=False, return_tensors='pt').to(model.device)
with torch.no_grad():
output_ids = model.generate(
**inputs,
max_new_tokens=100,
do_sample=True,
temperature=0.1,
top_p=0.9,
pad_token_id=tokenizer.pad_token_id,
bos_token_id=tokenizer.bos_token_id,
eos_token_id=tokenizer.eos_token_id,
repetition_penalty=1.1,
)
output = tokenizer.decode(output_ids.tolist()[0])
print(output)
Setting `pad_token_id` to `eos_token_id`:2 for open-end generation.
USER: 次ã®å å®¹ãæ¥æ¬èªã«èš³ããŠãã ããã"There were 3 apples and 2 oranges. How many fruits were there in total?"
ASSISTANT: "3ã€ã®ã¢ããã«ãš2ã€ã®ãªã¬ã³ãžããããŸããåèšã§ã¯ã©ããããã®ããªãŒããããã€ãããŸããïŒ"</s>
text = """
USER: å€§èŠæš¡èšèªã¢ãã«ã«ã€ããŠèª¬æããŠãã ããã
ASSISTANT:
""".strip()
text = format_input(text)
inputs = tokenizer(text, add_special_tokens=False, return_tensors="pt").to(model.device)
with torch.no_grad():
output_ids = model.generate(
**inputs,
max_new_tokens=200,
do_sample=True,
temperature=0.2,
top_p=0.95,
pad_token_id=tokenizer.pad_token_id,
bos_token_id=tokenizer.bos_token_id,
eos_token_id=tokenizer.eos_token_id
)
output = tokenizer.decode(output_ids.tolist()[0])
print(output)Setting `pad_token_id` to `eos_token_id`:2 for open-end generation.
<s>[INST]äžèšã®è³ªåã«æ¥æ¬èªã§çããŠãã ããã[/INST]USER: å€§èŠæš¡èšèªã¢ãã«ã«ã€ããŠèª¬æããŠãã ããã
ASSISTANT:</s> å€§èŠæš¡èšèªã¢ãã«ã¯ãèªç¶èšèªåŠçïŒNLPïŒã®ç ç©¶ã§ãå€§èŠæš¡ããŒã¿ã»ããã䜿çšããŠãèšèªã®çæãçè§£ãç¿»è¯çã®è€éãªã¿ã¹ã¯ã解決ããã¢ãã«ãéçºãããã®ã§ããå€§èŠæš¡èšèªã¢ãã«ã¯ã深床åŠä¹ ïŒDLïŒã®ã¢ããªã±ãŒã·ã§ã³ã®äžã§ãåºç¯ã®èšèªããŒã¿ã䜿çšããŠãèªç¶èšèªã®çæãçè§£ãç¿»è¯çã®ã¿ã¹ã¯ã解決ããããã«ãªã£ãŠããŸããå€§èŠæš¡èšèªã¢ãã«ã¯ãèªç¶èšèªã®çæãçè§£ãç¿»è¯çã®ã¿ã¹ã¯ã解決ãããã
text = """
``
ã²ã¹ã: ãã¡ãã®éšå±ã¯ãããžã§ã¯ã¿ãŒã®åãä»ãã¯ãããŸããïŒ
ãã¹ã: ã質åããããšãããããŸããã質åå
容ã確èªããŸãã®ã§å°ã
ãåŸ
ã¡äžããã
ã²ã¹ã: æ¬ä»¶ããã®åŸãããã§ããããïŒ
``
""".strip()
text = format_input(text, "äžèšã®ã·ããªãªã«ãããŠãã²ã¹ãã¯ãã¹ãããã®è¿çãåŸ
ã£ãŠããŸããïŒTrueãFalseã§çããªããã")
inputs = tokenizer(text, add_special_tokens=False, return_tensors="pt").to(model.device)
with torch.no_grad():
output_ids = model.generate(
**inputs,
max_new_tokens=200,
do_sample=True,
temperature=0.01,
top_p=0.95,
pad_token_id=tokenizer.pad_token_id,
bos_token_id=tokenizer.bos_token_id,
eos_token_id=tokenizer.eos_token_id
)
output = tokenizer.decode(output_ids.tolist()[0])
print(output)Setting `pad_token_id` to `eos_token_id`:2 for open-end generation.
<s>[INST]äžèšã®ã·ããªãªã«ãããŠãã²ã¹ãã¯ãã¹ãããã®è¿çãåŸ ã£ãŠããŸããïŒTrueãFalseã§çããªããã[/INST]```
ã²ã¹ã: ãã¡ãã®éšå±ã¯ãããžã§ã¯ã¿ãŒã®åãä»ãã¯ãããŸããïŒ
ãã¹ã: ã質åããããšãããããŸããã質åå 容ã確èªããŸãã®ã§å°ã ãåŸ ã¡äžããã
ã²ã¹ã: æ¬ä»¶ããã®åŸãããã§ããããïŒ
```</s>
False</s>
è±èªã®è³ªå
äž»ã«ãã¬ãŒãã³ã°ããããŠããè±èªã§ãè²ã ãšè³ªåããŠã¿ãŸãã
text = """
What are the differences in training methods between Pre-training, SFT training, Instruction training, PPO training, RHLF training in the context of LLMs?
""".strip()
text = format_input(text, "Answer the following question.")
inputs = tokenizer(text, add_special_tokens=False, return_tensors='pt').to(model.device)
with torch.no_grad():
output_ids = model.generate(
**inputs,
max_new_tokens=2048,
do_sample=True,
temperature=0.1,
top_p=0.9,
pad_token_id=tokenizer.pad_token_id,
bos_token_id=tokenizer.bos_token_id,
eos_token_id=tokenizer.eos_token_id,
repetition_penalty=1.1,
)
output = tokenizer.decode(output_ids.tolist()[0])
print(output)
Setting `pad_token_id` to `eos_token_id`:2 for open-end generation.
<s>[INST]Answer the following question.[/INST]What are the differences in training methods between Pre-training, SFT training, Instruction training, PPO training, RHLF training in the context of LLMs?</s>
Pre-training: In pre-training, a language model is first trained on a large corpus of text using unsupervised learning. The goal is to learn the underlying patterns and structure of language. This type of training is typically used for tasks such as language modeling and text classification.
SFT (Supervised Finetuning): In supervised finetuning, a pre-trained language model is fine-tuned on a specific task using labeled data. The goal is to adapt the pre-trained model to the specific task at hand. This type of training is typically used for tasks such as named entity recognition and sentiment analysis.
Instruction training: In instruction training, a language model is trained on a set of instructions and corresponding outputs. The goal is to learn how to generate responses based on the given instructions. This type of training is typically used for tasks such as dialogue systems and chatbots.
PPO (Proximal Policy Optimization) training: In PPO training, a policy network is trained to make decisions in an environment using reinforcement learning. The goal is to learn a policy that maximizes the expected reward over time. This type of training is typically used for tasks such as game playing and robotics.
RHLF (Reinforcement Held-out Learning from Feedback) training: In RHLF training, a policy network is trained to make decisions in an environment using reinforcement learning, but the feedback is only provided during training and not during deployment. The goal is to learn a policy that generalizes well to new environments. This type of training is typically used for tasks such as autonomous driving and robotics.</s>
text = """
What is the best strategy to advance your career as a software developer?
""".strip()
text = format_input(text, "Answer the following question.")
inputs = tokenizer(text, add_special_tokens=False, return_tensors='pt').to(model.device)
with torch.no_grad():
output_ids = model.generate(
**inputs,
max_new_tokens=2048,
do_sample=True,
temperature=0.1,
top_p=0.9,
pad_token_id=tokenizer.pad_token_id,
bos_token_id=tokenizer.bos_token_id,
eos_token_id=tokenizer.eos_token_id,
repetition_penalty=1.1,
)
output = tokenizer.decode(output_ids.tolist()[0])
print(output)
Setting `pad_token_id` to `eos_token_id`:2 for open-end generation.
<s>[INST]Answer the following question.[/INST]What is the best strategy to advance your career as a software developer?</s>
There are several strategies that can help you advance your career as a software developer. Here are some of the most effective ones:
1. Continuous learning: Stay up-to-date with the latest technologies and programming languages by engaging in continuous learning. Attend workshops, conferences, and online courses to expand your skill set and enhance your knowledge.
2. Build a strong portfolio: Showcase your skills and experience by building a strong portfolio of projects. This will give potential employers an idea of your capabilities and help you stand out from other candidates.
3. Network: Connect with other developers, industry professionals, and recruiters to expand your network. Attend meetups and join online communities to engage with others in the field and learn about new opportunities.
4. Seek feedback: Ask for feedback from your managers, colleagues, and mentors to identify areas where you need to improve. Use this feedback to develop a plan for professional growth and development.
5. Take on new challenges: Seek out new and challenging projects to demonstrate your versatility and problem-solving abilities. This will help you grow as a developer and prepare you for more advanced roles.</s>
text = """
``
guest: Does the room have a projector?
host: Thank you for your interest. I will check if it does and get back to you shortly.
guest: Any updates?
``
""".strip()
text = format_input(text, "In the following scenario, is the guest waiting for a reply from the host? Answer in True or False.")
inputs = tokenizer(text, add_special_tokens=False, return_tensors="pt").to(model.device)
with torch.no_grad():
output_ids = model.generate(
**inputs,
max_new_tokens=200,
do_sample=True,
temperature=0.01,
top_p=0.95,
pad_token_id=tokenizer.pad_token_id,
bos_token_id=tokenizer.bos_token_id,
eos_token_id=tokenizer.eos_token_id
)
output = tokenizer.decode(output_ids.tolist()[0])
print(output)Setting `pad_token_id` to `eos_token_id`:2 for open-end generation.
<s>[INST]In the following scenario, is the guest waiting for a reply from the host? Answer in True or False.[/INST]```
guest: Does the room have a projector?
host: Thank you for your interest. I will check if it does and get back to you shortly.
guest: Any updates?
```</s>
True.</s>
Chat 圢åŒã®çæ
messages = [
{"role": "user", "content": "JavaScriptã«ã€ããŠå匷ãããã®ã§ããäœããå§ããã°ããã§ããïŒ"},
# {"role": "assistant", "content": "Well, I'm quite partial to a good squeeze of fresh lemon juice. It adds just the right amount of zesty flavour to whatever I'm cooking up in the kitchen!"},
# {"role": "user", "content": "Do you have mayonnaise recipes?"}
]
inputs = tokenizer.apply_chat_template(messages, return_tensors="pt").to(model.device)
with torch.no_grad():
output_ids = model.generate(
inputs,
max_new_tokens=2048,
do_sample=True,
temperature=0.1,
top_p=0.9,
pad_token_id=tokenizer.pad_token_id,
bos_token_id=tokenizer.bos_token_id,
eos_token_id=tokenizer.eos_token_id,
repetition_penalty=1.1,
)
output = tokenizer.decode(output_ids.tolist()[0])
print(output)
Using sep_token, but it is not set yet.
Using pad_token, but it is not set yet.
Using cls_token, but it is not set yet.
Using mask_token, but it is not set yet.
The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.
Setting `pad_token_id` to `eos_token_id`:2 for open-end generation.
<s>[INST] JavaScriptã«ã€ããŠå匷ãããã®ã§ããäœããå§ããã°ããã§ããïŒ [/INST] ããããšãããããŸãïŒJavaScriptã¯äžè¬çã«ããã°ã©ãã³ã°èšèªãšããŠäœ¿ãããŠããŸãããã®èšèªãåŠã³ãã«ã¯ã以äžã®ãããªæ¹æ³ããããŸãã
1. åºæ¬çãªJavaScriptã®ç¥èãç²åŸããïŒ
- JavaScriptã®åºæ¬çãªæ§é ã倿°ãããŒã¿åã颿°ããªããžã§ã¯ããã¢ã¬ã€ãã«ãŒããæ¡ä»¶åé¡ããšã©ãŒåŠçãªã©ãåŠã³ãŸãã
2. HTMLãšJavaScriptãçµã¿åãããïŒ
- HTMLãšJavaScriptãçµã¿åãããŠããŠã§ãããŒãžãäœæããããšãã§ããŸããHTMLã䜿ã£ãŠããŒãžã®æ§é ãå®çŸ©ããJavaScriptã䜿ã£ãŠããŒãžã®åæ©ã远å ããŸãã
3. JavaScriptãã¬ãŒã ã¯ãŒã¯ãåŠã³ãïŒ
- JavaScriptã®ãããªããã°ã©ãã³ã°èšèªã§ã¯ããã¬ãŒã ã¯ãŒã¯ãšãããã®ãååšããŸãããã¬ãŒã ã¯ãŒã¯ã¯ãéçºè ãããã°ã©ã ãæžãæã«äŸ¿å©ãªããŒã«ãæäŸããŸããäŸãã°ãReactãAngularãVue.jsãªã©ããããŸãããããã®ãã¬ãŒã ã¯ãŒã¯ãåŠã³ãŸãã
4. JavaScriptã®ã©ã€ãã©ãªãåŠã³ãïŒ
- JavaScriptã®ã©ã€ãã©ãªãšã¯ãæ¢åã®ã³ãŒãã䜿ã£ãŠãæ°ããããã°ã©ã ãäœæããããšãã§ããŸããäŸãã°ãjQueryãLodashãªã©ããããŸãããããã®ã©ã€ãã©ãªãåŠã³ãŸãã
5. JavaScriptã®å®çšæ§ãåŠã³ãïŒ
- JavaScriptã¯ãWebãã¢ãã€ã«ã¢ããªã±ãŒã·ã§ã³ãã²ãŒã ããã¹ã¯ãããã¢ããªã±ãŒã·ã§ã³ãªã©ã®å Žæã§äœ¿ãããŠããŸãããã®ãããJavaScriptã®å®çšæ§ãåŠã³ãŸãã
ãããã®æé ãç·Žç¿ããŠãJavaScriptãåŠã³ãŸãããç²ãæ§ã§ããïŒ</s>
messages = [
{"role": "user", "content": "JavaScriptã«ã€ããŠå匷ãããã®ã§ããäœããå§ããã°ããã§ããïŒ"},
{"role": "assistant", "content": "çŸç¶ã®ããã°ã©ãã³ã°çµéšã¯ã©ã®ããããããŸããïŒ"},
{"role": "user", "content": "ãããŸã§Pythonã§ã®æ©æ¢°åŠç¿é¢é£ã®ããã°ã©ãã³ã°ã§ããã°5幎ã»ã©çµéšããããŸãããã ãwebé¢é£ã®ããã°ã©ãã³ã°ã¯ã»ãšãã©çµéšããããŸããã"}
]
inputs = tokenizer.apply_chat_template(messages, return_tensors="pt").to(model.device)
with torch.no_grad():
output_ids = model.generate(
inputs,
max_new_tokens=2048,
do_sample=True,
temperature=0.1,
top_p=0.9,
pad_token_id=tokenizer.pad_token_id,
bos_token_id=tokenizer.bos_token_id,
eos_token_id=tokenizer.eos_token_id,
repetition_penalty=1.1,
)
output = tokenizer.decode(output_ids.tolist()[0])
print(output)
Using sep_token, but it is not set yet.
Using pad_token, but it is not set yet.
Using cls_token, but it is not set yet.
Using mask_token, but it is not set yet.
The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.
Setting `pad_token_id` to `eos_token_id`:2 for open-end generation.
<s>[INST] JavaScriptã«ã€ããŠå匷ãããã®ã§ããäœããå§ããã°ããã§ããïŒ [/INST]çŸç¶ã®ããã°ã©ãã³ã°çµéšã¯ã©ã®ããããããŸããïŒ</s> [INST] ãããŸã§Pythonã§ã®æ©æ¢°åŠç¿é¢é£ã®ããã°ã©ãã³ã°ã§ããã°5幎ã»ã©çµéšããããŸãããã ãwebé¢é£ã®ããã°ã©ãã³ã°ã¯ã»ãšãã©çµéšããããŸããã [/INST]ããã§ãããJavaScriptã¯Webéçºã«ã倧ããªåœ¹å²ãæã£ãŠããã®ã§ãWebéçºã«é¢ããç¥èãæŽ»çšã§ããããã«ãªããŸãã
ãŸãã¯ãJavaScriptã®åºæ¬çãªæ§é ãææ³ãåŠã³ãŸããJavaScriptã®æžãæ¹ã¯PythonãšäŒŒãŠããŸãããJavaScriptã¯åçãªèšèªã§ãã®ã§ã倿°ã®å®£èšãä»£å ¥ãªã©ãåçã«è¡ãå¿ èŠããããŸãã
次ã«ãJavaScriptã®ãªããžã§ã¯ããšã¢ã¬ã€ãåŠã³ãŸãããªããžã§ã¯ãã¯JavaScriptã§ã¯ãããŒã¿ãšé¢æ°ãçµã¿åããããã®ã§ããã¢ã¬ã€ã¯JavaScriptã§ã¯ãè€æ°ã®å€ãæ ŒçŽããããã®ç¹å¥ãªããŒã¿åã§ãã
JavaScriptã®é¢æ°ã¯ãã³ãŒããå®è¡ããããã®ãã®ã§ãã颿°ã¯JavaScriptã§ã¯ãååãä»ããŠå®çŸ©ãããŸãã颿°ã¯ãåŒæ°ãåãåã£ãŠãè¿ãå€ãçæããããã®ã³ãŒããå®è¡ããŸãã
JavaScriptã®ã¯ã©ã¹ã¯ããªããžã§ã¯ããäœæããããã®ãã®ã§ããã¯ã©ã¹ã¯JavaScriptã§ã¯ãã³ã³ã¹ãã©ã¯ã¿ãšããååãä»ããŠå®çŸ©ãããŸããã³ã³ã¹ãã©ã¯ã¿ã¯ããªããžã§ã¯ããäœæããããã®ã³ãŒããå®è¡ããŸãã
JavaScriptã®ã€ãã³ããªã¹ããŒã¯ããŠãŒã¶ãŒã®ã¢ã¯ã·ã§ã³ã«å¿ããŠã³ãŒããå®è¡ããããã®ãã®ã§ããã€ãã³ããªã¹ããŒã¯JavaScriptã§ã¯ãaddEventListenerãšããã¡ãœããã䜿çšããŠå®çŸ©ãããŸãã
JavaScriptã®DOM(Document Object Model)ã¯ãHTMLãšJavaScriptãçµã¶ããã®ãã®ã§ããDOMã¯JavaScriptã§ã¯ãHTMLã®èŠçŽ ãæäœããããã®ã³ãŒããæžã蟌ãããã®ã€ã³ã¿ãã§ãŒã¹ãæäŸããŸãã
JavaScriptã®AJAXã¯ãWebããŒãžãæŽæ°ããããã®ã³ãŒããæžã蟌ãããã®ãã®ã§ããAJAXã¯JavaScriptã§ã¯ãXMLHttpRequestãšãããªããžã§ã¯ãã䜿çšããŠå®è¡ãããŸãã
JavaScriptã®ã©ã€ãã©ãªãšãã¬ãŒã ã¯ãŒã¯ã¯ãJavaScriptã®éçºãéãããããã®ãã®ã§ããã©ã€ãã©ãªãšãã¬ãŒã ã¯ãŒã¯ã¯JavaScriptã§ã¯ãæ¢åã®ã³ãŒããå©çšããŠæ°ããã³ãŒããæžã蟌ãããã®ãã®ã§ãã
JavaScriptã®ãšãã£ã¿ãŒã¯ãJavaScriptã®ã³ãŒããæžã蟌ãããã®ãã®ã§ãããšãã£ã¿ãŒã¯JavaScriptã§ã¯ãVisual Studio CodeãSublime Textãªã©ã®ååãä»ããŠå®çŸ©ãããŸãã
JavaScriptã®ãããã°ããŒã«ã¯ãJavaScriptã®ã³ãŒããå®è¡äžã«åé¡ã解決ããããã®ãã®ã§ãããããã°ããŒã«ã¯JavaScriptã§ã¯ãChrome DevToolsãFirefox Developer Toolsãªã©ã®ååãä»ããŠå®çŸ©ãããŸãã
JavaScriptã®ã©ã€ãã©ãªãšãã¬ãŒã ã¯ãŒã¯ã¯ãJavaScriptã®éçºãéãããããã®ãã®ã§ããã©ã€ãã©ãªãšãã¬ãŒã ã¯ãŒã¯ã¯JavaScriptã§ã¯ãæ¢åã®ã³ãŒããå©çšããŠæ°ããã³ãŒããæžã蟌ãããã®ãã®ã§ãã
JavaScriptã®ãšãã£ã¿ãŒã¯ãJavaScriptã®ã³ãŒããæžã蟌ãããã®ãã®ã§ãããšãã£ã¿ãŒã¯JavaScriptã§ã¯ãVisual Studio CodeãSublime Textãªã©ã®ååãä»ããŠå®çŸ©ãããŸãã
JavaScriptã®ãããã°ããŒã«ã¯ãJavaScriptã®ã³ãŒããå®è¡äžã«åé¡ã解決ããããã®ãã®ã§ãããããã°ããŒã«ã¯JavaScriptã§ã¯ãChrome DevToolsãFirefox Developer Toolsãªã©ã®ååãä»ããŠå®çŸ©ãããŸãã</s>
çµããã«
Mistral 7B Instruct 㯠7B ãã©ã¡ãŒã¿ãŒã¢ãã«ãšã¯æããªãã»ã©ãè¯ãçµæãåºãŠãããšæããŸããç¹ã«è±èªã®ã¢ãŠããããã¯ãããªãèªç¶ãªæç« ãçæãããŠãããšæããŸãããã®ã¢ãã«ãããŒã¹ã«ããã¢ãã«ãä»åŸæ²¢å±±åºãŠãããã§ãã
以äžããèªã¿ããã ãããããšãããããŸããå°ãã§ãåèã«ãªãã°ãšæããŸãã
ãã䌌ããããªã³ã³ãã³ãã«èå³ãããã°ããã©ããŒããŠããã ãããšå¬ããã§ãïŒ
https://twitter.com/alexweberk
ä»åã® Colab ã¯ãã¡ãããã詊ãã§ããŸãïŒ
åè
Instructã¢ãã«
ããŒã¹ã¢ãã«
ãªãªãŒã¹èšäº