Exemplo n.º 1
0
from hare import Hare, Conversation
from hare.brain import BiGruBrain

brain: BiGruBrain = BiGruBrain()
brain.embedding_location = '/vol/bigdata/word_embeddings/glove/glove.6B.50d.txt'
brain.verbose = True

hare = Hare()
hare.brain = brain

convo = Conversation()
convo.add_utterance(speaker='a', content='hate you')
convo.add_utterance(speaker='b', content='i love you')
convo.label_speaker('a', 1)

hare.add_conversation(convo)

hare.train()
hare.save('/vol/tensusers2/wstoop/HaRe/hare/pretrained/simple')

hare.update_status_history_for_conversation()
hare.visualize_history_for_conversation()
Exemplo n.º 2
0
from hare import Hare, Conversation
from hare.tensorflowbrain import BiGruBrain

mockhare = Hare()
mockhare.brain = BiGruBrain()

for i in range(10000):
    convo = Conversation()
    convo.add_utterance(speaker='a', content='c c c c c')
    convo.add_utterance(speaker='b', content='c c c c c')
    convo.add_utterance(speaker='b', content='c c c c b')
    convo.add_utterance(speaker='a', content='c c c c a')
    convo.label_speaker('b', 1)

    mockhare.add_conversation(convo)

mockhare.train()
mockhare.visualize_history_for_conversation()
    for n, line in enumerate(open(conv_hist_file)):
        status_per_conversation.append(loads(line)[:CONVERSATION_LENGTH])

        if n % 100 == 0:
            print(conv_hist_file, n)

    for threshold in THRESHOLDS:
        h = Hare(name=threshold)
        h.status_per_conversation = status_per_conversation
        h.cut_off_value = threshold

        hares.append(h)

#Load the conversations
conversations = []
current_conversation = Conversation()

for line in open(CONVERSATIONS_FILE):

    line = line.strip()

    if len(line) == 0:
        continue
    elif line[0] == '#':
        try:
            current_conversation.label_speaker(line.split()[1], 1)
        except IndexError:
            continue

        current_conversation.utterances = current_conversation.utterances[:
                                                                          CONVERSATION_LENGTH]
Exemplo n.º 4
0
from hare import load_pretrained, Conversation, load_example_conversations
from hare.tensorflowbrain import BiGruBrain

simple_hare = load_pretrained('hare/pretrained/moba')

print(simple_hare.brain.determine_impact_of_words('well played noob'))

convo = Conversation()
convo.add_utterance(speaker='a', content='i am nice')
convo.add_utterance(speaker='b', content='FCK U YOU SUCK')
convo.add_utterance(speaker='b', content='YOU ARE LOSERS')
convo.add_utterance(speaker='a', content='well done')
convo.add_utterance(speaker='b', content='noobs fuckheads')
convo.add_utterance(speaker='a', content='no problem')
convo.label_speaker('b', 1)

simple_hare.add_conversation(convo)

simple_hare.update_status_history_for_conversation()
simple_hare.visualize_history_for_conversation()

for n, conversation in enumerate(load_example_conversations()):
    simple_hare.add_conversation(conversation)
    simple_hare.visualize_history_for_conversation(n + 1)
Exemplo n.º 5
0
from hare import Hare, Conversation
from hare.bigrubrain import BiGruBrain

#Load the conversations
CONVERSATIONS_FILE = 'datasets/LoL/conversations_anon.txt'
NR_OF_CONVERSATIONS = 5000
conversations = []
current_conversation = Conversation()

for line in open(CONVERSATIONS_FILE):

    line = line.strip()

    if len(line) == 0:
        continue
    elif line[0] == '#':
        try:
            current_conversation.label_speaker(line.split()[1], 1)
        except IndexError:
            continue

        conversations.append(current_conversation)
        current_conversation = Conversation()

        if len(conversations) % 100 == 0:
            print(len(conversations))

        if len(conversations) == NR_OF_CONVERSATIONS:
            break

        continue
Exemplo n.º 6
0
from hare import load_pretrained, Conversation

CONVERSATIONS_FILE = 'datasets/LoL/single_conversation.txt'

current_conversation = Conversation()

print('loading conversation')

for line in open(CONVERSATIONS_FILE):

    line = line.strip()

    if len(line) == 0:
        continue

    elif line[0] == '#':
        break

    speaker, content = line.split('\t')
    current_conversation.add_utterance(speaker, content)

print('loading pretrained moba')

moba_hare = load_pretrained('hare/pretrained/moba')

print('adding conversation')

moba_hare.add_conversation(current_conversation)

print('visualizing convo')
Exemplo n.º 7
0
from hare import Hare, Conversation
from hare.brain import RandomBrain

random_hare = Hare()
random_hare.brain = RandomBrain()

convo = Conversation()
random_hare.add_conversation(convo)

convo.add_utterance(speaker='a', content='hello')
convo.add_utterance(speaker='b', content='hello')
convo.add_utterance(speaker='a', content='how is everyone doing?')

random_hare.update_status_history_for_conversation(0)
print(random_hare.status_per_conversation[0])

convo.label_speaker('b', 0.9)
acc = random_hare.calculate_retrospective_accuracy()

print(acc)