1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

llama-cpp-pythonでmadlad400の英日翻訳を試してみた

Last updated at Posted at 2024-09-07

llama.cppでT5のサポートを始めたそうで、llama-cpp-pythonでもお試し実装があったのでmadlad400のggufで翻訳を試してみた。

セットアップ

$ git clone --recurse-submodules https://github.com/fairydreaming/llama-cpp-python.git -b t5
$ cd llama-cpp-python
$ pip install -e .

# madlad400 ggufモデル取得
$ curl -LO https://huggingface.co/mtsdurica/madlad400-3b-mt-Q8_0-GGUF/resolve/main/madlad400-3b-mt-q8_0.gguf

m1 macなのでpip installではなく、makeでllama-cpp-pythonをインストールした。

$ make build.metal

# cudaの場合
$ make build.cuda

サンプルコード

英語ニュースから英文を取得

test.py
from llama_cpp import Llama

llama = Llama("madlad400-3b-mt-q8_0.gguf")

def trans(text):
    text = f"<2ja>{text}".encode()
    tokens = llama.tokenize(text)
    llama.encode(tokens)
    tokens = [llama.decoder_start_token()]
    buf = ""
    for token in llama.generate(tokens, top_k=0, top_p=0.95, temp=0, repeat_penalty=1.0):
        buf += llama.detokenize([token]).decode()
        if token == llama.token_eos():
            break
    return buf

text = """
IT glitch hits airlines, banks around the world.

A massive tech failure hit computers around the globe on July 19, disrupting banks, airlines and telecommunications companies.

In the United States, several major airlines, including United, American Airlines and Delta, stopped all flights."

In Australia, telecommunications provider Telstra reported outages, while National Australia Bank and ANZ had access issues.

The global glitch was reportedly caused by a software update that cybersecurity firm CrowdStrike provided to Windows computers of its corporate customers.
"""

for txt in text.split("\n"):
    if txt == "":
        continue
    buf = trans(txt)
    print(buf)

int8 結果

 ITの問題で航空会社や銀行が 世界中で倒産してる
 7月19日に 世界中のコンピュータに 巨大な技術的故障が起きました 銀行や航空会社 電気通信会社を混乱させました
 アメリカ合衆国では、ユナイテッド航空、アメリカン航空、デルタ航空などの主要航空会社が全ての飛行を停止した。
 オーストラリアでは、電気通信プロバイダのテルストラが停電を報告し、ナショナル・オーストラリア銀行とANZはアクセス問題を抱えていた。
  世界的なグリッチは、サイバーセキュリティ会社CrowdStrikeがその企業顧客のWindowsコンピュータに提供したソフトウェアアップデートによって引き起こされたと報告されている。

最初の一文から航空会社と銀行が倒産している(笑)

和訳

世界各地の航空会社や銀行にシステム障害

7 月 19 日、世界各地のコンピュータに大規模な障害が発生し、銀行、航空会社、通信会社に混乱が生じた。

米国では、ユナイテッド航空、アメリカン航空、デルタ航空を含む大手航空会社数社が全便を欠航とした。

オーストラリアでは、通信会社のテルストラがサービス停止を報告し、ナショナルオーストラリア銀行と オーストラリア・ニュージーランド銀行でもアクセスに問題があった。

世界各地で起きた不具合は、サイバーセキュリティー企業クラウドストライク(CrowdStrike)がウィンドウズを搭載した顧客のコンピュータにアップデートしたソフトウェアを提供した際に引き起こされたとされている。

MEMO

その他の環境でのmadlad400の実行

mlx float16

ctranslate2 int8

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?