Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

warn if generation prompt does not start with a control code #50

Merged
merged 2 commits into from
Oct 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions control_codes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@

CONTROL_CODES = {
"Pregnancy": 168629,
"Christianity": 7675,
"Explain": 106423,
"Fitness": 63440,
"Saving": 63163,
"Ask": 27171,
"Ass": 95985,
"Joke": 163509,
"Questions": 45622,
"Thoughts": 49605,
"Retail": 52342,
"Feminism": 164338,
"Writing": 11992,
"Atheism": 192263,
"Netflix": 48616,
"Computing": 39639,
"Opinion": 43213,
"Alone": 44967,
"Funny": 58917,
"Gaming": 40358,
"Human": 4088,
"India": 1331,
"Joker": 77138,
"Diet": 36206,
"Legal": 11859,
"Norman": 4939,
"Tip": 72689,
"Weight": 52343,
"Movies": 46273,
"Running": 23425,
"Science": 2090,
"Horror": 37793,
"Confession": 60572,
"Finance": 12250,
"Politics": 16360,
"Scary": 191985,
"Support": 12654,
"Technologies": 32516,
"Teenage": 66160,
"Event": 32769,
"Learned": 67460,
"Notion": 182770,
"Wikipedia": 37583,
"Books": 6665,
"Extract": 76050,
"Confessions": 102701,
"Conspiracy": 75932,
"Links": 63674,
"Narcissus": 150425,
"Relationship": 54766,
"Relationships": 134796,
"Reviews": 41671,
"News": 4256,
"Translation": 26820,
"multilingual": 128406,
}
3 changes: 3 additions & 0 deletions generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from tensorflow.python.ops import embedding_ops
import fastBPE
import platform
from control_codes import CONTROL_CODES

use_py3 = platform.python_version()[0] == '3'

Expand Down Expand Up @@ -170,6 +171,8 @@ def serving_input_fn():

# tokenize provided prompt
split_prompt = bpe.apply([prompt])[0].split()
if not any(split_prompt[0] == x for x in CONTROL_CODES.keys()):
print("WARNING! You are not starting your generation from a control code so you won't get good results")
text = [word2idx[i] for i in split_prompt]

# pad with 0s and create a mini-batch of 2 (arbitrary, for ease of code)
Expand Down
3 changes: 3 additions & 0 deletions pytorch_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import tensorflow as tf
import fastBPE
from tensorflow.python import pywrap_tensorflow
from control_codes import CONTROL_CODES

use_py3 = platform.python_version()[0] == '3'

Expand Down Expand Up @@ -163,6 +164,8 @@ def predict_fn(inputs):

# tokenize provided prompt
split_prompt = bpe.apply([prompt])[0].split()
if not any(split_prompt[0] == x for x in CONTROL_CODES.keys()):
print("WARNING! You are not starting your generation from a control code so you won't get good results")
text = [word2idx[i] for i in split_prompt]


Expand Down