Created
August 1, 2021 21:30
-
-
Save EricFillion/7752b6584591935edb8cfcbad8c2b9ed to your computer and use it in GitHub Desktop.
Styleformer With Happy Transformer
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
# In terminal | |
# pip install happytransformer | |
# Python code below | |
#------------------------------------------------------------------------------------------------------------------------------ | |
# Casual to Formal | |
#------------------------------------------------------------------------------------------------------------------------------ | |
from happytransformer import HappyTextToText | |
happy_c_t_f = HappyTextToText("T5", "prithivida/informal_to_formal_styletransfer") | |
from happytransformer import TTSettings | |
# Learn more about adjusting the settings here: | |
# https://happytransformer.com/text-to-text/settings/ | |
top_k_sampling_settings = TTSettings(do_sample=True, top_k=20, temperature=0.5, min_length=1, max_length=100) | |
prefix_c_t_f = "transfer Casual to Formal: " | |
text_c_t_f = "I wanna play chess with you as we watch TV" | |
input_c_t_f = prefix_c_t_f + text_c_t_f | |
result_c_t_f = happy_c_t_f.generate_text(input_c_t_f, args=top_k_sampling_settings) | |
print(result_c_t_f.text) # I would like to play chess with you while we watch television. | |
#------------------------------------------------------------------------------------------------------------------------------ | |
# Formal to Casual | |
#------------------------------------------------------------------------------------------------------------------------------ | |
happy_f_t_c = HappyTextToText("T5", "prithivida/formal_to_informal_styletransfer") | |
prefix_f_t_c = "transfer Formal to Casual: " | |
text_f_t_c = "Shall we have dinner this evening downtown?" | |
input_f_t_c = prefix_f_t_c + text_f_t_c | |
result_f_t_c = happy_f_t_c.generate_text(input_f_t_c, args=top_k_sampling_settings) | |
print(result_f_t_c.text) # will we have dinner downtown tonight? | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment