Last active
October 9, 2019 02:07
-
-
Save joeyism/e106934aaf81c4011c9b5d580e87e850 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
import string | |
import copy | |
import gpt2 | |
predictor = gpt2.Gpt2Predictor() | |
def predict_until_punctuation(input_str): | |
if not input_str: | |
raise Exception('input string required') | |
output_str = copy.deepcopy(input_str) | |
while len(output_str) != 0 and output_str[-1] not in [".", "!", "?"]: | |
prediction = predictor.predict_json({"previous": output_str}) | |
output_str += prediction["words"][0] | |
return output_str | |
if __name__ == "__main__": | |
text = predict_until_punctuation("Toronto Raptors, who are currently tied for the league leader in wins") | |
print(text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment