Skip to content

Instantly share code, notes, and snippets.

@Lexie88rus
Created August 30, 2019 21:01
Show Gist options
  • Save Lexie88rus/bf61f83277f939a7eb7a321ef0e9e73f to your computer and use it in GitHub Desktop.
Save Lexie88rus/bf61f83277f939a7eb7a321ef0e9e73f to your computer and use it in GitHub Desktop.
Function to convert model output into a word
# Define a function which converts output into word
def wordFromOutput(output):
'''
Functions returns an index from the vocabulary and the corresponding word
'''
top_n, top_i = output.topk(1)
category_i = top_i[0].item()
return [k for (k, v) in vocab.items() if v == category_i], category_i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment