Edit model card

image/png

モデルカード(Model Card for Model ID)

C3TR-AdapterはGoogleが発表したLLMであるgemma-7bの日英・英日翻訳性能を向上させるQLoRA Adapterです。
C3TR-Adapter is a QLoRA Adapter that improves the Japanese-English and English-Japanese translation performance of gemma-7b released by Google.

モデル詳細(Model Details)

C3TR-Adapterは翻訳ベンチマークで多言語翻訳モデルであるGoogleのMadlad400やmetaのSeamless m4t v2 large、ALMA-Ja-V2 (私達の以前のllama 2ベースのモデル)よりも大幅に優れた日英・日英翻訳性能を持っています。
Benchmarks show significantly better English-Japanese and Japanese-English translation performance than Google's Madlad400, META's Seamless m4t v2 large, and ALMA-Ja-V2 (our previous llama2 model).

GoogleのウェブサービスColabを使うと無料でC3TR-Adapterを試す事が出来ます。リンク先でOpen In Colabボタンを押して起動してください。
You can try C3TR-Adapter for free using Google's web service Colab. Please press the Open In Colab button on the link to activate it.

モデルの動かし方(How to use Model)

自分のパソコンで動かす場合は、少なくとも約8.3GB以上のGPU RAMが必要です。GPUメモリが足りない場合は上記のgguf版を試すか、パラメーターを調整してください(max_length、max_new_tokensを減らす)
If you want to run it on your own local computer, you will need at least approximately 8.3 GB or more of GPU RAM.If you do not have enough GPU memory, try the gguf version above or decrease parameters(max_length、max_new_tokens).

必要なライブラリのインストール(Installation of required libraries)

# もし、pytorchがまだインストールされていなかったら公式マニュアルを参考にインストールしてください
# If pytorch is not already installed, please refer to the official manual to install it.
# https://pytorch.org/get-started/locally/#start-locally

# example for linux user with CUDA 12.1.
# pip3 install torch torchvision torchaudio

# example for windows user with CUDA 12.1.
# pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121

# Gemmaは最新のライブラリでなくては動かないので、以下のVersionに更新してください
# Gemma will not work without the latest library, so please update to the following version
pip install transformers==4.38.2
pip install peft==0.9.0
pip install bitsandbytes==0.42.0

サンプルスクリプト(sample script)

import torch
import os
import json
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel

model_id = "unsloth/gemma-7b-bnb-4bit"
peft_model_id = "webbigdata/C3TR-Adapter"

model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto") 
model = PeftModel.from_pretrained(model = model, model_id = peft_model_id)
tokenizer = AutoTokenizer.from_pretrained(model_id)

def trans(my_str):
    input_ids = tokenizer(my_str, return_tensors="pt",
        padding=True, max_length=1600, truncation=True).input_ids.cuda()

    # Translation
    generated_ids = model.generate(input_ids=input_ids,
        max_new_tokens=800, use_cache=True
        )
    full_outputs = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)
    return full_outputs[0].split("### Answer:\n")[-1].strip()
    
ret = trans("""
### Instructions:
Translate Japanese to English.
### Input:
現地時間2月22日午後8時05分(日本時間2月23日午前8時05分)から約1時間半、G20外相会合出席のためリオデジャネイロを訪問中の上川陽子外務大臣は、「WPS+イノベ-ション in リオ」と題する意見交換会を主催したところ、概要は以下のとおりです。

続いて、エリカ・タキモト・リオデジャネイロ州議会議員、ジョイス・トリンダ-ジ・リオ市女性活躍推進局長、スザンナ・カ-ン・リオデジャネイロ連邦大学工学部長、柔道家のシルヴァナ・ナガイ氏から、それぞれブラジルにおける現場での経験を踏まえつつ、貧困や環境問題、女性の社会進出等の社会課題について、女性の視点を共有しつつ、発言しました。
### Answer:
""")
print(ret)

プロンプトフォーマットはalpacaです。
The prompt format is alpaca.

Instructionsは"Translate Japanese to English."(日英翻訳)と"Translate English to Japanese."(英日翻訳)の2種類です。
There are two types of instructions: "Translate Japanese to English." and "Translate English to Japanese.".

実験的な試みとして、インフォーマルな場面を想定した翻訳を行う際にsubculture文脈指定ができるようになっています。
As an experiment, subculture context can be specified when translating for informal situations.

eg:
Translate English to Japanese within the context of subculture.

image/png

留意事項 Attention

このアダプターをモデルとマージして保存すると性能が下がってしまう不具合が存在するため、ベースモデル(gemma-7b-bnb-4bit)とアダプターをマージして保存しないでください
Do not save this adapter merged with the base model(gemma-7b-bnb-4bit), as there exists a bug that reduces performance when saving this adapter merged with the model.

どうしてもマージしたい場合は必ずPerplexityではなく、翻訳ベンチマークで性能を確認してから使うようにしてください
If you must merge, be sure to use a translation benchmark to check performance, not Perplexity!

利用規約 Terms of Use

基本的にはgemmaと同じライセンスです
Basically the same license as gemma.

加えて貴方に以下のお願いがあります。
Additionally, We have the following request to you.

私たちの以前のモデルであるALMA-7B-Ja-V2のダウンロード件数は15万件を超えているのですが、どんな人がどのような場面で使っているのか全く把握できていません。
Our previous model, ALMA-7B-Ja-V2, has over 150K downloads, but we have no idea who is using it and in what situations.

そのため、使用した後はGoogleフォームに感想や今後期待する方向性、気が付いた誤訳の例、参考にして欲しいデータの場所、Webサイトなどを是非とも記入してください。
So, after you use it, please fill out the Google form below with your impressions, future directions you expect us to take, examples of mistranslations you have noticed, and locations of data you would like us to reference, websites, etc. by all means.

個人情報やメールアドレスは収集しないので、気軽にご記入をお願いします
We do not collect personal information or email address, so please feel free to fill out the form!

どんなご意見でも感謝します! Any feedback would be appreciated!

謝辞 Acknowledgment

Original Base Model
google/gemma-7b
https://huggingface.co/google/gemma-7b

Base Model
unsloth/gemma-7b-bnb-4bit
https://huggingface.co/unsloth/gemma-7b-bnb-4bit

QLoRA Adapter
webbigdata/C3TR-Adapter
https://huggingface.co/webbigdata/C3TR-Adapter

This adapter was trained with Unsloth.
https://github.com/unslothai/unsloth

その他、ALMAをはじめ、コミュニティの皆さんからヒントを貰っています。ありがとう
Other tips I have received from ALMA and others in the community. Thank you.

Downloads last month
383
Inference Examples
Inference API (serverless) does not yet support peft models for this pipeline type.

Adapter for