language: sv
widget:
GPT2-瑞典语-维基百科
一个基于Flax CLM流程训练的瑞典语GPT2风格模型,训练数据来自wiki40b数据集的瑞典语部分。
https://huggingface.co/datasets/wiki40b
模型系列
该模型是Huggingface Flax/Jax挑战期间使用Flax Jax在TPU上训练的一系列模型之一。
GPT模型
瑞典语GPT
https://huggingface.co/birgermoell/swedish-gpt/
瑞典语GPT维基
https://huggingface.co/flax-community/swe-gpt-wiki
北欧GPT维基
https://huggingface.co/flax-community/nordic-gpt-wiki
丹麦语GPT维基
https://huggingface.co/flax-community/dansk-gpt-wiki
挪威语GPT维基
https://huggingface.co/flax-community/norsk-gpt-wiki
Roberta模型
北欧Roberta维基
https://huggingface.co/flax-community/nordic-roberta-wiki
瑞典语Roberta维基Oscar
https://huggingface.co/flax-community/swe-roberta-wiki-oscar
Roberta瑞典语斯堪的纳维亚
https://huggingface.co/birgermoell/roberta-swedish-scandi
Roberta瑞典语
https://huggingface.co/birgermoell/roberta-swedish
瑞典语T5模型
https://huggingface.co/birgermoell/t5-base-swedish
数据清洗与预处理
使用以下脚本对数据进行清洗和预处理。确保安装beam_runner的依赖以使数据集正常工作。
from datasets import load_dataset
def load_and_clean_wiki():
dataset = load_dataset('wiki40b', 'sv', beam_runner='DirectRunner', split="train")
dataset = dataset.remove_columns(['wikidata_id', 'version_id'])
filtered_dataset = dataset.map(filter_wikipedia)
return filtered_dataset
def filter_wikipedia(batch):
batch["text"] = " ".join(batch["text"].split("\
_START_SECTION_\
"))
batch["text"] = " ".join(batch["text"].split("\
_START_ARTICLE_\
"))
batch["text"] = " ".join(batch["text"].split("\
_START_ARTICLE_\
"))
batch["text"] = " ".join(batch["text"].split("\
_START_PARAGRAPH_\
"))
batch["text"] = " ".join(batch["text"].split("_NEWLINE_"))
batch["text"] = " ".join(batch["text"].split("\xa0"))
return batch
训练脚本
使用以下训练脚本训练模型。
./run_clm_flax.py --output_dir="${MODEL_DIR}" --model_type="gpt2" --config_name="${MODEL_DIR}" --tokenizer_name="${MODEL_DIR}" --dataset_name="wiki40b" --dataset_config_name="sv" --do_train --do_eval --block_size="512" --per_device_train_batch_size="64" --per_device_eval_batch_size="64" --learning_rate="5e-3" --warmup_steps="1000" --adam_beta1="0.9" --adam_beta2="0.98" --weight_decay="0.01" --overwrite_output_dir --num_train_epochs="20" --logging_steps="500" --save_steps="1000" --eval_steps="2500" --push_to_hub