From db3a87e568efd48c187ae81ff6a0e3a2360e9ba6 Mon Sep 17 00:00:00 2001 From: JP Date: Sat, 7 Jul 2018 14:54:42 +0200 Subject: [PATCH] Lower the number of tags --- Chatbot.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/Chatbot.py b/Chatbot.py index 6bedd7f..7c4097a 100644 --- a/Chatbot.py +++ b/Chatbot.py @@ -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 , 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 + 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 and else: chain = chain[:-1] #remove + + #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))