Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
def postprocess_gen_text(gen_text):
sentences = gen_text.split(".")
for i, sent in enumerate(sentences):
sent = ". ".join([s.strip() for s in sent.split(".")]).capitalize().strip()
sent = re.sub(r"\bi\b", "I", sent)
sent = re.sub(r"\bgod\b", "God", sent)
sent = re.sub(r"\bchrist\b", "Christ", sent)
sentences[i] = sent
return ". ".join(sentences).strip()
def generate_quote(model_name: ModelName, seed: str, gen_kwargs: dict):
global model
global tokenizer
global current_model_name
if model_name != current_model_name:
gpt2_finetune = pipeline(
"text-generation", model=model, tokenizer=tokenizer, device=-1,
gen_text = gpt2_finetune(seed, **gen_kwargs)[0]["generated_text"]
return postprocess_gen_text(gen_text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment