初始化项目,由ModelHub XC社区提供模型
Model: smgriffin/pop-lyrics-generator-v1 Source: Original Platform
This commit is contained in:
35
.gitattributes
vendored
Normal file
35
.gitattributes
vendored
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
*.7z filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.arrow filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.bin filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.ftz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.gz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.h5 filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.joblib filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.model filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.npy filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.npz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.onnx filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.ot filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.parquet filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.pb filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.pickle filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.pkl filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.pt filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.pth filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.rar filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
||||||
|
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.tar filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.tflite filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.tgz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.wasm filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.xz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.zip filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.zst filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
||||||
179
README.md
Normal file
179
README.md
Normal file
@@ -0,0 +1,179 @@
|
|||||||
|
---
|
||||||
|
library_name: transformers
|
||||||
|
tags:
|
||||||
|
- lyrics
|
||||||
|
- text
|
||||||
|
- text-to-lyrics
|
||||||
|
- artist-to-lyrics
|
||||||
|
- text-generation
|
||||||
|
datasets:
|
||||||
|
- smgriffin/modern-pop-lyrics
|
||||||
|
language:
|
||||||
|
- en
|
||||||
|
base_model:
|
||||||
|
- openai-community/gpt2
|
||||||
|
pipeline_tag: text-generation
|
||||||
|
---
|
||||||
|
|
||||||
|
# Model Card for pop-lyrics-generator-v1
|
||||||
|
|
||||||
|
<!-- Provide a quick summary of what the model is/does. -->
|
||||||
|
Finetuned from openai-community/gpt2 on smgriffin/modern-pop-lyrics - generates lyrics for specific pop artists.
|
||||||
|
|
||||||
|
|
||||||
|
### Model Description
|
||||||
|
|
||||||
|
<!-- Provide a longer summary of what this model is. -->
|
||||||
|
|
||||||
|
It's pretty good at generating a song structure and stylized lyrics by artist, but bad at rhyming. Sometimes repeats the same thing over and over, but so do pop artists.
|
||||||
|
It might be good for inspiration while writing lyrics. Some of the content generated can be really silly and potentially offensive - especially if you input Lil Wayne.
|
||||||
|
|
||||||
|
- **Developed by:** Scott Griffin
|
||||||
|
- **Model type:** Generative Language
|
||||||
|
- **Language(s) (NLP):** English, Spanish
|
||||||
|
- **Finetuned from model [optional]:** openai-community/gpt2
|
||||||
|
|
||||||
|
Check out the w&b run here: [https://wandb.ai/scottgriffinm-scott-griffin-industrial-complex/pop-lyrics-generator-v1?nw=nwuserscottgriffinm](https://wandb.ai/scottgriffinm-scott-griffin-industrial-complex/pop-lyrics-generator-v1?nw=nwuserscottgriffinm)
|
||||||
|
|
||||||
|
& my blog post on making it here: [https://scottsblog.glitch.me#pop-lyrics-generator-v1](https://scottsblog.glitch.me#pop-lyrics-generator-v1)
|
||||||
|
|
||||||
|
## Uses
|
||||||
|
|
||||||
|
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
||||||
|
This model is not for commercial use. The content is the property of the individual artist from which the model was finetuned.
|
||||||
|
This is for research purposes only.
|
||||||
|
|
||||||
|
## How to Use
|
||||||
|
|
||||||
|
Use the code below to generate lyrics:
|
||||||
|
|
||||||
|
```python
|
||||||
|
from transformers import GPT2LMHeadModel, GPT2Tokenizer, pipeline
|
||||||
|
|
||||||
|
# load model
|
||||||
|
model_name = "smgriffin/pop-lyrics-generator-v1"
|
||||||
|
model = GPT2LMHeadModel.from_pretrained(model_name)
|
||||||
|
tokenizer = GPT2Tokenizer.from_pretrained(model_name)
|
||||||
|
|
||||||
|
# create text generation pipeline
|
||||||
|
text_generator = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
||||||
|
|
||||||
|
# prompt for justin bieber lyrics
|
||||||
|
artist_name = "Justin Bieber"
|
||||||
|
prompt = f"Artist: {artist_name}\nLyrics:"
|
||||||
|
|
||||||
|
# generate and print
|
||||||
|
generated_texts = text_generator(
|
||||||
|
prompt,
|
||||||
|
max_length=150,
|
||||||
|
num_return_sequences=1,
|
||||||
|
temperature=0.9, # less than .9 results in a lot of repeated lyrics
|
||||||
|
top_k=50,
|
||||||
|
top_p=0.95,
|
||||||
|
do_sample=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
print("Generated Lyrics:")
|
||||||
|
print(generated_texts[0]["generated_text"])
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## How to Fine-Tune Your Own Lyric Generation Model
|
||||||
|
|
||||||
|
Use the code below to get finetune your own GPT2 model (for example on the smgriffin/modern-pop-lyrics dataset):
|
||||||
|
|
||||||
|
```python
|
||||||
|
import os
|
||||||
|
import pandas as pd
|
||||||
|
from datasets import load_dataset
|
||||||
|
from transformers import GPT2Tokenizer, GPT2LMHeadModel, Trainer, TrainingArguments, DataCollatorForLanguageModeling
|
||||||
|
|
||||||
|
|
||||||
|
# output directory
|
||||||
|
output_dir = "/your/output/directory"
|
||||||
|
os.makedirs(output_dir, exist_ok=True)
|
||||||
|
|
||||||
|
# load dataset
|
||||||
|
dataset = load_dataset("smgriffin/modern-pop-lyrics")
|
||||||
|
|
||||||
|
# preprocess dataset
|
||||||
|
def preprocess_function(example):
|
||||||
|
# Combine artist name with lyrics for conditioning
|
||||||
|
combined = [f"Artist: {artist}\nLyrics: {lyrics}\n\n" for artist, lyrics in zip(example['artist'], example['lyrics'])]
|
||||||
|
return {"text": combined}
|
||||||
|
|
||||||
|
processed_dataset = dataset.map(preprocess_function, batched=True)
|
||||||
|
|
||||||
|
# split to train and test sets
|
||||||
|
train_test_split = processed_dataset["train"].train_test_split(test_size=0.1, seed=42)
|
||||||
|
train_dataset = train_test_split["train"]
|
||||||
|
val_dataset = train_test_split["test"]
|
||||||
|
|
||||||
|
# load tokenizer, model
|
||||||
|
model_name = "gpt2" # Base GPT-2 model for fine-tuning
|
||||||
|
tokenizer = GPT2Tokenizer.from_pretrained(model_name)
|
||||||
|
|
||||||
|
# fill pad_token with eos_tone (gpt2 doesn't have a padding token)
|
||||||
|
tokenizer.pad_token = tokenizer.eos_token
|
||||||
|
|
||||||
|
# tokenize dataset
|
||||||
|
def tokenize_function(example):
|
||||||
|
tokenized = tokenizer(
|
||||||
|
example["text"],
|
||||||
|
truncation=True,
|
||||||
|
padding="max_length",
|
||||||
|
max_length=512,
|
||||||
|
)
|
||||||
|
return {
|
||||||
|
"input_ids": tokenized["input_ids"],
|
||||||
|
"attention_mask": tokenized["attention_mask"],
|
||||||
|
"labels": tokenized["input_ids"],
|
||||||
|
}
|
||||||
|
|
||||||
|
train_dataset = train_dataset.map(tokenize_function, batched=True, remove_columns=["artist", "lyrics", "text"])
|
||||||
|
val_dataset = val_dataset.map(tokenize_function, batched=True, remove_columns=["artist", "lyrics", "text"])
|
||||||
|
|
||||||
|
# data collator
|
||||||
|
data_collator = DataCollatorForLanguageModeling(tokenizer=tokenizer, mlm=False)
|
||||||
|
|
||||||
|
# load GPT-2
|
||||||
|
model = GPT2LMHeadModel.from_pretrained(model_name)
|
||||||
|
|
||||||
|
# training arguments
|
||||||
|
training_args = TrainingArguments(
|
||||||
|
output_dir=output_dir,
|
||||||
|
overwrite_output_dir=True,
|
||||||
|
evaluation_strategy="epoch",
|
||||||
|
learning_rate=2e-5,
|
||||||
|
weight_decay=0.01,
|
||||||
|
per_device_train_batch_size=8,
|
||||||
|
per_device_eval_batch_size=8,
|
||||||
|
num_train_epochs=10,
|
||||||
|
save_steps=1000,
|
||||||
|
save_total_limit=1,
|
||||||
|
logging_dir=f"{output_dir}/logs",
|
||||||
|
logging_steps=50,
|
||||||
|
gradient_accumulation_steps=2,
|
||||||
|
fp16=True,
|
||||||
|
max_grad_norm=1.0,
|
||||||
|
push_to_hub=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
# init trainer
|
||||||
|
trainer = Trainer(
|
||||||
|
model=model,
|
||||||
|
args=training_args,
|
||||||
|
train_dataset=train_dataset,
|
||||||
|
eval_dataset=val_dataset,
|
||||||
|
tokenizer=tokenizer,
|
||||||
|
data_collator=data_collator,
|
||||||
|
)
|
||||||
|
|
||||||
|
# start fine-tuning
|
||||||
|
trainer.train()
|
||||||
|
|
||||||
|
# save model
|
||||||
|
trainer.save_model(output_dir)
|
||||||
|
tokenizer.save_pretrained(output_dir)
|
||||||
|
|
||||||
|
```
|
||||||
39
config.json
Normal file
39
config.json
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
{
|
||||||
|
"_name_or_path": "/content/drive/MyDrive/new_new_checkpoints/checkpoint-34000",
|
||||||
|
"activation_function": "gelu_new",
|
||||||
|
"architectures": [
|
||||||
|
"GPT2LMHeadModel"
|
||||||
|
],
|
||||||
|
"attn_pdrop": 0.1,
|
||||||
|
"bos_token_id": 50256,
|
||||||
|
"embd_pdrop": 0.1,
|
||||||
|
"eos_token_id": 50256,
|
||||||
|
"initializer_range": 0.02,
|
||||||
|
"layer_norm_epsilon": 1e-05,
|
||||||
|
"model_type": "gpt2",
|
||||||
|
"n_ctx": 1024,
|
||||||
|
"n_embd": 768,
|
||||||
|
"n_head": 12,
|
||||||
|
"n_inner": null,
|
||||||
|
"n_layer": 12,
|
||||||
|
"n_positions": 1024,
|
||||||
|
"reorder_and_upcast_attn": false,
|
||||||
|
"resid_pdrop": 0.1,
|
||||||
|
"scale_attn_by_inverse_layer_idx": false,
|
||||||
|
"scale_attn_weights": true,
|
||||||
|
"summary_activation": null,
|
||||||
|
"summary_first_dropout": 0.1,
|
||||||
|
"summary_proj_to_labels": true,
|
||||||
|
"summary_type": "cls_index",
|
||||||
|
"summary_use_proj": true,
|
||||||
|
"task_specific_params": {
|
||||||
|
"text-generation": {
|
||||||
|
"do_sample": true,
|
||||||
|
"max_length": 50
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"torch_dtype": "float32",
|
||||||
|
"transformers_version": "4.46.3",
|
||||||
|
"use_cache": true,
|
||||||
|
"vocab_size": 50257
|
||||||
|
}
|
||||||
6
generation_config.json
Normal file
6
generation_config.json
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"_from_model_config": true,
|
||||||
|
"bos_token_id": 50256,
|
||||||
|
"eos_token_id": 50256,
|
||||||
|
"transformers_version": "4.46.3"
|
||||||
|
}
|
||||||
50001
merges.txt
Normal file
50001
merges.txt
Normal file
File diff suppressed because it is too large
Load Diff
3
model.safetensors
Normal file
3
model.safetensors
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:f18ca8e26ee8ec3a023a759dce60fdd392beb54b2a3b5134ce5ebce822ede509
|
||||||
|
size 497774208
|
||||||
30
special_tokens_map.json
Normal file
30
special_tokens_map.json
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
{
|
||||||
|
"bos_token": {
|
||||||
|
"content": "<|endoftext|>",
|
||||||
|
"lstrip": false,
|
||||||
|
"normalized": true,
|
||||||
|
"rstrip": false,
|
||||||
|
"single_word": false
|
||||||
|
},
|
||||||
|
"eos_token": {
|
||||||
|
"content": "<|endoftext|>",
|
||||||
|
"lstrip": false,
|
||||||
|
"normalized": true,
|
||||||
|
"rstrip": false,
|
||||||
|
"single_word": false
|
||||||
|
},
|
||||||
|
"pad_token": {
|
||||||
|
"content": "<|endoftext|>",
|
||||||
|
"lstrip": false,
|
||||||
|
"normalized": true,
|
||||||
|
"rstrip": false,
|
||||||
|
"single_word": false
|
||||||
|
},
|
||||||
|
"unk_token": {
|
||||||
|
"content": "<|endoftext|>",
|
||||||
|
"lstrip": false,
|
||||||
|
"normalized": true,
|
||||||
|
"rstrip": false,
|
||||||
|
"single_word": false
|
||||||
|
}
|
||||||
|
}
|
||||||
22
tokenizer_config.json
Normal file
22
tokenizer_config.json
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"add_bos_token": false,
|
||||||
|
"add_prefix_space": false,
|
||||||
|
"added_tokens_decoder": {
|
||||||
|
"50256": {
|
||||||
|
"content": "<|endoftext|>",
|
||||||
|
"lstrip": false,
|
||||||
|
"normalized": true,
|
||||||
|
"rstrip": false,
|
||||||
|
"single_word": false,
|
||||||
|
"special": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"bos_token": "<|endoftext|>",
|
||||||
|
"clean_up_tokenization_spaces": false,
|
||||||
|
"eos_token": "<|endoftext|>",
|
||||||
|
"errors": "replace",
|
||||||
|
"model_max_length": 1024,
|
||||||
|
"pad_token": "<|endoftext|>",
|
||||||
|
"tokenizer_class": "GPT2Tokenizer",
|
||||||
|
"unk_token": "<|endoftext|>"
|
||||||
|
}
|
||||||
50259
vocab.json
Normal file
50259
vocab.json
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user