🚀 希伯来语GPT Neo XL诗歌生成模型
这是一个希伯来语诗歌文本生成模型,它基于 hebrew - gpt_neo - xl 进行了微调。该模型能够生成富有创意的希伯来语诗歌文本,为希伯来语诗歌创作提供了新的可能。
🚀 快速开始
你可以通过以下方式快速使用本模型:
- Google Colab Notebook:点击 此处 即可使用。
✨ 主要特性
- 基于强大基础模型:在
hebrew-gpt_neo-xl
基础上微调,继承了其强大的语言理解和生成能力。
- 丰富数据集训练:使用多种希伯来语书籍、杂志和诗歌语料库进行训练,生成的诗歌更具多样性和专业性。
📦 安装指南
在使用模型前,你需要安装必要的依赖库,可使用以下命令进行安装:
!pip install tokenizers==0.10.3 transformers==4.8.0
💻 使用示例
基础用法
!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 * '-')
📚 详细文档
数据集
本模型使用了多种希伯来语书籍、杂志和诗歌语料库进行训练,这些丰富的数据集为模型提供了多样化的语言模式和知识。
训练配置
训练配置与 此配置 类似。
📄 许可证
本项目采用 MIT 许可证。