Lower the number of tags
This commit is contained in:
+17
-10
@@ -43,8 +43,15 @@ class Chatbot(object):
|
||||
newPairDict = wordDictPairs
|
||||
newTrairDict = wordDictTrairs
|
||||
|
||||
#If the message is only a tag, don't learn from it. return
|
||||
if message.count(' ') == 0 and message[0:2] == "<@":
|
||||
return newPairDict, newTrairDict;
|
||||
|
||||
message = self.START_OF_MESSAGE + " " + message + " " + self.END_OF_MESSAGE
|
||||
corpus = message.split()
|
||||
for n, word in enumerate(corpus):
|
||||
if word == "@everyone":
|
||||
corpus[n] = "@iedereen"
|
||||
pairs = self.makePairs(corpus)
|
||||
trairs = self.makeTrairs(corpus)
|
||||
|
||||
@@ -196,16 +203,8 @@ class Chatbot(object):
|
||||
except:
|
||||
pass
|
||||
|
||||
#Pick a random first word (Which is not an end-of-message)
|
||||
#Usually, we start with a regular <SOM>, but sometimes we don't
|
||||
a = random.randint(1,15)
|
||||
if a == 1:
|
||||
first_word = np.random.choice(list(wordPairDict.keys()))
|
||||
while first_word == self.END_OF_MESSAGE:
|
||||
first_word = np.random.choice(list(wordPairDict.keys()))
|
||||
else:
|
||||
first_word = self.START_OF_MESSAGE
|
||||
chain = [first_word]
|
||||
#Wtart with <SOM>
|
||||
chain = [self.START_OF_MESSAGE]
|
||||
|
||||
#Go through the chain:
|
||||
for i in range(1, MAX_N_WORDS):
|
||||
@@ -236,11 +235,19 @@ class Chatbot(object):
|
||||
weights = np.array(list(pairPossibilities.values()))
|
||||
probs = weights / weights.sum()
|
||||
chain.append(np.random.choice(possible_words, p=probs))
|
||||
|
||||
|
||||
if chain[0] == self.START_OF_MESSAGE:
|
||||
chain = chain[1:-1] #remove <SOM> and <EOM>
|
||||
else:
|
||||
chain = chain[:-1] #remove <EOM>
|
||||
|
||||
#remove 90% of tags:
|
||||
for n, word in enumerate(chain):
|
||||
if word[0:2] == "<@":
|
||||
a = random.randint(1,10)
|
||||
if a != 1:
|
||||
chain[n] = "@jemoeder"
|
||||
|
||||
#print(' '.join(chain))
|
||||
yield from ctx.channel.send(' '.join(chain))
|
||||
|
||||
Reference in New Issue
Block a user