-
-
Save vered1986/e40f15d69f74715fba62e51ab9b76133 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 numpy as np | |
# Create a very simple unigram LM with a small vocabulary | |
vocab = ['<s>', 'This', 'LM', 'is', 'stupid', 'cool', '</s>'] | |
word2index = {w: i for i, w in enumerate(vocab)} | |
probabilities = np.array([[0.01, 0.94, 0.01, 0.01, 0.01, 0.01, 0.01], | |
[0.01, 0.01, 0.94, 0.01, 0.01, 0.01, 0.01], | |
[0.01, 0.01, 0.01, 0.94, 0.01, 0.01, 0.01], | |
[0.01, 0.01, 0.01, 0.01, 0.47, 0.48, 0.01], | |
[0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.94], | |
[0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.94], | |
[0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.94]]) | |
stupid_lm = lambda s: probabilities[word2index.get(s.split()[-1], -1), :] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment