forked from openai/generating-reviews-discovering-sentiment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_generative.py
36 lines (27 loc) · 1.49 KB
/
test_generative.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from encoder import Model
mdl = Model()
base = "I couldn’t figure out"
print("\'%s\'... --> (argmax sampling):" % base)
#Overriden values are slightly on the extreme on either end of
#the sentiment's activation distribution
positive = mdl.generate_sequence(base, override={2388 : 1.0})
print("Positive sentiment (1 sentence): " + positive)
negative = mdl.generate_sequence(base, override={2388 : -1.5}, len_add = 100)
print("\nNegative sentiment (+100 chars):" + negative + '...')
n = 3
print("\n\n\'%s\'... --> (weighted samples after each word):" % base)
print("Positive sentiment (%d examples, 2 sentences each):" %n)
for i in range(n):
positive = mdl.generate_sequence(base, override={2388 : 1.0}, len_add = '..', sampling = 1)
print("(%d)%s" % (i, positive[1:]))
print("\nNegative sentiment (%d examples, 2 sentences each):" %n)
for i in range(n):
positive = mdl.generate_sequence(base, override={2388 : -1.5}, len_add = '..', sampling = 1)
print("(%d)%s" % (i, positive[1:]))
print("\n\n\'%s\'... --> (weighted samples after each character):" % base)
neutral = mdl.generate_sequence(base, len_add = '...', sampling = 2)
print("Sentiment not influenced (3 sentences):" + neutral)
neutral = mdl.generate_sequence(base, override={2388 : 0.0}, len_add = '...', sampling = 2)
print("\nSentiment fixed to 0 (3 sentences):" + neutral)
negative = mdl.generate_sequence(base, override={2388 : -1.0}, len_add = '...', sampling = 2)
print("\nSligthly negative sentiment (3 sentences):" + negative)