mirror of
https://github.com/wassname/Clover-Edition.git
synced 2026-09-09 11:13:26 +08:00
update
This commit is contained in:
+1
-1
@@ -122,7 +122,7 @@ def play_cached_hospital():
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
play_constrained()
|
||||
play_unconstrained()
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ def loss(labels, logits):
|
||||
|
||||
class CTRLGenerator():
|
||||
|
||||
def __init__(self, control_code="Writing Text: ", generate_num=40, temperature=0.3, topk=20, nucleus_prob=0):
|
||||
def __init__(self, control_code="Writing Text: ", generate_num=32, temperature=0.3, topk=20, nucleus_prob=0):
|
||||
|
||||
self.generate_num=generate_num
|
||||
model_dir = "generator/ctrl/training_utils/seqlen256_v1.ckpt/"
|
||||
@@ -219,10 +219,7 @@ class CTRLGenerator():
|
||||
forbidden_tokens = ['<unk>', 'Sco@@', "&@@", "1]@@", "2]@@", "3]@@", "4]@@", "https://www.@@", "[@@", ":@@",
|
||||
"Edit", "&@@", "2:","1:", ":", "Edit@@", "EDI@@", "EDIT@@", "edit", "TL@@", "tl@@", ";@@",
|
||||
'**', "http://@@", "Redd@@", "UP@@", "mom", "Up@@", "Me:", "Update", "mom@@", "Part",
|
||||
"http://www.@@", "edit@@", "*@@", "\n", "Writing", "Text@@", "\\@@", "<br>@@", "<div", "|@@"]
|
||||
|
||||
if num_new_lines > self.max_new_lines:
|
||||
forbidden_tokens.append("\n")
|
||||
"http://www.@@", "edit@@", "*@@", "Writing", "Text@@", "\\@@", "<br>@@", "<div", "|@@"]
|
||||
|
||||
for forbidden_token in forbidden_tokens:
|
||||
prompt_logits[_token][self.word2idx[forbidden_token]] = -1e8
|
||||
@@ -266,6 +263,8 @@ class CTRLGenerator():
|
||||
# assign the token for generation
|
||||
tokens_generated[0][token + 1] = idx
|
||||
|
||||
"\n",
|
||||
|
||||
return idx
|
||||
|
||||
def generate(self, prompt, options=None):
|
||||
@@ -296,6 +295,8 @@ class CTRLGenerator():
|
||||
idx = self.generate_next_token(token, tokens_generated, options, num_new_lines, token_num, first_token=first_token)
|
||||
if self.idx2word[idx] is "\n":
|
||||
num_new_lines += 1
|
||||
if num_new_lines > 1:
|
||||
self.result_replace(result)
|
||||
|
||||
print(repr(self.idx2word[idx]), end="_")
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ def make_samples_helper(context, story_block, action_results, path, tree_id):
|
||||
new_path = path[:]
|
||||
new_path.append(i)
|
||||
if action_result["result"] is not None:
|
||||
sample = [context, story_block, "action:", action_result["action"], "result:", action_result["result"]]
|
||||
sample = [context, story_block, action_result["action"], action_result["result"]]
|
||||
samples.append(sample)
|
||||
if len(action_result["action_results"]) is not 0:
|
||||
sub_result = make_samples_helper(context, action_result["result"], action_result["action_results"], new_path, tree_id)
|
||||
@@ -43,8 +43,8 @@ def build_tokenized_samples(bpe, tree):
|
||||
for sample in samples:
|
||||
sample = [string.strip() for string in sample]
|
||||
|
||||
sample[3] = sample[3][0].lower() + sample[3][1:]
|
||||
sample[3] = "You " + sample[3]
|
||||
sample[2] = sample[2][0].lower() + sample[2][1:]
|
||||
sample[2] = "You " + sample[2]
|
||||
string_samples.append(" ".join(sample))
|
||||
|
||||
tokenized_samples = [bpe.apply([sample.encode('ascii', errors='ignore') if not use_py3 else sample])[0] for sample in
|
||||
|
||||
@@ -212,7 +212,7 @@ class CTRLStoryManager(ConstrainedStoryManager):
|
||||
results = []
|
||||
options = {"word_blacklist": {0:[]}}
|
||||
for phrase in self.action_phrases:
|
||||
result = self.generate_action_result(self.story_context() + " action: ", phrase, options=options)
|
||||
result = self.generate_action_result(self.story_context(), phrase, options=options)
|
||||
action_verb = result[0].split()[1]
|
||||
print("blacklisted verb is ", action_verb)
|
||||
options["word_blacklist"][0].append(action_verb)
|
||||
|
||||
Reference in New Issue
Block a user