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