-
-
Save manujosephv/7e6c02982b50f26961be90d334ad48a2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | |
_load_model(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