mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-07-15 01:00:53 +08:00
11 KiB
11 KiB
In [ ]:
!pip install transformersIn [2]:
essay = """
We live in a world driven by technology — hardly anyone would argue with you if you said this.
Technology, literally meaning the “science of craft”, refers to the collection of techniques,
skills, methods, and processes used to produce goods or services or for accomplishing objectives
such as scientific investigation. Technology can be embedded in machines enabling them to be
used by people even without a detailed knowledge of their inner workings. Technological growth
is closely linked to the expansion of scientific research and knowledge. In the last 50 years,
thanks to the exponential increases in computing power and microchip design and manufacture,
there has been unprecedented innovation and technological growth in nearly every field of human
endeavour from health and transport to industrial production and education.
It is automotive technology that drives today’s electric and hybrid cars, and which will drive
tomorrow’s driverless cars, hover-taxis and space cabs. It is technology that drives the
ubiquitous mobile phones that you will now find in the hands of even the poorest of the world’s
poor. It is technology that creates hybrid seeds that resist inhospitable climatic conditions
and difficult terrain, giving high yields in shorter times. It is advancing medical technology
that makes remote surgery, minimally invasive surgery and life-saving cures using stem cell
transplants. Technology puts spacecrafts on asteroids and distant planets and lets us see
new worlds. Technology splits atoms, revealing their secrets, and gives us ways to exploit
them to create energy, quantum storage for data, and virtual reality games.
There are people who strongly oppose technology and claim that it spells the death of
‘humanity’, and that we are approaching the day when machines will rule everything. They refer
to fans of technology as ‘techies’ or sometimes ‘geeks’. On the other hand, proponents of
technology call these people Luddites, a derogatory name for someone who is opposed to
industrialisation, automation, computerisation and new technologies in general.
Is this true? Is technology really a curse disguised as a blessing? Many believe that the
convergence of biotechnology and AI might be the most consequential development of all.
In the last five decades, two areas in particular have grown faster than the rest, powered
by research and advances in computing power. One is artificial intelligence, or AI; the other
is biotechnology. Huge benefits have emerged from each of them for human beings in general,
such as self-driving cars — which will dramatically reduce the death rate from road accidents
— and robotic surgery, which enables precise, highly efficient and targeted surgical
interventions. Yet, visionaries like Yuval Noah Harari, author of the best-selling "Homo
Sapiens" and "Deus", are now warning that the convergence of biotechnology and AI will
irreversibly and unpredictably change both the quality of human life and its challenges in
the next few decades. A good example of this is the facial recognition technology that is
now present in all photo management programs. The AI in the software is capable of not
only spotting the faces in every photograph but also recognising the person by name.
This technology has now expanded so that photo apps can recognise cats, dogs, beaches,
mountains and cars too. Computers with AI are already correctly identifying human emotions
through observing facial expressions and body movements. Some robots are able to mimic
human emotions. This is called affective computing, sometimes called artificial emotional
intelligence, and refers to the study and development of systems and devices that can
recognize, interpret, process, and simulate human affects.
How could this be a negative?
The ability to read human emotions is just a step away from predicting human emotions. For
example, if a computer attached to a video camera could identify which products a consumer
is showing greater interest in or which ones he is really keen to buy, various tactics
could be used to influence her to buy it. Activists worry that computers that can understand
and anticipate human wishes and desires by scanning their irises and analysing their
micro-expressions could also be programmed to exploit and manipulate them. Another very real
fear is that humanoid computers with human-like skin, speech, and expressions could jeopardise
and dehumanise relationship and create emotional vacuums.
An enduring fear of Luddites has always been that computers will rob humans of their
livelihood by taking their jobs and doing them more efficiently at lower cost. However, in
reality the exact opposite has happened. As computerised machines began taking over mechanical
and repetitive human activities, new jobs for people opened up that needs thinking and
analytical skills and judgement, or human interpersonal skills. A good example is the
worldwide proliferation of call centres. When drones were invented many feared that pilots
would soon be redundant. However, few people know that it takes almost 30 people to fly
one military drone, and an additional 50 people to analyze and make sense of the data being
streamed back by the drone. The US army suffers from a serious shortage of trained, high
quality drone pilots; anyone who masters this skill will have a job. But a social scientist
warns that in 10 years, it is certain that computers will be flying that drone and humans
will be redundant. Equally sure is that some brand new skill requirement will have opened
up with advancing technology, calling for new talents.
In the 20th century, a young man was supposed to choose a skill, vocation or profession,
master it through education and practice, and then earn a living from it till he or she
retired. However, the fast-changing nature of technology is making skills obsolete at a
higher rate than ever before. To survive, tomorrow young man must keep re-inventing himself
and updating his skills continuously. Life could be difficult if every new skill has a shelf
life of only a decade or so. Or perhaps one could look at it the other way — and say that
changing technology will keep human beings on their toes throughout their life.
Technology is the result of human inventiveness. It reflects our evolutionary heritage. We
are neither strong like gorillas or tigers, nor fast like cheetahs and hawks, but our
brains and thinking powers have given us the greatest edge of any species on the planet.
Technology is a result. Technology is either inherently good or bad; it is how we use it
that makes it so. The splitting of a hydrogen atom is technology at work. As history has
shown us, technology can equally be used to make a nuclear bomb that kills millions — or
generate electricity that lights up a million homes.
"""In [3]:
essay_paragraphs = essay.split("\n\n")In [ ]:
model_name = "snrspeaks/t5-one-line-summary"
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)In [ ]:
preds = []
for para in essay_paragraphs:
input_ids = tokenizer.encode(para, return_tensors="pt", add_special_tokens=True)
generated_ids = model.generate(
input_ids=input_ids,
num_beams=5,
max_length=35,
repetition_penalty=4.5,
length_penalty=1.5,
early_stopping=True,
num_return_sequences=1,
)
preds.append(tokenizer.decode(generated_ids[0], skip_special_tokens=True, clean_up_tokenization_spaces=True))
prompts = (
["Write an intro paragraph to an essay called"]
+ ["Write a paragraph to an essay about"] * len(preds[1:-1])
+ ["Write a concluding paragraph about"]
)
assert len(preds) == len(prompts)
for prompt, pred in zip(prompts, preds):
print(prompt, pred.lower())