<jupyter_start><jupyter_text>Vorbereitung2. Zelle für Generierungen mit dem spezialisierten Modell3. Für Generierungen mit dem originalen Modell<jupyter_code># Install packages
try:
  import gpt_2_simple as gpt2
except:
  %tensorflow_version 1.x
  !pip install -q gpt-2-simple

import os
import gpt_2_simple as gpt2


# Mount Drive
if not os.path.isdir("/content/drive/"):
  gpt2.mount_gdrive()
# Load lyrics Model
checkpoint_dir='/content/drive/MyDrive/Training-Data/gpt-2/saved/1558M-41343'
sess = gpt2.start_tf_sess()
gpt2.load_gpt2(sess,
              checkpoint='latest',
              run_name='1558M-41343',
              checkpoint_dir='/content/drive/MyDrive/Training-Data/gpt-2/saved/',
              model_name=None,)
# Load regular Model
sess = gpt2.start_tf_sess()
gpt2.download_gpt2(model_name="1558M")
gpt2.load_gpt2(sess,model_name="1558M")<jupyter_output><empty_output><jupyter_text>Kapitel 4. Liedtexte generieren Musiktexte erzeugen (ohne Eingabekontext)<jupyter_code>#1h 4min for n=100
n = 300
file_dir= "/content/drive/MyDrive/Training-Data/generated/"
file_name = file_dir + str(len(os.listdir(file_dir))) + "-generated-"+ str(n) +".txt"

gpt2.generate_to_file(
              sess,
              run_name='1558M-41343',
              checkpoint_dir='/content/drive/MyDrive/Training-Data/gpt-2/saved/',
              length=1023,
              nsamples=n,
              top_k=40,
              sample_delim="=" * 20 + "\n",
              destination_path=file_name,
              prefix="<|startoftext|>",
              truncate='<|endoftext|>',
              include_prefix=False
              )<jupyter_output><empty_output><jupyter_text>Texte mit regulärem GPT-2 erzeugen<jupyter_code>n = 300
file_dir= "/content/drive/MyDrive/Training-Data/generated_orig/"
file_name = file_dir + str(len(os.listdir(file_dir))) + "-generated-"+ str(n) +".txt"

text = gpt2.generate(
              sess,
              length=1023,
              nsamples=n,
              destination_path=file_name,
              model_name="1558M",
              top_k=40,
              sample_delim="=" * 20 + "\n",
              truncate='<|endoftext|>',
              include_prefix=False
              )<jupyter_output><empty_output><jupyter_text>Kapitel 5: Cover erzeugen<jupyter_code>from tqdm import tqdm 
import pandas as pd
import numpy as np

# Input data for which to genrate covers
df = pd.read_csv("/content/drive/MyDrive/Training-Data/covers/eval_results_org.csv", index_col=0)


# Loop over every song
for index in tqdm(df.index, unit="covers"):
  try:
    if not pd.isna(df["completions"][index]):
      continue
  except KeyError :
    pass

  # get first and second half for current song
  text = df["original"][index]
  c_index = text.index("\n", int(len(text) / 2), len(text)-1)
  end = text[c_index:len(text)-1]
  start = text[0:c_index]

  # Generate 15 cover passages 
  completions = gpt2.generate(
      sess,
                run_name='1558M-41343',
                checkpoint_dir='/content/drive/MyDrive/Training-Data/gpt-2/saved/',
                return_as_list=True,
                length=1023,
                nsamples=15,
                temperature=0.7,
                prefix="<|startoftext|>" + start,
                truncate='<|endoftext|>',
                include_prefix=False
                )
  
  df["start"][index]=start
  df["end"][index]=end
  # store cover versions after every generation
  df["completions"][index]=completions
  df.to_csv("/content/drive/MyDrive/Training-Data/covers/eval_results_org.csv")<jupyter_output>100%|██████████| 100/100 [09:00<00:00,  5.40s/covers]<jupyter_text>Kapitel 3 EvaluierungEine vervollständigung pro Lied<jupyter_code>import pandas as pd
from tqdm import tqdm

df = pd.read_csv("/content/drive/MyDrive/Training-Data/completion-1.0.csv", index_col=0)

for index in tqdm(df.index, unit="covers"):
  if not pd.isna(df["completion"][index]):
    continue
  input = df["original"][index]
  try:
    c_index = input.index("\n", int(len(input) / 2), len(input)-1)
  except:
    continue
  end = input[c_index:len(input)-1]
  input = input[0:c_index]

  text = gpt2.generate(
                sess,
                run_name='1558M-41343',
                checkpoint_dir='/content/drive/MyDrive/Training-Data/gpt-2/saved/',
                return_as_list=True,
                length=1023,
                nsamples=1,
                top_k=40,
                prefix="<|startoftext|>" + context,
                truncate='<|endoftext|>',
                include_prefix=False
                )

  df["start"][index]=input
  df["end"][index]=end
  df["completion"][index]=text
  df.to_csv("/content/drive/MyDrive/Training-Data/completion-1.0.csv")<jupyter_output>7%|▋         | 297/4443 [14:54:24<806:16:55, 700.10s/covers]
{'fraction_non_alphanumeric': 0.1345591307981613, 'fraction_numerical': 0.039908065190137905, 'mean_word_length': 2.7252918287937744, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '167462', 'license': 'MIT', 'n_tokens_mistral': 1835, 'n_tokens_neox': 1656, 'n_words': 268, 'path': 'Colab_Notebooks/GPT_2_Generation_(GPU).ipynb', 'repo_name': 'curi0sity-97/lyrics-generation-gpt2', 'size': '4786'}