Question: # models.py import numpy as np # type: ignore class LanguageModel ( object ) : def get _ next _ char _ log _ probs
# models.py
import numpy as np # type: ignore
class LanguageModelobject:
def getnextcharlogprobsself context npndarray:
Returns a log probability distribution over the next characters given a context.
The log should be base e
NOTE: You should make sure you call model.eval to determinize inference here turns off dropout
layers in TransformerEncoder
:param context: the string context that the LM conditions on
:return: A numpy vector log Py context where y ranges over the output vocabulary.
raise ExceptionOnly implemented in subclasses"
def getlogprobsequenceself nextchars, context float:
Scores a bunch of characters following context. That is returns
log Pnc nc nc context log Pnc context log Pnc context, nc
The log should be base e
NOTE: You should make sure you call model.eval to determinize inference here turns off dropout
layers in TransformerEncoder
:param nextchars:
:param context:
:return: The float probability
raise ExceptionOnly implemented in subclasses"
class UniformLanguageModelLanguageModel:
def initself vocsize:
self.vocsize vocsize
def getnextcharlogprobsself context:
return nponesselfvocsize nplogselfvocsize
def getlogprobsequenceself nextchars, context:
return nplogselfvocsize lennextchars
class NeuralLanguageModelLanguageModel:
def initself:
raise ExceptionImplement me
def getnextcharlogprobsself context:
raise ExceptionImplement me
def getlogprobsequenceself nextchars, context:
raise ExceptionImplement me
def trainlmargs traintext, devtext, vocabindex:
:param args: commandline args, passed through here for your convenience
:param traintext: train text as a sequence of characters
:param devtext: dev text as a sequence of characters
:param vocabindex: an Indexer of the character vocabulary characters
:return: a NeuralLanguageModel instance trained on the given data
raise ExceptionImplement me please help me to implement this code
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
