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
"""NumPy implementation of Beam Search. Can be used for decoding in Seq2Seq | |
models or transformer. | |
See https://chao-ji.github.io/jekyll/update/2019/01/24/Beam_Search.html | |
for an in-depth disucssion. | |
""" | |
import numpy as np | |
NEG_INF = -1e9 |
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 matplotlib.pyplot as plt | |
import numpy as np | |
figsize(20,8) | |
#clf is a sklearn classifier e.g. clf = LogisticRegression() | |
#vecotorizer is a sklearn vectorizer, e.g. vectorizer = TfidfVectorizer() | |
#let's get the coefficients: | |
coef = clf.coef_.ravel() | |
important = np.argsort(np.abs(coef))[-100:] |