🚀 ヘブライ語GPT_neo-xl詩歌生成モデル
このモデルは、hebrew-gpt_neo-xl をベースに微調整されたヘブライ語の詩歌テキスト生成モデルです。
🚀 クイックスタート
このモデルを使用することで、ヘブライ語の詩歌を生成することができます。以下に使用方法や関連情報を紹介します。
✨ 主な機能
- ヘブライ語の詩歌テキストを生成することができます。
- 様々なヘブライ語の書籍、雑誌、詩歌コーパスを用いて訓練されています。
📦 インストール
使用するには、以下のライブラリをインストールする必要があります。
!pip install tokenizers==0.10.3 transformers==4.8.0
💻 使用例
基本的な使用法
以下のコードは、このモデルを使用してヘブライ語の詩歌を生成する基本的な例です。
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("Norod78/hebrew-gpt_neo-xl-poetry")
model = AutoModelForCausalLM.from_pretrained("Norod78/hebrew-gpt_neo-xl-poetry", pad_token_id=tokenizer.eos_token_id)
prompt_text = "אני אוהב שוקולד ועוגות"
max_len = 512
sample_output_num = 3
seed = 1000
import numpy as np
import torch
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
n_gpu = 0 if torch.cuda.is_available()==False else torch.cuda.device_count()
print(f"device: {device}, n_gpu: {n_gpu}")
np.random.seed(seed)
torch.manual_seed(seed)
if n_gpu > 0:
torch.cuda.manual_seed_all(seed)
model.to(device)
encoded_prompt = tokenizer.encode(
prompt_text, add_special_tokens=False, return_tensors="pt")
encoded_prompt = encoded_prompt.to(device)
if encoded_prompt.size()[-1] == 0:
input_ids = None
else:
input_ids = encoded_prompt
print("input_ids = " + str(input_ids))
if input_ids != None:
max_len += len(encoded_prompt[0])
if max_len > 2048:
max_len = 2048
print("Updated max_len = " + str(max_len))
stop_token = "<|endoftext|>"
new_lines = "\n\n\n"
sample_outputs = model.generate(
input_ids,
do_sample=True,
max_length=max_len,
top_k=50,
top_p=0.95,
num_return_sequences=sample_output_num
)
print(100 * '-' + "\n\t\tOutput\n" + 100 * '-')
for i, sample_output in enumerate(sample_outputs):
text = tokenizer.decode(sample_output, skip_special_tokens=True)
text = text[: text.find(stop_token) if stop_token else None]
text = text[: text.find(new_lines) if new_lines else None]
print("\n{}: {}".format(i, text))
print("\n" + 100 * '-')
Google Colab Notebook
Google Colabでこのモデルを使用することができます。こちら からアクセスできます。
📚 ドキュメント
データセット
このモデルの訓練には、様々なヘブライ語の書籍、雑誌、詩歌コーパスが使用されています。
訓練設定
訓練設定は、こちら の設定に似ています。
📄 ライセンス
このプロジェクトはMITライセンスの下で公開されています。