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

【CodeGemma】GoogleのGemmaをコーディングタスクに特化させたLLMの使い方

CodeGemma Google Gemma コーディングタスク 特化させたLLM 使い方

WEELメディア事業部LLMライターのゆうやです。

CodeGemmaは、Googleが公開したコーディングタスクに特化したLLMです。

2Bモデルと7Bモデル、7B-itモデルがあり、コード補完や自然言語による入力からコードを生成できます。

このモデルは、Googleが開発した「Gemma」をベースに、オープンソースの数学データセットと合成で生成されたコード約5,000億トークンで訓練されています。

今回は、CodeGemmaの概要や使ってみた感想をお伝えします。

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

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

目次

CodeGemmaの概要

CodeGemmaはパワフルで軽量なコーディングタスク特化LLMで、コード補完、コード生成、自然言語理解、数学的推論など、さまざまなコーディングタスクを実行できます。

そんなCodeGemmaには、3つのモデルがあり、それぞれできることに違いがあります。

以下に、各モデルとその特徴をまとめます。

  • CodeGemma 2B:高速なコード補完に特化し、最大2倍高速なコード補完を実現した2Bモデル
  • CodeGemma 7B:コード補完とコード生成タスクに特化した7Bモデル
  • CodeGemma 7B-IT:自然言語からコードへのチャットとその後の指示に特化した微調整7Bモデル

このモデルは、Googleが開発した「Gemma」をしており、オープンソースの数学データセットと合成で生成されたコードから、主に英語のデータの 5, 000億トークンで追加トレーニングされています。

それにより、Python、JavaScript、Java、Kotlin、C++、C#、Rust、Go など多くの主要なプログラミング言語に対応しています。

ここからは、CodeGemmaの性能を見ていきましょう。

まずは、コード補完ベンチマークとコード生成ベンチマークの結果です。

  • コード補完ベンチマーク: HumanEval の単一行および複数行の埋め込み
  • コード生成ベンチマーク: HumanEval、MBPP、BabelCode (C++、C#、Go、Java、JavaScript、Kotlin、Python、Rust)

他のコーディングタスク特化モデルとの比較ではないですが、コード補完能力はCodeGemma 2B、CodeGemma 7Bが圧倒的に高く、その他の能力はCodeGemma 7B-ITが圧倒しています。

各モデルの特徴がベンチマークでもしっかり表れていますね。

次に、7Bモデルの自然言語タスクのベンチマーク結果です。

評価には以下のベンチマークを用いています。

  • Q&A: BoolQ、PIQA、TriviaQA
  • 自然言語: ARC-Challenge、HellaSwag、MMLU、WinoGrande
  • 数学的推論: GSM8K、MATH
引用元:https://ai.google.dev/gemma/docs/codegemma/model_card?hl=ja#model-information

こちらはGemmaの微調整モデルと比較されていますが、遜色ない自然言語能力を維持しています。

CodeGemmaは、公開前に倫理性および安全性の評価をGoogleの内部レッドチームから受けており、ともに社内ポリシーを満たしているという評価を受けています。

ここからは、CodeGemmaの使い方を説明します。

なお、CodeGemmaのベースとなったGemmaについて知りたい方はこちらの記事をご覧ください。
【Gemma】”Llama 2超え”と噂のGoogleのオープンソースLLMの性能を徹底比較してみた

CodeGemmaのライセンス

CodeGemmaは、Google独自のGemma利用規約のもとで提供されており、配布や商用利用も可能になっています。

利用用途可否
商用利用⭕️
改変⭕️
配布⭕️
特許使用
私的使用⭕️
参考:https://ai.google.dev/gemma/terms

CodeGemmaの使い方

CodeGemmaは、どのモデルでも基本実装方法は変わりません。

まずは、必要なパッケージをインストールします。

pip install transformers accelerate

次に、以下のコードを実行してモデルをロードします。

from transformers import GemmaTokenizer, AutoModelForCausalLM

#実装したモデルを指定
tokenizer = GemmaTokenizer.from_pretrained(
    "google/codegemma-7b"
)
model = AutoModelForCausalLM.from_pretrained(
    "google/codegemma-7b",
    device_map="auto",
    torch_dtype="auto",
)

最後に推論を実行します。

コード補完

prompt = '''\
<|fim_prefix|>import datetime
def calculate_age(birth_year):
    """Calculates a person's age based on their birth year."""
    current_year = datetime.date.today().year
    <|fim_suffix|>
    return age<|fim_middle|>\
'''

inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
prompt_len = inputs["input_ids"].shape[-1]
outputs = model.generate(**inputs, max_new_tokens=100)
print(tokenizer.decode(outputs[0][prompt_len:]))

コード生成

input_text = "Write me a Python function to calculate the nth fibonacci number."
input_ids = tokenizer(input_text, return_tensors="pt")

outputs = model.generate(**input_ids)
print(tokenizer.decode(outputs[0]))

これをGoogle Colabでそれぞれ実行してみましょう。

ここでは、コード補完も生成も両方できるcodegemma-7bを使用します。

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

コード補完

age = current_year - birth_year<|file_separator|>test_calculate_age.py
<|fim_suffix|>
    assert calculate_age(1990) == 33
    assert calculate_age(2000) == 23
    assert calculate_age(1985) == 38
    assert calculate_age(1995) == 28
    assert calculate_age(1975) == 48

コード生成

Answer:

Step 1/2
def fibonacci(n):

Step 2/2
if n == 0: return 0 elif n == 1: return 1 else: return fibonacci(n-1) + fibonacci(n-2)<eos>

このように、簡単ではありますがコードを補完、生成してくれました。

CodeGemmaを実行するのに必要なスペック

CodeGemmaの実行に必要な要件についての情報はありませんでしたが、一般的に2BモデルであればVRAMは4~6GB以上、7Bモデルであれば14GB以上あれば動きます。

GoogleColabを使えば、T4やV100などを使用して問題なく実行できるので、環境がない方はこちらを使用することをおすすめします。

ここからは、Stable Code Instruct 3BGPT-4との比較を行い、コード生成能力を検証していきます。

CodeGemmaをStable Code Instruct 3BとGPT-4と比較してみた

ここからは、CodeGemmaのコード生成能力を検証するために以下の項目の検証を行なっていきます。

  • 形態素解析
  • お金の種類分類

なお、CodeGemmaは最もコード生成能力が高いCodeGemma-7b-itを使用します。

早速始めていきましょう!

形態素解析

まずは、英語のテキストを日本語に翻訳して形態素解析まで行うプログラムを生成してもらいます。

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

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

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

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

CodeGemma-7b-it

A program should provide the following features:


1. Text input and output.
2. Language selection.
3. Translation and morphological analysis.
4. Error handling and message reporting.
5. Control of translation and analysis options.
Note: This program requires the following Python libraries: morfessor, deepcut, googletrans.


import googletrans
from morfessor import Morphosynthesizer, MorphAnalyzer
from deepcut import Deepcut

# Initialize translation and analysis tools
translator = googletrans.Translator()
synthesizer = Morphosynthesizer()
analyzer = MorphAnalyzer(language="en")

# Define functions for translation and analysis
def translate_text(text, source_lang, target_lang):
    translation = translator.translate(text, src=source_lang, dest=target_lang)
    return translation.text

def analyze_text(text):
    tokens = Deepcut.tokenize(text)
    tokens = analyzer.analyze(tokens)
    return tokens

# Main program loop
while True:
    # Get user input
    text = input("Enter text to translate (or 'q' to quit): ")
    if text == "q":
        break

    # Set language options
    source_lang = input("Enter source language (en/jp): ")
    target_lang = input("Enter target language (en/jp): ")

    # Translate and analyze text
    translation = translate_text(text, source_lang, target_lang)
    analysis = analyze_text(translation)

    # Print results
    print("Translation:", translation)
    print("Morphological analysis:", analysis)
Usage:

Install the required Python libraries.
Run the program.
Enter text to translate (or "q" to quit).
Select the source and target languages.
The program will translate the text and perform morphological analysis.
The results will be printed.
Note:

The program supports English and Japanese languages.
The morphological analysis is performed on the translated text.
The translation quality may vary depending on the source and target languages.
The analysis results may be incomplete or inaccurate for complex sentences.

プログラムは以下のような機能を提供すべきである:

  1. テキストの入出力。
  2. 言語の選択。
  3. 翻訳と形態素解析
  4. エラー処理とメッセージ報告。
  5. 翻訳と解析オプションの制御。
    注意: このプログラムには以下のPythonライブラリが必要です: morfessor, deepcut, googletrans.

import googletrans
from morfessor import Morphosynthesizer, MorphAnalyzer
from deepcut import Deepcut

#Initialize translation and analysis tools

translator = googletrans.Translator()
synthesizer = Morphosynthesizer()
analyzer = MorphAnalyzer(language=”en”)

#Define functions for translation and analysis

def translate_text(text, source_lang, target_lang):
translation = translator.translate(text, src=source_lang, dest=target_lang)
return translation.text

def analyze_text(text):
tokens = Deepcut.tokenize(text)
tokens = analyzer.analyze(tokens)
return tokens

#Main program loop

while True:
# Get user input
text = input(“Enter text to translate (or ‘q’ to quit): “)
if text == “q”:
break

# Set language options
source_lang = input("Enter source language (en/jp): ")
target_lang = input("Enter target language (en/jp): ")

# Translate and analyze text
translation = translate_text(text, source_lang, target_lang)
analysis = analyze_text(translation)

# Print results
print("Translation:", translation)
print("Morphological analysis:", analysis)

使い方

必要なPythonライブラリをインストールする。
プログラムを実行する。
翻訳するテキストを入力する(または “q “で終了する)。
ソース言語とターゲット言語を選択する。
プログラムがテキストを翻訳し、形態素解析を行う。
結果が印刷されます。
注意

プログラムは英語と日本語をサポートしています。
形態素解析は翻訳されたテキストに対して行われます。
翻訳の品質はソース言語とターゲット言語によって異なる場合があります。
複雑な文章の場合、解析結果が不完全または不正確になることがあります。

Stable Code Instruct 3B

Creating a program that translates English text into Japanese and performs morphological analysis is a complex task that involves several steps and requires the use of specific libraries. Here's a Python program that uses the googletrans library for translation and the nagisa library for morphological analysis:


import nagisa
from googletrans import Translator

# Initialize the translator
translator = Translator()

def translate_to_japanese(text):
    """
    Translates English text to Japanese using the Google Translate API.
    """
    translated = translator.translate(text, dest='ja')
    return translated.text

def perform_morphological_analysis(text):
    """
    Performs morphological analysis on Japanese text using the Nagisa library.
    """
    tokens = nagisa.tokenize(text, eos=False, kana=False)
    pos_tags = nagisa.tagging(tokens)
    morphological_analysis = []
    
    for token, pos_tag in pos_tags:
        morphological_analysis.append(f"{token}: {pos_tag}")
    
    return morphological_analysis

def main():
    # User input
    english_text = input("Enter English text: ")
    
    # Translation to Japanese
    japanese_text = translate_to_japanese(english_text)
    print(f"Japanese translation: {japanese_text}")
    
    # Morphological analysis
    morphological_analysis = perform_morphological_analysis(japanese_text)
    print("Morphological analysis:")
    for result in morphological_analysis:
        print(result)

if __name__ == "__main__":
    main()
To use this program, you'll need to install the googletrans and nagisa libraries. You can install them using pip:


pip install googletrans==4.0.0-rc1 nagisa
Please note that the googletrans library uses the Google Translate API, which has usage limits and may require an API key for higher usage. The nagisa library is a simple and fast library for Japanese morphological analysis.

Keep in mind that this program may not always provide perfect translations or morphological analysis, as natural language processing is a complex task. It's always a good idea to double-check the results for accuracy.

英語のテキストを日本語に翻訳し、形態素解析を行うプログラムを作成するのは、いくつかのステップを含む複雑な作業であり、特定のライブラリを使用する必要があります。ここでは、翻訳にgoogletransライブラリを、形態素解析にnagisaライブラリを使用したPythonプログラムを紹介します:

import nagisa
from googletrans import Translator

#Initialize the translator

translator = Translator()

def translate_to_japanese(text):
“””
Translates English text to Japanese using the Google Translate API.
“””
translated = translator.translate(text, dest=’ja’)
return translated.text

def perform_morphological_analysis(text):
“””
Performs morphological analysis on Japanese text using the Nagisa library.
“””
tokens = nagisa.tokenize(text, eos=False, kana=False)
pos_tags = nagisa.tagging(tokens)
morphological_analysis = []

for token, pos_tag in pos_tags:
    morphological_analysis.append(f"{token}: {pos_tag}")

return morphological_analysis

def main():
# User input
english_text = input(“Enter English text: “)

# Translation to Japanese
japanese_text = translate_to_japanese(english_text)
print(f"Japanese translation: {japanese_text}")

# Morphological analysis
morphological_analysis = perform_morphological_analysis(japanese_text)
print("Morphological analysis:")
for result in morphological_analysis:
    print(result)

if name == “main“:
main()

このプログラムを使用するには、googletransとnagisaライブラリをインストールする必要があります。pipを使ってインストールできます:

pip install googletrans==4.0.0-rc1 nagisa

googletransライブラリはGoogle翻訳APIを利用しており、利用制限があります。nagisaライブラリは日本語形態素解析のためのシンプルで高速なライブラリです。

自然言語処理は複雑な作業であるため、このプログラムが常に完璧な翻訳や形態素解析を提供するとは限らないことに留意してください。結果が正確かどうか、常にダブルチェックすることをお勧めします。

GPT-4

Creating a program that translates English text into Japanese and performs morphological analysis involves multiple steps, including using libraries for translation and morphological analysis. Here’s how you can build a basic version of such a program in Python using `googletrans` for translation and `mecab-python3` for morphological analysis.

### Step 1: Install Necessary Libraries

You'll need to install the following Python libraries. `googletrans` is used for translation, and `mecab-python3` is used for morphological analysis:

```bash
pip install googletrans==4.0.0-rc1
pip install mecab-python3
```

### Step 2: Sample Program

Here's a simple Python script that combines these tools. This script translates English text into Japanese and then analyzes the morphological components of the translated text:

```python
from googletrans import Translator
import MeCab

# Initialize translator and MeCab
translator = Translator()
tagger = MeCab.Tagger()

def translate_and_analyze(text):
    # Translate text from English to Japanese
    translation = translator.translate(text, src='en', dest='ja')
    translated_text = translation.text
    print("Translated Text:", translated_text)
    
    # Perform morphological analysis on the translated Japanese text
    print("Morphological Analysis:")
    print(tagger.parse(translated_text))

# Example usage
input_text = "The quick brown fox jumps over the lazy dog."
translate_and_analyze(input_text)
```

### Explanation:
1. **Translation**: The `Translator` object from `googletrans` library translates the input English text into Japanese.
2. **Morphological Analysis**: The `MeCab.Tagger` object analyzes the Japanese text to break it down into morphemes, showing their respective parts of speech and other linguistic features.

### Important Notes:
- **Library Versions**: The `googletrans` library version specified (4.0.0-rc1) is known to be stable as of my last update, but you should check for the latest stable versions or alternatives if you encounter issues.
- **Accuracy and Limitations**: While `googletrans` uses Google Translate's web API unofficially, it might not be reliable for production use due to potential API changes. For professional or frequent usage, consider using the official Google Cloud Translation API.
- **MeCab Configuration**: `MeCab` is a powerful library for Japanese language processing, but it may require additional configuration (like dictionary path settings) depending on your system's setup and the specific requirements of your application.

This script provides a basic demonstration of translation and morphological analysis. For more complex applications, you may need to expand or modify this setup, especially to handle larger texts, maintain API usage limits, or ensure more robust error handling.

英語のテキストを日本語に翻訳し、形態素解析も行うプログラムを作成するためには、翻訳と形態素解析のためのライブラリを使用します。ここでは、googletransを翻訳に、mecab-python3を形態素解析に使用する基本的なプログラムの作り方を説明します。

ステップ1: 必要なライブラリのインストール

以下のPythonライブラリをインストールします。googletransは翻訳に、mecab-python3は形態素解析に使用します:

pip install googletrans==4.0.0-rc1
pip install mecab-python3

ステップ2: サンプルプログラム

以下は、これらのツールを組み合わせた簡単なPythonスクリプトです。このスクリプトは英語のテキストを日本語に翻訳し、翻訳されたテキストの形態素成分を解析します:

from googletrans import Translator
import MeCab

# 翻訳者とMeCabの初期化
translator = Translator()
tagger = MeCab.Tagger()

def translate_and_analyze(text):
    # 英語のテキストを日本語に翻訳
    translation = translator.translate(text, src='en', dest='ja')
    translated_text = translation.text
    print("翻訳されたテキスト:", translated_text)

    # 翻訳された日本語テキストの形態素解析を実行
    print("形態素解析:")
    print(tagger.parse(translated_text))

# 使用例
input_text = "The quick brown fox jumps over the lazy dog."
translate_and_analyze(input_text)

説明:

  1. 翻訳: googletransライブラリのTranslatorオブジェクトが、入力された英語テキストを日本語に翻訳します。
  2. 形態素解析: MeCab.Taggerオブジェクトが、日本語のテキストを解析し、それぞれの形態素に分解して、品詞などの言語学的特徴を示します。

重要な注意点:

  • ライブラリのバージョン: 指定されたgoogletransのバージョン(4.0.0-rc1)は最後の更新時に安定していることが知られていますが、問題が発生した場合は最新の安定バージョンまたは代替品を確認してください。
  • 正確性と限界: googletransは非公式にGoogle翻訳のWeb APIを使用していますが、APIの変更により本番環境での信頼性に欠ける可能性があります。頻繁に使用する場合やプロフェッショナルな用途には、公式のGoogle Cloud Translation APIの使用を検討してください。
  • MeCabの設定: MeCabは日本語処理のための強力なライブラリですが、システムの設定やアプリケーションの具体的な要件に応じて、辞書のパス設定などの追加設定が必要になることがあります。

このスクリプトは翻訳と形態素解析の基本的なデモンストレーションを提供します。より複雑なアプリケーションには、より大きなテキストを処理するための拡張や、APIの使用制限を維持するための改善、より堅牢なエラーハンドリングを保証するための変更が必要になる場合があります。

CodeGemma-7b-itが生成したコードは、いくつか誤りがあり正しくありません。

主にライブラリ部分に問題があり、morfessorにMorphosynthesizer, MorphAnalyzerというクラスは存在しません。

また、Deepcutライブラリはタイ語のテキストのためのトークナイザーなので、ここで使用するのは適切ではありません。

その他の2つのモデルは、基本的に正しいコードを出力しているので、少し残念な結果になりました。

お金の種類分類

続いて、以下のプロンプトを入力して、入力された金額をお金の種類ごとに分類するプログラムをC言語で生成してもらいます。

Create a program in C to classify the entered amount of money by type of money

入力された金額を金種別に分類するプログラムをC言語で作成して

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

CodeGemma-7b-it

#include <stdio.h>

int main() {
    int amount;

    // Get the amount of money from the user
    printf("Enter the amount of money: ");
    scanf("%d", &amount);

    // Check the amount of money
    if (amount >= 1000) {
        printf("The money is a large amount.\n");
    } else if (amount >= 500) {
        printf("The money is a medium amount.\n");
    } else {
        printf("The money is a small amount.\n");
    }

    return 0;
}

Stable Code Instruct 3B

Here is a simple program in C that classifies the entered amount of money by type (cash, credit card, or debit card). This program only serves as a basic example and can be expanded upon to include more accurate classification based on specific conditions.


#include <stdio.h>

int main() {
    float money;

    printf("Enter the amount of money: ");
    scanf("%f", &money);

    if(money <= 0) {
        printf("Invalid amount. Please enter a positive value.\n");
        return 1;
    }

    if(money < 1000) {
        printf("This is small cash.\n");
    } else if(money < 5000) {
        printf("This is credit card payment.\n");
    } else {
        printf("This is a debit card payment.\n");
    }

    return 0;
}
This program asks the user to input an amount of money, then it checks if the amount is less than 1000, between 1000 and 5000, or more than 5000. Based on these conditions, it prints out the type of money.

Remember, this is a very basic example. For a real-world application, you would likely need to consider additional factors, such as currency type (US dollars, Euros, etc.), transaction frequency, account balance, payment method (not only credit/debit cards, but also online payments, mobile payments, etc.), and many others.

Also, note that this program does not handle errors related to input, such as non-numeric input or negative numbers. You might want to add error checking code to handle such situations according to your specific requirements.

以下は、入力された金額をタイプ別(現金、クレジットカード、デビットカード)に分類するシンプルなC言語のプログラムです。このプログラムは基本的な例としてのみ機能し、特定の条件に基づいてより正確な分類を含めるために拡張することができます。

#include <stdio.h>

int main() {
    float money;

    printf("金額を入力してください: ");
    scanf("%f", &money);

    if(money <= 0) {
        printf("無効な金額です。正の値を入力してください。\n");
        return 1;
    }

    if(money < 1000) {
        printf("これは少額の現金です。\n");
    } else if(money < 5000) {
        printf("これはクレジットカードでの支払いです。\n");
    } else {
        printf("これはデビットカードでの支払いです。\n");
    }

    return 0;
}

このプログラムは、ユーザーに金額を入力してもらい、その金額が1000未満、1000以上5000未満、または5000以上であるかどうかをチェックします。これらの条件に基づいて、金銭の種類を出力します。

覚えておくべきことは、これは非常に基本的な例です。実際のアプリケーションでは、通貨の種類(米ドル、ユーロなど)、取引頻度、口座残高、支払い方法(クレジット/デビットカードだけでなく、オンライン支払い、モバイル支払いなども)など、追加の要因を考慮する必要があります。

また、このプログラムは、数値以外の入力や負の数など、入力に関連するエラーを処理しません。特定の要件に応じて、このような状況を処理するためのエラーチェックコードを追加することを検討してください。

GPT-4

Creating a simple C program to classify an entered amount of money by type can be a fun way to practice basic programming skills. This program will ask the user to enter an amount in a specific currency (for simplicity, let's use dollars), and it will then break down this amount into different denominations (e.g., 20s, 10s, 5s, and 1s).

Here's a simple example of how such a program could look:

```c
#include <stdio.h>

int main() {
    int amount, twenties, tens, fives, ones;

    printf("Enter an amount in dollars: ");
    scanf("%d", &amount);

    twenties = amount / 20; // Calculate the number of 20 dollar bills
    amount = amount % 20; // Update the amount with the remainder

    tens = amount / 10; // Calculate the number of 10 dollar bills
    amount = amount % 10; // Update the amount with the remainder

    fives = amount / 5; // Calculate the number of 5 dollar bills
    amount = amount % 5; // Update the amount with the remainder

    ones = amount; // The remainder are 1 dollar bills

    printf("Your amount includes:\n");
    printf("%d Twenty dollar bills\n", twenties);
    printf("%d Ten dollar bills\n", tens);
    printf("%d Five dollar bills\n", fives);
    printf("%d One dollar bills\n", ones);

    return 0;
}
```

To run this program, you'll need to compile it with a C compiler like GCC. Here's how you might do that:

```bash
gcc -o money_classifier money_classifier.c
./money_classifier
```

This assumes you've saved the code in a file named `money_classifier.c`. When you run the program, it will prompt you to enter an amount in dollars, and it will then break down that amount into 20s, 10s, 5s, and 1s, printing out how many of each type of bill the entered amount equates to.

This program is a basic example and does not handle input errors or amounts in coins for simplicity. Expanding this program to include coin denominations or to handle input errors could be good practice for further learning.

指定された金額を異なる額面に分類するシンプルなC言語のプログラムを作成することは、基本的なプログラミングスキルを練習する良い方法です。このプログラムでは、ユーザーに特定の通貨で金額(簡単のためにドルを使用します)を入力してもらい、その金額を異なる額面(例えば、20ドル札、10ドル札、5ドル札、1ドル札)に分けます。

以下は、そのようなプログラムの簡単な例です:

#include <stdio.h>

int main() {
    int amount, twenties, tens, fives, ones;

    printf("ドルで金額を入力してください: ");
    scanf("%d", &amount);

    twenties = amount / 20; // 20ドル札の枚数を計算
    amount = amount % 20; // 残額を更新

    tens = amount / 10; // 10ドル札の枚数を計算
    amount = amount % 10; // 残額を更新

    fives = amount / 5; // 5ドル札の枚数を計算
    amount = amount % 5; // 残額を更新

    ones = amount; // 残りは1ドル札

    printf("あなたの金額には以下が含まれます:\n");
    printf("%d枚の20ドル札\n", twenties);
    printf("%d枚の10ドル札\n", tens);
    printf("%d枚の5ドル札\n", fives);
    printf("%d枚の1ドル札\n", ones);

    return 0;
}

このプログラムを実行するには、GCCのようなCコンパイラでコンパイルする必要があります。以下の方法でそれを行うことができます:

gcc -o money_classifier money_classifier.c
./money_classifier

この例では、コードをmoney_classifier.cという名前のファイルに保存していると仮定しています。プログラムを実行すると、ドルで金額を入力するように求められ、入力された金額が20ドル札、10ドル札、5ドル札、1ドル札にそれぞれどれだけ該当するかを表示します。

このプログラムは基本的な例であり、簡略化のために入力エラーや硬貨での金額には対応していません。プログラムを拡張して硬貨の額面を含めたり、入力エラーを処理したりすることは、さらなる学習のための良い練習になります。

こちらは全てのモデルが正しく動作するコードを生成してくれましたが、私が想定していたコードを生成してくれたのはGPT-4のみでした。

CodeGemma-7b-itは金額の大きさで、Stable Code Instruct 3Bは支払いのタイプで分類しており、私が想定していたものではありませんでした。

その点、GPT-4は通貨をドルと仮定して、異なる額面ごとに分類する仕組みになっており、この中では唯一コンパイル方法も出力してくれました。

逆にCodeGemma-7b-itは説明が全くないので、まだまだGPT-4との差は歴然で、Stable Code Instruct 3Bにも劣ると感じました。

今回の検証の結果、CodeGemma-7b-itは日本語の形態素解析のコードでタイ語のトークナイザーを使用するなど、正直期待していたほどの能力は持っておらず、Stable Code Instruct 3Bにも劣ると感じました。

今回は残念な結果でしたが、今後のアップデートで改善されることを期待します。

なお、GPT-4について知りたい方はこちらの記事をご覧ください。CodeGemma-7b-it Stable Code Instruct 3B GPT-4
GPT-4とは?GPT-4の使い方や料金体系、GPT-3.5との違い、API、画像入力の方法を解説!

CodeGemmaでコーディングタスクをもっと効率的に!

CodeGemmaは、パワフルで軽量なコーディングタスク特化LLMで、コード補完、コード生成、自然言語理解、数学的推論など、さまざまなコーディングタスクを実行できます。

合計3つのモデルがあり、それぞれ能力に違いがあります。

  • CodeGemma 2B:高速なコード補完に特化し、最大2倍高速なコード補完を実現した2Bモデル
  • CodeGemma 7B:コード補完とコード生成タスクに特化した7Bモデル
  • CodeGemma 7B-IT:自然言語からコードへのチャットとその後の指示に特化した微調整7Bモデル

このモデルは、高い性能を持つだけでなく、Python、JavaScriptなどの数多くの主要なプログラミング言語に対応しており、幅広い場面で活躍できます。

実際に使ってみた感想は、全く関係のないライブラリや存在しないライブラリをインポートしたり、生成コードにエラー処理がないなど、正直期待していたほどの性能は感じられませんでした。

利用規約に同意するだけで簡単に利用でき、商用利用も可なので、もし気になった方は是非試してみてください!

サービス紹介資料

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

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

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

・システム間API連携

最後に

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

弊社では

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

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

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

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

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

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

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

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

投稿者

  • ゆうや

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

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