LoginSignup
1
1

Preferred NetworksのPLaMo-13BをDatabricksで動かしてみる

Posted at

週末の趣味みたいになってますが。

%pip install numpy safetensors sentencepiece torch transformers
import transformers
pipeline = transformers.pipeline("text-generation", model="pfnet/plamo-13b", trust_remote_code=True)
print(pipeline("The future of artificial intelligence technology is ", max_new_tokens=32))

最初はこれで以下のエラーになりました。

AttributeError: module 'torch.nn.functional' has no attribute 'scaled_dot_product_attention'

こちらを参考にtorchのバージョンを上げたら解消しました。

%pip install --upgrade torch
dbutils.library.restartPython()

再度実行。

import transformers
pipeline = transformers.pipeline("text-generation", model="pfnet/plamo-13b", trust_remote_code=True)
print(pipeline("The future of artificial intelligence technology is ", max_new_tokens=32))

動きました。

[{'generated_text': 'The future of artificial intelligence technology is fascinating, but it’s also scary. There are many scenarios that could play out, and there’s'}]

日本語でも。

from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("pfnet/plamo-13b", trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained("pfnet/plamo-13b", trust_remote_code=True)
text = "これからの人工知能技術は"
input_ids = tokenizer(text, return_tensors="pt").input_ids
generated_tokens = model.generate(
    inputs=input_ids,
    max_new_tokens=32,
    do_sample=True,
    top_k=50,
    top_p=0.95,
    temperature=1.0,
)[0]
generated_text = tokenizer.decode(generated_tokens)
print(generated_text)
これからの人工知能技術は、その発展が見込まれます。しかしそれだけではなく、人工知能が進化することによって、社会のシステムを根本から変えてしまうようなことも起こり得ると、筆者は

恒例の。

def gen_text(text):
  input_ids = tokenizer(text, return_tensors="pt").input_ids
  generated_tokens = model.generate(
    inputs=input_ids,
    max_new_tokens=32,
    do_sample=True,
    top_k=50,
    top_p=0.95,
    temperature=1.0,
  )[0]
  generated_text = tokenizer.decode(generated_tokens)
  return generated_text
print(gen_text("Databricksとは"))

Databricksとは、AIと分析を、ビジネスの最前線で活用するためのソフトウェアとサポートを提供する企業である。Databricksは、世界をリードするテクノロジーとデータ・プロバイダ

print(gen_text("What is Databricks?"))

Databricks is a privately held software company which was founded in 2013 by the creators of Apache Spark, and is based in

日英対応というのはいいですね。活用の幅が広がりそうです。

Databricksクイックスタートガイド

Databricksクイックスタートガイド

Databricks無料トライアル

Databricks無料トライアル

1
1
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
1