Last active
April 9, 2018 11:49
-
-
Save eisenjulian/bbc04291b346acaf2d1fe40db83a665a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| # Load the tensor with the model weights | |
| weights = classifier.get_variable_value('linear/linear_model/x/weights').flatten() | |
| # Find biggest weights in absolute value | |
| extremes = np.concatenate((sorted_indexes[-8:], sorted_indexes[:8])) | |
| # word_inverted_index is a dictionary that maps from indexes back to tokens | |
| extreme_weights = sorted( | |
| [(weights[i], word_inverted_index[i]) for i in extremes]) | |
| # Create plot | |
| y_pos = np.arange(len(extreme_weights)) | |
| plt.bar(y_pos, [pair[0] for pair in extreme_weights], align='center', alpha=0.5) | |
| plt.xticks(y_pos, [pair[1] for pair in extreme_weights], rotation=45, ha='right') | |
| plt.ylabel('Weight') | |
| plt.title('Most significant tokens') | |
| plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment