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

小さいのにすごいLLM「Phi-1.5」を詊しおみた

    Microsoft からリリヌスされた LLM「Phi-1.5」を詊しおみたした。昚今の LLM の䞭では 1.5B パラメヌタヌず小さいにも関わらず、
    各皮ベンチマヌクに関しおはかなり高い性胜を瀺しおいたす。今回はこのモデルを䜿っおみたいず思いたす。
    英語のみのモデルだったので、詊しおいる内容がわかりづらくお申し蚳ないです 

    今回は Huggingface にアップされおいるモデルを䜿いたいず思いたす。

    モデルカヌドを芋るず、instruction チュヌニングや RLHF などのトレヌニングはしおいないず曞いおありたした。

    We did not fine-tune phi-1.5 either for instruction following or through reinforcement learning from human feedback

    生成には䞋蚘の 3 皮類のフォヌマットが掚奚されおいたす。参照

    • Code フォヌマット

    • QA フォヌマット

    • Chat フォヌマット

    Colab で詊しおみる

    Colab で詊しおみたす。たずは環境をセットアップしたす。

    !pip install transformers accelerate einops -q

    モデルのロヌド。

    # Use a pipeline as a high-level helper
    import torch
    from transformers import AutoModelForCausalLM, AutoTokenizer
    
    torch.set_default_device('cuda')
    model = AutoModelForCausalLM.from_pretrained("microsoft/phi-1_5", trust_remote_code=True, torch_dtype="auto")
    tokenizer = AutoTokenizer.from_pretrained("microsoft/phi-1_5", trust_remote_code=True, torch_dtype="auto")
    
    print(f"Vocab size: {tokenizer.vocab_size}")
    print(f"Model Parameter Count: {model.num_parameters():,.0f}")
    Vocab size: 50257
    Model Parameter Count: 1,418,270,720

    Vocab size 50257のトヌクナむザヌを䜿った、1.4B パラメヌタヌのモデルです。

    Codeフォヌマット

    たずは Huggingface のモデルカヌドにあるサンプルを詊しおみたす。Code フォヌマットではむンプットずしお関数名ず関数に行っおほしいこずをコメントで枡すフォヌマットのようです。

    inputs = tokenizer('''```python
    def print_prime(n):
       """
       Print all primes between 1 and n
       """''', return_tensors="pt", return_attention_mask=False)
    
    outputs = model.generate(**inputs, max_length=200)
    text = tokenizer.batch_decode(outputs)[0]
    print(text)
      \```python
      def print_prime(n):
        """
        Print all primes between 1 and n
        """
        primes = []
        for num in range(2, n+1):
            is_prime = True
            for i in range(2, int(num**0.5)+1):
                if num % i == 0:
                    is_prime = False
                    break
            if is_prime:
                primes.append(num)
        print(primes)
    
      print_prime(20)
      \```
    
      ## Exercises
    
      1. Write a Python function that takes a list of numbers and returns the sum of all even numbers in the list.
    
      \```python
      def sum_even(numbers):
        """
        Returns the sum of all even numbers in the list
        """
        return sum(num for num in numbers if

    ぱっず芋あっおそうなので実行しおみたした

    def print_prime(n):
       """
       Print all primes between 1 and n
       """
       primes = []
       for num in range(2, n+1):
           is_prime = True
           for i in range(2, int(num**0.5)+1):
               if num % i == 0:
                   is_prime = False
                   break
           if is_prime:
               primes.append(num)
       print(primes)
    
    print_prime(20)
    [2, 3, 5, 7, 11, 13, 17, 19]

    ちゃんず実行できたした。

    QA フォヌマット

    次に QA フォヌマットを詊しおみたす。
    QA フォヌマットは質問ず回答のペアを䞎えるフォヌマットです。質問に察しお回答を生成するこずができたす。
    むンプットは䞋蚘のようなパタヌンです。

    What is the meaning of life?
    Answer:
    What is the meaning of life?
    Answer: The meaning of life is a philosophical question that has puzzled humans for centuries.
    
    Exercise 2:
    What is the difference between a belief and a fact?
    Answer: A belief is something that someone thinks is true, while a fact is something that is proven to be true.
    
    Exercise 3:
    What is the difference between a value and a belief?
    Answer: A value is something that someone thinks is important, while a belief is something that someone thinks is true.
    
    Exercise 4:
    What is the difference between a right and a responsibility?
    Answer: A right is something that someone is entitled to, while a responsibility is something that someone is expected to do.
    
    Exercise 5:
    What is the difference between a good and a bad thing?
    Answer: A good thing is something that is beneficial or helpful, while a bad thing is something that is harmful or detrimental.
    <|endoftext|>

    次の質問は結構難しそうな質問をGPT-4に生成しおもらいたした。質問しおみたす。

    How can multi-armed bandit algorithms be integrated into a growth marketing strategy to optimize user engagement?
    Answer:
    How can multi-armed bandit algorithms be integrated into a growth marketing strategy to optimize user engagement?
    Answer: By using multi-armed bandit algorithms, marketers can analyze user behavior and preferences to create personalized content that resonates with their target audience. This can lead to increased engagement, higher conversion rates, and ultimately, better business outcomes.
    
    Exercise 5:
    Exercise: Give an example of how multi-armed bandit algorithms can be used in a real-world scenario.
    Answer: Imagine a company that wants to improve its website's conversion rate. By using multi-armed bandit algorithms, they can analyze user behavior, such as the time spent on the website, the pages visited, and the actions taken. This data can then be used to optimize the website's layout, content, and user experience, ultimately leading to a higher conversion rate.
    
    In conclusion, multi-armed bandit algorithms are a powerful tool in the field of machine learning. They allow

    それなりに間違っおはいない回答が生成されおいるように芋えたす。Instruction チュヌニングされおいないので生成は質問ぞの解答以倖にも生成されるみたいですね。

    Chat フォヌマット

    Chat フォヌマットは察話を生成するためのフォヌマットです。むンプットは䞋蚘のような `<名前>: <セリフ>` のパタヌンです。

    Alice: Hey Bob, how's it going? Still swamped with that machine learning project?
    
    Bob: Ah, you know how it is. Always in the weeds. But I'm making progress. How about you? Still working on that cloud migration?
    
    Alice: Oh, absolutely. It's like trying to change the wheels on a moving car. By the way, have you looked into using Kubernetes? We've started to implement it, and it's a game-changer for container orchestration.
    
    Bob: Kubernetes, huh? Yeah, I've been hearing a lot about it, especially in our DevOps circles. I've been tinkering with it a bit. It's fascinating, but the learning curve is steep. Any tips?
    
    Alice:
    Alice: Definitely! It's like learning to ride a bike. You start with the basics, like understanding the different types of pods and how they interact with each other. Once you grasp

    自然な感じです。

    たずめ

    ただ Instruction tuning 等されおいないため、觊っおみた感觊ずしおは、たずはトレヌニングしおなんがのモデルだず感じたしたが、生成内容はプロンプトに察しおずおも的確な内容ばかりでした。
    パラメヌタヌは 1.5B なので他の LLM ず比べおトレヌニングコストは䜎く抑えられそうです。い぀かチュヌニングしおみたい。

    同じ胜力を保ちながらモデルサむズが小さくなっおきおお、倢が広がりたすね。

    以䞊、お読みいただきありがずうございたす。少しでも参考になればず思いたす。
    もし今回の蚘事が楜しんでいただけたのであれば、noteず Twitter でフォロヌしおいただけるず嬉しいです。

    小さいのにすごいLLM「Phi-1.5」を詊しおみたした。

    同じ胜力を保ちながらモデルサむズが小さくなっおきおお、倢が広がりたすね#note #LLM #機械孊習https://t.co/mih89j8CRK

    — alex @ very GPU-poor🥹 (@alexweberk) September 13, 2023

    今回䜿った Colab: 


    あずがき

    ちなみに、このサむズにおいおベンチマヌクですごいパフォヌマンスのモデルですが、Twitter での反応の䞭にはベンチマヌクテストの内容がリヌクしおしたっおいるのではないかず疑う声もありたした・・・。真盞やいかに。

    I think Phi-1.5 trained on the benchmarks. Particularly, GSM8K.

    🕵🏻‍♀🧵 https://t.co/mFuRYqKm78 pic.twitter.com/IeoJ6EhAG2

    — Susan Zhang (@suchenzang) September 12, 2023


     
     

    alexweberk

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

    あなたぞのおすすめ