🚀 希伯來語GPT-Neo-Tiny模型
這是一個基於EleutherAI的gpt - neo的希伯來語文本生成模型。每個模型都在TPUv3 - 8上進行訓練,該TPU是通過TPU研究雲計劃提供的。
📚 詳細文檔
數據集
- 各類希伯來語語料庫:我已將其發佈在[此處](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語料庫進行語言分類和過濾而獲得的。
訓練配置
訓練配置可在[此處](https://github.com/Norod/hebrew - gpt_neo/tree/main/hebrew - gpt_neo - tiny/configs)獲取。
🚀 快速開始
Google Colab筆記本
你可以在[此處](https://colab.research.google.com/github/Norod/hebrew - gpt_neo/blob/main/hebrew - gpt_neo - tiny/Norod78_hebrew_gpt_neo_tiny_Colab.ipynb)訪問Google Colab筆記本。
💻 使用示例
基礎用法
!pip install tokenizers==0.10.2 transformers==4.6.0
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("Norod78/hebrew-gpt_neo-tiny")
model = AutoModelForCausalLM.from_pretrained("Norod78/hebrew-gpt_neo-tiny", 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 > 1024:
max_len = 1024
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 * '-')
📄 許可證
本項目採用MIT許可證。