Antoine Chaffin commited on
Commit
802f7de
1 Parent(s): 995dea4

Adapting max_length to the prompt

Browse files
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -25,24 +25,26 @@ DETECT_METHODS = [ 'aaronson', 'aaronson_simplified', 'aaronson_neyman_pearson',
25
  PAYLOAD_BITS = 2
26
  device = torch.device('cuda:0') if torch.cuda.is_available() else torch.device('cpu')
27
 
28
- DEFAULT_SYSTEM_PROMPT = """\
29
- You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature.
30
- If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information.\
31
- """
32
  model = AutoModelForCausalLM.from_pretrained(args.model, use_auth_token=hf_token, torch_dtype=torch.float16,
33
  device_map='auto').to(device)
34
  tokenizer = AutoTokenizer.from_pretrained(args.model, use_auth_token=hf_token)
35
  tokenizer.pad_token = tokenizer.eos_token
36
 
 
 
 
 
 
37
  def embed(user, max_length, window_size, method, prompt):
38
  uid = USERS.index(user)
39
  watermarker = Watermarker(tokenizer=tokenizer, model=model, window_size=window_size, payload_bits=PAYLOAD_BITS)
40
  prompt = get_prompt(prompt)
41
  watermarked_texts = watermarker.embed(key=args.key, messages=[ uid ],
42
- max_length=max_length, method=method, prompt=prompt)
43
  print("watermarked_texts: ", watermarked_texts)
44
  print(watermarked_texts[0].replace(prompt, ""))
45
- watermarked_texts[0].split("[/INST]")[-1]
46
  return watermarked_texts[0].replace(prompt, "")
47
 
48
  def detect(attacked_text, window_size, method, prompt):
 
25
  PAYLOAD_BITS = 2
26
  device = torch.device('cuda:0') if torch.cuda.is_available() else torch.device('cpu')
27
 
28
+
 
 
 
29
  model = AutoModelForCausalLM.from_pretrained(args.model, use_auth_token=hf_token, torch_dtype=torch.float16,
30
  device_map='auto').to(device)
31
  tokenizer = AutoTokenizer.from_pretrained(args.model, use_auth_token=hf_token)
32
  tokenizer.pad_token = tokenizer.eos_token
33
 
34
+ DEFAULT_SYSTEM_PROMPT = """\
35
+ You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature.
36
+ If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information.\
37
+ """
38
+ LEN_DEFAULT_PROMPT = len(tokenizer.encode(DEFAULT_SYSTEM_PROMPT))
39
  def embed(user, max_length, window_size, method, prompt):
40
  uid = USERS.index(user)
41
  watermarker = Watermarker(tokenizer=tokenizer, model=model, window_size=window_size, payload_bits=PAYLOAD_BITS)
42
  prompt = get_prompt(prompt)
43
  watermarked_texts = watermarker.embed(key=args.key, messages=[ uid ],
44
+ max_length=max_length+LEN_DEFAULT_PROMPT, method=method, prompt=prompt)
45
  print("watermarked_texts: ", watermarked_texts)
46
  print(watermarked_texts[0].replace(prompt, ""))
47
+ print(watermarked_texts[0].split("[/INST]")[-1:])
48
  return watermarked_texts[0].replace(prompt, "")
49
 
50
  def detect(attacked_text, window_size, method, prompt):