Views
No views yet
1from vllm import LLM, SamplingParams
2import re
3
4# -----------------------
5# 1. Define model and params
6# -----------------------
7llm = LLM(model="cx-cmu/repro-rephraser-1B")
8
9sampling_params = SamplingParams(
10 temperature=1.0,
11 top_p=0.9,
12 max_tokens=2048,
13)
14
15# -----------------------
16# 2. Define the paraphrasing prompt
17# -----------------------
18template = """Your task is to read and paraphrase the provided text following these instructions:
19- Delete clearly irrelevant content:
20 - Website headers, navigation bars, or menu items (e.g., "Home | About | Contact")
21 - Unrelated HTTP links (e.g., ads, trackers, developer tools)
22 - Generic footers (e.g., contact info, privacy policies, unsubscribe links)
23 - Empty lines or decorative elements (e.g., "---")
24- Preserve all content that is relevant and meaningful:
25 - Informative or independently useful
26 - Related to the topic, even tangentially
27 - Provides context, background, or supporting value
28 - Includes technical terms, key concepts, factual details, reasoning, and examples
29- Handle mixed-relevance sentences carefully:
30 - Remove only the irrelevant fragment if the rest remains coherent
31 - Delete the whole sentence if the remainder loses meaning
32- Do not alter meaningful content unnecessarily:
33 - Only delete or modify when content is clearly meaningless or off-topic
34 - Preserve the original structure, logic, and depth of the text
35- Do not add explanations, notes, assumptions, or claims not found in the original text
36Here is the text:
37{TEXT}
38Task:
39After thoroughly reading the above text, paraphrase it in high-quality and clear English following the instructions.
40Start your response immediately with "Here is a paraphrased version:" and then provide the paraphrased text."""
41
42# -----------------------
43# 3. Prepare a sample conversation
44# -----------------------
45sample_text = """The Pittsburgh Steelers are a professional American football team based in Pittsburgh, Pennsylvania.
46They were established in 1933 and are one of the oldest franchises in the NFL."""
47
48conversation = [
49 {
50 "role": "system",
51 "content": "A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the questions.",
52 },
53 {
54 "role": "user",
55 "content": template.format(TEXT=sample_text),
56 },
57]
58
59# -----------------------
60# 4. Run vLLM inference
61# -----------------------
62output = llm.chat([conversation], sampling_params)
63response_text = output[0].outputs[0].text
64
65# -----------------------
66# 5. Extract paraphrased text
67# -----------------------
68match = re.search(r"Here is a paraphrased version:(.*)", response_text, re.DOTALL)
69if match:
70 paraphrased = match.group(1).strip()
71else:
72 paraphrased = response_text.strip()
73
74print("=== Paraphrased Output ===")
75print(paraphrased)