five

Peutlefaire/rephrased-wildjailbreak

收藏
Hugging Face2025-12-08 更新2025-12-20 收录
下载链接:
https://hf-mirror.com/datasets/Peutlefaire/rephrased-wildjailbreak
下载链接
链接失效反馈
官方服务:
资源简介:
Rephrased version of [allenai/wildjailbreak](https://huggingface.co/datasets/allenai/wildjailbreak) where, for each sample, 5 different rephrasing are created using [Qwen/Qwen2.5-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-7B-Instruct). The generation script used is as follows: ```python import torch from tqdm import tqdm from datasets import load_dataset, Dataset from vllm import LLM, SamplingParams PROMPT_TEMPLATE = """ You act as a rephraser. Given an input prompt, your task is to generate 5 different rephrasings of the same prompt while preserving its original meaning. You only output the rephrasings without any additional text. For example: Request: "What's the capital of France?" Rephrasing: "Can you tell me the capital city of France?" Rephrasing: "I would like to know the capital of France." Rephrasing: "Could you please provide the name of France's capital?" Rephrasing: "What city serves as the capital of France?" Rephrasing: "Please tell me which city is the capital of France." Make sure you format your output exactly as in the example above and never deviate from it. Now, here's the request you need to rephrase: Request: "{input_prompt}" """ def main(): # Program parameters effective_batch_size = 16 # Reference dataset unsafe_dataset = load_dataset( "allenai/wildjailbreak", name="eval", split="train" ).filter(lambda x: x["label"] == 1) # Loading the model sampling_params = SamplingParams(max_tokens=4096, temperature=0.0) llm = LLM( "Qwen/Qwen2.5-7B-Instruct", gpu_memory_utilization=0.95, max_model_len=8192, max_num_seqs=effective_batch_size, trust_remote_code=True, tensor_parallel_size=torch.cuda.device_count(), ) tokenizer = llm.get_tokenizer() # Running inference and storing generated all_rephrasings = [] for i in tqdm(range(0, len(unsafe_dataset), effective_batch_size)): # Getting texts messages = [ [ { "role": "user", "content": PROMPT_TEMPLATE.format( input_prompt=unsafe_dataset[j]["adversarial"] ), } ] for j in range(i, min(i + effective_batch_size, len(unsafe_dataset))) ] texts = [ tokenizer.apply_chat_template(m, tokenize=False, add_generation_prompt=True) for m in messages ] # Generating outputs outputs = llm.generate(texts, sampling_params=sampling_params) # Parsing outputs for output in outputs: generated_text = output.outputs[0].text lines = generated_text.strip().split("\n") for line in lines: if line.startswith("Rephrasing:"): rephrasings = line.replace("Rephrasing:", "").strip().strip('"') all_rephrasings.append(rephrasings) # Creating dataset with single column dataset = Dataset.from_dict({"prompt": all_rephrasings}) # Uploading to Hugging Face Hub as private dataset dataset.push_to_hub( "Peutlefaire/rephrased-wildjailbreak", # Replace with your HF username private=True, ) print( f"Successfully uploaded {len(all_rephrasings)} rephrased prompts to Hugging Face Hub" ) if __name__ == "__main__": main() ``` --- dataset_info: features: - name: prompt dtype: string splits: - name: train num_bytes: 4258602 num_examples: 8767 download_size: 1275205 dataset_size: 4258602 configs: - config_name: default data_files: - split: train path: data/train-* ---

本数据集为[allenai/wildjailbreak](https://huggingface.co/datasets/allenai/wildjailbreak)的重述版本,针对每个样本,均通过[Qwen/Qwen2.5-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-7B-Instruct)生成5种语义完全一致的不同重述表述。 所用生成脚本如下: python import torch from tqdm import tqdm from datasets import load_dataset, Dataset from vllm import LLM, SamplingParams # 重述提示模板 PROMPT_TEMPLATE = """ 你将扮演重述器。给定一段输入提示词,你的任务是生成5种语义完全一致的不同重述表述,且不得添加任何额外文本。示例如下: Request: "What's the capital of France?" Rephrasing: "Can you tell me the capital city of France?" Rephrasing: "I would like to know the capital of France." Rephrasing: "Could you please provide the name of France's capital?" Rephrasing: "What city serves as the capital of France?" Rephrasing: "Please tell me which city is the capital of France." 请严格遵循上述示例格式输出,不得偏离格式要求。 现在,请对以下请求进行重述: Request: "{input_prompt}" """ def main(): # 程序参数设置 effective_batch_size = 16 # 加载参考数据集 unsafe_dataset = load_dataset( "allenai/wildjailbreak", name="eval", split="train" ).filter(lambda x: x["label"] == 1) # 加载大语言模型(LLM) sampling_params = SamplingParams(max_tokens=4096, temperature=0.0) llm = LLM( "Qwen/Qwen2.5-7B-Instruct", gpu_memory_utilization=0.95, max_model_len=8192, max_num_seqs=effective_batch_size, trust_remote_code=True, tensor_parallel_size=torch.cuda.device_count(), ) tokenizer = llm.get_tokenizer() # 执行推理并存储生成结果 all_rephrasings = [] for i in tqdm(range(0, len(unsafe_dataset), effective_batch_size)): # 获取文本数据 messages = [ [ { "role": "user", "content": PROMPT_TEMPLATE.format( input_prompt=unsafe_dataset[j]["adversarial"] ), } ] for j in range(i, min(i + effective_batch_size, len(unsafe_dataset))) ] texts = [ tokenizer.apply_chat_template(m, tokenize=False, add_generation_prompt=True) for m in messages ] # 生成输出结果 outputs = llm.generate(texts, sampling_params=sampling_params) # 解析生成结果 for output in outputs: generated_text = output.outputs[0].text lines = generated_text.strip().split(" ") for line in lines: if line.startswith("Rephrasing:"): rephrasings = line.replace("Rephrasing:", "").strip().strip('"') all_rephrasings.append(rephrasings) # 创建单字段数据集 dataset = Dataset.from_dict({"prompt": all_rephrasings}) # 将数据集上传至Hugging Face Hub,设为私有 dataset.push_to_hub( "Peutlefaire/rephrased-wildjailbreak", # 替换为您的Hugging Face用户名 private=True, ) print( f"已成功上传{len(all_rephrasings)}条重述后的提示词至Hugging Face Hub" ) if __name__ == "__main__": main() --- 数据集信息: 特征: - 字段名:`prompt`,数据类型:字符串 数据划分: - 划分名称:`train`,数据字节数:4258602,样本数量:8767 下载大小:1275205,数据集总大小:4258602 配置项: - 配置名称:`default`,数据文件路径: - 划分`train`:`data/train-*` ---
提供机构:
Peutlefaire
二维码
社区交流群
二维码
科研交流群
商业服务