class UnigramDist:
def __init__(self, corpus):
self.counts = defaultdict(float)
self.total = 0.0
self.train(corpus)
# Get number of unique words (type)
def getType(self, corpus):
unique = []
for sen in corpus:
for word in sen:
if(word not in unique):
unique.append(word)
return len(unique)
def probWithLapalce(self, word):
V = self.getType(corpus)
word = word.strip()
probVal = (self.counts[word] + 1) / (self.total + V)
return math.log(probVal)
#enddef
I am creating a class called UnigramDist that contains some methods that compute the probability of a unigram model, and I am trying to use the getType method in my probWithLaplace method in the same class.
But when I use this class in my test, it gives me a message that says:
V = self.getType(corpus)
NameError: name 'corpus' is not defined
I don't get it since all other functions are using corpus just fine.
corpusis defined where you are callinggetType, i.e. inprobWithLapalce. I don't see it defined anywhere.