From 6754eb8b0ba2c01da7e19172ddde4c7cdb689a99 Mon Sep 17 00:00:00 2001 From: buzz-lightsnack-2007 <73412182+buzz-lightsnack-2007@users.noreply.github.com> Date: Thu, 22 Aug 2024 15:31:33 +0000 Subject: [PATCH] write model testing section --- main.ipynb | 303 ++++++++++++++++++++++++++++++++++++++++++++++ preparation.ipynb | 257 --------------------------------------- 2 files changed, 303 insertions(+), 257 deletions(-) create mode 100644 main.ipynb delete mode 100644 preparation.ipynb diff --git a/main.ipynb b/main.ipynb new file mode 100644 index 0000000..94ad2da --- /dev/null +++ b/main.ipynb @@ -0,0 +1,303 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# An Evaluation on the Effectiveness of Large Language Models in Self-Detection" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Dependencies" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This section is where the dependencies required for all tests will be installed. For all or most tests, the following are needed: \n", + "- gpt4all\n", + "- kaggle\n", + "- kagglehub\n", + "- pandas" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "vscode": { + "languageId": "shellscript" + } + }, + "outputs": [], + "source": [ + "pip install --upgrade -r dependencies.txt" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Data Fetch and Preview" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "For this study, the dataset from [Thite (2023)](https://www.kaggle.com/datasets/sunilthite/llm-detect-ai-generated-text-dataset) will be employed due to its sufficient size and technical limitations. " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The code block below imports all the modules needed for this section. " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import kagglehub\n", + "import json\n", + "import os\n", + "import pandas" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The code below sets up a reference to the files. " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "FILES = {\"datasets\": {}, \"models\": {}};" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "def download_datasets(): \n", + " # Read the dataset listings. \n", + " SOURCES = json.load(open(\"data/sources.json\"));\n", + "\n", + " # Loop through each dataset target.\n", + " for TARGET in SOURCES.keys(): \n", + " print((\"Attempting to download \" + TARGET + \" from dataset \" + SOURCES[TARGET]));\n", + " \n", + " # Set the location of the Kaggle dataset. \n", + " kagglehub.dataset_download(SOURCES[TARGET]);\n", + " \n", + " # Do not continue when an error has occured. \n", + " print((\"Finished downloading \" + TARGET + \" from dataset \" + SOURCES[TARGET]));\n", + "\n", + " # Link each file.\n", + " if (not(os.path.isfile((\"data/\" + TARGET))) and os.system((\"ln -s ~/.cache/kagglehub/datasets/\" + SOURCES[TARGET] + \"/\" + TARGET + \" data/\" + TARGET))): \n", + " print((\"We weren’t able to link the file \" + TARGET + \" from dataset \" + SOURCES[TARGET] + \". Please perform this manually.\"));\n", + " else: \n", + " print((\"The file \" + TARGET + \" from dataset \" + SOURCES[TARGET] + \" has been linked.\"));\n", + " FILES[\"datasets\"][TARGET] = open(\"data/\" + TARGET)\n", + "\n", + "download_datasets();" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Below, the code blocks are converted into dataframes for preview purposes. " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "DATAFRAMES = {};\n", + "\n", + "def convert_datasets(): \n", + " if len(FILES[\"datasets\"].keys()): \n", + " for DATASET_NAME in FILES[\"datasets\"].keys(): \n", + " DATAFRAMES[DATASET_NAME] = pandas.read_csv(FILES[\"datasets\"][DATASET_NAME])\n", + "\n", + "def merge_datasets(): \n", + " DATAFRAMES_ALL = [];\n", + "\n", + " if (len(DATAFRAMES.keys())): \n", + " for DATASET_NAME in DATAFRAMES.keys(): \n", + " DATAFRAMES_ALL.append(DATAFRAMES[DATASET_NAME]);\n", + " DATAFRAMES[\"all\"] = pandas.concat(DATAFRAMES_ALL); \n", + "\n", + " return (DATAFRAMES_ALL);\n", + "\n", + "convert_datasets();\n", + "merge_datasets();" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The datasets could be previewed below. Note that in the \"generated\" field, `0` indicates a human-written text, whereas `1` means generated by large language models. " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "print(DATAFRAMES[\"all\"]);" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Data Classifcation" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "With the dataset presented above, it will be further segregated to distinguish the two voices and to generate the testing and training data. " + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [], + "source": [ + "STRINGS = {};\n", + "\n", + "def datasets_segregate_type(): \n", + " for GENERATION_TYPE_INDEX in range(2): \n", + " # DATASET_FILTERED = DATAFRAMES[\"all\"][(DATAFRAMES[\"all\"] == GENERATION_TYPE_INDEX or DATAFRAMES[\"all\"] == str(GENERATION_TYPE_INDEX)).any(axis=1)];\n", + " \n", + " DATASET_FILTERED = DATAFRAMES[\"all\"][(DATAFRAMES[\"all\"].generated == GENERATION_TYPE_INDEX) | (DATAFRAMES[\"all\"].generated == str(GENERATION_TYPE_INDEX))];\n", + "\n", + " GENERATION_TYPE = \"\";\n", + " if (GENERATION_TYPE_INDEX == 1): \n", + " GENERATION_TYPE = \"AI\"\n", + " else: \n", + " GENERATION_TYPE = \"human\"\n", + "\n", + " DATASET_FILTERED_LIST = DATASET_FILTERED['text'].tolist();\n", + " STRINGS[GENERATION_TYPE] = {};\n", + " STRINGS[GENERATION_TYPE][\"training\"] = DATASET_FILTERED_LIST[0:25];\n", + " STRINGS[GENERATION_TYPE][\"testing\"] = DATASET_FILTERED_LIST[50:200];\n", + "\n", + " return (STRINGS);\n", + "\n", + "datasets_segregate_type();" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "human: ['Cars. Cars have been around since they became famous in the 1900s, when Henry Ford created and built the first ModelT. Cars have played a major role in our every day lives since then. But now, people are starting to question if limiting car usage would be a good thing. To me, limiting the use of cars might be a good thing to do.\\n\\nIn like matter of this, article, \"In German Suburb, Life Goes On Without Cars,\" by Elizabeth Rosenthal states, how automobiles are the linchpin of suburbs, where middle class families from either Shanghai or Chicago tend to make their homes. Experts say how this is a huge impediment to current efforts to reduce greenhouse gas emissions from tailpipe. Passenger cars are responsible for 12 percent of greenhouse gas emissions in Europe...and up to 50 percent in some carintensive areas in the United States. Cars are the main reason for the greenhouse gas emissions because of a lot of people driving them around all the time getting where they need to go. Article, \"Paris bans driving due to smog,\" by Robert Duffer says, how Paris, after days of nearrecord pollution, enforced a partial driving ban to clear the air of the global city. It also says, how on Monday, motorist with evennumbered license plates were ordered to leave their cars at home or be fined a 22euro fine 31. The same order would be applied to oddnumbered plates the following day. Cars are the reason for polluting entire cities like Paris. This shows how bad cars can be because, of all the pollution that they can cause to an entire city.\\n\\nLikewise, in the article, \"Carfree day is spinning into a big hit in Bogota,\" by Andrew Selsky says, how programs that\\'s set to spread to other countries, millions of Columbians hiked, biked, skated, or took the bus to work during a carfree day, leaving streets of this capital city eerily devoid of traffic jams. It was the third straight year cars have been banned with only buses and taxis permitted for the Day Without Cars in the capital city of 7 million. People like the idea of having carfree days because, it allows them to lesson the pollution that cars put out of their exhaust from people driving all the time. The article also tells how parks and sports centers have bustled throughout the city uneven, pitted sidewalks have been replaced by broad, smooth sidewalks rushhour restrictions have dramatically cut traffic and new restaurants and upscale shopping districts have cropped up. Having no cars has been good for the country of Columbia because, it has aloud them to repair things that have needed repairs for a long time, traffic jams have gone down, and restaurants and shopping districts have popped up, all due to the fact of having less cars around.\\n\\nIn conclusion, the use of less cars and having carfree days, have had a big impact on the environment of cities because, it is cutting down the air pollution that the cars have majorly polluted, it has aloud countries like Columbia to repair sidewalks, and cut down traffic jams. Limiting the use of cars would be a good thing for America. So we should limit the use of cars by maybe riding a bike, or maybe walking somewhere that isn\\'t that far from you and doesn\\'t need the use of a car to get you there. To me, limiting the use of cars might be a good thing to do.', 'Transportation is a large necessity in most countries worldwide. With no doubt, cars, buses, and other means of transportation make going from place to place easier and faster. However there\\'s always a negative pollution. Although mobile transportation are a huge part of daily lives, we are endangering the Earth with harmful greenhouse gases, which could be suppressed.\\n\\nA small suburb community in Germany called Vauban, has started a \"carfree\" lifestyle. In this city, markets and stores are placed nearby homes, instead of being located by farend highways. Although Vauban is not completely carfree, 70% of Vauban families do not own cars Even a large 57% of families stated to have sold their cars to move to Vauban. Some families have even said to be less stressed depending on car transportation. Cars are responsible for about 12% of greenhouse gases, and can even be up to 50% in some carintensive areas in the United States.\\n\\nAnother insight to reduced car zones brings Paris\\' incident with smog. Paris\\' officials created a system that would in fact lower smog rates. On Monday, the motorists with evennumbered license plates numbers would be ordered to leave their cars at home, or they would suffer a fine. Same rule would occur on Tuesday, except motorists with oddnumbered license plates were targeted with fines. Congestion, or traffic, was reduced by 60% after five days of intense smog. Diesel fuel played a huge part in this pollution, having the fact that 67% of vehicles in France are of Diesel fuel. The impact of the clearing of smog, resided in banning the Tuesday rule of odd license plates.\\n\\nCould you imagine a day without seeing a single car being used? This phenomenon occurs once a year in Bogota, Colombia. With the exception of buses and taxis being used, cars are to be left unattended for an entire day. Having a carfree day just once a year can even reduce the pollution slightly. The day without cars is part of a campaign that originated in Bogota in the mid 1990s. This campaign has renewed and constructed numerous bicycle paths and sidewalks all over the city. Parks and sports centers have also sprung from this campaign. Devoting your time to a carfree lifestyle has it\\'s hassles, but in hindsight, it has it\\'s benefits.\\n\\nTo conclude, living a carfree lifestyle does not seem like a possibility in this day and age, however managing the use of cars and pollution is something every country should take time investing in. Think about how much of an impact it would be if everywhere worldwide would take part in airpollution reduction. Mobile transportation is lifestyle in a sense, and being dependent on cars or other means of transportation can impact the health of the Earth and even ourselves.', '\"America\\'s love affair with it\\'s vehicles seems to be cooling\" says Elisabeth rosenthal. To understand rosenthal\\'s perspective, it is easier to suggest that America\\'s car usage is decreasing slowly. This isn\\'t necessarily bad in the sense that it has certain positive effects. The advantages of limiting car usage includes an increase in security and health, along with a decrease in pollution and dependence.\\n\\nFirstly, when car usage is limited security and health is more likely to be guaranteed. The feeling of being secure is highly important to individuals everywhere. For example, many people in colombia used public transportation during a car free day \"leaving the streets of this capital city \", according to Andrew Selsky, \"eerily devoid of traffic jams\". The complications that stem from traffic jams end with a feeling of confidence. The plan to get from point A to B was more simple just a second ago. This complication in your personal plans leads you to become stressed as a feeling of doubt overcomes all thoughts. If car usage was limited, there would be a control on how much traffic accumulates thus minimizing chance of stress. As Heidrun Walter states \"when i had a car i was always tense. I\\'m much happier this way\". not only does car usage minimize conditions detrimental to health, it also enlarges your capacity for exercise. The main purpose of the car is to get someone from one place to another. when an important job takes over your personal life, it becomes difficult to do things most enjoyed in life. limits on car usage forces you to stay in shape. According to Andrew Selsky \"parks and sports centers also have bloomed throughout the city\". Less cars means healthier and natural situations. With parks and sport centers becoming more efficient, it becomes easier to find a more physically active population. Overall, less usage on cars minimizes stress and increases health.\\n\\nSecondly, limting car usage becomes beneficial to the environment. Now a days people have become annoyed with others who care so passionately about the environment. If you look behind their constant cries for action, there are solid facts. Yespollution is bad for the environment. Yes a bad envorment means unhealthy living. Yes cars are one of the main contributors to pollution in the environment. A pattern of less car usage, as Elisabeth Rosenthal states \"will have beneficial implications for carbon emissions and the environment\". The less use of cars, the less pollution in the environment. One must observe limiting car usage as an opportunity to create a cleaner world and better future. The effects of pollution in the environment is completley dangerous and we, the car users, are to blame.\\n\\nAdditionally, it would lower the dependence on cars. Many people today find that their car is so useful. While it has many features and is a form of transportation, many do not figure what they would do if they did not have such a possesion. The development of people and their interaction with technology has left a wide gap between historic, natural ways and what is thought of as modern society. Being dependent is not always good for individuals. As david goldberg says \"all our development since world war II has been centered on the car, and that will have to change\". Many people could disagree and wonder why it is necessary to change our ways especially if we are so highly devloped. If being developed means being dependent on a harmful machine, then it could not be effective devlopment. According to Elisabeth Rosenthal \"cashstrapped americans could not afford new cars, and the unemployed were\\'t going to work anyway\". Many people can\\'t have the precious luxury of private transportation in the first place. Those who have had it have become distant to a more natural society. Peope have become so use to having cars that they have become oblivious to the significant effects. With limits on car usage , these effcts could be controlled.\\n\\nTo conclude, the advantages of limiting car usage is an increase in health, along with a decrease in pollution, and less dependence on cars. limiting car usage is a positive way to enfore an organized and clean environment, and ensure health and security of those who live in it. This is one reason America can be reffered to as a succesful country. It is not that America has decreased use of vehicles, but the fact that they have done what is best for majority.', 'How often do you ride in a car? Do you drive a one or any other motor vehicle to work? The store? To the mall? Have you ever thought about how many people in the world do that exact same thing travel to every destination using a fuel powered motorvehicle. Not many people realize the intensive damage that they\\'re doing when they turn their key in the ignition. What if you didn\\'t drive to work today? If you\\'re like any regular car user, the thought \"What?! I could never survive without my car!\" may run through your mind. It is possible though, to live without your main mean of transport. Just look at cities like cuban, Paris, and Bogota each one has in some way restricted their people\\'s usage of cars and they actually enjoy it! If you limit your car usage, it can intern result in many advantages and benefits in yourself and in your community.\\n\\nA not so recognized benefit to giving up your car usage would be the positive consequences it has on your health. In source 1, Heidrun Walter states that \"When he had a car, he was always tense. He\\'s much happier without it.\" Think about it, imagine all the angry road rage you experience while driving. That surely does not have a positive effect on your mood or health. Driving takes a copious amount of focus and mental activity, such as, trying to navigate, dealing with bad drivers, etc., that after a short period of time, you\\'re stressed out and tired. In cities like New York and Paris, the population is high. This leads to congestion in the streets and excessive amounts of pollution. Warm layers of air, according to Robert Duffer in \"Paris bans driving due to smog,\" traps the car emissions. How is that healthy? He also states that Paris had to enforce a temporary driving ban after the pollution levels reached an all time record. After a few days of less driving the pollution went way down. Since people aren\\'t driving, they have to find other means of transport. This could include walking, biking, or skating to destinations. Those are all physical excercises! Your body is getting to work out and you\\'ll mentally feel fresher more than you would sitting in a car.\\n\\nTaking a break from driving also can help with the overall look of your city. Pollution doesn\\'t cause the flowers to grow. It certainly doesn\\'t smell nice. It sets a filter over the town and gives off a \"dirty\" vibe. With less driving, there is less nasty pollution being emitted, therefore leading to a cleaner community. In Elisabeth Rosenthal\\'s article, \"In German Suburb, Life goes on Without Cars,\" she gives the good point that since there is a restriction on car and motor vehicle transportation, there is going to be more walkers. If you have tons of people taking the sidewalks instead of the roads, you might need a few more pathways and closer stores that are in walking distance. Andrew Selsky states that \"Parks and sports centers have bloomed throughout the city uneven pitted sidewalks have been replaced by broad, smooth sidewalks... and new restaurants and upscale shopping districts have cropped up.\" As stated previously, pollution is not benefiting the environment. Organizations such as the Envronmental Protection Agency in the U.S., are promoting \"car reduced\" communities, says Rosenthal. These communities have far less pollution and are much cleaner. Cities are also promoting this idea and are having days devoted to \"nocar driving.\" In Bogota, Colombia, they hold an anual \"carfree\" day where only buses and taxis are permitted. Any other drivers would be fined. Although fining someone for using a posession they own might ruffle some feathers, it did have a successful turn out and significantly reduced the \"smog.\" In conclusion, although the idea of giving up our precious automobiles for walking to our destination might sound impossible, it\\'s not. Reducing our driving can lead to many benefits and advantages in our daily lives. These include an increase in health, an improved look to our cities, and an improved environment all around us.', 'Cars are a wonderful thing. They are perhaps one of the worlds greatest advancements and technologies. Cars get us from point a to point i. That is exactly what we want isnt it? We as humans want to get from one place to anther as fast as possiile. Cars are a suitaile to do that. They get us across the city in a matter of minutes. Much faster than anyhting else we have. A train isnt going to get me across the city as fast as my car is and neither is a puilic ius, iut those other forms of transportation just might ie the way to go. Don\\'t get me wrong, cars are an aisolutly amazing thing iut, mayie they just cause way to much stress, and mayie they hurt our environment in ways that we don\\'t think they will. With a ius or a train you do not have to worry aiout washing your car or getting frustrated when stuck in a iad traffic jam on I4. Also there is not as much pollution in air hurting our environment. You might not think so, iut there are many advantages to limiting our car usage.\\n\\nOne advantage that not only humans would ienefit from, iut also plants and animals is that there would ie a lot less pollution in the air hurting out environment. Right now our cars give off gases that are extremely harmful towards our environment. These gases are called green house gases and come out of the exhaust pipes in our cars. Your car alone docent give off much gas iut collectively, our cars give off enormous amounts of gases. This is especially true in iig cities like France. In France, their pollution level was so high it was record ireaking. due to that france decided to enforce a partial ian on cars. This is descriied in the second article \" Paris ians driving due to smog\", iy Roiert Duffer, \" On Monday motorists with evennumiered license plates were orderd to leave their cars at home or suffer a 22euro fine 31. The same would apply to oddnumiered plates the following day.\" After France limited driving there congestion was down iy 60 percent. \" Congestion was down 60 percent in the capital of France\". So after five days of intense smog, 60 percent of it was clear after not using cars for only a little while. Even across the world in Bogota, columiia they are limiting driving and reducing smog levels. In the third article \"carfree day is spinning into a iig hit in Bogota\", iy Andrew Selsky, it descriies the annual carfree day they have to reduce smog. \" the goal is to promote alternative transportation and reduce smog\". So all over the world people are relizing that without cars, we are insuring the safety and well ieing of our environment.\\n\\nThe second advantage that would come with limiting car use is less stress. Everyone knows that driving a car causes emence amounts of stress. Getting caught in traffic is a major cause of stress in someones life. having to repeating wash your car just to get it dirt again causes stress. Having people in the iack of your car screaming and yelling all while music is ilasting, causes stress. So oiviously driving causes stress. If we were to limit our car usage we would not ie as stressed as we usually are. There would ie no traffic, no car washes and no one screaming in a small confineded space. In the first article \" In German Suiuri, life goes on without cars\", iy Elisaieth Rosenthal, a citizen named humdrum Walter, states \" When i had a car i was always tense. I\\'m much happier this way\". So with out the stress of a car humdrum Walter is a looser and happier person, less stress equals happier person. In the third article, \" Carfree dai is spinning into a iig hit in Bogota\", iy Andrew Selsky, it states \" It\\'s a good opportunity to take away stress...\". If we have the opportunity to take away stress, why not take it. It is a huge advantage in our lives to limit driving if it takes away stress. No one wants stress, no one needs stress, and if we have an opportunity to take some of the stress away, take that opportunity.\\n\\nIn conclusion, there are many advantages to limiting car use, one ieing theat we get to help the environment and two ieing that it helps reduce stress. Our environment is already screwed up in so many ways, if we can help it to iecome the healthy environment it once was, then do it. Stress is proven to impare your personal health, no one wants to ie unhealthy and no one wants stress in their life. If you want the environment to get ietter and you want to reduce stress in your life then take this advantage and impliment it. Some might not think that this is an advantage, iut i just explained that it is a clear advantege that has ieen proved to help the enviornment and reduce stress. Limiting car use is a very effective advantage that really does work in more than one place.']\n", + "AI: [\"Car-free cities have become a subject of increasing interest and debate in recent years, as urban areas around the world grapple with the challenges of congestion, pollution, and limited resources. The concept of a car-free city involves creating urban environments where private automobiles are either significantly restricted or completely banned, with a focus on alternative transportation methods and sustainable urban planning. This essay explores the benefits, challenges, and potential solutions associated with the idea of car-free cities. Benefits of Car-Free Cities Environmental Sustainability: Car-free cities promote environmental sustainability by reducing air pollution and greenhouse gas emissions. Fewer cars on the road mean cleaner air and a significant decrease in the contribution to global warming. Improved Public Health: A reduction in automobile usage can lead to better public health outcomes. Fewer cars on the road result in fewer accidents and a safer urban environment for pedestrians and cyclists. Moreover, less air pollution can lead to reduced respiratory and cardiovascular problems. Efficient Use of Space: Car-free cities utilize urban space more efficiently. Parking lots and wide roads can be repurposed for green spaces, parks, and pedestrian zones, enhancing the overall quality of life in the city. Reduced Traffic Congestion: By eliminating or restricting car usage, traffic congestion is significantly reduced, leading to faster commute times and less frustration for residents and commuters. Cost Savings: Car ownership and maintenance can be expensive. Car-free cities allow residents to save money on vehicles, fuel, and insurance, improving their overall financial well-being. Challenges of Car-Free Cities Resistance to Change: Transitioning to a car-free city can face resistance from citizens, especially those who rely heavily on their cars for daily activities and commutes. Public Transportation Infrastructure: An effective public transportation system is crucial for the success of car-free cities. Cities need to invest in and expand their public transportation networks to ensure that people have viable alternatives to cars. Economic Impact: Businesses that rely on car-dependent customers may experience a decline in revenue in a car-free city. It's essential to address this economic impact and find ways to support affected businesses during the transition. Urban Planning and Infrastructure: The redesign of urban areas for car-free living requires significant planning and investment in infrastructure, which can be a lengthy and complex process. Solutions for Car-Free Cities Expand Public Transportation: Invest in the expansion and improvement of public transportation systems to provide convenient and affordable alternatives to private cars. Promote Active Transportation: Encourage walking and cycling by building bike lanes, pedestrian-friendly streets, and ensuring safe infrastructure for these activities. Implement Carpooling and Ride-Sharing: Promote carpooling and ride-sharing services to reduce the number of private vehicles on the road. Adopt Electric and Sustainable Transportation: Encourage the use of electric vehicles and promote sustainability by using renewable energy sources to power transportation. Education and Public Awareness: Educate citizens about the benefits of a car-free city and involve them in the planning process to increase support and understanding. Conclusion Car-free cities represent a vision for a sustainable and healthier urban future. While the transition to a car-free city is not without challenges, the potential benefits in terms of environmental sustainability, public health, and efficient urban living make it a compelling goal. Through a combination of investment in public transportation, promotion of alternative transportation methods, and public engagement, cities can work towards a future where cars are no longer the dominant mode of transportation. Car-free cities offer a promising vision of a more sustainable and vibrant urban environment.\", 'Car Free Cities Car-free cities, a concept gaining traction in contemporary urban planning, seek to transform the way we live, commute, and interact with our surroundings. These cities envision a future where private automobiles are either severely restricted or completely eliminated from urban landscapes, making room for alternative modes of transportation, green spaces, and sustainable living. In this essay, we will explore the various aspects of car-free cities, including their benefits, challenges, and potential solutions. The idea of car-free cities stems from a growing awareness of the negative consequences of car-centric urban planning. Congestion, air pollution, and the diminishing quality of life in crowded, noisy, and car-infested streets have prompted urban planners to seek alternatives. Car-free cities offer several advantages: Environmental Sustainability: By reducing the number of vehicles on the road, car-free cities significantly decrease air pollution and greenhouse gas emissions. This step towards environmental sustainability helps combat climate change and fosters cleaner, healthier urban environments. Public Health: Fewer cars on the road mean fewer accidents and a safer environment for pedestrians and cyclists. Additionally, the reduction in air pollution results in improved respiratory and cardiovascular health for city dwellers. Efficient Space Utilization: Car-free cities optimize urban space usage. Parking lots and wide roads can be repurposed for parks, green spaces, and pedestrian zones, enhancing the overall quality of life. Reduced Traffic Congestion: Less reliance on private cars leads to reduced traffic congestion, shorter commute times, and less stress for residents and commuters. Cost Savings: Owning and maintaining a car can be expensive. Car-free cities allow residents to save money on vehicle purchase, fuel, and insurance, thereby improving their financial well-being. However, transitioning to car-free cities presents its own set of challenges: Resistance to Change: Many people heavily rely on their cars for daily activities and commutes. Transitioning to car-free living can face resistance from those who fear the loss of convenience and autonomy. Public Transportation Infrastructure: Effective public transportation systems are critical for the success of car-free cities. Investments and improvements in public transit are necessary to provide convenient alternatives to private cars. Economic Impact: Businesses that rely on car-dependent customers may experience declining revenue. Addressing this economic impact and supporting affected businesses during the transition is essential. Urban Planning and Infrastructure: Redesigning urban areas for car-free living demands comprehensive planning and substantial investment in infrastructure, which can be a complex and lengthy process. Solutions for the successful implementation of car-free cities include expanding public transportation, promoting active transportation, encouraging carpooling and ride-sharing, adopting electric and sustainable transportation, and focusing on public education and awareness. In conclusion, car-free cities represent a promising vision for a more sustainable and healthy urban future. While challenges exist, the potential benefits in terms of environmental sustainability, public health, efficient urban living, and cost savings make it a compelling goal. By investing in public transportation, promoting alternative transportation methods, and involving the public in the planning process, cities can work toward a future where cars are no longer the dominant mode of transportation. Car-free cities offer a promising vision of a more sustainable and vibrant urban environment.', ' A Sustainable Urban Future Car-free cities are emerging as a powerful response to the pressing challenges of urbanization. These cities aspire to create environments where private automobiles are either severely restricted or completely banned, emphasizing sustainable transportation alternatives, cleaner air, and vibrant urban living. This essay delves into the concept of car-free cities, exploring their potential benefits, challenges, and solutions. Car-free cities are gaining momentum as a solution to pressing urban challenges. These cities aim to create environments where private automobiles are either restricted or entirely eliminated in favor of sustainable transportation alternatives. This essay explores the concept of car-free cities, emphasizing their potential benefits, challenges, and solutions. Car-free cities represent a vision for urban living that emphasizes sustainability, health, and efficiency: Environmental Sustainability: A reduced reliance on cars leads to decreased air pollution and greenhouse gas emissions. This shift towards environmental sustainability helps mitigate climate change and promotes cleaner, healthier cities. Public Health: Car-free cities create safer environments for pedestrians and cyclists. Reduced air pollution levels contribute to better respiratory and cardiovascular health, enhancing overall public well-being. Optimal Space Utilization: Car-free cities make efficient use of urban space. Parking lots and wide roads can be repurposed into green spaces, parks, and pedestrian zones, enhancing the quality of life. Traffic Congestion Reduction: Fewer private cars on the road result in less traffic congestion, shorter commutes, and lower stress levels for city residents and commuters. Economic Savings: Car ownership can be expensive, including vehicle purchase, fuel, and insurance. Car-free cities offer residents an opportunity to save money and improve their financial stability. Despite their potential, transitioning to car-free cities is not without its challenges: Resistance to Change: Many individuals rely heavily on cars for daily activities and commutes. The shift to car-free living can face resistance from those who fear inconvenience and a loss of personal autonomy. Public Transportation Infrastructure: A robust public transportation system is vital for the success of car-free cities. Investments in public transit and its expansion are crucial to provide convenient alternatives to private cars. Economic Impact: Businesses that depend on car-dependent customers may experience revenue declines during the transition. Addressing this economic impact and supporting affected businesses is essential. Urban Planning and Infrastructure: Redesigning urban areas for car-free living requires comprehensive planning and substantial infrastructure investments, which can be complex and time-consuming. Solutions for the successful adoption of car-free cities include expanding public transportation networks, promoting active transportation such as walking and cycling, encouraging carpooling and ride-sharing, adopting electric and sustainable transportation options, and focusing on public education and awareness. In conclusion, car-free cities present a promising vision for a more sustainable and healthy urban future. While they come with challenges, the potential benefits in terms of environmental sustainability, public health, efficient urban living, and cost savings make them a compelling objective. By investing in public transportation, promoting alternative transportation methods, and involving the public in the planning process, cities can work towards a future where private cars no longer dominate the urban landscape. Car-free cities offer a hopeful glimpse of a more sustainable and vibrant urban environment.', ' Pioneering Sustainable Urban Living In an era marked by rapid urbanization, car-free cities have emerged as a visionary solution to the many challenges that densely populated urban areas face. The concept of car-free cities envisions a future where private automobiles are either restricted or entirely absent, making way for sustainable transportation alternatives and green, people-centered urban spaces. This essay delves into the idea of car-free cities, exploring their potential benefits, challenges, and solutions. Car-free cities are a response to the urgent need for sustainable urban living: Environmental Sustainability: The reduced use of cars significantly lowers air pollution and greenhouse gas emissions, contributing to a healthier planet. These cities serve as beacons of environmental responsibility in an era where climate change is a pressing concern. Public Health: Car-free cities prioritize pedestrian and cyclist safety, resulting in fewer accidents and better health outcomes. Decreased air pollution levels lead to improved respiratory and cardiovascular health among residents. Optimal Space Utilization: These cities make efficient use of urban space by repurposing parking lots and roads into parks, green spaces, and pedestrian zones. The urban landscape is transformed into an inviting and vibrant place to live. Traffic Congestion Reduction: With fewer private cars on the road, traffic congestion is greatly reduced, resulting in shorter commutes and less stress for city dwellers. Economic Benefits: Car ownership can be a costly endeavor. By reducing their reliance on private vehicles, residents in car-free cities have the opportunity to save money on vehicle-related expenses, improving their overall financial stability. However, the transition to car-free cities presents a unique set of challenges: Resistance to Change: Many individuals depend heavily on their cars for daily routines and commutes, and the transition to car-free living may face resistance from those who fear the loss of convenience and personal freedom. Public Transportation Infrastructure: Effective public transportation systems are crucial for the success of car-free cities. Substantial investments are needed to expand and enhance public transit options, providing convenient alternatives to private cars. Economic Impact: Businesses relying on car-dependent customers may experience declining revenues during the transition. Addressing this economic impact and supporting affected businesses is a critical aspect of the transition. Urban Planning and Infrastructure: The redesign of urban areas for car-free living demands comprehensive planning and significant investments in infrastructure, which can be a complex and time-consuming process. Solutions to successfully implement car-free cities include the expansion and improvement of public transportation, the promotion of active transportation methods such as walking and cycling, the encouragement of carpooling and ride-sharing, the adoption of electric and sustainable transportation, and a focus on public education and awareness. In conclusion, car-free cities offer a glimpse into a more sustainable and vibrant urban future. Despite the challenges, the potential benefits in terms of environmental sustainability, public health, efficient urban living, and cost savings make them a compelling goal. By investing in public transportation, promoting alternative transportation methods, and involving the public in the planning process, cities can work towards a future where private cars are no longer the dominant mode of transportation. Car-free cities represent an inspiring vision of a more sustainable and people-centric urban environment.', ' The Path to Sustainable Urban Living In an age of rapid urbanization, the concept of car-free cities is gaining momentum as a visionary solution to the complex challenges posed by urban areas. Car-free cities are urban environments where private automobiles are either heavily restricted or completely prohibited, promoting the use of sustainable transportation alternatives and fostering a healthier, more vibrant urban lifestyle. This essay explores the concept of car-free cities, examining the potential benefits, challenges, and strategies for their successful implementation. Car-free cities offer a vision of urban living focused on sustainability and well-being: Environmental Sustainability: By significantly reducing the number of cars on the road, car-free cities contribute to cleaner air and a reduction in greenhouse gas emissions, thus playing a vital role in mitigating climate change. Public Health: These cities prioritize pedestrian and cyclist safety, leading to fewer accidents and enhanced public health. Reduced air pollution levels result in better respiratory and cardiovascular health for urban residents. Optimal Use of Space: Car-free cities make efficient use of urban space by converting parking lots and wide roads into green areas, parks, and pedestrian zones. This transformation enriches the overall urban landscape and quality of life. Traffic Congestion Reduction: Fewer private cars on the road mean less traffic congestion, shorter commute times, and a less stressful daily life for urban inhabitants. Economic Benefits: Car ownership can be costly. By relying less on private vehicles, residents of car-free cities have the opportunity to save money on car-related expenses, which can contribute to improved financial stability. Transitioning to car-free cities, however, poses unique challenges: Resistance to Change: Many individuals heavily rely on their cars for daily activities and commutes, leading to potential resistance to the transition to car-free living due to fears of inconvenience and a loss of autonomy. Public Transportation Infrastructure: A robust public transportation system is essential for the success of car-free cities. Substantial investments are needed to expand and enhance public transit options, providing convenient alternatives to private cars. Economic Impact: Businesses that depend on car-dependent customers may face a decline in revenue during the transition. Addressing this economic impact and supporting affected businesses is a crucial aspect of the transition. Urban Planning and Infrastructure: The reconfiguration of urban areas for car-free living requires comprehensive planning and significant investments in infrastructure, a complex and time-consuming process. To realize car-free cities successfully, strategies include expanding and enhancing public transportation, promoting active transportation methods like walking and cycling, encouraging carpooling and ride-sharing, adopting electric and sustainable transportation, and focusing on public education and awareness. In conclusion, car-free cities offer an inspiring vision of a more sustainable and vibrant urban future. Despite the challenges, the potential benefits in terms of environmental sustainability, public health, efficient urban living, and cost savings make them a compelling goal. By investing in public transportation, promoting alternative transportation methods, and engaging the public in the planning process, cities can work toward a future where private cars are no longer the dominant mode of transportation. Car-free cities represent a promising glimpse of a more sustainable and people-centric urban environment.']\n" + ] + } + ], + "source": [ + "for GENERATION_TYPE in STRINGS.keys(): \n", + " print((GENERATION_TYPE + \": \" + str(STRINGS[GENERATION_TYPE][\"training\"][0:5])))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Model Testing" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Model Preparation" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The models in use for this study are the following: \n", + "- `Meta-Llama-3-8B-Instruct.Q4_0.gguf`\n", + "- `Phi-3-mini-4k-instruct.Q4_0.gguf`\n", + "- `gemini-1.5-pro`\n", + "\n", + "The former two are yet to be downloaded, which is to be done here. " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from gpt4all import GPT4All\n", + "import google.generativeai as Gemini" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "MODELS = {};\n", + "for MODEL_NAME in [\"Meta-Llama-3-8B-Instruct.Q4_0.gguf\", \"Phi-3-mini-4k-instruct.Q4_0.gguf\"]: \n", + " MODELS[MODEL_NAME] = GPT4All(MODEL_NAME);\n", + "MODELS[\"gemini-1.5-pro\"] = Gemini.GenerativeModel('gemini-1.5-pro-exp-0801');\n" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.1" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/preparation.ipynb b/preparation.ipynb deleted file mode 100644 index 5ec7f34..0000000 --- a/preparation.ipynb +++ /dev/null @@ -1,257 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# An Evaluation on the Effectiveness of Large Language Models in Self-Detection" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "This paper seeks to investigate and evaluate the self-detection abilities of language learning models through its architecture and its execution performance. This Jupyter notebook, in particular, will contain experimental data to evaluate the said performance. \n", - "\n", - "This notebook contains scripts needed for configuring the testing environment and does not perform the tests itself. This would be done in notebooks within the `tests/` directory. " - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Dependencies" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "This section is where the dependencies required for all tests will be installed. For all or most tests, the following are needed: \n", - "- gpt4all\n", - "- kaggle\n", - "- kagglehub\n", - "- pandas" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": { - "vscode": { - "languageId": "shellscript" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Requirement already satisfied: pip in /home/codespace/.python/current/lib/python3.12/site-packages (from -r dependencies.txt (line 1)) (24.2)\n", - "Requirement already satisfied: kaggle in /home/codespace/.python/current/lib/python3.12/site-packages (from -r dependencies.txt (line 2)) (1.6.17)\n", - "Requirement already satisfied: kagglehub in /home/codespace/.python/current/lib/python3.12/site-packages (from -r dependencies.txt (line 3)) (0.2.9)\n", - "Requirement already satisfied: gpt4all in /home/codespace/.python/current/lib/python3.12/site-packages (from -r dependencies.txt (line 4)) (2.8.2)\n", - "Requirement already satisfied: pandas in /home/codespace/.local/lib/python3.12/site-packages (from -r dependencies.txt (line 5)) (2.2.2)\n", - "Requirement already satisfied: six>=1.10 in /home/codespace/.local/lib/python3.12/site-packages (from kaggle->-r dependencies.txt (line 2)) (1.16.0)\n", - "Requirement already satisfied: certifi>=2023.7.22 in /home/codespace/.local/lib/python3.12/site-packages (from kaggle->-r dependencies.txt (line 2)) (2024.7.4)\n", - "Requirement already satisfied: python-dateutil in /home/codespace/.local/lib/python3.12/site-packages (from kaggle->-r dependencies.txt (line 2)) (2.9.0.post0)\n", - "Requirement already satisfied: requests in /home/codespace/.local/lib/python3.12/site-packages (from kaggle->-r dependencies.txt (line 2)) (2.32.3)\n", - "Requirement already satisfied: tqdm in /home/codespace/.python/current/lib/python3.12/site-packages (from kaggle->-r dependencies.txt (line 2)) (4.66.5)\n", - "Requirement already satisfied: python-slugify in /home/codespace/.python/current/lib/python3.12/site-packages (from kaggle->-r dependencies.txt (line 2)) (8.0.4)\n", - "Requirement already satisfied: urllib3 in /home/codespace/.local/lib/python3.12/site-packages (from kaggle->-r dependencies.txt (line 2)) (2.2.2)\n", - "Requirement already satisfied: bleach in /home/codespace/.local/lib/python3.12/site-packages (from kaggle->-r dependencies.txt (line 2)) (6.1.0)\n", - "Requirement already satisfied: packaging in /home/codespace/.local/lib/python3.12/site-packages (from kagglehub->-r dependencies.txt (line 3)) (24.1)\n", - "Requirement already satisfied: numpy>=1.26.0 in /home/codespace/.local/lib/python3.12/site-packages (from pandas->-r dependencies.txt (line 5)) (2.0.1)\n", - "Requirement already satisfied: pytz>=2020.1 in /home/codespace/.local/lib/python3.12/site-packages (from pandas->-r dependencies.txt (line 5)) (2024.1)\n", - "Requirement already satisfied: tzdata>=2022.7 in /home/codespace/.local/lib/python3.12/site-packages (from pandas->-r dependencies.txt (line 5)) (2024.1)\n", - "Requirement already satisfied: webencodings in /home/codespace/.local/lib/python3.12/site-packages (from bleach->kaggle->-r dependencies.txt (line 2)) (0.5.1)\n", - "Requirement already satisfied: text-unidecode>=1.3 in /home/codespace/.python/current/lib/python3.12/site-packages (from python-slugify->kaggle->-r dependencies.txt (line 2)) (1.3)\n", - "Requirement already satisfied: charset-normalizer<4,>=2 in /home/codespace/.local/lib/python3.12/site-packages (from requests->kaggle->-r dependencies.txt (line 2)) (3.3.2)\n", - "Requirement already satisfied: idna<4,>=2.5 in /home/codespace/.local/lib/python3.12/site-packages (from requests->kaggle->-r dependencies.txt (line 2)) (3.7)\n", - "Note: you may need to restart the kernel to use updated packages.\n" - ] - } - ], - "source": [ - "pip install --upgrade -r dependencies.txt" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Data Fetch" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "For this study, the dataset from [Thite (2023)](https://www.kaggle.com/datasets/sunilthite/llm-detect-ai-generated-text-dataset) will be employed due to its sufficient size and technical limitations. " - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The code block below imports all the modules needed for this section. " - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [ - "import kagglehub\n", - "import json\n", - "import os\n", - "import pandas" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The code below sets up a reference to the files. " - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [], - "source": [ - "FILES = {\"datasets\": {}, \"models\": {}};" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Attempting to download Training_Essay_Data.csv from dataset sunilthite/llm-detect-ai-generated-text-dataset/versions/1\n", - "Finished downloading Training_Essay_Data.csv from dataset sunilthite/llm-detect-ai-generated-text-dataset/versions/1\n", - "The file Training_Essay_Data.csv from dataset sunilthite/llm-detect-ai-generated-text-dataset/versions/1 has been linked.\n" - ] - } - ], - "source": [ - "def download_datasets(): \n", - " # Read the dataset listings. \n", - " SOURCES = json.load(open(\"data/sources.json\"));\n", - "\n", - " # Loop through each dataset target.\n", - " for TARGET in SOURCES.keys(): \n", - " print((\"Attempting to download \" + TARGET + \" from dataset \" + SOURCES[TARGET]));\n", - " \n", - " # Set the location of the Kaggle dataset. \n", - " kagglehub.dataset_download(SOURCES[TARGET]);\n", - " \n", - " # Do not continue when an error has occured. \n", - " print((\"Finished downloading \" + TARGET + \" from dataset \" + SOURCES[TARGET]));\n", - "\n", - " # Link each file.\n", - " if (not(os.path.isfile((\"data/\" + TARGET))) and os.system((\"ln -s ~/.cache/kagglehub/datasets/\" + SOURCES[TARGET] + \"/\" + TARGET + \" data/\" + TARGET))): \n", - " print((\"We weren’t able to link the file \" + TARGET + \" from dataset \" + SOURCES[TARGET] + \". Please perform this manually.\"));\n", - " else: \n", - " print((\"The file \" + TARGET + \" from dataset \" + SOURCES[TARGET] + \" has been linked.\"));\n", - " FILES[\"datasets\"][TARGET] = open(\"data/\" + TARGET)\n", - "\n", - "download_datasets();" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Below, the code blocks are converted into dataframes for preview purposes. " - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [], - "source": [ - "DATAFRAMES = {};\n", - "\n", - "def convert_datasets(): \n", - " if len(FILES[\"datasets\"].keys()): \n", - " for DATASET_NAME in FILES[\"datasets\"].keys(): \n", - " DATAFRAMES[DATASET_NAME] = pandas.read_csv(FILES[\"datasets\"][DATASET_NAME])\n", - "\n", - "convert_datasets();" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The datasets could be previewed below. " - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Training_Essay_Data.csv\n", - " text generated\n", - "0 Car-free cities have become a subject of incre... 1\n", - "1 Car Free Cities Car-free cities, a concept ga... 1\n", - "2 A Sustainable Urban Future Car-free cities ... 1\n", - "3 Pioneering Sustainable Urban Living In an e... 1\n", - "4 The Path to Sustainable Urban Living In an ... 1\n", - "... ... ...\n", - "29140 There has been a fuss about the Elector Colleg... 0\n", - "29141 Limiting car usage has many advantages. Such a... 0\n", - "29142 There's a new trend that has been developing f... 0\n", - "29143 As we all know cars are a big part of our soci... 0\n", - "29144 Cars have been around since the 1800's and hav... 0\n", - "\n", - "[29145 rows x 2 columns]\n" - ] - } - ], - "source": [ - "def convert_datasets(): \n", - " if len(DATAFRAMES.keys()): \n", - " for DATASET_NAME in DATAFRAMES.keys(): \n", - " print(DATASET_NAME);\n", - " print(DATAFRAMES[DATASET_NAME]);\n", - "\n", - "convert_datasets();" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.12.1" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -}