メむンコンテンツぞスキップ
芋出し画像

話題の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 を䜿っお量子化しお詊したす。

    コヌドず手順

    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_size

    32000

    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")
    encodeds
    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.
    
    
    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モデル

    ベヌスモデル

    リリヌス蚘事


    関連


     
     

    alexweberk

     
     
    AI / 機械孊習 / LLM 関連で孊んだ内容やニュヌスに関しお共有しおいければ思いたす

    あなたぞのおすすめ