🚀 希伯来语GPT-Neo小模型
基于EleutherAI的gpt - neo的希伯来语文本生成模型。每个模型都在TPUv3 - 8上进行训练,该TPU通过TPU研究云计划提供给我使用。
🚀 快速开始
本项目是一个基于EleutherAI的gpt - neo的希伯来语文本生成模型。以下将为你介绍数据集、训练配置和使用方法等内容。
✨ 主要特性
- 基于EleutherAI的gpt - neo架构,适用于希伯来语文本生成。
- 在TPUv3 - 8上进行训练,借助TPU研究云计划。
📦 安装指南
在使用模型前,你需要安装必要的库:
!pip install tokenizers==0.10.2 transformers==4.6.0
💻 使用示例
基础用法
你可以通过Google Colab Notebook使用该模型,点击此处访问。
以下是一个简单的使用示例代码:
!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 * '-')
📚 详细文档
数据集
- 各种希伯来语语料库:我已将其放在此处。
- oscar / unshuffled_deduplicated_he:主页 | 数据集永久链接。Open Super - large Crawled ALMAnaCH coRpus是一个巨大的多语言语料库,通过使用goclassy架构对Common Crawl语料库进行语言分类和过滤获得。
- CC100 - 希伯来语数据集:主页。该数据集由Conneau和Wenzek等人在2020年创建,是从CC - Net存储库中2018年1月 - 12月的Commoncrawl快照处理得到的100个单语言语料库之一。该语料库大小为6.1G,为希伯来语。
训练配置
训练配置可在此处获取。
📄 许可证
本项目采用MIT许可证。