Views
No views yet
1from transformers import AutoModelForCausalLM, AutoTokenizer
2
3model_name = "cnmoro/Qwen2.5-0.5B-Chunk-Compressor"
4tokenizer = AutoTokenizer.from_pretrained(model_name)
5model = AutoModelForCausalLM.from_pretrained(model_name).to("cuda")
6
7prompt = """<|im_start|>system
8Você deve compactar textos sem necessidade de legibilidade para humanos, mas mantendo informações essenciais compreensíveis para outro modelo de linguagem.
9
10Regras para compressão:
11Remova palavras desnecessárias como artigos, preposições e pronomes quando possível, desde que a compreensão seja preservada.
12Preserve informações essenciais (nomes, locais, ações, conceitos-chave).
13Reduza expressões complexas mantendo o significado.
14Use listas e separadores para organizar as informações de forma eficiente.
15Remova redundâncias e detalhes secundários que não impactam a compreensão geral.<|im_end|>
16<|im_start|>user
17Texto para compressão:
18<Input>
19Cleaning the toilet is a task that doesn't interest people. Many, however, pray
20for technology that can save them from the unpleasant mission. Apparently, those
21prayers were answered: a group of Chinese scientists developed the concept of a
22self-cleaning toilet and managed to make it a reality. Thanks to 3D printing,
23researchers at Huazhong University of Science and Technology have managed to
24revolutionize the unpleasant household chore. The self-cleaning toilet, known
25as “ARSFT”, an acronym for “abrasion-resistant super slippery toilet flush” — the
26technology that allows automatic cleaning — emerged from a complex combination
27of plastic and grains of sand that repel water. In plain English, the technology
28ensures that no substance sticks to the surface. Therefore, in addition to being
29a salvation for many, this can be a more sustainable alternative to conventional
30toilets. The website New Scientist interviewed one of the project's scientists,
31Yike Li, who created the self-cleaning toilet. According to Li, the Chinese used,
32in addition to the combination of plastic and grains of sand, a laser to bring the
33particles together, thus creating the 3D printed self-cleaning toilet. After printing,
34the researchers used silicon oil to lubricate the surface of the toilet, managing
35to penetrate it due to the structure of the model. This generated the toilet's
36self-cleaning capacity, with the following materials leaving no marks after
37flushing: Milk; Yogurt; Honey; Muddy water; Starch gel mixed with porridge.
38Chinese scientists also tested the self-cleaning toilet with synthetic feces,
39using a mixture of miso, yeast, peanut oil and water, managing to imitate human
40excrement. Although it may be strange that scientists work to create toilet technologies,
41several seemingly “unnecessary” innovations can have a major global impact.
42The self-cleaning toilet created by Chinese researchers can considerably reduce water waste.
43According to Chinese scientists, the self-cleaning toilet can withstand a thousand scraping
44cycles thanks to its super slippery capacity. Therefore, the self-cleaning toilet has
45a new flushing method that minimizes water consumption – and waste. The Daily Mail
46points out that, since its invention in the 18th century, although the toilet has
47increased hygiene, a significant amount of water is required due to the adhesion
48between the surface of the toilet and human feces and urine. Worldwide, toilet
49flushes correspond to 141 billion liters of water daily. Therefore, in addition
50to saving a valuable resource for humanity, the self-cleaning toilet also has another
51environmental benefit. In places such as public and chemical bathrooms, especially
52where there is no connection to the sanitation system, the self-cleaning toilet
53appears as an ideal solution.
54</Input><|im_end|>
55<|im_start|>assistant
56Texto comprimido:
57<Output>
58"""
59
60inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
61outputs = model.generate(**inputs, max_new_tokens=384, temperature=0.5, do_sample=True)
62
63input_length = inputs.input_ids.shape[1]
64generated_tokens = outputs[0, input_length:]
65generated_text = tokenizer.decode(generated_tokens, skip_special_tokens=True)
66
67# Remove the stop token from the generated text
68generated_text = generated_text.split("</Output>")[0]
69
70print(generated_text)
71# Output text:
72# - Toilet cleaner - China developed self-cleaning toilet technology.
73# - 3D printing - recycled material repels water, prevents sticking.
74# - Self-cleaning toilet - reduces water use, waste, improves hygiene.
75# - Environmental benefits: reduced water usage globally (141 billion liters/day), reduces resource waste.
76# - Public/private bathroom solutions - ideal solution for areas lacking sanitation systems.