🚀 ヘブライ語GPT - Neo Small
このモデルは、[EleutherAIのgpt - neo](https://github.com/EleutherAI/gpt - neo)に基づいたヘブライ語のテキスト生成モデルです。各モデルは、TPU Research Cloudプログラムを通じて利用可能になったTPUv3 - 8上でトレーニングされました。
✨ 主な機能
- ヘブライ語のテキスト生成が可能です。
- 複数のヘブライ語コーパスを用いてトレーニングされています。
📦 インストール
使用には以下のライブラリをインストールする必要があります。
!pip install tokenizers==0.10.2 transformers==4.6.0
📚 ドキュメント
データセット
- 様々なヘブライ語コーパスの集合 - [こちら](https://mega.nz/folder/CodSSA4R#4INvMes - 56m_WUi7jQMbJQ)で利用可能です。
- oscar / unshuffled_deduplicated_he - [ホームページ](https://oscar - corpus.com) | データセットのパーマリンク
Open Super - large Crawled ALMAnaCH coRpusは、goclassyアーキテクチャを使用してCommon Crawlコーパスを言語分類およびフィルタリングすることで得られた巨大な多言語コーパスです。
- CC100 - ヘブライ語データセット [ホームページ](https://metatext.io/datasets/cc100 - hebrew)
2020年にConneau & Wenzekらによって作成されたCC100 - ヘブライ語データセットは、CC - Netリポジトリの2018年1月 - 12月のCommoncrawlスナップショットから処理された100の単言語データコーパスの1つです。このコーパスのサイズは6.1GBで、ヘブライ語です。
トレーニング設定
[こちら](https://github.com/Norod/hebrew - gpt_neo/tree/main/hebrew - gpt_neo - small/configs)で利用可能です。
💻 使用例
基本的な使用法
!pip install tokenizers==0.10.2 transformers==4.6.0
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("Norod78/hebrew-gpt_neo-small")
model = AutoModelForCausalLM.from_pretrained("Norod78/hebrew-gpt_neo-small", 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
[こちら](https://colab.research.google.com/github/Norod/hebrew - gpt_neo/blob/main/hebrew - gpt_neo - small/Norod78_hebrew_gpt_neo_small_Colab.ipynb)で利用可能です。
📄 ライセンス
このプロジェクトはMITライセンスの下で公開されています。