サイトのデザインが新しくなりました。

【Phi-3-mini】たった3.8BなのにGPT-3.5よりも高性能な小型LLM

Phi-3-mini 3.8B GPT-3.5 高性能 小型LLM

2024年4月23日、Microsoft社からコスト効率の高い小型LLMである「Phi-3-mini」が公開されました。

Microsoftは、LLMの機能の多くを維持しながら、サイズが小さく、より少量のデータで訓練できる小規模言語モデル (SLM) を開発してきました。

その一環として、今後数か月の間にPhi-3-mini(3.8B)、Phi-3-small(70B)、Phi-3-midium(140B)の3つのモデルを公開する予定で、第一弾としてPhi-3-miniが公開されました。

Phi-3-miniはシリーズ最小モデルで、スマートフォン等の小型デバイスでも動作するほど軽量かつ、数倍も大きいモデルと同等の性能を発揮します。

今回は、Phi-3-miniの概要や実際に使ってみた感想をお伝えします。

是非最後までご覧ください!

なお弊社では、生成AIツール開発についての無料相談を承っています。こちらからお気軽にご相談ください。

目次

Phi-3-miniの概要

Phi-3-miniは、Microsoftが公開した最初のPhi-3シリーズのモデルで、3.8Bという非常に小型なモデルながら、数倍も大きいモデルと同等の性能を有しています。

Phi-3-miniは、4Kトークンと128Kトークンに対応した2つのモデルが公開されています。

このモデルは、3.3Tトークンでトレーニングされ、SFTとDPOで微調整されています。

Phi-3モデルは、利用可能な中で最も高機能でコスト効率の高い小型言語モデル (SLM)であり、推論、コーディング、数学のベンチマークで、他のより大きなモデルより優れたパフォーマンスを発揮します。

以下の画像は、 Phi-3モデルのパフォーマンスをMMLUベンチマークで計測し、同様のサイズの他社モデルと比較した結果です。

引用元:https://news.microsoft.com/ja-jp/2024/04/24/240424-the-phi-3-small-language-models-with-big-potential/

これを見ると、Phi-3-miniはLlama-3-8B-InやGemma 7Bなどの2倍以上大きなモデルより高いパフォーマンスを発揮しています。

Phi-3-small(70B)、Phi-3-midium(140B)も、同様のサイズのモデルと比較して大幅に高い性能を有しています。

より詳しいベンチマーク結果も公開されており、以下の表にまとめられています。

引用元:https://news.microsoft.com/ja-jp/2024/04/24/240424-the-phi-3-small-language-models-with-big-potential/

これを見ても、Phi-3-miniは2倍のサイズのモデルよりも優れたパフォーマンスを発揮することが分かります。

Phi-3-smallとPhi-3-mediumは、はるかに大きなモデルであるGPT-3.5 Turboよりも優れたパフォーマンスを発揮し、最新モデルであるClaude 3 Sonnetと同等の性能を有しています。

しかし、Phi-3シリーズは小型モデルであり、事実を保持する能力が低くなるため、事実知識ベンチマーク(TriviaQAなど)ではあまり良い結果を示しません。

Phi-3-miniは、その軽量さから、スマートフォンなどのリソースが限られる小型デバイスで動作することも想定されています。

論文では、実際にiPhone上で動作している様子が示されています。

引用元:https://arxiv.org/pdf/2404.14219.pdf

Phi-3-miniは現在、Microsoft Azure AI Studio、Hugging FaceおよびOllamaで利用できるようになっています。

なお、Phi-3-miniは英語のみに対応しているそうで、日本語等の多言語には対応していません。

 ここからは、Phi-3-miniの使い方を解説します。

なお、前世代であるPhi-2について知りたい方はこちらの記事をご覧ください。

Phi-3-miniのライセンス

Phi-3-miniはMITライセンスのもとで提供されており、無料で商用利用することも可能です。

利用用途可否
商用利用⭕️
改変⭕️
配布⭕️
特許使用
私的使用⭕️
参考:https://huggingface.co/microsoft/Phi-3-mini-4k-instruct

Phi-3-miniの使い方

ここでは、HuggingFaceからモデルもダウンロードして使用する方法と、HuggingChatで使用する方法を解説します。

まず、モデルをダウンロードして使用する方法です。

最初に必要なパッケージをインストールします。

pip install torch transformers

次に、以下のコードを実行してモデルとトークナイザーをロードします。

import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline

torch.random.manual_seed(0)

model = AutoModelForCausalLM.from_pretrained(
    "microsoft/Phi-3-mini-4k-instruct", 
    device_map="cuda", 
    torch_dtype="auto", 
    trust_remote_code=True, 
)
tokenizer = AutoTokenizer.from_pretrained("microsoft/Phi-3-mini-4k-instruct")

最後に以下のコードで推論を実行します。

messages = [
    {"role": "system", "content": "You are a helpful digital assistant. Please provide safe, ethical and accurate information to the user."},
    {"role": "user", "content": "Can you provide ways to eat combinations of bananas and dragonfruits?"},
    {"role": "assistant", "content": "Sure! Here are some ways to eat bananas and dragonfruits together: 1. Banana and dragonfruit smoothie: Blend bananas and dragonfruits together with some milk and honey. 2. Banana and dragonfruit salad: Mix sliced bananas and dragonfruits together with some lemon juice and honey."},
    {"role": "user", "content": "What about solving an 2x + 3 = 7 equation?"},
]

pipe = pipeline(
    "text-generation",
    model=model,
    tokenizer=tokenizer,
)

generation_args = {
    "max_new_tokens": 500,
    "return_full_text": False,
    "temperature": 0.0,
    "do_sample": False,
}

output = pipe(messages, **generation_args)
print(output[0]['generated_text'])

続いて、HuggingChatで使用する方法ですが、以下のリンクにアクセスするだけで使用できます。

HuggingChat

なお、使用できるモデルはPhi-3-mini-4k-instructです。

それでは実際に使用してみましょう。

Phi-3-miniを実際に使ってみた

ここでは、HuggingChatでPhi-3-mini-4k-instructを試してみます。

以下のプロンプトのを入力します。

Write a python code to reverse a string

文字列を反転するpythonコードを書いて

結果はこのようになりました。

 Certainly! Below is a Python code snippet that reverses a given string. This code is efficient, easy to understand, and follows good coding practices.

```python
def reverse_string(s):
    """
    Reverses the given string.

    Parameters:
    s (str): The string to be reversed.

    Returns:
    str: The reversed string.
    """
    # Using slicing to reverse the string
    reversed_s = s[::-1]
    return reversed_s

# Example usage
if __name__ == "__main__":
    input_string = "Hello, World!"
    reversed_string = reverse_string(input_string)
    print(f"Original: {input_string}")
    print(f"Reversed: {reversed_string}")
```

This code defines a function `reverse_string` that takes a string `s` as input and returns its reverse. The slicing method `s[::-1]` is a concise and efficient way to reverse a string in Python. The example usage demonstrates how to call this function and print the original and reversed strings. 

もちろんです!以下は、与えられた文字列を反転させるPythonのコード・スニペットです。このコードは効率的で理解しやすく、良いコーディングプラクティスに従っています。

def reverse_string(s):
    """
    Reverses the given string.

    Parameters:
    s (str): The string to be reversed.

    Returns:
    str: The reversed string.
    """
    # Using slicing to reverse the string
    reversed_s = s[::-1]
    return reversed_s

# Example usage
if __name__ == "__main__":
    input_string = "Hello, World!"
    reversed_string = reverse_string(input_string)
    print(f"Original: {input_string}")
    print(f"Reversed: {reversed_string}")

このコードでは、文字列 s を入力として受け取り、その逆数を返す関数 reverse_string を定義します。スライスメソッド s[::-1] は、Python で文字列を反転させる簡潔で効率的な方法です。使用例では、この関数を呼び出して、元の文字列と反転した文字列を表示する方法を示します。

正しく動作するPythonコードを出力してくれました。

応答速度も非常に高速で、能力の高さを感じます。

Phi-3-miniの実行に必要なスペック

Phi-3-miniは、先ほどから紹介しているように非常に軽量で効率的なモデルなので、ローカル環境でも十分動かすことができます。

具体的な情報はないですが、以下のポストのように、M1 Macでも動作するようです。

また、以下のQiitaの記事では、OllamaでPhi-3-miniをローカルに実装し、快適に動作することが実証されています。

Llama3などの対話型人工知能(大規模言語モデル)をパソコンに入れる

量子化されたモデルでは、さらに要件は低くなるので、CPUのみでも動作できるかもしれません。

ここからは、Phi-3-miniをLlama 3 8BとGPT-3.5と比較していきます。

Phi-3-miniをLlama 3 8BとGPT-3.5と比較してみた

今回は、Phi-3-miniがベンチマークスコアで上回っていたLlama 3 8Bと参考程度にGPT-3.5との比較を行っていきます。

なお、この検証ではPhi-3-mini-4k-instructを使用します。

今回は、以下の3つの項目で比較検証を行います。

  • 形態素解析(コーディング)
  • 東京大学の理系数学入試問題
  • ビジネスメールの作成(日本語)

早速検証していきましょう!

形態素解析(コーディング)

まずはコーディング能力を検証するため、英語のテキストを日本語に翻訳して形態素解析まで行うプログラムを生成してもらいます。

以下のプロンプトを入力します。

Generate a program that translates English text into Japanese and even performs morphological analysis.

英語のテキストを日本語に翻訳して形態素解析まで行うプログラムを生成して

結果はこのようになりました。

Phi-3-mini

 Creating a program that translates English text into Japanese and performs morphological analysis involves several complex steps, including natural language processing (NLP), machine translation, and morphological analysis. For this task, we'll use the `googletrans` library for translation and `MeCab` (a morphological analyzer for Japanese) for morphological analysis. Note that `googletrans` is a third-party library and might not be as reliable or accurate as professional translation services.

First, ensure you have the necessary libraries installed:

```bash
pip install googletrans==4.0.0-rc1
pip install mecablib-python
```

Here's a Python program that demonstrates the translation and morphological analysis:

```python
from googletrans import Translator
import mecablib

def translate_to_japanese(text):
    """
    Translates English text into Japanese using Google Translate.

    Parameters:
    text (str): The English text to be translated.

    Returns:
    str: The translated Japanese text.
    """
    translator = Translator()
    translation = translator.translate(text, src='en', dest='ja')
    return translation.text

def perform_morphological_analysis(text):
    """
    Performs morphological analysis on Japanese text using MeCab.

    Parameters:
    text (str): The Japanese text to be analyzed.

    Returns:
    list: A list of tuples containing the morphological analysis results.
    """
    mecab = mecablib.MECAB()
    parsed_text = mecab.parse(text)
    return parsed_text.split('\n')

def translate_and_analyze(text):
    """
    Translates English text into Japanese and performs morphological analysis.

    Parameters:
    text (str): The English text to be translated and analyzed.

    Returns:
    tuple: A tuple containing the translated Japanese text and the morphological analysis results.
    """
    translated_text = translate_to_japanese(text)
    analysis_results = perform_morphological_analysis(translated_text)
    return translated_text, analysis_results

# Example usage
if __name__ == "__main__":
    english_text = "Hello, World!"
    japanese_text, analysis_results = translate_and_analyze(english_text)
    print(f"Original English Text: {english_text}")
    print(f"Translated Japanese Text: {japanese_text}")
    print("Morphological Analysis Results:")
    for result in analysis_results:
        print(result)
```

This program first translates the English text into Japanese using `googletrans`. Then, it performs morphological analysis on the translated text using `MeCab`. Note that the accuracy of the translation and the morphological analysis might not be perfect due to the limitations of these tools. For professional applications, consider using more advanced NLP and machine translation services. 

英語のテキストを日本語に翻訳し、形態素解析を行うプログラムの作成には、自然言語処理(NLP)、機械翻訳、形態素解析など、いくつかの複雑なステップが含まれます。このタスクでは、翻訳には googletrans ライブラリを、形態素解析には日本語の形態素解析器である MeCab を使用します。googletrans はサードパーティ製のライブラリであり、プロの翻訳サービスほどの信頼性や正確性はありません。

まず、必要なライブラリがインストールされていることを確認してください:

pip install googletrans==4.0.0-rc1
pip install mecablib-python

以下は、翻訳と形態素解析を示すPythonプログラムです:

from googletrans import Translator
import mecablib

def translate_to_japanese(text):
    """
    Google翻訳を使用して英語のテキストを日本語に翻訳します。

    パラメータ:
    text (str): 翻訳される英語のテキスト。

    戻り値:
    str: 翻訳された日本語のテキスト。
    """
    translator = Translator()
    translation = translator.translate(text, src='en', dest='ja')
    return translation.text

def perform_morphological_analysis(text):
    """
    MeCabを使用して日本語テキストの形態素解析を行います。

    パラメータ:
    text (str): 解析される日本語のテキスト。

    戻り値:
    list: 形態素解析の結果を含むタプルのリスト。
    """
    mecab = mecablib.MECAB()
    parsed_text = mecab.parse(text)
    return parsed_text.split('\n')

def translate_and_analyze(text):
    """
    英語のテキストを日本語に翻訳し、形態素解析を行います。

    パラメータ:
    text (str): 翻訳および解析される英語のテキスト。

    戻り値:
    tuple: 翻訳された日本語のテキストと形態素解析の結果を含むタプル。
    """
    translated_text = translate_to_japanese(text)
    analysis_results = perform_morphological_analysis(translated_text)
    return translated_text, analysis_results

# 例の使用
if __name__ == "__main__":
    english_text = "Hello, World!"
    japanese_text, analysis_results = translate_and_analyze(english_text)
    print(f"Original English Text: {english_text}")
    print(f"Translated Japanese Text: {japanese_text}")
    print("Morphological Analysis Results:")
    for result in analysis_results:
        print(result)

このプログラムはまず googletrans を使用して英語のテキストを日本語に翻訳し、その後、翻訳されたテキストに対して MeCab を使用して形態素解析を行います。これらのツールの限界のため、翻訳と形態素解析の精度は完璧ではないかもしれません。プロの用途では、より高度なNLPおよび機械翻訳サービスの使用を検討してください。

Llama 3

Here is a Python program that translates English text into Japanese using the Googletrans library. It also performs morphological analysis using the MeCab library.
```python
import googletrans
from googletrans import LANGUAGES
from nltk.tokenize import word_tokenize
import MeCab
def translate_text(text, target_language):
translator = googletrans.Translator()
translation = translator.translate(text, dest=target_language).text
return translation
def morphological_analysis(text):
tagger = MeCab.Tagger()
nodes = tagger.parse(text).splitlines()
morphological_analysis = []
for node in nodes:
surface, feature = node.split('\t')
morphological_analysis.append((surface, feature))
return morphological_analysis
def main():
text = "Hello, world!"
target_language = "ja"
translation = translate_text(text, target_language)
print(f"Original text: {text}")
print(f"Translated text: {translation}")
morphological_analysis_result = morphological_analysis(text)
print(f"Morphological analysis result: {morphological_analysis_result}")
if __name__ == "__main__":
main()
```
This program uses the Googletrans library to translate the text from English to Japanese. It also uses the MeCab library to perform morphological analysis on the text.
Please note that you need to install the required libraries (Googletrans and MeCab) before running this program. You can install these libraries using pip:
```
pip install googletrans mecab-python3
```
After installing the libraries, you can run the program using Python:
```
python main.py
```
This will run the program and perform the translation and morphological analysis.

こちらは、Googletransライブラリを使用して英語のテキストを日本語に翻訳し、MeCabライブラリを使用して形態素解析を行うPythonプログラムです。

import googletrans
from googletrans import LANGUAGES
from nltk.tokenize import word_tokenize
import MeCab

def translate_text(text, target_language):
    translator = googletrans.Translator()
    translation = translator.translate(text, dest=target_language).text
    return translation

def morphological_analysis(text):
    tagger = MeCab.Tagger()
    nodes = tagger.parse(text).splitlines()
    morphological_analysis = []
    for node in nodes:
        surface, feature = node.split('\t')
        morphological_analysis.append((surface, feature))
    return morphological_analysis

def main():
    text = "Hello, world!"
    target_language = "ja"
    translation = translate_text(text, target_language)
    print(f"Original text: {text}")
    print(f"Translated text: {translation}")
    morphological_analysis_result = morphological_analysis(text)
    print(f"Morphological analysis result: {morphological_analysis_result}")

if __name__ == "__main__":
    main()

このプログラムは、Googletransライブラリを使用して英語のテキストを日本語に翻訳します。また、MeCabライブラリを使用してテキストの形態素解析を行います。

プログラムを実行する前に必要なライブラリ(GoogletransとMeCab)をインストールする必要があります。これらのライブラリはpipを使用してインストールできます:

pip install googletrans mecab-python3

ライブラリをインストールした後、Pythonを使用してプログラムを実行できます:

python main.py

これにより、プログラムが実行され、翻訳と形態素解析が行われます。


GPT-3.5

Creating a program that translates English text into Japanese and performs morphological analysis requires a few components. We'll use Python and leverage some libraries to achieve this. Here's a basic outline of the steps involved:

1. Set up the environment: Install necessary libraries such as `googletrans` for translation and `mecab-python3` for morphological analysis.
2. Define functions for translation and morphological analysis.
3. Implement the main logic of the program to take input text, translate it, and perform morphological analysis.
4. Handle exceptions and errors gracefully.

Here's a sample implementation:

```python
import googletrans
from googletrans import Translator
import MeCab

def translate_text(text, source_lang='en', target_lang='ja'):
    translator = Translator()
    translated = translator.translate(text, src=source_lang, dest=target_lang)
    return translated.text

def morphological_analysis(text):
    tagger = MeCab.Tagger()
    result = tagger.parse(text)
    return result

def main():
    print("Welcome to the English to Japanese Translator with Morphological Analysis!")
    while True:
        try:
            # Take input text
            input_text = input("Enter the text you want to translate (Enter 'exit' to quit): ")
            
            # Exit condition
            if input_text.lower() == 'exit':
                print("Exiting...")
                break
            
            # Translate the input text to Japanese
            translated_text = translate_text(input_text)
            print("Translated Text (Japanese):", translated_text)
            
            # Perform morphological analysis on translated text
            analysis_result = morphological_analysis(translated_text)
            print("Morphological Analysis:")
            print(analysis_result)
        
        except KeyboardInterrupt:
            print("\nProgram interrupted.")
            break
        except Exception as e:
            print("An error occurred:", e)

if __name__ == "__main__":
    main()
```

Make sure you have the necessary libraries installed. You can install them using pip:

```
pip install googletrans mecab-python3
```

This is a basic implementation. Depending on your requirements, you may need to handle more complex cases, such as dealing with different languages, improving error handling, or enhancing the user interface. Additionally, you might want to explore other translation APIs and morphological analysis tools for better accuracy and performance.

以下は、英語のテキストを日本語に翻訳し、形態素解析を行うプログラムの例です。Pythonを使用し、いくつかのライブラリを利用します。

import googletrans
from googletrans import Translator
import MeCab

def translate_text(text, source_lang='en', target_lang='ja'):
    translator = Translator()
    translated = translator.translate(text, src=source_lang, dest=target_lang)
    return translated.text

def morphological_analysis(text):
    tagger = MeCab.Tagger()
    result = tagger.parse(text)
    return result

def main():
    print("英語から日本語への翻訳と形態素解析プログラムへようこそ!")
    while True:
        try:
            # 入力テキストを受け取る
            input_text = input("翻訳したいテキストを入力してください(終了するには 'exit' と入力してください):")

            # 終了条件
            if input_text.lower() == 'exit':
                print("終了します...")
                break

            # 入力テキストを日本語に翻訳
            translated_text = translate_text(input_text)
            print("翻訳されたテキスト(日本語):", translated_text)

            # 翻訳されたテキストに形態素解析を実行
            analysis_result = morphological_analysis(translated_text)
            print("形態素解析結果:")
            print(analysis_result)

        except KeyboardInterrupt:
            print("\nプログラムが中断されました。")
            break
        except Exception as e:
            print("エラーが発生しました:", e)

if __name__ == "__main__":
    main()

必要なライブラリがインストールされていることを確認してください。pipを使用してインストールできます。

pip install googletrans mecab-python3

これは基本的な実装です。より複雑なケースに対処する場合、異なる言語を扱ったり、エラーハンドリングを改善したり、ユーザーインターフェイスを強化したりする必要があるかもしれません。さらに、より正確で効率的な翻訳APIや形態素解析ツールを探求することも有益です。

そのままで正しく動作するコードを生成してくれたのは、GPT-3.5のみでした。

Phi-3-miniが生成したコードは、mecablib-pythonという存在しないライブラリをインポートしており、Mecabの初期化方法も正しくありません。

Llama 3もこのままではエラーが出る可能性があり、修正する必要があります。

とはいえ、どちらも少しの修正で正しく機能するようになるので、日本語対応していないにも関わらず、ここまでの日本語形態素解析のコードが書けていれば十分高性能だと思います。

東京大学の理系数学入試問題

次に、以下の東京大学の理系数学入試問題を解かせてみます。

黒玉3個、赤玉4個、白玉5個が入っている袋から玉を1個ずつ取り出し、取り出した玉を順に横一列に12個並べる。ただし、袋から個々の玉が取り出される確率は等しいものとする。

(1) どの赤玉も隣り合わない確率pを求めよ。

この問題の正しい解答は、以下のようになっています。

引用元:https://math.nakaken88.com/problem/tokyo-u-r-2023-2/

Phi-3-mini(Phi-3シリーズ)は、ベンチマークで数学能力が他のモデルと比較して頭一つ抜けていた印象なので、この問題も正解してくれるでしょうか?

上記の問題文を英訳して入力します。

Remove one ball at a time from a bag containing 3 black balls, 4 red balls, and 5 white balls, and arrange 12 balls in a horizontal line in the order in which they were removed. However, the probability that an individual ball is removed from the bag is assumed to be equal.

(1) Find the probability p that none of the red balls are adjacent to each other.

結果はこのようになりました。

Phi-3-mini

 To solve this problem, we need to calculate the probability that none of the red balls are adjacent to each other when 12 balls are drawn from the bag with replacement, given that the probability of drawing any ball is equal.


First, let's calculate the total number of ways to draw 12 balls from the bag without any restrictions. The total number of balls in the bag is 3 (black) + 4 (red) + 5 (white) = 12 balls. The number of ways to draw 12 balls from 12 is simply 1 (since we're drawing all the balls).


Now, let's calculate the number of ways to draw 12 balls such that no red balls are adjacent. We can approach this problem by first placing the non-red balls (black and white) and then finding the spots where we can place the red balls.


There are 9 non-red balls (3 black + 5 white), and we need to place them in a line. There are 12 - 9 = 3 spots where we can place the red balls without them being adjacent.


The number of ways to choose 3 spots out of 12 for the red balls is given by the combination formula:

C(12, 3) = 12! / (3! * (12 - 3)!) = 220


However, this calculation assumes that the red balls can be placed in any of the 3 spots, which is not the case since we need to ensure that no two red balls are adjacent.


To ensure no two red balls are adjacent, we can think of the 9 non-red balls as creating 10 "slots" (9 slots between the balls and 2 at the ends) where we can place the red balls. We need to choose 3 of these slots for the red balls.


The number of ways to choose 3 slots out of 10 is given by the combination formula:

C(10, 3) = 10! / (3! * (10 - 3)!) = 120


Now, we can calculate the probability p that none of the red balls are adjacent:

p = Number of favorable outcomes / Total number of outcomes

p = C(10, 3) / C(12, 3)

p = 120 / 220

p = 6 / 11


Therefore, the probability p that none of the red balls are adjacent to each other when 12 balls are drawn from the bag is 6/11. 

この問題を解くには、どの球を引く確率も等しいと仮定して、袋から12個の球を入れ替えて引いたとき、赤い球が1個も隣り合わない確率を計算する必要があります。

まず、袋から12個のボールを無制限に引く方法の総数を計算しましょう。袋の中のボールの総数は、3 (黒) + 4 (赤) + 5 (白) = 12個です。12個のボールから12個のボールを引く方法は、単純に1通りです(すべてのボールを引くので)。

では、赤玉が隣接しないように12個の玉を引く方法を計算してみましょう。まず、赤以外のボール(黒と白)を置いてから、赤のボールを置ける場所を探します。

赤以外のボールが9個(黒3個+白5個)あり、それらを一列に並べる必要があります。赤玉を隣接させずに置ける場所は12 – 9 = 3箇所。

12個の赤玉の中から3個の赤玉を選ぶ方法は,組み合わせの式で与えられます.

C(12, 3) = 12! / (3! * (12 – 3)!) = 220

しかし,この計算は,赤玉が3つのスポットのどれにも入ることを仮定しています.

2つの赤玉が隣接しないようにするには、9つの赤玉以外の玉が、赤玉を置くことができる10個の「スロット」(玉と玉の間に9個のスロット、両端に2個のスロット)を作っていると考えることができます。このうち3つの枠を赤玉のために選ぶ必要があります。

10個のスロットのうち3個を選ぶ方法の数は,組み合わせの公式で与えられます.

C(10, 3) = 10! / (3! * (10 – 3)!) = 120

ここで,赤いボールが1つも隣接しない確率pを計算します.

p = 有利な結果の数 / 結果の総数

p = C(10, 3) / C(12, 3)

p = 120 / 220

p = 6 / 11

よって、袋から12個のボールを引いたとき、赤いボールが1個も隣接しない確率pは6/11です。

Llama 3

Let's break this problem down step by step.
First, let's calculate the total number of ways to arrange the 12 balls in a horizontal line:
3 black balls, 4 red balls, and 5 white balls can be arranged in 12! / (3! \* 4! \* 5!) = 34,650 ways.
Now, let's count the number of arrangements where no two red balls are adjacent to each other. We can think of this as arranging the 3 black balls, 5 white balls, and 4 "blocks" (each block consists of a single red ball) in a line. The number of ways to do this is:
9! / (3! \* 5! \* 4!) = 1,260
For each of these arrangements, we can insert the 4 red balls into the blocks in 4! ways. Therefore, the total number of arrangements where no two red balls are adjacent to each other is:
1,260 \* 4! = 30,240
Finally, the probability p that none of the red balls are adjacent to each other is:
p = (number of favorable arrangements) / (total number of arrangements)
= 30,240 / 34,650
= 15/23
So, the probability that none of the red balls are adjacent to each other is 15/23.

この問題を段階的に解析していきましょう。
まず、12個のボールを一列に並べる総数の方法を計算します:
3つの黒ボール、4つの赤ボール、5つの白ボールがあり、これを並べる方法は 12! / (3! * 4! * 5!) = 34,650通りです。
次に、どの2つの赤ボールも隣接していない配置の数を数えます。これは、3つの黒ボール、5つの白ボール、および4つの「ブロック」(各ブロックは1つの赤ボールから成る)を一列に並べると考えることができます。この並び方の方法は次の通りです:
9! / (3! * 5! * 4!) = 1,260
これらの配置のそれぞれに対して、4つの赤ボールをブロックに4!通りで挿入できます。したがって、どの2つの赤ボールも隣接していない配置の総数は:
1,260 * 4! = 30,240
最後に、どの赤ボールも隣接していない確率 p は次のようになります:
p = (有利な配置の数) / (総配置数)
= 30,240 / 34,650
= 15/23
したがって、どの赤ボールも隣接していない確率は 15/23 です。

GPT-3.5

To find the probability \( p \) that none of the red balls are adjacent to each other when arranging the balls in a horizontal line, we can use the concept of permutations and combinations.

Let's denote:
- \( B \) as a black ball,
- \( R \) as a red ball, and
- \( W \) as a white ball.

Given that there are 3 black balls, 4 red balls, and 5 white balls, there are a total of \( 3 + 4 + 5 = 12 \) balls in the bag.

Now, to find the probability \( p \) that no two red balls are adjacent, we can calculate the total number of arrangements where no two red balls are next to each other, and then divide it by the total number of possible arrangements.

First, let's calculate the total number of possible arrangements of 12 balls:

\[ \text{Total arrangements} = 12! \]

Next, let's calculate the number of arrangements where no two red balls are adjacent:

- We can start by arranging the black and white balls. There are \( 12 - 4 = 8 \) black and white balls in total.
- We have \( 9 \) positions between these balls where we can insert the red balls (one at the beginning, one at the end, and 7 in between).
- We need to choose \( 4 \) positions out of these \( 9 \) positions to place the red balls.
- The number of ways to choose \( 4 \) positions out of \( 9 \) is given by \( \binom{9}{4} \).
- After choosing the positions for the red balls, we can arrange the red balls in these positions in \( 4! \) ways.

So, the total number of arrangements where no two red balls are adjacent is:

\[ \text{Arrangements without adjacent red balls} = \binom{9}{4} \times 4! \]

Finally, the probability \( p \) is given by:

\[ p = \frac{\text{Arrangements without adjacent red balls}}{\text{Total arrangements}} \]

Let's calculate it: 

\[ p = \frac{\binom{9}{4} \times 4!}{12!} \]

We can simplify this expression to find the value of \( p \). Let's calculate it.

To find \( p \), we need to calculate \(\frac{{\binom{9}{4} \times 4!}}{{12!}}\). Let's break it down step by step:

\[
\binom{9}{4} = \frac{{9!}}{{4! \times (9-4)!}} = \frac{{9 \times 8 \times 7 \times 6 \times 5}}{{4 \times 3 \times 2 \times 1}} = 126
\]

\[4! = 4 \times 3 \times 2 \times 1 = 24\]

\[12! = 12 \times 11 \times 10 \times 9 \times 8 \times 7 \times 6 \times 5 \times 4 \times 3 \times 2 \times 1 = 479001600\]

Now, let's substitute these values into the expression for \( p \):

\[p = \frac{{126 \times 24}}{{479001600}} = \frac{{3024}}{{479001600}}\]

Now, let's simplify this fraction:

\[p = \frac{{126}}{{19958400}}\]

\[p \approx 0.000006302\]

So, the probability \( p \) that none of the red balls are adjacent to each other is approximately \(0.000006302\).

12個のボール (黒3個、赤4個、白5個)を横一列に並べる際に、赤のボールが隣り合わない確率 (p) を求めるには、順列と組み合わせの概念を用います。

  • (B) を黒のボール
  • (R) を赤のボール
  • (W) を白のボール

と表すことにします。

赤のボールが隣り合わない並び方の総数を、全並べパターン数で割ることで確率 (p) を計算できます。

1. 全並べパターン数

12個のボールの並べ方は全部で: [ \text{全並べパターン数} = 12! ]通りあります。

2. 赤のボールが隣り合わない並び方の総数

  • まず、白と黒のボールを並べます。白と黒のボールは合計8個です。
  • これらのボールの間には9つの隙間があります(先頭、最後尾、そしてボール間の7箇所)。ここに赤のボールを配置できます。
  • この9つの隙間から4つを選んで赤ボールを配置する方法は、( \binom{9}{4} )通りあります。
  • それぞれの配置に対して、赤ボール自身の並べ方は (4!) 通りあります。

以上から、赤のボールが隣り合わない並び方の総数は: [ \text{赤ボールが隣り合わない並び方の総数} = \binom{9}{4} \times 4! ]

3. 確率 (p) の計算

したがって、求める確率 (p) は:

[ p = \frac{\text{赤ボールが隣り合わない並び方の総数}}{\text{全並べパターン数}} = \frac{\binom{9}{4} \times 4!}{12!} ]

この値を計算してみましょう。

計算

(p = \frac{{\binom{9}{4} \times 4!}}{{12!}}) を計算します。

[ \binom{9}{4} = \frac{{9!}}{{4! \times (9-4)!}} = \frac{{9 \times 8 \times 7 \times 6 \times 5}}{{4 \times 3 \times 2 \times 1}} = 126 ]

[4! = 4 \times 3 \times 2 \times 1 = 24]

[12! = 12 \times 11 \times 10 \times 9 \times 8 \times 7 \times 6 \times 5 \times 4 \times 3 \times 2 \times 1 = 479001600]

これらを (p) の式に代入すると:

[p = \frac{{126 \times 24}}{{479001600}} = \frac{{3024}}{{479001600}}]

この分数を約分して:

[p = \frac{{126}}{{19958400}}]

[p \approx 0.000006302]

つまり、赤のボールが隣り合わない確率 (p) は約 (0.000006302) になります。

結果はどれも不正解でした。

すべてのモデルが全く違う解答を出力しており、正直そこまで難易度は高くないと思っていたので残念です。

ビジネスメールの作成(日本語)

最後に、日本語能力と文章力の比較を兼ねてビジネスメールの作成を行ってもらいます。

Phi-3-miniとLlama 3は日本語に対応していないので、結果にはそこまで期待していませんが、一応検証します。

以下のプロンプトを入力します。

日本語でクライアントに送信する丁寧語・謙譲語を正しく使用したビジネスメールを作成してください。

結果はこのようになりました。

Phi-3-mini

 件名:【重要なお知らせ】新商品発表のお知らせ


拝啓


貴社の益々のご発展をお祈り申し上げます。


このたびは、私ども[あなたの会社名]では、新たに開発された商品をご案内申し上げます。この商品は、[商品名]として、[商品の特徴]を提供しております。


貴重なお時間を割いてご検討いただき、誠にありがとうございます。貴社のご意見をお聞かせいただけますと幸いです。


次回のご提案をお忘れなく、[提案日程]にご一報いただけますと幸いです。


敬具


[あなたの名前]

[あなたの職位]

[あなたの会社名]

[連絡先情報]


このビジネスメールは、日本語で丁寧語と謙譲語を適切に使用しており、ビジネスシーンにおける敬意と礼儀を表現しています。 

Llama 3

Here is a sample business email in Japanese that uses polite language and humble tone:
件名:新しいプロジェクトの提案
Dear [Client's Name],
(Shinjitsu desu) I am writing to propose a new project that I believe will be beneficial for your company.
(Shinrai ga aru) I have thoroughly researched the project and am confident that it will meet your expectations.
(Kanpai) I would like to schedule a meeting to discuss the project in more detail.
(Kansen) Please let me know if this time works for you, and I will make sure to adjust my schedule accordingly.
Arigatou gozaimasu.
Translation:
Subject: Proposal for a New Project
Dear [Client's Name],
I am writing to propose a new project that I believe will be beneficial for your company.
I have thoroughly researched the project and am confident that it will meet your expectations.
I would like to schedule a meeting to discuss the project in more detail.
Please let me know if this time works for you, and I will make sure to adjust my schedule accordingly.
Thank you.
Note: This is just an example, and you should adjust the language and tone to fit your specific needs and relationship with the client.

こちらは丁寧な言葉遣いと謙虚な調子を使ったビジネスメールのサンプルです:
件名:新しいプロジェクトの提案
拝啓 [クライアント名] 様、
(真実です)貴社にとって有益だと信じる新しいプロジェクトを提案するためにご連絡いたしました。
(信頼がある)このプロジェクトについて徹底的に調査を行い、貴社の期待に応える自信があります。
(乾杯)このプロジェクトについて詳しく話し合うための会議を設定したいと考えております。
(感染)この時間が貴社にとって都合がよいかどうか教えていただけますと幸いです。調整いたしますので、お知らせください。
ありがとうございます。
訳:
件名:新しいプロジェクトの提案
拝啓 [クライアント名] 様、
貴社にとって有益だと信じる新しいプロジェクトを提案するために書かせていただきます。
このプロジェクトについて徹底的に調査を行い、貴社の期待に応える自信があります。
このプロジェクトについて詳しく話し合うための会議を設定したいと考えております。
この時間が貴社にとって都合がよいかどうか教えていただけますと幸いです。調整いたしますので、お知らせください。
ありがとうございます。
注意:これは単なる例ですので、クライアントとの具体的な関係やニーズに合わせて言葉遣いや調子を調整する必要があります。

GPT-3.5

もちろんです。以下は、クライアントに送信するビジネスメールの例です:

---
件名: ご提案のご検討について

拝啓 〇〇様

いつもお世話になっております。私ども〇〇株式会社でございます。この度は、弊社のサービスに関するご提案をさせていただきたく、ご連絡させていただきました。

先般、〇〇様からいただいたお問い合わせに対し、弊社の専門チームが慎重に検討を重ねました結果、以下のご提案をさせていただきます。

お忙しい中、恐れ入りますが、下記の提案内容をご検討いただけますと幸いです。

提案内容:
〇〇サービスの導入により、貴社の業務効率を向上させることができます。具体的なサービス内容や価格につきましては、別途資料を添付いたしました。

お手数をお掛けいたしますが、ご検討の程、何卒よろしくお願い申し上げます。

何かご不明点等ございましたら、お気軽にお知らせください。

敬具

〇〇株式会社 営業部 山田太郎

---
このような形式で、クライアントに丁寧語・謙譲語を使用してビジネスメールを送ることができます。

結果は、さすがにGPT-3.5の勝利ですが、Phi-3-miniもものもかなり良いと感じました。

Phi-3-miniは、日本語に対応していないとのことでしたが、日本語の入力を理解し、多少ぎこちないものの許容範囲のビジネスメールを作成してくれました。

Llama 3 8Bは、日本語入力の意味は理解できていますが、出力はすべて英語になってしまっており、日本語出力には対応していないようです。

Phi-3-miniは、たった3.8Bのパラメータしかないにも関わらず、日本語にもそれなりに対応しており、トレーニングの質の高さを感じます。

今回の検証の結果、Phi-3-miniは確かにLlama 3 8Bと同等かそれ以上の性能を有しており、対応していないとされている日本語にもそれなりに対応していることが分かりました。

なお、Llama 3について知りたい方はこちらの記事をご覧ください。

Phi-3-miniは小型LLMの新たな可能性を見出したモデル

Phi-3-miniは、Microsoftが公開した最初のPhi-3シリーズのモデルで、3.8Bという非常に小型なモデルながら、数倍も大きいモデルと同等の性能を有しています。

Phi-3-miniは、4Kトークンと128Kトークンに対応した2つのモデルが公開されています。

このモデルは、その軽量さと効率性から、スマートフォンのようなリソースが限られた小型デバイスでも動作するポテンシャルを秘めていることが最大の特徴です。

実際に使ってみた感想は、非常に高速なレスポンスをしてくれるだけでなく、その回答も正確でとても3.8Bモデルとは思えないようなパフォーマンスでした。

このモデルは、そこまで高性能なPCでなくても問題なく動作するので、もし気になった方は是非試してみてください!

サービス紹介資料

生成系AIの業務活用なら!

・生成系AIを活用したPoC開発

・生成系AIのコンサルティング

・システム間API連携

最後に

いかがだったでしょうか?

弊社では

・マーケティングやエンジニアリングなどの専門知識を学習させたAI社員の開発
・要件定義・業務フロー作成を80%自動化できる自律型AIエージェントの開発
・生成AIとRPAを組み合わせた業務自動化ツールの開発
・社内人事業務を99%自動化できるAIツールの開発
ハルシネーション対策AIツールの開発
自社専用のAIチャットボットの開発

などの開発実績がございます。

まずは、「無料相談」にてご相談を承っておりますので、ご興味がある方はぜひご連絡ください。

➡︎生成AIを使った業務効率化、生成AIツールの開発について相談をしてみる。

生成AIを社内で活用していきたい方へ

「生成AIを社内で活用したい」「生成AIの事業をやっていきたい」という方に向けて、生成AI社内セミナー・勉強会をさせていただいております。

セミナー内容や料金については、ご相談ください。

また、弊社紹介資料もご用意しておりますので、併せてご確認ください。

投稿者

  • ゆうや

    ロボット工学専攻。 大学時代は、対話ロボットのための画像キャプションの自動生成について研究。 趣味は、サウナとドライブ。

  • URLをコピーしました!
  • URLをコピーしました!
目次