Skip to content

Instantly share code, notes, and snippets.

@joeyism
Last active October 9, 2019 02:07
Show Gist options
  • Save joeyism/e106934aaf81c4011c9b5d580e87e850 to your computer and use it in GitHub Desktop.
Save joeyism/e106934aaf81c4011c9b5d580e87e850 to your computer and use it in GitHub Desktop.
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